Chromium Code Reviews| Index: chrome/browser/profiles/profile_impl_io_data.cc |
| diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc |
| index 4e7e378b5b3ed8250d15fee8dc37546f221a8f62..1fee8d27909423f484bbd73702c8b81de6edc790 100644 |
| --- a/chrome/browser/profiles/profile_impl_io_data.cc |
| +++ b/chrome/browser/profiles/profile_impl_io_data.cc |
| @@ -443,54 +443,18 @@ void ProfileImplIOData::LazyInitializeInternal( |
| media_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| - int set_protocol = main_job_factory_->SetProtocolHandler( |
| - chrome::kFileScheme, new net::FileProtocolHandler()); |
| - DCHECK(set_protocol); |
| - set_protocol = media_request_job_factory_->SetProtocolHandler( |
| - chrome::kFileScheme, new net::FileProtocolHandler()); |
| - DCHECK(set_protocol); |
| + SetupJobFactory(main_job_factory_.get(), network_delegate(), |
| + main_context->ftp_auth_cache()); |
| + SetupJobFactory(media_request_job_factory_.get(), network_delegate(), |
| + media_request_context_->ftp_auth_cache()); |
| // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| // Without a network_delegate, this protocol handler will never |
| // handle file: requests, but as a side effect it makes |
| // job_factory::IsHandledProtocol return true, which prevents attempts to |
| - // handle the protocol externally. |
| - set_protocol = extensions_job_factory_->SetProtocolHandler( |
| - chrome::kFileScheme, new net::FileProtocolHandler()); |
| - DCHECK(set_protocol); |
| - |
| - set_protocol = main_job_factory_->SetProtocolHandler( |
| - chrome::kChromeDevToolsScheme, |
| - CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), |
| - network_delegate())); |
| - DCHECK(set_protocol); |
| - set_protocol = media_request_job_factory_->SetProtocolHandler( |
| - chrome::kChromeDevToolsScheme, |
| - CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), |
| - network_delegate())); |
| - DCHECK(set_protocol); |
| - set_protocol = extensions_job_factory_->SetProtocolHandler( |
| - chrome::kChromeDevToolsScheme, |
| - CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), NULL)); |
| - DCHECK(set_protocol); |
| - |
| - net::URLRequestJobFactory* job_factories[3]; |
| - job_factories[0] = main_job_factory_.get(); |
| - job_factories[1] = media_request_job_factory_.get(); |
| - job_factories[2] = extensions_job_factory_.get(); |
| - |
| - net::FtpAuthCache* ftp_auth_caches[3]; |
| - ftp_auth_caches[0] = main_context->ftp_auth_cache(); |
| - ftp_auth_caches[1] = media_request_context_->ftp_auth_cache(); |
| - ftp_auth_caches[2] = extensions_context->ftp_auth_cache(); |
| - |
| - for (int i = 0; i < 3; i++) { |
| - SetUpJobFactoryDefaults(job_factories[i]); |
| - job_factories[i]->SetProtocolHandler(chrome::kAboutScheme, |
| - new net::AboutProtocolHandler()); |
| - CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]); |
| - job_factories[i]->AddInterceptor( |
| - new chrome_browser_net::ConnectInterceptor(predictor_.get())); |
| - } |
| + // handle the protocol externally. We pass NULL in to SetupJobFactory to |
| + // get this effect. |
| + SetupJobFactory(extensions_job_factory_.get(), NULL, |
| + extensions_context->ftp_auth_cache()); |
| main_context->set_job_factory(main_job_factory_.get()); |
| media_request_context_->set_job_factory(media_request_job_factory_.get()); |
| @@ -569,7 +533,16 @@ ProfileImplIOData::InitializeAppRequestContext( |
| // Transfer ownership of the cookies and cache to AppRequestContext. |
| context->SetCookieStore(cookie_store); |
| - context->SetHttpTransactionFactory(app_http_cache); |
| + context->SetHttpTransactionFactory( |
| + scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| + |
| + // Overwrite the job factory that we inherit from the main context so |
| + // that we can later provide our own handles for storage related protocols. |
| + scoped_ptr<net::URLRequestJobFactory> job_factory( |
| + new net::URLRequestJobFactoryImpl()); |
| + SetupJobFactory(job_factory.get(), network_delegate(), |
| + context->ftp_auth_cache()); |
| + context->SetJobFactory(job_factory.Pass()); |
| return context; |
| } |
| @@ -609,11 +582,11 @@ ProfileImplIOData::InitializeMediaRequestContext( |
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| net::HttpNetworkSession* main_network_session = |
| main_http_factory_->GetSession(); |
| - net::HttpCache* media_http_cache = |
| - new net::HttpCache(main_network_session, media_backend); |
| + scoped_ptr<net::HttpTransactionFactory> media_http_cache( |
| + new net::HttpCache(main_network_session, media_backend)); |
| // Transfer ownership of the cache to MediaRequestContext. |
| - context->SetHttpTransactionFactory(media_http_cache); |
| + context->SetHttpTransactionFactory(media_http_cache.Pass()); |
|
Charlie Reis
2012/09/20 17:47:03
Why don't we need to call SetupJobFactory here as
awong
2012/09/20 22:11:00
Because MediaRequestContext actually reuses the jo
|
| return context; |
| } |
| @@ -651,6 +624,28 @@ chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( |
| return io_thread_globals->load_time_stats.get(); |
| } |
| +void ProfileImplIOData::SetupJobFactory( |
| + net::URLRequestJobFactory* job_factory, |
| + net::NetworkDelegate* network_delegate, |
| + net::FtpAuthCache* ftp_auth_cache) const { |
| + int set_protocol = job_factory->SetProtocolHandler( |
| + chrome::kFileScheme, new net::FileProtocolHandler()); |
| + DCHECK(set_protocol); |
| + |
| + set_protocol = job_factory->SetProtocolHandler( |
| + chrome::kChromeDevToolsScheme, |
| + CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), |
| + network_delegate)); |
| + DCHECK(set_protocol); |
| + |
| + SetUpJobFactoryDefaults(job_factory); |
| + job_factory->SetProtocolHandler(chrome::kAboutScheme, |
| + new net::AboutProtocolHandler()); |
| + CreateFtpProtocolHandler(job_factory, ftp_auth_cache); |
| + job_factory->AddInterceptor( |
| + new chrome_browser_net::ConnectInterceptor(predictor_.get())); |
| +} |
| + |
| void ProfileImplIOData::CreateFtpProtocolHandler( |
| net::URLRequestJobFactory* job_factory, |
| net::FtpAuthCache* ftp_auth_cache) const { |