Add Delegate for URLRequestContextGetter.
This commit is contained in:
parent
bbb3702543
commit
c30f11f38c
4 changed files with 35 additions and 37 deletions
|
@ -104,25 +104,24 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(
|
|||
content::ProtocolHandlerScopedVector protocol_interceptors) {
|
||||
DCHECK(!url_request_getter_);
|
||||
url_request_getter_ = new URLRequestContextGetter(
|
||||
this,
|
||||
GetPath(),
|
||||
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
|
||||
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
|
||||
base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)),
|
||||
base::Bind(&BrowserContext::CreateURLRequestJobFactory, base::Unretained(this)),
|
||||
protocol_handlers,
|
||||
protocol_interceptors.Pass());
|
||||
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
||||
return url_request_getter_.get();
|
||||
}
|
||||
|
||||
scoped_ptr<NetworkDelegate> BrowserContext::CreateNetworkDelegate() {
|
||||
return make_scoped_ptr(new NetworkDelegate).Pass();
|
||||
net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() {
|
||||
return new NetworkDelegate;
|
||||
}
|
||||
|
||||
scoped_ptr<net::URLRequestJobFactory> BrowserContext::CreateURLRequestJobFactory(
|
||||
net::URLRequestJobFactory* BrowserContext::CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector* protocol_interceptors) {
|
||||
return scoped_ptr<net::URLRequestJobFactory>();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
base::FilePath BrowserContext::GetPath() const {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "browser/url_request_context_getter.h"
|
||||
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
|
||||
class PrefRegistrySimple;
|
||||
class PrefService;
|
||||
|
@ -16,9 +15,9 @@ class PrefService;
|
|||
namespace brightray {
|
||||
|
||||
class DownloadManagerDelegate;
|
||||
class NetworkDelegate;
|
||||
|
||||
class BrowserContext : public content::BrowserContext {
|
||||
class BrowserContext : public content::BrowserContext,
|
||||
public brightray::URLRequestContextGetter::Delegate {
|
||||
public:
|
||||
BrowserContext();
|
||||
~BrowserContext();
|
||||
|
@ -39,15 +38,11 @@ class BrowserContext : public content::BrowserContext {
|
|||
// Subclasses should override this to register custom preferences.
|
||||
virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {}
|
||||
|
||||
// Subclasses should override this to provide a custom NetworkDelegate
|
||||
// implementation.
|
||||
virtual scoped_ptr<NetworkDelegate> CreateNetworkDelegate();
|
||||
|
||||
// Subclasses should override this to provide a custom URLRequestJobFactory
|
||||
// implementation.
|
||||
virtual scoped_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory(
|
||||
// URLRequestContextGetter::Delegate:
|
||||
virtual net::NetworkDelegate* CreateNetworkDelegate() OVERRIDE;
|
||||
virtual net::URLRequestJobFactory* CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector* protocol_interceptors);
|
||||
content::ProtocolHandlerScopedVector* protocol_interceptors) OVERRIDE;
|
||||
|
||||
virtual base::FilePath GetPath() const OVERRIDE;
|
||||
|
||||
|
|
|
@ -74,18 +74,16 @@ const char kProxyServer[] = "proxy-server";
|
|||
} // namespace
|
||||
|
||||
URLRequestContextGetter::URLRequestContextGetter(
|
||||
Delegate* delegate,
|
||||
const base::FilePath& base_path,
|
||||
base::MessageLoop* io_loop,
|
||||
base::MessageLoop* file_loop,
|
||||
base::Callback<scoped_ptr<NetworkDelegate>(void)> network_delegate_factory,
|
||||
URLRequestJobFactoryFactory job_factory_factory,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector protocol_interceptors)
|
||||
: base_path_(base_path),
|
||||
: delegate_(delegate),
|
||||
base_path_(base_path),
|
||||
io_loop_(io_loop),
|
||||
file_loop_(file_loop),
|
||||
network_delegate_factory_(network_delegate_factory),
|
||||
job_factory_factory_(job_factory_factory),
|
||||
protocol_interceptors_(protocol_interceptors.Pass()) {
|
||||
// Must first be created on the UI thread.
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
|
@ -110,7 +108,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
|||
|
||||
if (!url_request_context_.get()) {
|
||||
url_request_context_.reset(new net::URLRequestContext());
|
||||
network_delegate_ = network_delegate_factory_.Run().Pass();
|
||||
network_delegate_.reset(delegate_->CreateNetworkDelegate());
|
||||
url_request_context_->set_network_delegate(network_delegate_.get());
|
||||
storage_.reset(
|
||||
new net::URLRequestContextStorage(url_request_context_.get()));
|
||||
|
@ -210,7 +208,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
|||
|
||||
// Give user a chance to create their own job factory.
|
||||
scoped_ptr<net::URLRequestJobFactory> user_job_factory(
|
||||
job_factory_factory_.Run(&protocol_handlers_, &protocol_interceptors_));
|
||||
delegate_->CreateURLRequestJobFactory(&protocol_handlers_, &protocol_interceptors_));
|
||||
if (user_job_factory) {
|
||||
storage_->set_job_factory(user_job_factory.release());
|
||||
return url_request_context_.get();
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#ifndef BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
#define BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
|
@ -18,26 +17,34 @@ class MessageLoop;
|
|||
namespace net {
|
||||
class HostMappingRules;
|
||||
class HostResolver;
|
||||
class NetworkDelegate;
|
||||
class ProxyConfigService;
|
||||
class URLRequestContextStorage;
|
||||
class URLRequestJobFactory;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class NetworkDelegate;
|
||||
|
||||
typedef base::Callback<scoped_ptr<net::URLRequestJobFactory>(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector* protocol_interceptors)> URLRequestJobFactoryFactory;
|
||||
|
||||
class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||
public:
|
||||
class Delegate {
|
||||
public:
|
||||
Delegate() {}
|
||||
virtual ~Delegate() {}
|
||||
|
||||
virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; };
|
||||
virtual net::URLRequestJobFactory* CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector* protocol_interceptors) {
|
||||
return NULL;
|
||||
};
|
||||
};
|
||||
|
||||
URLRequestContextGetter(
|
||||
Delegate* delegate,
|
||||
const base::FilePath& base_path,
|
||||
base::MessageLoop* io_loop,
|
||||
base::MessageLoop* file_loop,
|
||||
base::Callback<scoped_ptr<NetworkDelegate>(void)>,
|
||||
URLRequestJobFactoryFactory job_factory_factory,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector protocol_interceptors);
|
||||
virtual ~URLRequestContextGetter();
|
||||
|
@ -49,15 +56,14 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
|||
virtual scoped_refptr<base::SingleThreadTaskRunner>
|
||||
GetNetworkTaskRunner() const OVERRIDE;
|
||||
|
||||
Delegate* delegate_;
|
||||
|
||||
base::FilePath base_path_;
|
||||
base::MessageLoop* io_loop_;
|
||||
base::MessageLoop* file_loop_;
|
||||
|
||||
base::Callback<scoped_ptr<NetworkDelegate>(void)> network_delegate_factory_;
|
||||
URLRequestJobFactoryFactory job_factory_factory_;
|
||||
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
|
||||
scoped_ptr<NetworkDelegate> network_delegate_;
|
||||
scoped_ptr<net::NetworkDelegate> network_delegate_;
|
||||
scoped_ptr<net::URLRequestContextStorage> storage_;
|
||||
scoped_ptr<net::URLRequestContext> url_request_context_;
|
||||
scoped_ptr<net::HostMappingRules> host_mapping_rules_;
|
||||
|
|
Loading…
Reference in a new issue