Separate the archive cache out to ArchiveFactory.

This commit is contained in:
Cheng Zhao 2014-09-23 22:31:45 +08:00
parent b6583635d4
commit 7081f7799b
5 changed files with 69 additions and 18 deletions

View file

@ -0,0 +1,29 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/asar/archive_factory.h"
#include "atom/common/asar/archive.h"
#include "base/stl_util.h"
namespace asar {
ArchiveFactory::ArchiveFactory() {}
ArchiveFactory::~ArchiveFactory() {}
scoped_refptr<Archive> ArchiveFactory::GetOrCreate(const base::FilePath& path) {
// Create a cache of Archive.
if (!ContainsKey(archives_, path)) {
scoped_refptr<Archive> archive(new Archive(path));
if (!archive->Init())
return NULL;
archives_[path] = archive;
return archive;
}
return archives_[path];
}
} // namespace asar

View file

@ -0,0 +1,31 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_
#define ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_
#include "base/containers/hash_tables.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
namespace asar {
class Archive;
class ArchiveFactory {
public:
ArchiveFactory();
virtual ~ArchiveFactory();
scoped_refptr<Archive> GetOrCreate(const base::FilePath& path);
private:
base::hash_map<base::FilePath, scoped_refptr<Archive> > archives_; // NOLINT
DISALLOW_COPY_AND_ASSIGN(ArchiveFactory);
};
} // namespace asar
#endif // ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_