diff --git a/atom.gyp b/atom.gyp index 0e059c5c3364..90fd8324fa68 100644 --- a/atom.gyp +++ b/atom.gyp @@ -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', diff --git a/atom/browser/net/asar/asar_protocol_handler.cc b/atom/browser/net/asar/asar_protocol_handler.cc index 47507ba6b337..04f0aa94dd3f 100644 --- a/atom/browser/net/asar/asar_protocol_handler.cc +++ b/atom/browser/net/asar/asar_protocol_handler.cc @@ -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(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); diff --git a/atom/browser/net/asar/asar_protocol_handler.h b/atom/browser/net/asar/asar_protocol_handler.h index 5771e3833357..e88ee9b8691b 100644 --- a/atom/browser/net/asar/asar_protocol_handler.h +++ b/atom/browser/net/asar/asar_protocol_handler.h @@ -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& 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 file_task_runner_; - mutable ArchiveFactory archive_factory_; + mutable base::ScopedPtrHashMap archives_; DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler); }; diff --git a/atom/common/api/atom_api_asar.cc b/atom/common/api/atom_api_asar.cc index 6d7ff76351dc..625b16eda1ba 100644 --- a/atom/common/api/atom_api_asar.cc +++ b/atom/common/api/atom_api_asar.cc @@ -5,7 +5,6 @@ #include #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" diff --git a/atom/common/asar/archive_factory.cc b/atom/common/asar/archive_factory.cc deleted file mode 100644 index 9a0fcf83f0de..000000000000 --- a/atom/common/asar/archive_factory.cc +++ /dev/null @@ -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(new Archive(path)); - if (!archive->Init()) - return nullptr; - - archives_.set(path, archive.Pass()); - } - - return archives_.get(path); -} - -} // namespace asar diff --git a/atom/common/asar/archive_factory.h b/atom/common/asar/archive_factory.h deleted file mode 100644 index b770a83dbfa1..000000000000 --- a/atom/common/asar/archive_factory.h +++ /dev/null @@ -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 archives_; - - DISALLOW_COPY_AND_ASSIGN(ArchiveFactory); -}; - -} // namespace asar - -#endif // ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_