Give user a chance to create custom URLRequestJobFactory.

This commit is contained in:
Cheng Zhao 2014-08-13 15:48:16 +08:00
parent d01aa51686
commit 2d03c983e4
4 changed files with 34 additions and 0 deletions

View file

@ -45,12 +45,14 @@ URLRequestContextGetter::URLRequestContextGetter(
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),
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));
@ -149,6 +151,14 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
network_session_params, main_backend);
storage_->set_http_transaction_factory(main_cache);
// 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_));
if (user_job_factory) {
storage_->set_job_factory(user_job_factory.release());
return url_request_context_.get();
}
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
for (auto it = protocol_handlers_.begin(),