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

Side by Side Diff: chrome/browser/profiles/profile_io_data.cc

Issue 2978443002: Make ProfileIOData use URLRequestContextBuilder (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 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/profiles/profile_io_data.h" 5 #include "chrome/browser/profiles/profile_io_data.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 #include "net/ssl/channel_id_service.h" 99 #include "net/ssl/channel_id_service.h"
100 #include "net/ssl/client_cert_store.h" 100 #include "net/ssl/client_cert_store.h"
101 #include "net/traffic_annotation/network_traffic_annotation.h" 101 #include "net/traffic_annotation/network_traffic_annotation.h"
102 #include "net/url_request/data_protocol_handler.h" 102 #include "net/url_request/data_protocol_handler.h"
103 #include "net/url_request/file_protocol_handler.h" 103 #include "net/url_request/file_protocol_handler.h"
104 #include "net/url_request/ftp_protocol_handler.h" 104 #include "net/url_request/ftp_protocol_handler.h"
105 #include "net/url_request/report_sender.h" 105 #include "net/url_request/report_sender.h"
106 #include "net/url_request/url_request.h" 106 #include "net/url_request/url_request.h"
107 #include "net/url_request/url_request_context.h" 107 #include "net/url_request/url_request_context.h"
108 #include "net/url_request/url_request_context_builder.h" 108 #include "net/url_request/url_request_context_builder.h"
109 #include "net/url_request/url_request_context_builder_mojo.h"
109 #include "net/url_request/url_request_context_storage.h" 110 #include "net/url_request/url_request_context_storage.h"
110 #include "net/url_request/url_request_file_job.h" 111 #include "net/url_request/url_request_file_job.h"
111 #include "net/url_request/url_request_intercepting_job_factory.h" 112 #include "net/url_request/url_request_intercepting_job_factory.h"
112 #include "net/url_request/url_request_interceptor.h" 113 #include "net/url_request/url_request_interceptor.h"
113 #include "net/url_request/url_request_job_factory_impl.h" 114 #include "net/url_request/url_request_job_factory_impl.h"
114 #include "third_party/WebKit/public/public_features.h" 115 #include "third_party/WebKit/public/public_features.h"
115 116
116 #if BUILDFLAG(ENABLE_EXTENSIONS) 117 #if BUILDFLAG(ENABLE_EXTENSIONS)
117 #include "chrome/browser/extensions/extension_cookie_monster_delegate.h" 118 #include "chrome/browser/extensions/extension_cookie_monster_delegate.h"
118 #include "extensions/browser/extension_protocols.h" 119 #include "extensions/browser/extension_protocols.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // For safe shutdown, must be called before the ProfileIOData is destroyed. 363 // For safe shutdown, must be called before the ProfileIOData is destroyed.
363 void NotifyContextGettersOfShutdownOnIO( 364 void NotifyContextGettersOfShutdownOnIO(
364 std::unique_ptr<ProfileIOData::ChromeURLRequestContextGetterVector> 365 std::unique_ptr<ProfileIOData::ChromeURLRequestContextGetterVector>
365 getters) { 366 getters) {
366 DCHECK_CURRENTLY_ON(BrowserThread::IO); 367 DCHECK_CURRENTLY_ON(BrowserThread::IO);
367 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter; 368 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter;
368 for (auto& chrome_context_getter : *getters) 369 for (auto& chrome_context_getter : *getters)
369 chrome_context_getter->NotifyContextShuttingDown(); 370 chrome_context_getter->NotifyContextShuttingDown();
370 } 371 }
371 372
373 // Wraps |inner_job_factory| with |protocol_handler_interceptor|.
374 std::unique_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory(
375 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
376 protocol_handler_interceptor,
377 std::unique_ptr<net::URLRequestJobFactory> inner_job_factory) {
378 protocol_handler_interceptor->Chain(std::move(inner_job_factory));
379 return std::move(protocol_handler_interceptor);
380 }
381
372 } // namespace 382 } // namespace
373 383
374 void ProfileIOData::InitializeOnUIThread(Profile* profile) { 384 void ProfileIOData::InitializeOnUIThread(Profile* profile) {
375 DCHECK_CURRENTLY_ON(BrowserThread::UI); 385 DCHECK_CURRENTLY_ON(BrowserThread::UI);
376 PrefService* pref_service = profile->GetPrefs(); 386 PrefService* pref_service = profile->GetPrefs();
377 387
378 std::unique_ptr<ProfileParams> params(new ProfileParams); 388 std::unique_ptr<ProfileParams> params(new ProfileParams);
379 params->path = profile->GetPath(); 389 params->path = profile->GetPath();
380 390
381 params->io_thread = g_browser_process->io_thread(); 391 params->io_thread = g_browser_process->io_thread();
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 // since the former has a reference to the latter. 680 // since the former has a reference to the latter.
671 main_request_context_->transport_security_state()->SetReportSender(nullptr); 681 main_request_context_->transport_security_state()->SetReportSender(nullptr);
672 certificate_report_sender_.reset(); 682 certificate_report_sender_.reset();
673 683
674 main_request_context_->transport_security_state()->SetExpectCTReporter( 684 main_request_context_->transport_security_state()->SetExpectCTReporter(
675 nullptr); 685 nullptr);
676 expect_ct_reporter_.reset(); 686 expect_ct_reporter_.reset();
677 687
678 main_request_context_->transport_security_state()->SetRequireCTDelegate( 688 main_request_context_->transport_security_state()->SetRequireCTDelegate(
679 nullptr); 689 nullptr);
680
681 // And the same for the ReportingService.
682 main_request_context_storage()->set_reporting_service(
683 std::unique_ptr<net::ReportingService>());
684
685 // This should be shut down last, as any other requests may initiate more
686 // activity when the ProxyService aborts lookups.
687 main_request_context_->proxy_service()->OnShutdown();
688 } 690 }
689 691
690 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they 692 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
691 // are already done in the URLRequestContext destructor. 693 // are already done in the URLRequestContext destructor.
692 if (main_request_context_)
693 main_request_context_->AssertNoURLRequests();
694 if (extensions_request_context_) 694 if (extensions_request_context_)
695 extensions_request_context_->AssertNoURLRequests(); 695 extensions_request_context_->AssertNoURLRequests();
696 696
697 current_context = 0; 697 current_context = 0;
698 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); 698 for (URLRequestContextMap::iterator it = app_request_context_map_.begin();
699 it != app_request_context_map_.end(); ++it) { 699 it != app_request_context_map_.end(); ++it) {
700 if (current_context < kMaxCachedContexts) { 700 if (current_context < kMaxCachedContexts) {
701 CHECK_EQ(app_context_cache[current_context], it->second); 701 CHECK_EQ(app_context_cache[current_context], it->second);
702 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); 702 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*));
703 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); 703 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 it != protocol_handlers->end(); 780 it != protocol_handlers->end();
781 ++it) { 781 ++it) {
782 bool set_protocol = job_factory->SetProtocolHandler( 782 bool set_protocol = job_factory->SetProtocolHandler(
783 it->first, base::WrapUnique(it->second.release())); 783 it->first, base::WrapUnique(it->second.release()));
784 DCHECK(set_protocol); 784 DCHECK(set_protocol);
785 } 785 }
786 protocol_handlers->clear(); 786 protocol_handlers->clear();
787 } 787 }
788 788
789 // static 789 // static
790 void ProfileIOData::AddProtocolHandlersToBuilder(
791 net::URLRequestContextBuilder* builder,
792 content::ProtocolHandlerMap* protocol_handlers) {
793 for (auto& protocol_handler : *protocol_handlers) {
794 builder->SetProtocolHandler(
795 protocol_handler.first,
796 base::WrapUnique(protocol_handler.second.release()));
797 }
798 protocol_handlers->clear();
799 }
800
801 // static
790 void ProfileIOData::SetCertVerifierForTesting( 802 void ProfileIOData::SetCertVerifierForTesting(
791 net::CertVerifier* cert_verifier) { 803 net::CertVerifier* cert_verifier) {
792 g_cert_verifier_for_testing = cert_verifier; 804 g_cert_verifier_for_testing = cert_verifier;
793 } 805 }
794 806
795 content::ResourceContext* ProfileIOData::GetResourceContext() const { 807 content::ResourceContext* ProfileIOData::GetResourceContext() const {
796 return resource_context_.get(); 808 return resource_context_.get();
797 } 809 }
798 810
799 net::URLRequestContext* ProfileIOData::GetMainRequestContext() const { 811 net::URLRequestContext* ProfileIOData::GetMainRequestContext() const {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 #else 950 #else
939 #error Unknown platform. 951 #error Unknown platform.
940 #endif 952 #endif
941 } 953 }
942 954
943 void ProfileIOData::DisableQuicOnIOThread() { 955 void ProfileIOData::DisableQuicOnIOThread() {
944 // If the URLRequestContext has not been created yet, it will not be updated 956 // If the URLRequestContext has not been created yet, it will not be updated
945 // here. Instead, it will inherit its QUIC enablement from IOThread on 957 // here. Instead, it will inherit its QUIC enablement from IOThread on
946 // construction, which is fine, as NetHttpSessionParamsObserver also disables 958 // construction, which is fine, as NetHttpSessionParamsObserver also disables
947 // QUIC there. 959 // QUIC there.
948 if (!main_request_context_storage_ || 960 if (!main_request_context_)
949 !main_request_context_storage_->http_network_session())
950 return; 961 return;
951 962
952 main_request_context_storage_->http_network_session()->DisableQuic(); 963 main_request_context_->http_transaction_factory()
964 ->GetSession()
965 ->DisableQuic();
953 } 966 }
954 967
955 void ProfileIOData::set_data_reduction_proxy_io_data( 968 void ProfileIOData::set_data_reduction_proxy_io_data(
956 std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData> 969 std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData>
957 data_reduction_proxy_io_data) const { 970 data_reduction_proxy_io_data) const {
958 data_reduction_proxy_io_data_ = std::move(data_reduction_proxy_io_data); 971 data_reduction_proxy_io_data_ = std::move(data_reduction_proxy_io_data);
959 } 972 }
960 973
961 void ProfileIOData::set_previews_io_data( 974 void ProfileIOData::set_previews_io_data(
962 std::unique_ptr<previews::PreviewsIOData> previews_io_data) const { 975 std::unique_ptr<previews::PreviewsIOData> previews_io_data) const {
(...skipping 26 matching lines...) Expand all
989 content::URLRequestInterceptorScopedVector request_interceptors) const { 1002 content::URLRequestInterceptorScopedVector request_interceptors) const {
990 // The basic logic is implemented here. The specific initialization 1003 // The basic logic is implemented here. The specific initialization
991 // is done in InitializeInternal(), implemented by subtypes. Static helper 1004 // is done in InitializeInternal(), implemented by subtypes. Static helper
992 // functions have been provided to assist in common operations. 1005 // functions have been provided to assist in common operations.
993 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1006 DCHECK_CURRENTLY_ON(BrowserThread::IO);
994 DCHECK(!initialized_); 1007 DCHECK(!initialized_);
995 DCHECK(profile_params_.get()); 1008 DCHECK(profile_params_.get());
996 1009
997 IOThread* const io_thread = profile_params_->io_thread; 1010 IOThread* const io_thread = profile_params_->io_thread;
998 IOThread::Globals* const io_thread_globals = io_thread->globals(); 1011 IOThread::Globals* const io_thread_globals = io_thread->globals();
999 const base::CommandLine& command_line =
1000 *base::CommandLine::ForCurrentProcess();
1001 1012
1002 // Create extension request context. Only used for cookies. 1013 // Create extension request context. Only used for cookies.
1003 extensions_request_context_.reset(new net::URLRequestContext()); 1014 extensions_request_context_.reset(new net::URLRequestContext());
1004 extensions_request_context_->set_name("extensions"); 1015 extensions_request_context_->set_name("extensions");
1005 1016
1006 // Create the main request context. 1017 // Create the main request context.
1007 main_request_context_.reset(new net::URLRequestContext()); 1018 net::URLRequestContextBuilderMojo builder;
1008 main_request_context_storage_.reset( 1019 builder.set_name("main");
1009 new net::URLRequestContextStorage(main_request_context_.get()));
1010 main_request_context_->set_name("main");
1011 1020
1012 ApplyProfileParamsToContext(main_request_context_.get()); 1021 builder.set_net_log(io_thread->net_log());
1013 main_request_context_->set_net_log(io_thread->net_log()); 1022 builder.set_shared_http_user_agent_settings(
1023 chrome_http_user_agent_settings_.get());
1024 builder.set_ssl_config_service(profile_params_->ssl_config_service);
1014 1025
1015 main_request_context_->set_enable_brotli(io_thread_globals->enable_brotli); 1026 builder.set_enable_brotli(io_thread_globals->enable_brotli);
1016 1027
1017 std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate( 1028 std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate(
1018 new ChromeNetworkDelegate( 1029 new ChromeNetworkDelegate(
1019 #if BUILDFLAG(ENABLE_EXTENSIONS) 1030 #if BUILDFLAG(ENABLE_EXTENSIONS)
1020 io_thread_globals->extension_event_router_forwarder.get(), 1031 io_thread_globals->extension_event_router_forwarder.get(),
1021 #else 1032 #else
1022 NULL, 1033 NULL,
1023 #endif 1034 #endif
1024 &enable_referrers_)); 1035 &enable_referrers_));
1025 #if BUILDFLAG(ENABLE_EXTENSIONS) 1036 #if BUILDFLAG(ENABLE_EXTENSIONS)
1026 chrome_network_delegate->set_extension_info_map( 1037 chrome_network_delegate->set_extension_info_map(
1027 profile_params_->extension_info_map.get()); 1038 profile_params_->extension_info_map.get());
1028 if (!command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) { 1039 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1040 switches::kDisableExtensionsHttpThrottling)) {
1029 extension_throttle_manager_.reset( 1041 extension_throttle_manager_.reset(
1030 new extensions::ExtensionThrottleManager()); 1042 new extensions::ExtensionThrottleManager());
1031 } 1043 }
1032 #endif 1044 #endif
1033 1045
1034 chrome_network_delegate->set_url_blacklist_manager( 1046 chrome_network_delegate->set_url_blacklist_manager(
1035 url_blacklist_manager_.get()); 1047 url_blacklist_manager_.get());
1036 chrome_network_delegate->set_profile(profile_params_->profile); 1048 chrome_network_delegate->set_profile(profile_params_->profile);
1037 chrome_network_delegate->set_profile_path(profile_params_->path); 1049 chrome_network_delegate->set_profile_path(profile_params_->path);
1038 chrome_network_delegate->set_cookie_settings( 1050 chrome_network_delegate->set_cookie_settings(
1039 profile_params_->cookie_settings.get()); 1051 profile_params_->cookie_settings.get());
1040 chrome_network_delegate->set_enable_do_not_track(&enable_do_not_track_); 1052 chrome_network_delegate->set_enable_do_not_track(&enable_do_not_track_);
1041 chrome_network_delegate->set_force_google_safe_search( 1053 chrome_network_delegate->set_force_google_safe_search(
1042 &force_google_safesearch_); 1054 &force_google_safesearch_);
1043 chrome_network_delegate->set_force_youtube_restrict(&force_youtube_restrict_); 1055 chrome_network_delegate->set_force_youtube_restrict(&force_youtube_restrict_);
1044 chrome_network_delegate->set_allowed_domains_for_apps( 1056 chrome_network_delegate->set_allowed_domains_for_apps(
1045 &allowed_domains_for_apps_); 1057 &allowed_domains_for_apps_);
1046 chrome_network_delegate->set_data_use_aggregator( 1058 chrome_network_delegate->set_data_use_aggregator(
1047 io_thread_globals->data_use_aggregator.get(), IsOffTheRecord()); 1059 io_thread_globals->data_use_aggregator.get(), IsOffTheRecord());
1048 1060
1049 std::unique_ptr<net::NetworkDelegate> network_delegate = 1061 std::unique_ptr<net::NetworkDelegate> network_delegate =
1050 ConfigureNetworkDelegate(profile_params_->io_thread, 1062 ConfigureNetworkDelegate(profile_params_->io_thread,
1051 std::move(chrome_network_delegate)); 1063 std::move(chrome_network_delegate));
1052 1064
1053 main_request_context_->set_host_resolver( 1065 builder.set_shared_host_resolver(
1054 io_thread_globals->system_request_context->host_resolver()); 1066 io_thread_globals->system_request_context->host_resolver());
1055 1067
1056 main_request_context_->set_http_auth_handler_factory( 1068 builder.set_shared_http_auth_handler_factory(
1057 io_thread_globals->system_request_context->http_auth_handler_factory()); 1069 io_thread_globals->system_request_context->http_auth_handler_factory());
1058 1070
1059 main_request_context_storage_->set_proxy_service( 1071 io_thread->SetUpProxyConfigService(
1060 ProxyServiceFactory::CreateProxyService( 1072 &builder, std::move(profile_params_->proxy_config_service));
1061 io_thread->net_log(), main_request_context_.get(),
1062 network_delegate.get(),
1063 std::move(profile_params_->proxy_config_service), command_line,
1064 io_thread->WpadQuickCheckEnabled(),
1065 io_thread->PacHttpsUrlStrippingEnabled()));
1066 1073
1067 main_request_context_storage_->set_network_delegate( 1074 builder.set_network_delegate(std::move(network_delegate));
1068 std::move(network_delegate));
1069 1075
1070 std::unique_ptr<net::TransportSecurityState> transport_security_state( 1076 builder.set_transport_security_persister_path(profile_params_->path);
1071 base::MakeUnique<net::TransportSecurityState>()); 1077 builder.set_transport_security_persister_readonly(IsOffTheRecord());
1072 transport_security_persister_.reset(new net::TransportSecurityPersister(
1073 transport_security_state.get(), profile_params_->path,
1074 base::CreateSequencedTaskRunnerWithTraits(
1075 {base::MayBlock(), base::TaskPriority::BACKGROUND,
1076 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}),
1077 IsOffTheRecord()));
1078 main_request_context_storage_->set_transport_security_state(
1079 std::move(transport_security_state));
1080 1078
1081 // Take ownership over these parameters. 1079 // Take ownership over these parameters.
1082 cookie_settings_ = profile_params_->cookie_settings; 1080 cookie_settings_ = profile_params_->cookie_settings;
1083 host_content_settings_map_ = profile_params_->host_content_settings_map; 1081 host_content_settings_map_ = profile_params_->host_content_settings_map;
1084 #if BUILDFLAG(ENABLE_EXTENSIONS) 1082 #if BUILDFLAG(ENABLE_EXTENSIONS)
1085 extension_info_map_ = profile_params_->extension_info_map; 1083 extension_info_map_ = profile_params_->extension_info_map;
1086 #endif 1084 #endif
1087 1085
1088 resource_context_->host_resolver_ =
1089 io_thread_globals->system_request_context->host_resolver();
1090 resource_context_->request_context_ = main_request_context_.get();
1091
1092 if (profile_params_->loading_predictor_observer_) { 1086 if (profile_params_->loading_predictor_observer_) {
1093 loading_predictor_observer_ = 1087 loading_predictor_observer_ =
1094 std::move(profile_params_->loading_predictor_observer_); 1088 std::move(profile_params_->loading_predictor_observer_);
1095 } 1089 }
1096 1090
1097 #if defined(OS_CHROMEOS) 1091 #if defined(OS_CHROMEOS)
1098 username_hash_ = profile_params_->username_hash; 1092 username_hash_ = profile_params_->username_hash;
1099 use_system_key_slot_ = profile_params_->use_system_key_slot; 1093 use_system_key_slot_ = profile_params_->use_system_key_slot;
1100 if (use_system_key_slot_) 1094 if (use_system_key_slot_)
1101 EnableNSSSystemKeySlotForResourceContext(resource_context_.get()); 1095 EnableNSSSystemKeySlotForResourceContext(resource_context_.get());
1102 1096
1103 certificate_provider_ = std::move(profile_params_->certificate_provider); 1097 certificate_provider_ = std::move(profile_params_->certificate_provider);
1104 #endif 1098 #endif
1105 1099
1106 if (g_cert_verifier_for_testing) { 1100 if (g_cert_verifier_for_testing) {
1107 main_request_context_->set_cert_verifier(g_cert_verifier_for_testing); 1101 builder.set_shared_cert_verifier(g_cert_verifier_for_testing);
1108 } else { 1102 } else {
1109 #if defined(OS_CHROMEOS) 1103 #if defined(OS_CHROMEOS)
1110 crypto::ScopedPK11Slot public_slot = 1104 crypto::ScopedPK11Slot public_slot =
1111 crypto::GetPublicSlotForChromeOSUser(username_hash_); 1105 crypto::GetPublicSlotForChromeOSUser(username_hash_);
1112 // The private slot won't be ready by this point. It shouldn't be necessary 1106 // The private slot won't be ready by this point. It shouldn't be necessary
1113 // for cert trust purposes anyway. 1107 // for cert trust purposes anyway.
1114 scoped_refptr<net::CertVerifyProc> verify_proc( 1108 scoped_refptr<net::CertVerifyProc> verify_proc(
1115 new chromeos::CertVerifyProcChromeOS(std::move(public_slot))); 1109 new chromeos::CertVerifyProcChromeOS(std::move(public_slot)));
1116 if (policy_cert_verifier_) { 1110 if (policy_cert_verifier_) {
1117 DCHECK_EQ(policy_cert_verifier_, cert_verifier_.get()); 1111 DCHECK_EQ(policy_cert_verifier_, cert_verifier_.get());
1118 policy_cert_verifier_->InitializeOnIOThread(verify_proc); 1112 policy_cert_verifier_->InitializeOnIOThread(verify_proc);
1119 } else { 1113 } else {
1120 cert_verifier_ = base::MakeUnique<net::CachingCertVerifier>( 1114 cert_verifier_ = base::MakeUnique<net::CachingCertVerifier>(
1121 base::MakeUnique<net::MultiThreadedCertVerifier>(verify_proc.get())); 1115 base::MakeUnique<net::MultiThreadedCertVerifier>(verify_proc.get()));
1122 } 1116 }
1123 main_request_context_->set_cert_verifier(cert_verifier_.get()); 1117 builder.set_shared_cert_verifier(cert_verifier_.get());
1124 #else 1118 #else
1125 main_request_context_->set_cert_verifier( 1119 builder.set_shared_cert_verifier(
1126 io_thread_globals->system_request_context->cert_verifier()); 1120 io_thread_globals->system_request_context->cert_verifier());
1127 #endif 1121 #endif
1128 } 1122 }
1129 1123
1130 // Install the New Tab Page Interceptor. 1124 // Install the New Tab Page Interceptor.
1131 if (profile_params_->new_tab_page_interceptor.get()) { 1125 if (profile_params_->new_tab_page_interceptor.get()) {
1132 request_interceptors.push_back( 1126 request_interceptors.push_back(
1133 std::move(profile_params_->new_tab_page_interceptor)); 1127 std::move(profile_params_->new_tab_page_interceptor));
1134 } 1128 }
1135 1129
1136 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier( 1130 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier(
1137 new net::MultiLogCTVerifier()); 1131 new net::MultiLogCTVerifier());
1138 ct_verifier->AddLogs(io_thread_globals->ct_logs); 1132 ct_verifier->AddLogs(io_thread_globals->ct_logs);
1139 1133
1140 ct_tree_tracker_.reset(new certificate_transparency::TreeStateTracker( 1134 ct_tree_tracker_.reset(new certificate_transparency::TreeStateTracker(
1141 io_thread_globals->ct_logs, io_thread->net_log())); 1135 io_thread_globals->ct_logs, io_thread->net_log()));
1142 ct_verifier->SetObserver(ct_tree_tracker_.get()); 1136 ct_verifier->SetObserver(ct_tree_tracker_.get());
1143 1137
1144 main_request_context_storage_->set_cert_transparency_verifier( 1138 builder.set_ct_verifier(std::move(ct_verifier));
1145 std::move(ct_verifier));
1146 1139
1147 io_thread->RegisterSTHObserver(ct_tree_tracker_.get()); 1140 io_thread->RegisterSTHObserver(ct_tree_tracker_.get());
1148 ct_tree_tracker_unregistration_ = 1141 ct_tree_tracker_unregistration_ =
1149 base::Bind(&IOThread::UnregisterSTHObserver, base::Unretained(io_thread), 1142 base::Bind(&IOThread::UnregisterSTHObserver, base::Unretained(io_thread),
1150 ct_tree_tracker_.get()); 1143 ct_tree_tracker_.get());
1151 1144
1152 main_request_context_storage_->set_ct_policy_enforcer( 1145 builder.set_http_network_session_params(
1153 base::MakeUnique<net::CTPolicyEnforcer>()); 1146 profile_params_->io_thread->NetworkSessionParams());
1147 if (data_reduction_proxy_io_data_.get()) {
1148 builder.set_shared_proxy_delegate(
1149 data_reduction_proxy_io_data_->proxy_delegate());
1150 }
1154 1151
1155 InitializeInternal(profile_params_.get(), protocol_handlers, 1152 InitializeInternal(&builder, profile_params_.get(), protocol_handlers,
1156 std::move(request_interceptors)); 1153 std::move(request_interceptors));
1157 1154
1155 main_request_context_ = builder.Build();
1156
1157 // Attach some things to the URLRequestContextBuilder's
1158 // TransportSecurityState. Since no requests have been made yet, safe to do
1159 // this even after the call to Build().
1160
1158 net::NetworkTrafficAnnotationTag traffic_annotation = 1161 net::NetworkTrafficAnnotationTag traffic_annotation =
1159 net::DefineNetworkTrafficAnnotation("domain_security_policy", R"( 1162 net::DefineNetworkTrafficAnnotation("domain_security_policy", R"(
1160 semantics { 1163 semantics {
1161 sender: "Domain Security Policy" 1164 sender: "Domain Security Policy"
1162 description: 1165 description:
1163 "Websites can opt in to have Chrome send reports to them when " 1166 "Websites can opt in to have Chrome send reports to them when "
1164 "Chrome observes connections to that website that do not meet " 1167 "Chrome observes connections to that website that do not meet "
1165 "stricter security policies, such as with HTTP Public Key Pinning. " 1168 "stricter security policies, such as with HTTP Public Key Pinning. "
1166 "Websites can use this feature to discover misconfigurations that " 1169 "Websites can use this feature to discover misconfigurations that "
1167 "prevent them from complying with stricter security policies that " 1170 "prevent them from complying with stricter security policies that "
(...skipping 21 matching lines...) Expand all
1189 certificate_report_sender_.get()); 1192 certificate_report_sender_.get());
1190 1193
1191 expect_ct_reporter_.reset( 1194 expect_ct_reporter_.reset(
1192 new ChromeExpectCTReporter(main_request_context_.get())); 1195 new ChromeExpectCTReporter(main_request_context_.get()));
1193 main_request_context_->transport_security_state()->SetExpectCTReporter( 1196 main_request_context_->transport_security_state()->SetExpectCTReporter(
1194 expect_ct_reporter_.get()); 1197 expect_ct_reporter_.get());
1195 1198
1196 main_request_context_->transport_security_state()->SetRequireCTDelegate( 1199 main_request_context_->transport_security_state()->SetRequireCTDelegate(
1197 ct_policy_manager_->GetDelegate()); 1200 ct_policy_manager_->GetDelegate());
1198 1201
1202 resource_context_->host_resolver_ =
1203 io_thread_globals->system_request_context->host_resolver();
1204 resource_context_->request_context_ = main_request_context_.get();
1205
1206 OnMainRequestContextCreated(profile_params_.get());
1207
1199 profile_params_.reset(); 1208 profile_params_.reset();
1200 initialized_ = true; 1209 initialized_ = true;
1201 } 1210 }
1202 1211
1203 void ProfileIOData::ApplyProfileParamsToContext(
1204 net::URLRequestContext* context) const {
1205 context->set_http_user_agent_settings(
1206 chrome_http_user_agent_settings_.get());
1207 context->set_ssl_config_service(profile_params_->ssl_config_service.get());
1208 }
1209
1210 std::unique_ptr<net::URLRequestJobFactory> 1212 std::unique_ptr<net::URLRequestJobFactory>
1211 ProfileIOData::SetUpJobFactoryDefaults( 1213 ProfileIOData::SetUpJobFactoryDefaults(
1212 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory, 1214 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory,
1213 content::URLRequestInterceptorScopedVector request_interceptors, 1215 content::URLRequestInterceptorScopedVector request_interceptors,
1214 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 1216 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
1215 protocol_handler_interceptor, 1217 protocol_handler_interceptor,
1216 net::NetworkDelegate* network_delegate, 1218 net::NetworkDelegate* network_delegate,
1217 net::HostResolver* host_resolver) const { 1219 net::HostResolver* host_resolver) const {
1218 // NOTE(willchan): Keep these protocol handlers in sync with 1220 // NOTE(willchan): Keep these protocol handlers in sync with
1219 // ProfileIOData::IsHandledProtocol(). 1221 // ProfileIOData::IsHandledProtocol().
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 request_interceptors.clear(); 1281 request_interceptors.clear();
1280 1282
1281 if (protocol_handler_interceptor) { 1283 if (protocol_handler_interceptor) {
1282 protocol_handler_interceptor->Chain(std::move(top_job_factory)); 1284 protocol_handler_interceptor->Chain(std::move(top_job_factory));
1283 return std::move(protocol_handler_interceptor); 1285 return std::move(protocol_handler_interceptor);
1284 } else { 1286 } else {
1285 return top_job_factory; 1287 return top_job_factory;
1286 } 1288 }
1287 } 1289 }
1288 1290
1291 void ProfileIOData::SetUpJobFactoryDefaultsForBuilder(
1292 net::URLRequestContextBuilder* builder,
1293 content::URLRequestInterceptorScopedVector request_interceptors,
1294 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
1295 protocol_handler_interceptor,
1296 net::HostResolver* host_resolver) const {
1297 // NOTE(willchan): Keep these protocol handlers in sync with
1298 // ProfileIOData::IsHandledProtocol().
1299 builder->SetProtocolHandler(
1300 url::kFileScheme,
1301 base::MakeUnique<net::FileProtocolHandler>(
1302 base::CreateTaskRunnerWithTraits(
1303 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
1304 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})));
1305
1306 #if BUILDFLAG(ENABLE_EXTENSIONS)
1307 DCHECK(extension_info_map_.get());
1308 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1309 bool is_incognito = profile_type() == Profile::INCOGNITO_PROFILE;
1310 builder->SetProtocolHandler(extensions::kExtensionScheme,
1311 extensions::CreateExtensionProtocolHandler(
1312 is_incognito, extension_info_map_.get()));
1313 #endif
1314 builder->SetProtocolHandler(url::kDataScheme,
1315 base::MakeUnique<net::DataProtocolHandler>());
1316 #if defined(OS_CHROMEOS)
1317 if (profile_params_) {
1318 builder->SetProtocolHandler(
1319 content::kExternalFileScheme,
1320 base::MakeUnique<chromeos::ExternalFileProtocolHandler>(
1321 profile_params_->profile));
1322 }
1323 #endif // defined(OS_CHROMEOS)
1324 #if defined(OS_ANDROID)
1325 builder->SetProtocolHandler(
1326 url::kContentScheme,
1327 content::ContentProtocolHandler::Create(base::CreateTaskRunnerWithTraits(
1328 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
1329 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})));
1330 #endif
1331
1332 builder->SetProtocolHandler(
1333 url::kAboutScheme,
1334 base::MakeUnique<about_handler::AboutProtocolHandler>());
1335
1336 #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
1337 builder->SetProtocolHandler(url::kFtpScheme,
1338 net::FtpProtocolHandler::Create(host_resolver));
1339 #endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
1340
1341 #if BUILDFLAG(DEBUG_DEVTOOLS)
1342 request_interceptors.push_back(base::MakeUnique<DebugDevToolsInterceptor>());
1343 #endif
1344
1345 builder->SetInterceptors(std::move(request_interceptors));
1346
1347 if (protocol_handler_interceptor) {
1348 builder->set_create_intercepting_job_factory(
1349 base::BindOnce(&CreateURLRequestJobFactory,
1350 base::Passed(std::move(protocol_handler_interceptor))));
1351 }
1352 }
1353
1289 void ProfileIOData::ShutdownOnUIThread( 1354 void ProfileIOData::ShutdownOnUIThread(
1290 std::unique_ptr<ChromeURLRequestContextGetterVector> context_getters) { 1355 std::unique_ptr<ChromeURLRequestContextGetterVector> context_getters) {
1291 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1356 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1292 1357
1293 google_services_user_account_id_.Destroy(); 1358 google_services_user_account_id_.Destroy();
1294 sync_suppress_start_.Destroy(); 1359 sync_suppress_start_.Destroy();
1295 sync_first_setup_complete_.Destroy(); 1360 sync_first_setup_complete_.Destroy();
1296 enable_referrers_.Destroy(); 1361 enable_referrers_.Destroy();
1297 enable_do_not_track_.Destroy(); 1362 enable_do_not_track_.Destroy();
1298 force_google_safesearch_.Destroy(); 1363 force_google_safesearch_.Destroy();
(...skipping 22 matching lines...) Expand all
1321 1386
1322 bool posted = BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); 1387 bool posted = BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
1323 if (!posted) 1388 if (!posted)
1324 delete this; 1389 delete this;
1325 } 1390 }
1326 1391
1327 void ProfileIOData::DestroyResourceContext() { 1392 void ProfileIOData::DestroyResourceContext() {
1328 resource_context_.reset(); 1393 resource_context_.reset();
1329 } 1394 }
1330 1395
1331 std::unique_ptr<net::HttpNetworkSession>
1332 ProfileIOData::CreateHttpNetworkSession(
1333 const ProfileParams& profile_params) const {
1334 net::URLRequestContext* context = main_request_context();
1335
1336 IOThread* const io_thread = profile_params.io_thread;
1337
1338 net::HttpNetworkSession::Context session_context;
1339 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1340 context, &session_context);
1341 if (data_reduction_proxy_io_data_.get()) {
1342 session_context.proxy_delegate =
1343 data_reduction_proxy_io_data_->proxy_delegate();
1344 }
1345
1346 return std::unique_ptr<net::HttpNetworkSession>(new net::HttpNetworkSession(
1347 io_thread->NetworkSessionParams(), session_context));
1348 }
1349
1350 std::unique_ptr<net::HttpCache> ProfileIOData::CreateMainHttpFactory( 1396 std::unique_ptr<net::HttpCache> ProfileIOData::CreateMainHttpFactory(
1351 net::HttpNetworkSession* session, 1397 net::HttpNetworkSession* session,
1352 std::unique_ptr<net::HttpCache::BackendFactory> main_backend) const { 1398 std::unique_ptr<net::HttpCache::BackendFactory> main_backend) const {
1353 return base::MakeUnique<net::HttpCache>( 1399 return base::MakeUnique<net::HttpCache>(
1354 base::WrapUnique(new DevToolsNetworkTransactionFactory( 1400 base::WrapUnique(new DevToolsNetworkTransactionFactory(
1355 network_controller_handle_.GetController(), session)), 1401 network_controller_handle_.GetController(), session)),
1356 std::move(main_backend), true /* is_main_cache */); 1402 std::move(main_backend), true /* is_main_cache */);
1357 } 1403 }
1358 1404
1359 std::unique_ptr<net::HttpCache> ProfileIOData::CreateHttpFactory( 1405 std::unique_ptr<net::HttpCache> ProfileIOData::CreateHttpFactory(
(...skipping 17 matching lines...) Expand all
1377 void ProfileIOData::SetCookieSettingsForTesting( 1423 void ProfileIOData::SetCookieSettingsForTesting(
1378 content_settings::CookieSettings* cookie_settings) { 1424 content_settings::CookieSettings* cookie_settings) {
1379 DCHECK(!cookie_settings_.get()); 1425 DCHECK(!cookie_settings_.get());
1380 cookie_settings_ = cookie_settings; 1426 cookie_settings_ = cookie_settings;
1381 } 1427 }
1382 1428
1383 policy::URLBlacklist::URLBlacklistState ProfileIOData::GetURLBlacklistState( 1429 policy::URLBlacklist::URLBlacklistState ProfileIOData::GetURLBlacklistState(
1384 const GURL& url) const { 1430 const GURL& url) const {
1385 return url_blacklist_manager_->GetURLBlacklistState(url); 1431 return url_blacklist_manager_->GetURLBlacklistState(url);
1386 } 1432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698