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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 2860033003: Don't delay creation of system URLRequestContext until first use (Closed)
Patch Set: Remove comment Created 3 years, 7 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 net::CreateCertNetFetcher(this)); 196 net::CreateCertNetFetcher(this));
197 #endif 197 #endif
198 } 198 }
199 199
200 private: 200 private:
201 ~SystemURLRequestContext() override { 201 ~SystemURLRequestContext() override {
202 AssertNoURLRequests(); 202 AssertNoURLRequests();
203 #if defined(USE_NSS_CERTS) 203 #if defined(USE_NSS_CERTS)
204 net::SetURLRequestContextForNSSHttpIO(NULL); 204 net::SetURLRequestContextForNSSHttpIO(NULL);
205 #endif 205 #endif
206
207 #if defined(OS_ANDROID)
208 net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
209 #endif
206 } 210 }
207 }; 211 };
208 212
209 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver( 213 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
210 net::NetLog* net_log) { 214 net::NetLog* net_log) {
211 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); 215 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
212 const base::CommandLine& command_line = 216 const base::CommandLine& command_line =
213 *base::CommandLine::ForCurrentProcess(); 217 *base::CommandLine::ForCurrentProcess();
214 218
215 net::HostResolver::Options options; 219 net::HostResolver::Options options;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 393 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
390 #endif 394 #endif
391 #if defined(OS_CHROMEOS) 395 #if defined(OS_CHROMEOS)
392 policy::BrowserPolicyConnectorChromeOS* connector = 396 policy::BrowserPolicyConnectorChromeOS* connector =
393 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 397 g_browser_process->platform_part()->browser_policy_connector_chromeos();
394 allow_gssapi_library_load_ = connector->IsActiveDirectoryManaged(); 398 allow_gssapi_library_load_ = connector->IsActiveDirectoryManaged();
395 #endif 399 #endif
396 pref_proxy_config_tracker_.reset( 400 pref_proxy_config_tracker_.reset(
397 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 401 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
398 local_state)); 402 local_state));
403 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
404 pref_proxy_config_tracker_.get());
399 ChromeNetworkDelegate::InitializePrefsOnUIThread( 405 ChromeNetworkDelegate::InitializePrefsOnUIThread(
400 &system_enable_referrers_, 406 &system_enable_referrers_,
401 nullptr, 407 nullptr,
402 nullptr, 408 nullptr,
403 nullptr, 409 nullptr,
404 nullptr, 410 nullptr,
405 local_state); 411 local_state);
406 ssl_config_service_manager_.reset( 412 ssl_config_service_manager_.reset(
407 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 413 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
408 local_state, 414 local_state,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 DCHECK_CURRENTLY_ON(BrowserThread::UI); 486 DCHECK_CURRENTLY_ON(BrowserThread::UI);
481 BrowserThread::PostTask( 487 BrowserThread::PostTask(
482 BrowserThread::IO, FROM_HERE, 488 BrowserThread::IO, FROM_HERE,
483 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread, 489 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread,
484 base::Unretained(this))); 490 base::Unretained(this)));
485 } 491 }
486 492
487 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 493 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
488 DCHECK_CURRENTLY_ON(BrowserThread::UI); 494 DCHECK_CURRENTLY_ON(BrowserThread::UI);
489 if (!system_url_request_context_getter_.get()) { 495 if (!system_url_request_context_getter_.get()) {
490 InitSystemRequestContext(); 496 system_url_request_context_getter_ =
497 new SystemURLRequestContextGetter(this);
491 } 498 }
492 return system_url_request_context_getter_.get(); 499 return system_url_request_context_getter_.get();
493 } 500 }
494 501
495 void IOThread::Init() { 502 void IOThread::Init() {
496 TRACE_EVENT0("startup", "IOThread::InitAsync"); 503 TRACE_EVENT0("startup", "IOThread::InitAsync");
497 DCHECK_CURRENTLY_ON(BrowserThread::IO); 504 DCHECK_CURRENTLY_ON(BrowserThread::IO);
498 505
499 #if defined(USE_NSS_CERTS) 506 #if defined(USE_NSS_CERTS)
500 net::SetMessageLoopForNSSHttpIO(); 507 net::SetMessageLoopForNSSHttpIO();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 "IOThread::Init:ProxyScriptFetcherRequestContext"); 683 "IOThread::Init:ProxyScriptFetcherRequestContext");
677 684
678 #if defined(OS_MACOSX) 685 #if defined(OS_MACOSX)
679 // Start observing Keychain events. This needs to be done on the UI thread, 686 // Start observing Keychain events. This needs to be done on the UI thread,
680 // as Keychain services requires a CFRunLoop. 687 // as Keychain services requires a CFRunLoop.
681 BrowserThread::PostTask(BrowserThread::UI, 688 BrowserThread::PostTask(BrowserThread::UI,
682 FROM_HERE, 689 FROM_HERE,
683 base::Bind(&ObserveKeychainEvents)); 690 base::Bind(&ObserveKeychainEvents));
684 #endif 691 #endif
685 692
686 // InitSystemRequestContext turns right around and posts a task back
687 // to the IO thread, so we can't let it run until we know the IO
688 // thread has started.
689 //
690 // Note that since we are at BrowserThread::Init time, the UI thread
691 // is blocked waiting for the thread to start. Therefore, posting
692 // this task to the main thread's message loop here is guaranteed to
693 // get it onto the message loop while the IOThread object still
694 // exists. However, the message might not be processed on the UI
695 // thread until after IOThread is gone, so use a weak pointer.
696 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
697 base::BindOnce(&IOThread::InitSystemRequestContext,
698 weak_factory_.GetWeakPtr()));
699
700 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) 693 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
701 // Record how common CPUs with broken NEON units are. See 694 // Record how common CPUs with broken NEON units are. See
702 // https://crbug.com/341598. 695 // https://crbug.com/341598.
703 crypto::EnsureOpenSSLInit(); 696 crypto::EnsureOpenSSLInit();
704 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON()); 697 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON());
705 #endif 698 #endif
699
700 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
701 net_log_, globals_->proxy_script_fetcher_context.get(),
702 globals_->system_network_delegate.get(),
703 std::move(system_proxy_config_service_), command_line,
704 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
705
706 globals_->system_request_context.reset(
707 ConstructSystemRequestContext(globals_, params_, net_log_));
706 } 708 }
707 709
708 void IOThread::CleanUp() { 710 void IOThread::CleanUp() {
709 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); 711 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
710 712
711 #if defined(USE_NSS_CERTS) 713 #if defined(USE_NSS_CERTS)
712 net::ShutdownNSSHttpIO(); 714 net::ShutdownNSSHttpIO();
713 #endif 715 #endif
714 716
715 #if defined(OS_ANDROID)
716 net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
717 #endif
718
719 system_url_request_context_getter_ = NULL; 717 system_url_request_context_getter_ = NULL;
720 718
721 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier 719 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier
722 // and unregister it from new STH notifications so it will take no actions 720 // and unregister it from new STH notifications so it will take no actions
723 // on anything observed during CleanUp process. 721 // on anything observed during CleanUp process.
724 globals()->cert_transparency_verifier->SetObserver(nullptr); 722 //
725 UnregisterSTHObserver(ct_tree_tracker_.get()); 723 // Null checks are just for tests that use TestingIOThreadState.
726 724 if (globals()->cert_transparency_verifier)
727 ct_tree_tracker_.reset(); 725 globals()->cert_transparency_verifier->SetObserver(nullptr);
726 if (ct_tree_tracker_.get()) {
727 UnregisterSTHObserver(ct_tree_tracker_.get());
728 ct_tree_tracker_.reset();
729 }
728 730
729 // Release objects that the net::URLRequestContext could have been pointing 731 // Release objects that the net::URLRequestContext could have been pointing
730 // to. 732 // to.
731 733
732 // Shutdown the HistogramWatcher on the IO thread. 734 // Shutdown the HistogramWatcher on the IO thread.
733 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); 735 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
734 736
735 // This must be reset before the ChromeNetLog is destroyed. 737 // This must be reset before the ChromeNetLog is destroyed.
736 network_change_observer_.reset(); 738 network_change_observer_.reset();
737 739
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 848 }
847 849
848 void IOThread::ChangedToOnTheRecordOnIOThread() { 850 void IOThread::ChangedToOnTheRecordOnIOThread() {
849 DCHECK_CURRENTLY_ON(BrowserThread::IO); 851 DCHECK_CURRENTLY_ON(BrowserThread::IO);
850 852
851 // Clear the host cache to avoid showing entries from the OTR session 853 // Clear the host cache to avoid showing entries from the OTR session
852 // in about:net-internals. 854 // in about:net-internals.
853 ClearHostCache(base::Callback<bool(const std::string&)>()); 855 ClearHostCache(base::Callback<bool(const std::string&)>());
854 } 856 }
855 857
856 void IOThread::InitSystemRequestContext() {
857 if (system_url_request_context_getter_.get())
858 return;
859 // If we're in unit_tests, IOThread may not be run.
860 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
861 return;
862 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
863 pref_proxy_config_tracker_.get());
864 system_url_request_context_getter_ =
865 new SystemURLRequestContextGetter(this);
866 // Safe to post an unretained this pointer, since IOThread is
867 // guaranteed to outlive the IO BrowserThread.
868 BrowserThread::PostTask(
869 BrowserThread::IO, FROM_HERE,
870 base::BindOnce(&IOThread::InitSystemRequestContextOnIOThread,
871 base::Unretained(this)));
872 }
873
874 void IOThread::InitSystemRequestContextOnIOThread() {
875 DCHECK_CURRENTLY_ON(BrowserThread::IO);
876 DCHECK(!globals_->system_proxy_service.get());
877 DCHECK(system_proxy_config_service_.get());
878
879 const base::CommandLine& command_line =
880 *base::CommandLine::ForCurrentProcess();
881 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
882 net_log_, globals_->proxy_script_fetcher_context.get(),
883 globals_->system_network_delegate.get(),
884 std::move(system_proxy_config_service_), command_line,
885 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
886
887 globals_->system_request_context.reset(
888 ConstructSystemRequestContext(globals_, params_, net_log_));
889 }
890
891 void IOThread::UpdateDnsClientEnabled() { 858 void IOThread::UpdateDnsClientEnabled() {
892 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); 859 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
893 } 860 }
894 861
895 void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) { 862 void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) {
896 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer); 863 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer);
897 } 864 }
898 865
899 void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) { 866 void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) {
900 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer); 867 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 1092
1126 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 1093 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1127 // system URLRequestContext too. There's no reason this should be tied to a 1094 // system URLRequestContext too. There's no reason this should be tied to a
1128 // profile. 1095 // profile.
1129 return context; 1096 return context;
1130 } 1097 }
1131 1098
1132 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() { 1099 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() {
1133 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread); 1100 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread);
1134 } 1101 }
OLDNEW
« 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