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

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 testing_io_thread_state.h (Again) 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType, 383 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType,
384 base::Unretained(this))); 384 base::Unretained(this)));
385 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy); 385 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy);
386 #endif 386 #endif
387 #if defined(OS_POSIX) && !defined(OS_ANDROID) 387 #if defined(OS_POSIX) && !defined(OS_ANDROID)
388 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 388 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
389 #endif 389 #endif
390 pref_proxy_config_tracker_.reset( 390 pref_proxy_config_tracker_.reset(
391 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 391 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
392 local_state)); 392 local_state));
393 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
394 pref_proxy_config_tracker_.get());
393 ChromeNetworkDelegate::InitializePrefsOnUIThread( 395 ChromeNetworkDelegate::InitializePrefsOnUIThread(
394 &system_enable_referrers_, 396 &system_enable_referrers_,
395 nullptr, 397 nullptr,
396 nullptr, 398 nullptr,
397 nullptr, 399 nullptr,
398 nullptr, 400 nullptr,
399 local_state); 401 local_state);
400 ssl_config_service_manager_.reset( 402 ssl_config_service_manager_.reset(
401 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 403 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
402 local_state, 404 local_state,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 DCHECK_CURRENTLY_ON(BrowserThread::UI); 476 DCHECK_CURRENTLY_ON(BrowserThread::UI);
475 BrowserThread::PostTask( 477 BrowserThread::PostTask(
476 BrowserThread::IO, FROM_HERE, 478 BrowserThread::IO, FROM_HERE,
477 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread, 479 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread,
478 base::Unretained(this))); 480 base::Unretained(this)));
479 } 481 }
480 482
481 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 483 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
482 DCHECK_CURRENTLY_ON(BrowserThread::UI); 484 DCHECK_CURRENTLY_ON(BrowserThread::UI);
483 if (!system_url_request_context_getter_.get()) { 485 if (!system_url_request_context_getter_.get()) {
484 InitSystemRequestContext(); 486 system_url_request_context_getter_ =
487 new SystemURLRequestContextGetter(this);
485 } 488 }
486 return system_url_request_context_getter_.get(); 489 return system_url_request_context_getter_.get();
487 } 490 }
488 491
489 void IOThread::Init() { 492 void IOThread::Init() {
490 TRACE_EVENT0("startup", "IOThread::InitAsync"); 493 TRACE_EVENT0("startup", "IOThread::InitAsync");
491 DCHECK_CURRENTLY_ON(BrowserThread::IO); 494 DCHECK_CURRENTLY_ON(BrowserThread::IO);
492 495
493 #if defined(USE_NSS_CERTS) 496 #if defined(USE_NSS_CERTS)
494 net::SetMessageLoopForNSSHttpIO(); 497 net::SetMessageLoopForNSSHttpIO();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 "IOThread::Init:ProxyScriptFetcherRequestContext"); 671 "IOThread::Init:ProxyScriptFetcherRequestContext");
669 672
670 #if defined(OS_MACOSX) 673 #if defined(OS_MACOSX)
671 // Start observing Keychain events. This needs to be done on the UI thread, 674 // Start observing Keychain events. This needs to be done on the UI thread,
672 // as Keychain services requires a CFRunLoop. 675 // as Keychain services requires a CFRunLoop.
673 BrowserThread::PostTask(BrowserThread::UI, 676 BrowserThread::PostTask(BrowserThread::UI,
674 FROM_HERE, 677 FROM_HERE,
675 base::Bind(&ObserveKeychainEvents)); 678 base::Bind(&ObserveKeychainEvents));
676 #endif 679 #endif
677 680
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) 681 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
693 // Record how common CPUs with broken NEON units are. See 682 // Record how common CPUs with broken NEON units are. See
694 // https://crbug.com/341598. 683 // https://crbug.com/341598.
695 crypto::EnsureOpenSSLInit(); 684 crypto::EnsureOpenSSLInit();
696 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON()); 685 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON());
697 #endif 686 #endif
687
688 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
689 net_log_, globals_->proxy_script_fetcher_context.get(),
690 globals_->system_network_delegate.get(),
691 std::move(system_proxy_config_service_), command_line,
692 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
693
694 globals_->system_request_context.reset(
695 ConstructSystemRequestContext(globals_, params_, net_log_));
698 } 696 }
699 697
700 void IOThread::CleanUp() { 698 void IOThread::CleanUp() {
701 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); 699 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
702 700
703 #if defined(USE_NSS_CERTS) 701 #if defined(USE_NSS_CERTS)
704 net::ShutdownNSSHttpIO(); 702 net::ShutdownNSSHttpIO();
705 #endif 703 #endif
706 704
707 #if defined(OS_ANDROID) 705 #if defined(OS_ANDROID)
708 net::CertVerifyProcAndroid::ShutdownCertNetFetcher(); 706 net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
709 #endif 707 #endif
710 708
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