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

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

Issue 2860033003: Don't delay creation of system URLRequestContext until first use (Closed)
Patch Set: Fix android 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
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 net::CreateCertNetFetcher(this)); 195 net::CreateCertNetFetcher(this));
196 #endif 196 #endif
197 } 197 }
198 198
199 private: 199 private:
200 ~SystemURLRequestContext() override { 200 ~SystemURLRequestContext() override {
201 AssertNoURLRequests(); 201 AssertNoURLRequests();
202 #if defined(USE_NSS_CERTS) 202 #if defined(USE_NSS_CERTS)
203 net::SetURLRequestContextForNSSHttpIO(NULL); 203 net::SetURLRequestContextForNSSHttpIO(NULL);
204 #endif 204 #endif
205
206 #if defined(OS_ANDROID)
207 net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
208 #endif
205 } 209 }
206 }; 210 };
207 211
208 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver( 212 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
209 net::NetLog* net_log) { 213 net::NetLog* net_log) {
210 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); 214 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
211 const base::CommandLine& command_line = 215 const base::CommandLine& command_line =
212 *base::CommandLine::ForCurrentProcess(); 216 *base::CommandLine::ForCurrentProcess();
213 217
214 net::HostResolver::Options options; 218 net::HostResolver::Options options;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType, 387 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType,
384 base::Unretained(this))); 388 base::Unretained(this)));
385 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy); 389 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy);
386 #endif 390 #endif
387 #if defined(OS_POSIX) && !defined(OS_ANDROID) 391 #if defined(OS_POSIX) && !defined(OS_ANDROID)
388 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 392 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
389 #endif 393 #endif
390 pref_proxy_config_tracker_.reset( 394 pref_proxy_config_tracker_.reset(
391 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 395 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
392 local_state)); 396 local_state));
397 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
398 pref_proxy_config_tracker_.get());
393 ChromeNetworkDelegate::InitializePrefsOnUIThread( 399 ChromeNetworkDelegate::InitializePrefsOnUIThread(
394 &system_enable_referrers_, 400 &system_enable_referrers_,
395 nullptr, 401 nullptr,
396 nullptr, 402 nullptr,
397 nullptr, 403 nullptr,
398 nullptr, 404 nullptr,
399 local_state); 405 local_state);
400 ssl_config_service_manager_.reset( 406 ssl_config_service_manager_.reset(
401 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 407 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
402 local_state, 408 local_state,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 DCHECK_CURRENTLY_ON(BrowserThread::UI); 480 DCHECK_CURRENTLY_ON(BrowserThread::UI);
475 BrowserThread::PostTask( 481 BrowserThread::PostTask(
476 BrowserThread::IO, FROM_HERE, 482 BrowserThread::IO, FROM_HERE,
477 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread, 483 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread,
478 base::Unretained(this))); 484 base::Unretained(this)));
479 } 485 }
480 486
481 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 487 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
482 DCHECK_CURRENTLY_ON(BrowserThread::UI); 488 DCHECK_CURRENTLY_ON(BrowserThread::UI);
483 if (!system_url_request_context_getter_.get()) { 489 if (!system_url_request_context_getter_.get()) {
484 InitSystemRequestContext(); 490 system_url_request_context_getter_ =
491 new SystemURLRequestContextGetter(this);
485 } 492 }
486 return system_url_request_context_getter_.get(); 493 return system_url_request_context_getter_.get();
487 } 494 }
488 495
489 void IOThread::Init() { 496 void IOThread::Init() {
490 TRACE_EVENT0("startup", "IOThread::InitAsync"); 497 TRACE_EVENT0("startup", "IOThread::InitAsync");
491 DCHECK_CURRENTLY_ON(BrowserThread::IO); 498 DCHECK_CURRENTLY_ON(BrowserThread::IO);
492 499
493 #if defined(USE_NSS_CERTS) 500 #if defined(USE_NSS_CERTS)
494 net::SetMessageLoopForNSSHttpIO(); 501 net::SetMessageLoopForNSSHttpIO();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 "IOThread::Init:ProxyScriptFetcherRequestContext"); 675 "IOThread::Init:ProxyScriptFetcherRequestContext");
669 676
670 #if defined(OS_MACOSX) 677 #if defined(OS_MACOSX)
671 // Start observing Keychain events. This needs to be done on the UI thread, 678 // Start observing Keychain events. This needs to be done on the UI thread,
672 // as Keychain services requires a CFRunLoop. 679 // as Keychain services requires a CFRunLoop.
673 BrowserThread::PostTask(BrowserThread::UI, 680 BrowserThread::PostTask(BrowserThread::UI,
674 FROM_HERE, 681 FROM_HERE,
675 base::Bind(&ObserveKeychainEvents)); 682 base::Bind(&ObserveKeychainEvents));
676 #endif 683 #endif
677 684
678 // InitSystemRequestContext turns right around and posts a task back
679 // to the IO thread, so we can't let it run until we know the IO
680 // thread has started.
681 //
682 // Note that since we are at BrowserThread::Init time, the UI thread
683 // is blocked waiting for the thread to start. Therefore, posting
684 // this task to the main thread's message loop here is guaranteed to
685 // get it onto the message loop while the IOThread object still
686 // exists. However, the message might not be processed on the UI
687 // thread until after IOThread is gone, so use a weak pointer.
688 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
689 base::BindOnce(&IOThread::InitSystemRequestContext,
690 weak_factory_.GetWeakPtr()));
691
692 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) 685 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
693 // Record how common CPUs with broken NEON units are. See 686 // Record how common CPUs with broken NEON units are. See
694 // https://crbug.com/341598. 687 // https://crbug.com/341598.
695 crypto::EnsureOpenSSLInit(); 688 crypto::EnsureOpenSSLInit();
696 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON()); 689 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON());
697 #endif 690 #endif
691
692 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
693 net_log_, globals_->proxy_script_fetcher_context.get(),
694 globals_->system_network_delegate.get(),
695 std::move(system_proxy_config_service_), command_line,
696 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
697
698 globals_->system_request_context.reset(
699 ConstructSystemRequestContext(globals_, params_, net_log_));
698 } 700 }
699 701
700 void IOThread::CleanUp() { 702 void IOThread::CleanUp() {
701 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); 703 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
702 704
703 #if defined(USE_NSS_CERTS) 705 #if defined(USE_NSS_CERTS)
704 net::ShutdownNSSHttpIO(); 706 net::ShutdownNSSHttpIO();
705 #endif 707 #endif
706 708
707 #if defined(OS_ANDROID)
708 net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
709 #endif
710
711 system_url_request_context_getter_ = NULL; 709 system_url_request_context_getter_ = NULL;
712 710
713 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier 711 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier
714 // and unregister it from new STH notifications so it will take no actions 712 // and unregister it from new STH notifications so it will take no actions
715 // on anything observed during CleanUp process. 713 // on anything observed during CleanUp process.
716 globals()->cert_transparency_verifier->SetObserver(nullptr); 714 //
717 UnregisterSTHObserver(ct_tree_tracker_.get()); 715 // Null checks are just for tests that use TestingIOThreadState.
718 716 if (globals()->cert_transparency_verifier)
719 ct_tree_tracker_.reset(); 717 globals()->cert_transparency_verifier->SetObserver(nullptr);
718 if (ct_tree_tracker_.get()) {
719 UnregisterSTHObserver(ct_tree_tracker_.get());
720 ct_tree_tracker_.reset();
721 }
720 722
721 // Release objects that the net::URLRequestContext could have been pointing 723 // Release objects that the net::URLRequestContext could have been pointing
722 // to. 724 // to.
723 725
724 // Shutdown the HistogramWatcher on the IO thread. 726 // Shutdown the HistogramWatcher on the IO thread.
725 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); 727 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
726 728
727 // This must be reset before the ChromeNetLog is destroyed. 729 // This must be reset before the ChromeNetLog is destroyed.
728 network_change_observer_.reset(); 730 network_change_observer_.reset();
729 731
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 836 }
835 837
836 void IOThread::ChangedToOnTheRecordOnIOThread() { 838 void IOThread::ChangedToOnTheRecordOnIOThread() {
837 DCHECK_CURRENTLY_ON(BrowserThread::IO); 839 DCHECK_CURRENTLY_ON(BrowserThread::IO);
838 840
839 // Clear the host cache to avoid showing entries from the OTR session 841 // Clear the host cache to avoid showing entries from the OTR session
840 // in about:net-internals. 842 // in about:net-internals.
841 ClearHostCache(base::Callback<bool(const std::string&)>()); 843 ClearHostCache(base::Callback<bool(const std::string&)>());
842 } 844 }
843 845
844 void IOThread::InitSystemRequestContext() {
845 if (system_url_request_context_getter_.get())
846 return;
847 // If we're in unit_tests, IOThread may not be run.
848 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
849 return;
850 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
851 pref_proxy_config_tracker_.get());
852 system_url_request_context_getter_ =
853 new SystemURLRequestContextGetter(this);
854 // Safe to post an unretained this pointer, since IOThread is
855 // guaranteed to outlive the IO BrowserThread.
856 BrowserThread::PostTask(
857 BrowserThread::IO, FROM_HERE,
858 base::BindOnce(&IOThread::InitSystemRequestContextOnIOThread,
859 base::Unretained(this)));
860 }
861
862 void IOThread::InitSystemRequestContextOnIOThread() {
863 DCHECK_CURRENTLY_ON(BrowserThread::IO);
864 DCHECK(!globals_->system_proxy_service.get());
865 DCHECK(system_proxy_config_service_.get());
866
867 const base::CommandLine& command_line =
868 *base::CommandLine::ForCurrentProcess();
869 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
870 net_log_, globals_->proxy_script_fetcher_context.get(),
871 globals_->system_network_delegate.get(),
872 std::move(system_proxy_config_service_), command_line,
873 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
874
875 globals_->system_request_context.reset(
876 ConstructSystemRequestContext(globals_, params_, net_log_));
877 }
878
879 void IOThread::UpdateDnsClientEnabled() { 846 void IOThread::UpdateDnsClientEnabled() {
880 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); 847 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
881 } 848 }
882 849
883 void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) { 850 void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) {
884 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer); 851 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer);
885 } 852 }
886 853
887 void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) { 854 void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) {
888 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer); 855 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 1080
1114 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 1081 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1115 // system URLRequestContext too. There's no reason this should be tied to a 1082 // system URLRequestContext too. There's no reason this should be tied to a
1116 // profile. 1083 // profile.
1117 return context; 1084 return context;
1118 } 1085 }
1119 1086
1120 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() { 1087 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() {
1121 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread); 1088 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread);
1122 } 1089 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698