diff --git a/atom/browser/net/asar/asar_protocol_handler.cc b/atom/browser/net/asar/asar_protocol_handler.cc index 2688d51ada00..47507ba6b337 100644 --- a/atom/browser/net/asar/asar_protocol_handler.cc +++ b/atom/browser/net/asar/asar_protocol_handler.cc @@ -45,7 +45,9 @@ AsarProtocolHandler::AsarProtocolHandler( const scoped_refptr& file_task_runner) : file_task_runner_(file_task_runner) {} -AsarProtocolHandler::~AsarProtocolHandler() {} +AsarProtocolHandler::~AsarProtocolHandler() { + LOG(ERROR) << "~AsarProtocolHandler"; +} net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob( net::URLRequest* request, @@ -60,7 +62,7 @@ net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob( return new net::URLRequestFileJob(request, network_delegate, full_path, file_task_runner_); - scoped_refptr archive = archive_factory_.GetOrCreate(asar_path); + Archive* archive = archive_factory_.GetOrCreate(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 4a728b62262e..5771e3833357 100644 --- a/atom/browser/net/asar/asar_protocol_handler.h +++ b/atom/browser/net/asar/asar_protocol_handler.h @@ -6,6 +6,7 @@ #define ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_ #include "atom/common/asar/archive_factory.h" +#include "base/memory/ref_counted.h" #include "net/url_request/url_request_job_factory.h" namespace base { diff --git a/atom/browser/net/asar/url_request_asar_job.cc b/atom/browser/net/asar/url_request_asar_job.cc index 99c4abd7c44e..a66eaf57d717 100644 --- a/atom/browser/net/asar/url_request_asar_job.cc +++ b/atom/browser/net/asar/url_request_asar_job.cc @@ -17,7 +17,7 @@ namespace asar { URLRequestAsarJob::URLRequestAsarJob( net::URLRequest* request, net::NetworkDelegate* network_delegate, - const scoped_refptr& archive, + Archive* archive, const base::FilePath& file_path, const scoped_refptr& file_task_runner) : net::URLRequestJob(request, network_delegate), @@ -31,7 +31,7 @@ URLRequestAsarJob::URLRequestAsarJob( URLRequestAsarJob::~URLRequestAsarJob() {} void URLRequestAsarJob::Start() { - if (!archive_->GetFileInfo(file_path_, &file_info_)) { + if (!archive_ || !archive_->GetFileInfo(file_path_, &file_info_)) { NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FILE_NOT_FOUND)); return; diff --git a/atom/browser/net/asar/url_request_asar_job.h b/atom/browser/net/asar/url_request_asar_job.h index a15ba97cf597..f228d4312c74 100644 --- a/atom/browser/net/asar/url_request_asar_job.h +++ b/atom/browser/net/asar/url_request_asar_job.h @@ -27,7 +27,7 @@ class URLRequestAsarJob : public net::URLRequestJob { public: URLRequestAsarJob(net::URLRequest* request, net::NetworkDelegate* network_delegate, - const scoped_refptr& archive, + Archive* archive, const base::FilePath& file_path, const scoped_refptr& file_task_runner); @@ -53,7 +53,7 @@ class URLRequestAsarJob : public net::URLRequestJob { // Callback after data is asynchronously read from the file into |buf|. void DidRead(scoped_refptr buf, int result); - const scoped_refptr archive_; + Archive* archive_; Archive::FileInfo file_info_; base::FilePath file_path_; diff --git a/atom/common/api/atom_api_asar.cc b/atom/common/api/atom_api_asar.cc index 7f4521631822..ce0a8b625e1d 100644 --- a/atom/common/api/atom_api_asar.cc +++ b/atom/common/api/atom_api_asar.cc @@ -21,21 +21,21 @@ class Archive : public mate::Wrappable { static v8::Handle Create(v8::Isolate* isolate, const base::FilePath& path) { static asar::ArchiveFactory archive_factory; - scoped_refptr archive = archive_factory.GetOrCreate(path); + asar::Archive* archive = archive_factory.GetOrCreate(path); if (!archive) return v8::False(isolate); return (new Archive(archive))->GetWrapper(isolate); } protected: - explicit Archive(scoped_refptr archive) : archive_(archive) {} + explicit Archive(asar::Archive* archive) : archive_(archive) {} virtual ~Archive() {} // Reads the offset and size of file. v8::Handle GetFileInfo(v8::Isolate* isolate, const base::FilePath& path) { asar::Archive::FileInfo info; - if (!archive_->GetFileInfo(path, &info)) + if (!archive_ || !archive_->GetFileInfo(path, &info)) return v8::False(isolate); mate::Dictionary dict(isolate, v8::Object::New(isolate)); dict.Set("size", info.size); @@ -47,7 +47,7 @@ class Archive : public mate::Wrappable { v8::Handle Stat(v8::Isolate* isolate, const base::FilePath& path) { asar::Archive::Stats stats; - if (!archive_->Stat(path, &stats)) + if (!archive_ || !archive_->Stat(path, &stats)) return v8::False(isolate); mate::Dictionary dict(isolate, v8::Object::New(isolate)); dict.Set("size", stats.size); @@ -62,7 +62,7 @@ class Archive : public mate::Wrappable { v8::Handle Readdir(v8::Isolate* isolate, const base::FilePath& path) { std::vector files; - if (!archive_->Readdir(path, &files)) + if (!archive_ || !archive_->Readdir(path, &files)) return v8::False(isolate); return mate::ConvertToV8(isolate, files); } @@ -71,7 +71,7 @@ class Archive : public mate::Wrappable { v8::Handle CopyFileOut(v8::Isolate* isolate, const base::FilePath& path) { base::FilePath new_path; - if (!archive_->CopyFileOut(path, &new_path)) + if (!archive_ || !archive_->CopyFileOut(path, &new_path)) return v8::False(isolate); return mate::ConvertToV8(isolate, new_path); } @@ -87,7 +87,7 @@ class Archive : public mate::Wrappable { } private: - scoped_refptr archive_; + asar::Archive* archive_; DISALLOW_COPY_AND_ASSIGN(Archive); }; diff --git a/atom/common/asar/archive.cc b/atom/common/asar/archive.cc index 899eb6991053..31a808b96173 100644 --- a/atom/common/asar/archive.cc +++ b/atom/common/asar/archive.cc @@ -12,7 +12,6 @@ #include "base/logging.h" #include "base/pickle.h" #include "base/json/json_string_value_serializer.h" -#include "base/stl_util.h" #include "base/strings/string_number_conversions.h" namespace asar { @@ -184,8 +183,8 @@ bool Archive::Readdir(const base::FilePath& path, } bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) { - if (ContainsKey(external_files_, path)) { - *out = external_files_[path]->path(); + if (external_files_.contains(path)) { + *out = external_files_.get(path)->path(); return true; } @@ -193,12 +192,12 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) { if (!GetFileInfo(path, &info)) return false; - scoped_refptr temp_file(new ScopedTemporaryFile); + scoped_ptr temp_file(new ScopedTemporaryFile); if (!temp_file->InitFromFile(path_, info.offset, info.size)) return false; - external_files_[path] = temp_file; *out = temp_file->path(); + external_files_.set(path, temp_file.Pass()); return true; } diff --git a/atom/common/asar/archive.h b/atom/common/asar/archive.h index 4c44442b51f9..30926fb9f6a2 100644 --- a/atom/common/asar/archive.h +++ b/atom/common/asar/archive.h @@ -7,9 +7,8 @@ #include -#include "base/containers/hash_tables.h" +#include "base/containers/scoped_ptr_hash_map.h" #include "base/files/file_path.h" -#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" namespace base { @@ -22,7 +21,7 @@ class ScopedTemporaryFile; // This class represents an asar package, and provides methods to read // information from it. -class Archive : public base::RefCounted { +class Archive { public: struct FileInfo { FileInfo() : size(0), offset(0) {} @@ -38,6 +37,7 @@ class Archive : public base::RefCounted { }; explicit Archive(const base::FilePath& path); + virtual ~Archive(); // Read and parse the header. bool Init(); @@ -58,16 +58,12 @@ class Archive : public base::RefCounted { base::DictionaryValue* header() const { return header_.get(); } private: - friend class base::RefCounted; - virtual ~Archive(); - base::FilePath path_; uint32 header_size_; scoped_ptr header_; // Cached external temporary files. - base::hash_map > external_files_; + base::ScopedPtrHashMap external_files_; DISALLOW_COPY_AND_ASSIGN(Archive); }; diff --git a/atom/common/asar/archive_factory.cc b/atom/common/asar/archive_factory.cc index cf8bd2db28f0..6c8fd6a56a3f 100644 --- a/atom/common/asar/archive_factory.cc +++ b/atom/common/asar/archive_factory.cc @@ -5,25 +5,24 @@ #include "atom/common/asar/archive_factory.h" #include "atom/common/asar/archive.h" -#include "base/stl_util.h" namespace asar { ArchiveFactory::ArchiveFactory() {} -ArchiveFactory::~ArchiveFactory() {} +ArchiveFactory::~ArchiveFactory() { +} -scoped_refptr ArchiveFactory::GetOrCreate(const base::FilePath& path) { - // Create a cache of Archive. - if (!ContainsKey(archives_, path)) { - scoped_refptr archive(new Archive(path)); +Archive* ArchiveFactory::GetOrCreate(const base::FilePath& path) { + if (!archives_.contains(path)) { + scoped_ptr archive(new Archive(path)); if (!archive->Init()) - return NULL; - archives_[path] = archive; - return archive; + return nullptr; + + archives_.set(path, archive.Pass()); } - return archives_[path]; + return archives_.get(path); } } // namespace asar diff --git a/atom/common/asar/archive_factory.h b/atom/common/asar/archive_factory.h index 2f6700c6beed..b770a83dbfa1 100644 --- a/atom/common/asar/archive_factory.h +++ b/atom/common/asar/archive_factory.h @@ -5,9 +5,8 @@ #ifndef ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_ #define ATOM_COMMON_ASAR_ARCHIVE_FACTORY_H_ -#include "base/containers/hash_tables.h" +#include "base/containers/scoped_ptr_hash_map.h" #include "base/files/file_path.h" -#include "base/memory/ref_counted.h" namespace asar { @@ -18,10 +17,10 @@ class ArchiveFactory { ArchiveFactory(); virtual ~ArchiveFactory(); - scoped_refptr GetOrCreate(const base::FilePath& path); + Archive* GetOrCreate(const base::FilePath& path); private: - base::hash_map > archives_; // NOLINT + base::ScopedPtrHashMap archives_; DISALLOW_COPY_AND_ASSIGN(ArchiveFactory); }; diff --git a/atom/common/asar/scoped_temporary_file.h b/atom/common/asar/scoped_temporary_file.h index 190eecf4d621..69e76a05c56e 100644 --- a/atom/common/asar/scoped_temporary_file.h +++ b/atom/common/asar/scoped_temporary_file.h @@ -6,7 +6,6 @@ #define ATOM_COMMON_ASAR_SCOPED_TEMPORARY_FILE_H_ #include "base/files/file_path.h" -#include "base/memory/ref_counted.h" namespace asar { @@ -14,9 +13,10 @@ namespace asar { // object goes out of scope. Note that since deletion occurs during the // destructor, no further error handling is possible if the directory fails to // be deleted. As a result, deletion is not guaranteed by this class. -class ScopedTemporaryFile : public base::RefCounted { +class ScopedTemporaryFile { public: ScopedTemporaryFile(); + virtual ~ScopedTemporaryFile(); // Init an empty temporary file. bool Init(); @@ -27,9 +27,6 @@ class ScopedTemporaryFile : public base::RefCounted { base::FilePath path() const { return path_; } private: - friend class base::RefCounted; - virtual ~ScopedTemporaryFile(); - base::FilePath path_; DISALLOW_COPY_AND_ASSIGN(ScopedTemporaryFile);