Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2926)

Unified Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 1239393003: Refactor main URLRequestContext creation to use URLRequestContextBuilder Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63d388c96e1d4ec25af633a72c9d450118950cc0..d322aa902d03aeaf79de30c444d19ace0f247b8e 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -60,6 +60,8 @@
#include "net/http/http_server_properties_manager.h"
#include "net/sdch/sdch_owner.h"
#include "net/ssl/channel_id_service.h"
+#include "net/url_request/url_request_context_builder.h"
+#include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_intercepting_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "storage/browser/quota/special_storage_policy.h"
@@ -446,7 +448,8 @@ void ProfileImplIOData::InitializeInternal(
scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate,
ProfileParams* profile_params,
content::ProtocolHandlerMap* protocol_handlers,
- content::URLRequestInterceptorScopedVector request_interceptors) const {
+ content::URLRequestInterceptorScopedVector request_interceptors,
+ net::URLRequestContextBuilder* context_builder) const {
// Set up a persistent store for use by the network stack on the IO thread.
base::FilePath network_json_store_filepath(
profile_path_.Append(chrome::kNetworkPersistentStateFilename));
@@ -457,49 +460,31 @@ void ProfileImplIOData::InitializeInternal(
scoped_ptr<PrefFilter>());
network_json_store_->ReadPrefsAsync(nullptr);
- net::URLRequestContext* main_context = main_request_context();
-
IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const io_thread_globals = io_thread->globals();
- chrome_network_delegate->set_predictor(predictor_.get());
-
- if (domain_reliability_monitor_) {
- domain_reliability::DomainReliabilityMonitor* monitor =
- domain_reliability_monitor_.get();
- monitor->InitURLRequestContext(main_context);
- monitor->AddBakedInConfigs();
- monitor->SetDiscardUploads(!GetMetricsEnabledStateOnIOThread());
- chrome_network_delegate->set_domain_reliability_monitor(monitor);
- }
-
- ApplyProfileParamsToContext(main_context);
+ ApplyProfileParamsToContext(context_builder);
if (http_server_properties_manager_)
http_server_properties_manager_->InitializeOnNetworkThread();
- main_context->set_transport_security_state(transport_security_state());
+ context_builder->set_net_log_unowned(io_thread->net_log());
- main_context->set_net_log(io_thread->net_log());
+ // The context receives a WeakPtr to the server properties.
+ // TODO(wjmaclean): presumably this value gets copied to other contexts ...
+ // it would be nice to avoid this.
+ context_builder->set_http_server_properties(http_server_properties());
- network_delegate_ = data_reduction_proxy_io_data()->CreateNetworkDelegate(
- chrome_network_delegate.Pass(), true).Pass();
-
- main_context->set_network_delegate(network_delegate_.get());
-
- main_context->set_http_server_properties(http_server_properties());
-
- main_context->set_host_resolver(
+ context_builder->set_host_resolver_unowned(
io_thread_globals->host_resolver.get());
- main_context->set_cert_transparency_verifier(
+ context_builder->set_cert_transparency_verifier_unowned(
io_thread_globals->cert_transparency_verifier.get());
- main_context->set_http_auth_handler_factory(
+ context_builder->set_http_auth_handler_factory_unowned(
io_thread_globals->http_auth_handler_factory.get());
- main_context->set_fraudulent_certificate_reporter(
- fraudulent_certificate_reporter());
-
- main_context->set_proxy_service(proxy_service());
+ // TODO(wjmaclean): proxy_service() is currently built with all sorts of stuff
+ // from io_globals, so we'll treat it as an unowned pointer for now.
+ context_builder->set_proxy_service_unowned(proxy_service());
scoped_refptr<net::CookieStore> cookie_store = NULL;
net::ChannelIDService* channel_id_service = NULL;
@@ -518,8 +503,6 @@ void ProfileImplIOData::InitializeInternal(
cookie_store = content::CreateCookieStore(cookie_config);
}
- main_context->set_cookie_store(cookie_store.get());
-
// Set up server bound cert service.
if (!channel_id_service) {
DCHECK(!lazy_params_->channel_id_path.empty());
@@ -535,10 +518,9 @@ void ProfileImplIOData::InitializeInternal(
base::WorkerPool::GetTaskRunner(true));
}
- set_channel_id_service(channel_id_service);
- main_context->set_channel_id_service(channel_id_service);
+ context_builder->SetCookieAndChannelIdStores(
+ cookie_store.get(), make_scoped_ptr(channel_id_service));
- scoped_ptr<net::HttpCache> main_cache;
{
// TODO(ttuttle): Remove ScopedTracker below once crbug.com/436671 is fixed.
tracked_objects::ScopedTracker tracking_profile(
@@ -550,17 +532,20 @@ void ProfileImplIOData::InitializeInternal(
lazy_params_->cache_path,
lazy_params_->cache_max_size,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
- main_cache = CreateMainHttpFactory(profile_params, main_backend);
+ context_builder->set_http_transaction_factory_factory(
+ new ProfileIOData::HttpTransactionFactoryDelegate(this, profile_params,
+ main_backend));
}
- main_http_factory_.reset(main_cache.release());
- main_context->set_http_transaction_factory(main_http_factory_.get());
-
#if !defined(DISABLE_FTP_SUPPORT)
+ // The host_resolver used here should be the same one used for the main
+ // URLResourceContext.
ftp_factory_.reset(
new net::FtpNetworkLayer(io_thread_globals->host_resolver.get()));
#endif // !defined(DISABLE_FTP_SUPPORT)
+ chrome_network_delegate->set_predictor(predictor_.get());
+
scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
InstallProtocolHandlers(main_job_factory.get(), protocol_handlers);
@@ -570,24 +555,48 @@ void ProfileImplIOData::InitializeInternal(
request_interceptors.insert(
request_interceptors.begin(),
data_reduction_proxy_io_data()->CreateInterceptor().release());
- main_job_factory_ = SetUpJobFactoryDefaults(
+ scoped_ptr<net::NetworkDelegate> network_delegate =
+ data_reduction_proxy_io_data()->CreateNetworkDelegate(
+ chrome_network_delegate.Pass(), true);
+
+ context_builder->set_job_factory(SetUpJobFactoryDefaults(
main_job_factory.Pass(),
request_interceptors.Pass(),
profile_params->protocol_handler_interceptor.Pass(),
- main_context->network_delegate(),
- ftp_factory_.get());
- main_context->set_job_factory(main_job_factory_.get());
- main_context->set_network_quality_estimator(
+ network_delegate.get(),
+ ftp_factory_.get()).Pass());
+ // TODO(wjmaclean): make this Pass(), not release().
+ context_builder->set_network_delegate(network_delegate.release());
+ context_builder->set_network_quality_estimator_unowned(
io_thread_globals->network_quality_estimator.get());
#if defined(ENABLE_EXTENSIONS)
+ // This call initializes the extensions URLRequestContext *independently* of
+ // the, as-yet unbuilt, main URLRequestContext. If that ever changes, then
+ // this should not be called in this function.
InitializeExtensionsRequestContext(profile_params);
#endif
- // Setup SDCH for this profile.
- sdch_manager_.reset(new net::SdchManager);
- sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context));
- main_context->set_sdch_manager(sdch_manager_.get());
+ // Start setup of SDCH for this profile.
+ context_builder->set_sdch_manager(new net::SdchManager);
+}
+
+void ProfileImplIOData::InitPostContextSetup(
+ ChromeNetworkDelegate* chrome_network_delegate) const {
+ net::URLRequestContext* main_context = main_request_context();
+
+ if (domain_reliability_monitor_) {
+ domain_reliability::DomainReliabilityMonitor* monitor =
+ domain_reliability_monitor_.get();
+ monitor->InitURLRequestContext(main_context);
+ monitor->AddBakedInConfigs();
+ monitor->SetDiscardUploads(!GetMetricsEnabledStateOnIOThread());
+ chrome_network_delegate->set_domain_reliability_monitor(monitor);
+ }
+
+ // Finish setup of SDCH for this profile.
+ sdch_policy_.reset(
+ new net::SdchOwner(main_context->sdch_manager(), main_context));
if (ShouldUseSdchPersistence()) {
sdch_policy_->EnablePersistentStorage(network_json_store_.get());
}
@@ -598,6 +607,7 @@ void ProfileImplIOData::InitializeInternal(
media_request_context_.reset(InitializeMediaRequestContext(main_context,
details));
+ // lazy_params_ are last used in InitializeMediaRequestContext().
lazy_params_.reset();
}
@@ -673,8 +683,9 @@ net::URLRequestContext* ProfileImplIOData::InitializeAppRequestContext(
app_cache_max_size_,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
}
+ DCHECK(main_context->storage());
net::HttpNetworkSession* main_network_session =
- main_http_factory_->GetSession();
+ main_context->storage()->http_transaction_factory()->GetSession();
scoped_ptr<net::HttpCache> app_http_cache =
CreateHttpFactory(main_network_session, app_backend);
@@ -756,8 +767,9 @@ ProfileImplIOData::InitializeMediaRequestContext(
cache_path,
cache_max_size,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
+ DCHECK(original_context->storage());
net::HttpNetworkSession* main_network_session =
- main_http_factory_->GetSession();
+ original_context->storage()->http_transaction_factory()->GetSession();
scoped_ptr<net::HttpCache> media_http_cache =
CreateHttpFactory(main_network_session, media_backend);
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698