Move GetsOrCreateAsarArchive to asar_util.h
This commit is contained in:
parent
64622ceae3
commit
3b3a025ed4
7 changed files with 66 additions and 25 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "atom/browser/net/asar/url_request_asar_job.h"
|
||||
#include "atom/common/asar/archive.h"
|
||||
#include "atom/common/asar/asar_util.h"
|
||||
#include "net/base/filename_util.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/url_request/url_request_error_job.h"
|
||||
|
@ -49,19 +50,6 @@ AsarProtocolHandler::AsarProtocolHandler(
|
|||
AsarProtocolHandler::~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(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const {
|
||||
|
@ -75,7 +63,7 @@ net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
|
|||
return new net::URLRequestFileJob(request, network_delegate, full_path,
|
||||
file_task_runner_);
|
||||
|
||||
Archive* archive = GetOrCreateAsarArchive(asar_path);
|
||||
std::shared_ptr<Archive> archive = GetOrCreateAsarArchive(asar_path);
|
||||
if (!archive)
|
||||
return new net::URLRequestErrorJob(request, network_delegate,
|
||||
net::ERR_FILE_NOT_FOUND);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#ifndef ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
|
||||
#define ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_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"
|
||||
|
||||
|
@ -16,16 +14,12 @@ 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:
|
||||
net::URLRequestJob* MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
|
@ -35,8 +29,6 @@ class AsarProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
|||
private:
|
||||
const scoped_refptr<base::TaskRunner> file_task_runner_;
|
||||
|
||||
mutable base::ScopedPtrHashMap<base::FilePath, Archive> archives_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler);
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace asar {
|
|||
URLRequestAsarJob::URLRequestAsarJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
Archive* archive,
|
||||
std::shared_ptr<Archive> archive,
|
||||
const base::FilePath& file_path,
|
||||
const scoped_refptr<base::TaskRunner>& file_task_runner)
|
||||
: net::URLRequestJob(request, network_delegate),
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
||||
#define ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/asar/archive.h"
|
||||
|
@ -27,7 +28,7 @@ class URLRequestAsarJob : public net::URLRequestJob {
|
|||
public:
|
||||
URLRequestAsarJob(net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
Archive* archive,
|
||||
std::shared_ptr<Archive> archive,
|
||||
const base::FilePath& file_path,
|
||||
const scoped_refptr<base::TaskRunner>& file_task_runner);
|
||||
|
||||
|
@ -53,7 +54,7 @@ class URLRequestAsarJob : public net::URLRequestJob {
|
|||
// Callback after data is asynchronously read from the file into |buf|.
|
||||
void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
|
||||
|
||||
Archive* archive_;
|
||||
std::shared_ptr<Archive> archive_;
|
||||
Archive::FileInfo file_info_;
|
||||
base::FilePath file_path_;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue