Separate the archive cache out to ArchiveFactory.
This commit is contained in:
parent
b6583635d4
commit
7081f7799b
5 changed files with 69 additions and 18 deletions
29
atom/common/asar/archive_factory.cc
Normal file
29
atom/common/asar/archive_factory.cc
Normal 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
|
31
atom/common/asar/archive_factory.h
Normal file
31
atom/common/asar/archive_factory.h
Normal 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_
|
Loading…
Add table
Add a link
Reference in a new issue