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