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

Unified Diff: chrome/browser/io_thread.cc

Issue 2972223002: Revert https://codereview.chromium.org/2860033003 (Closed)
Patch Set: Created 3 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/io_thread.h ('k') | chrome/test/base/testing_io_thread_state.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/io_thread.cc
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 935ebc38f6145315bc250b6218e1d5633ef7f672..a7a020189430e3e64d77e84576c66022ddd257ab 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -110,7 +110,6 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_context_getter.h"
-#include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "url/url_constants.h"
@@ -200,19 +199,13 @@ class SystemURLRequestContext : public net::URLRequestContext {
#endif
}
+ private:
~SystemURLRequestContext() override {
AssertNoURLRequests();
#if defined(USE_NSS_CERTS)
net::SetURLRequestContextForNSSHttpIO(NULL);
#endif
-
-#if defined(OS_ANDROID)
- net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
-#endif
}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(SystemURLRequestContext);
};
std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
@@ -405,8 +398,6 @@ IOThread::IOThread(
pref_proxy_config_tracker_.reset(
ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
local_state));
- system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
- pref_proxy_config_tracker_.get());
ChromeNetworkDelegate::InitializePrefsOnUIThread(
&system_enable_referrers_,
nullptr,
@@ -498,8 +489,7 @@ void IOThread::ChangedToOnTheRecord() {
net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!system_url_request_context_getter_.get()) {
- system_url_request_context_getter_ =
- new SystemURLRequestContextGetter(this);
+ InitSystemRequestContext();
}
return system_url_request_context_getter_.get();
}
@@ -647,6 +637,14 @@ void IOThread::Init() {
// For the ProxyScriptFetcher, we use a direct ProxyService.
globals_->proxy_script_fetcher_proxy_service =
net::ProxyService::CreateDirectWithNetLog(net_log_);
+ // In-memory cookie store.
+ globals_->system_cookie_store =
+ content::CreateCookieStore(content::CookieStoreConfig());
+ // In-memory channel ID store.
+ globals_->system_channel_id_service.reset(
+ new net::ChannelIDService(new net::DefaultChannelIDStore(NULL)));
+ globals_->system_cookie_store->SetChannelIDServiceID(
+ globals_->system_channel_id_service->GetUniqueID());
globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
globals_->host_mapping_rules.reset(new net::HostMappingRules());
params_.host_mapping_rules = globals_->host_mapping_rules.get();
@@ -676,6 +674,13 @@ void IOThread::Init() {
command_line, is_quic_allowed_by_policy_,
http_09_on_non_default_ports_enabled_, &params_);
+ TRACE_EVENT_BEGIN0("startup",
+ "IOThread::Init:ProxyScriptFetcherRequestContext");
+ globals_->proxy_script_fetcher_context.reset(
+ ConstructProxyScriptFetcherContext(globals_, params_, net_log_));
+ TRACE_EVENT_END0("startup",
+ "IOThread::Init:ProxyScriptFetcherRequestContext");
+
#if defined(OS_MACOSX)
// Start observing Keychain events. This needs to be done on the UI thread,
// as Keychain services requires a CFRunLoop.
@@ -684,14 +689,26 @@ void IOThread::Init() {
base::Bind(&ObserveKeychainEvents));
#endif
+ // InitSystemRequestContext turns right around and posts a task back
+ // to the IO thread, so we can't let it run until we know the IO
+ // thread has started.
+ //
+ // Note that since we are at BrowserThread::Init time, the UI thread
+ // is blocked waiting for the thread to start. Therefore, posting
+ // this task to the main thread's message loop here is guaranteed to
+ // get it onto the message loop while the IOThread object still
+ // exists. However, the message might not be processed on the UI
+ // thread until after IOThread is gone, so use a weak pointer.
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::BindOnce(&IOThread::InitSystemRequestContext,
+ weak_factory_.GetWeakPtr()));
+
#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
// Record how common CPUs with broken NEON units are. See
// https://crbug.com/341598.
crypto::EnsureOpenSSLInit();
UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON());
#endif
-
- ConstructSystemRequestContext();
}
void IOThread::CleanUp() {
@@ -701,19 +718,19 @@ void IOThread::CleanUp() {
net::ShutdownNSSHttpIO();
#endif
+#if defined(OS_ANDROID)
+ net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
+#endif
+
system_url_request_context_getter_ = NULL;
// Unlink the ct_tree_tracker_ from the global cert_transparency_verifier
// and unregister it from new STH notifications so it will take no actions
// on anything observed during CleanUp process.
- //
- // Null checks are just for tests that use TestingIOThreadState.
- if (globals()->cert_transparency_verifier)
- globals()->cert_transparency_verifier->SetObserver(nullptr);
- if (ct_tree_tracker_.get()) {
- UnregisterSTHObserver(ct_tree_tracker_.get());
- ct_tree_tracker_.reset();
- }
+ globals()->cert_transparency_verifier->SetObserver(nullptr);
+ UnregisterSTHObserver(ct_tree_tracker_.get());
+
+ ct_tree_tracker_.reset();
// Release objects that the net::URLRequestContext could have been pointing
// to.
@@ -819,9 +836,8 @@ const net::HttpNetworkSession::Params& IOThread::NetworkSessionParams() const {
void IOThread::DisableQuic() {
params_.enable_quic = false;
- if (globals_->system_request_context_storage)
- globals_->system_request_context_storage->http_network_session()
- ->DisableQuic();
+ if (globals_->system_http_network_session)
+ globals_->system_http_network_session->DisableQuic();
if (globals_->proxy_script_fetcher_http_network_session)
globals_->proxy_script_fetcher_http_network_session->DisableQuic();
@@ -843,6 +859,41 @@ void IOThread::ChangedToOnTheRecordOnIOThread() {
ClearHostCache(base::Callback<bool(const std::string&)>());
}
+void IOThread::InitSystemRequestContext() {
+ if (system_url_request_context_getter_.get())
+ return;
+ // If we're in unit_tests, IOThread may not be run.
+ if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
+ return;
+ system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
+ pref_proxy_config_tracker_.get());
+ system_url_request_context_getter_ =
+ new SystemURLRequestContextGetter(this);
+ // Safe to post an unretained this pointer, since IOThread is
+ // guaranteed to outlive the IO BrowserThread.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(&IOThread::InitSystemRequestContextOnIOThread,
+ base::Unretained(this)));
+}
+
+void IOThread::InitSystemRequestContextOnIOThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(!globals_->system_proxy_service.get());
+ DCHECK(system_proxy_config_service_.get());
+
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+ globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
+ net_log_, globals_->proxy_script_fetcher_context.get(),
+ globals_->system_network_delegate.get(),
+ std::move(system_proxy_config_service_), command_line,
+ WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
+
+ globals_->system_request_context.reset(
+ ConstructSystemRequestContext(globals_, params_, net_log_));
+}
+
void IOThread::UpdateDnsClientEnabled() {
globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
}
@@ -863,77 +914,58 @@ bool IOThread::PacHttpsUrlStrippingEnabled() const {
return pac_https_url_stripping_enabled_.GetValue();
}
-void IOThread::ConstructSystemRequestContext() {
- globals_->system_request_context =
- base::MakeUnique<SystemURLRequestContext>();
- net::URLRequestContext* context = globals_->system_request_context.get();
- globals_->system_request_context_storage =
- base::MakeUnique<net::URLRequestContextStorage>(context);
- net::URLRequestContextStorage* context_storage =
- globals_->system_request_context_storage.get();
+// static
+net::URLRequestContext* IOThread::ConstructSystemRequestContext(
+ IOThread::Globals* globals,
+ const net::HttpNetworkSession::Params& params,
+ net::NetLog* net_log) {
+ net::URLRequestContext* context = new SystemURLRequestContext;
context->set_network_quality_estimator(
- globals_->network_quality_estimator.get());
- context->set_enable_brotli(globals_->enable_brotli);
+ globals->network_quality_estimator.get());
+ context->set_enable_brotli(globals->enable_brotli);
context->set_name("system");
context->set_http_user_agent_settings(
- globals_->http_user_agent_settings.get());
- context->set_network_delegate(globals_->system_network_delegate.get());
- context->set_net_log(net_log_);
- context->set_host_resolver(globals_->host_resolver.get());
-
- context->set_ssl_config_service(globals_->ssl_config_service.get());
+ globals->http_user_agent_settings.get());
+ context->set_network_delegate(globals->system_network_delegate.get());
+ context->set_net_log(net_log);
+ context->set_host_resolver(globals->host_resolver.get());
+ context->set_proxy_service(globals->system_proxy_service.get());
+ context->set_ssl_config_service(globals->ssl_config_service.get());
context->set_http_auth_handler_factory(
- globals_->http_auth_handler_factory.get());
-
- // In-memory cookie store.
- context_storage->set_cookie_store(
- content::CreateCookieStore(content::CookieStoreConfig()));
- // In-memory channel ID store.
- context_storage->set_channel_id_service(
- base::MakeUnique<net::ChannelIDService>(
- new net::DefaultChannelIDStore(nullptr)));
- context->cookie_store()->SetChannelIDServiceID(
- context->channel_id_service()->GetUniqueID());
+ globals->http_auth_handler_factory.get());
+ context->set_cookie_store(globals->system_cookie_store.get());
+ context->set_channel_id_service(
+ globals->system_channel_id_service.get());
context->set_transport_security_state(
- globals_->transport_security_state.get());
+ globals->transport_security_state.get());
- context->set_http_server_properties(globals_->http_server_properties.get());
+ context->set_http_server_properties(globals->http_server_properties.get());
- context->set_cert_verifier(globals_->cert_verifier.get());
+ context->set_cert_verifier(globals->cert_verifier.get());
context->set_cert_transparency_verifier(
- globals_->cert_transparency_verifier.get());
- context->set_ct_policy_enforcer(globals_->ct_policy_enforcer.get());
-
- TRACE_EVENT_BEGIN0("startup",
- "IOThread::Init:ProxyScriptFetcherRequestContext");
- globals_->proxy_script_fetcher_context.reset(
- ConstructProxyScriptFetcherContext(globals_, params_, net_log_));
- TRACE_EVENT_END0("startup",
- "IOThread::Init:ProxyScriptFetcherRequestContext");
-
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
- context_storage->set_proxy_service(ProxyServiceFactory::CreateProxyService(
- net_log_, globals_->proxy_script_fetcher_context.get(),
- globals_->system_network_delegate.get(),
- std::move(system_proxy_config_service_), command_line,
- WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled()));
+ globals->cert_transparency_verifier.get());
+ context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get());
- net::HttpNetworkSession::Params system_params(params_);
+ net::HttpNetworkSession::Params system_params(params);
net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
context, &system_params);
- context_storage->set_http_network_session(
- base::MakeUnique<net::HttpNetworkSession>(system_params));
- context_storage->set_http_transaction_factory(
- base::MakeUnique<net::HttpNetworkLayer>(
- context_storage->http_network_session()));
+ globals->system_http_network_session.reset(
+ new net::HttpNetworkSession(system_params));
+ globals->system_http_transaction_factory.reset(
+ new net::HttpNetworkLayer(globals->system_http_network_session.get()));
- context_storage->set_job_factory(
- base::MakeUnique<net::URLRequestJobFactoryImpl>());
+ context->set_http_transaction_factory(
+ globals->system_http_transaction_factory.get());
+
+ globals->system_url_request_job_factory.reset(
+ new net::URLRequestJobFactoryImpl());
+ context->set_job_factory(globals->system_url_request_job_factory.get());
+
+ return context;
}
// static
@@ -1052,9 +1084,9 @@ net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext(
context->set_job_factory(
globals->proxy_script_fetcher_url_request_job_factory.get());
- context->set_cookie_store(globals->system_request_context->cookie_store());
+ context->set_cookie_store(globals->system_cookie_store.get());
context->set_channel_id_service(
- globals->system_request_context->channel_id_service());
+ globals->system_channel_id_service.get());
context->set_network_delegate(globals->system_network_delegate.get());
context->set_http_user_agent_settings(
globals->http_user_agent_settings.get());
« no previous file with comments | « chrome/browser/io_thread.h ('k') | chrome/test/base/testing_io_thread_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698