const scoped_refptr<base::TaskRunner>& file_task_runner)
: file_task_runner_(file_task_runner) {}
-AsarProtocolHandler::~AsarProtocolHandler() {}
+AsarProtocolHandler::~AsarProtocolHandler() {
+ LOG(ERROR) << "~AsarProtocolHandler";
+}
net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
net::URLRequest* request,
return new net::URLRequestFileJob(request, network_delegate, full_path,
file_task_runner_);
- scoped_refptr<Archive> 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);
#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 {
URLRequestAsarJob::URLRequestAsarJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
- const scoped_refptr<Archive>& archive,
+ Archive* archive,
const base::FilePath& file_path,
const scoped_refptr<base::TaskRunner>& file_task_runner)
: net::URLRequestJob(request, network_delegate),
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;
public:
URLRequestAsarJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
- const scoped_refptr<Archive>& archive,
+ Archive* archive,
const base::FilePath& file_path,
const scoped_refptr<base::TaskRunner>& file_task_runner);
// Callback after data is asynchronously read from the file into |buf|.
void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
- const scoped_refptr<Archive> archive_;
+ Archive* archive_;
Archive::FileInfo file_info_;
base::FilePath file_path_;
static v8::Handle<v8::Value> Create(v8::Isolate* isolate,
const base::FilePath& path) {
static asar::ArchiveFactory archive_factory;
- scoped_refptr<asar::Archive> 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<asar::Archive> archive) : archive_(archive) {}
+ explicit Archive(asar::Archive* archive) : archive_(archive) {}
virtual ~Archive() {}
// Reads the offset and size of file.
v8::Handle<v8::Value> 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);
v8::Handle<v8::Value> 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);
v8::Handle<v8::Value> Readdir(v8::Isolate* isolate,
const base::FilePath& path) {
std::vector<base::FilePath> files;
- if (!archive_->Readdir(path, &files))
+ if (!archive_ || !archive_->Readdir(path, &files))
return v8::False(isolate);
return mate::ConvertToV8(isolate, files);
}
v8::Handle<v8::Value> 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);
}
}
private:
- scoped_refptr<asar::Archive> archive_;
+ asar::Archive* archive_;
DISALLOW_COPY_AND_ASSIGN(Archive);
};
#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 {
}
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;
}
if (!GetFileInfo(path, &info))
return false;
- scoped_refptr<ScopedTemporaryFile> temp_file(new ScopedTemporaryFile);
+ scoped_ptr<ScopedTemporaryFile> 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;
}
#include <vector>
-#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 {
// This class represents an asar package, and provides methods to read
// information from it.
-class Archive : public base::RefCounted<Archive> {
+class Archive {
public:
struct FileInfo {
FileInfo() : size(0), offset(0) {}
};
explicit Archive(const base::FilePath& path);
+ virtual ~Archive();
// Read and parse the header.
bool Init();
base::DictionaryValue* header() const { return header_.get(); }
private:
- friend class base::RefCounted<Archive>;
- virtual ~Archive();
-
base::FilePath path_;
uint32 header_size_;
scoped_ptr<base::DictionaryValue> header_;
// Cached external temporary files.
- base::hash_map<base::FilePath, // NOLINT
- scoped_refptr<ScopedTemporaryFile> > external_files_;
+ base::ScopedPtrHashMap<base::FilePath, ScopedTemporaryFile> external_files_;
DISALLOW_COPY_AND_ASSIGN(Archive);
};
#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<Archive> ArchiveFactory::GetOrCreate(const base::FilePath& path) {
- // Create a cache of Archive.
- if (!ContainsKey(archives_, path)) {
- scoped_refptr<Archive> archive(new Archive(path));
+Archive* ArchiveFactory::GetOrCreate(const base::FilePath& path) {
+ if (!archives_.contains(path)) {
+ scoped_ptr<Archive> 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
#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 {
ArchiveFactory();
virtual ~ArchiveFactory();
- scoped_refptr<Archive> GetOrCreate(const base::FilePath& path);
+ Archive* GetOrCreate(const base::FilePath& path);
private:
- base::hash_map<base::FilePath, scoped_refptr<Archive> > archives_; // NOLINT
+ base::ScopedPtrHashMap<base::FilePath, Archive> archives_;
DISALLOW_COPY_AND_ASSIGN(ArchiveFactory);
};
#define ATOM_COMMON_ASAR_SCOPED_TEMPORARY_FILE_H_
#include "base/files/file_path.h"
-#include "base/memory/ref_counted.h"
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<ScopedTemporaryFile> {
+class ScopedTemporaryFile {
public:
ScopedTemporaryFile();
+ virtual ~ScopedTemporaryFile();
// Init an empty temporary file.
bool Init();
base::FilePath path() const { return path_; }
private:
- friend class base::RefCounted<ScopedTemporaryFile>;
- virtual ~ScopedTemporaryFile();
-
base::FilePath path_;
DISALLOW_COPY_AND_ASSIGN(ScopedTemporaryFile);