Remove unneeded ArchiveFactory.

This commit is contained in:
Cheng Zhao 2014-09-25 21:54:59 +08:00
parent 390b804ca0
commit c49a44f944
6 changed files with 22 additions and 64 deletions

View file

@ -194,8 +194,6 @@
'atom/common/api/object_life_monitor.h',
'atom/common/asar/archive.cc',
'atom/common/asar/archive.h',
'atom/common/asar/archive_factory.cc',
'atom/common/asar/archive_factory.h',
'atom/common/asar/scoped_temporary_file.cc',
'atom/common/asar/scoped_temporary_file.h',
'atom/common/common_message_generator.cc',

View file

@ -5,6 +5,7 @@
#include "atom/browser/net/asar/asar_protocol_handler.h"
#include "atom/browser/net/asar/url_request_asar_job.h"
#include "atom/common/asar/archive.h"
#include "net/base/filename_util.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_error_job.h"
@ -46,7 +47,19 @@ AsarProtocolHandler::AsarProtocolHandler(
: file_task_runner_(file_task_runner) {}
AsarProtocolHandler::~AsarProtocolHandler() {
LOG(ERROR) << "~AsarProtocolHandler";
}
Archive* AsarProtocolHandler::GetOrCreateAsarArchive(
const base::FilePath& path) const {
if (!archives_.contains(path)) {
scoped_ptr<Archive> archive(new Archive(path));
if (!archive->Init())
return nullptr;
archives_.set(path, archive.Pass());
}
return archives_.get(path);
}
net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
@ -62,7 +75,7 @@ net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
return new net::URLRequestFileJob(request, network_delegate, full_path,
file_task_runner_);
Archive* archive = archive_factory_.GetOrCreate(asar_path);
Archive* archive = GetOrCreateAsarArchive(asar_path);
if (!archive)
return new net::URLRequestErrorJob(request, network_delegate,
net::ERR_FILE_NOT_FOUND);

View file

@ -5,7 +5,8 @@
#ifndef ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
#define ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
#include "atom/common/asar/archive_factory.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "net/url_request/url_request_job_factory.h"
@ -15,12 +16,16 @@ class TaskRunner;
namespace asar {
class Archive;
class AsarProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
public:
explicit AsarProtocolHandler(
const scoped_refptr<base::TaskRunner>& file_task_runner);
virtual ~AsarProtocolHandler();
Archive* GetOrCreateAsarArchive(const base::FilePath& path) const;
// net::URLRequestJobFactory::ProtocolHandler:
virtual net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
@ -30,7 +35,7 @@ class AsarProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
private:
const scoped_refptr<base::TaskRunner> file_task_runner_;
mutable ArchiveFactory archive_factory_;
mutable base::ScopedPtrHashMap<base::FilePath, Archive> archives_;
DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler);
};

View file

@ -5,7 +5,6 @@
#include <vector>
#include "atom/common/asar/archive.h"
#include "atom/common/asar/archive_factory.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"

View file

@ -1,27 +0,0 @@
// 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"
namespace asar {
ArchiveFactory::ArchiveFactory() {}
ArchiveFactory::~ArchiveFactory() {}
Archive* ArchiveFactory::GetOrCreate(const base::FilePath& path) {
if (!archives_.contains(path)) {
scoped_ptr<Archive> archive(new Archive(path));
if (!archive->Init())
return nullptr;
archives_.set(path, archive.Pass());
}
return archives_.get(path);
}
} // namespace asar

View file

@ -1,30 +0,0 @@
// 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/scoped_ptr_hash_map.h"
#include "base/files/file_path.h"
namespace asar {
class Archive;
class ArchiveFactory {
public:
ArchiveFactory();
virtual ~ArchiveFactory();
Archive* GetOrCreate(const base::FilePath& path);
private:
base::ScopedPtrHashMap<base::FilePath, Archive> archives_;
DISALLOW_COPY_AND_ASSIGN(ArchiveFactory);
};
} // namespace asar
#endif // ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_