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

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

Issue 2939433004: Move common main URLRequestContext setup code to ProfileIOData (Closed)
Patch Set: Fix Created 3 years, 6 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/profiles/profile_io_data.h ('k') | no next file » | 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/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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 for (URLRequestContextMap::const_iterator it = 645 for (URLRequestContextMap::const_iterator it =
646 isolated_media_request_context_map_.begin(); 646 isolated_media_request_context_map_.begin();
647 current_context < kMaxCachedContexts && 647 current_context < kMaxCachedContexts &&
648 it != isolated_media_request_context_map_.end(); 648 it != isolated_media_request_context_map_.end();
649 ++it, ++current_context) { 649 ++it, ++current_context) {
650 media_context_cache[current_context] = it->second; 650 media_context_cache[current_context] = it->second;
651 memcpy(&media_context_vtable_cache[current_context], 651 memcpy(&media_context_vtable_cache[current_context],
652 static_cast<void*>(it->second), sizeof(void*)); 652 static_cast<void*>(it->second), sizeof(void*));
653 } 653 }
654 654
655 // Prevent the TreeStateTracker from getting any more notifications by 655 if (main_request_context_) {
656 // severing the link between it and the CTVerifier and unregistering it from 656 // Prevent the TreeStateTracker from getting any more notifications by
657 // new STH notifications. 657 // severing the link between it and the CTVerifier and unregistering it from
658 // 658 // new STH notifications.
659 // Only do this if the |cert_transparency_verifier_| is not null. 659 main_request_context_->cert_transparency_verifier()->SetObserver(nullptr);
660 if (cert_transparency_verifier_) {
mmenke 2017/06/16 18:18:50 All of these null checks were basically checking t
661 cert_transparency_verifier_->SetObserver(nullptr);
662 ct_tree_tracker_unregistration_.Run(); 660 ct_tree_tracker_unregistration_.Run();
663 }
664 661
665 // Destroy certificate_report_sender_ before main_request_context_, 662 // Destroy certificate_report_sender_ before main_request_context_,
666 // since the former has a reference to the latter. 663 // since the former has a reference to the latter.
667 if (transport_security_state_) 664 main_request_context_->transport_security_state()->SetReportSender(nullptr);
668 transport_security_state_->SetReportSender(nullptr); 665 certificate_report_sender_.reset();
669 certificate_report_sender_.reset();
670 666
671 if (transport_security_state_) 667 main_request_context_->transport_security_state()->SetExpectCTReporter(
672 transport_security_state_->SetExpectCTReporter(nullptr); 668 nullptr);
673 expect_ct_reporter_.reset(); 669 expect_ct_reporter_.reset();
674 670
675 if (transport_security_state_) 671 main_request_context_->transport_security_state()->SetRequireCTDelegate(
676 transport_security_state_->SetRequireCTDelegate(nullptr); 672 nullptr);
677 673
678 // And the same for the ReportingService. 674 // And the same for the ReportingService.
679 if (main_request_context_storage()) {
680 main_request_context_storage()->set_reporting_service( 675 main_request_context_storage()->set_reporting_service(
681 std::unique_ptr<net::ReportingService>()); 676 std::unique_ptr<net::ReportingService>());
677
678 // This should be shut down last, as any other requests may initiate more
679 // activity when the ProxyService aborts lookups.
680 main_request_context_->proxy_service()->OnShutdown();
682 } 681 }
683 682
684 // This should be shut down last, as any other requests may initiate more
685 // activity when the ProxyService aborts lookups.
686 if (proxy_service_)
687 proxy_service_->OnShutdown();
688
689 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they 683 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
690 // are already done in the URLRequestContext destructor. 684 // are already done in the URLRequestContext destructor.
691 if (main_request_context_) 685 if (main_request_context_)
692 main_request_context_->AssertNoURLRequests(); 686 main_request_context_->AssertNoURLRequests();
693 if (extensions_request_context_) 687 if (extensions_request_context_)
694 extensions_request_context_->AssertNoURLRequests(); 688 extensions_request_context_->AssertNoURLRequests();
695 689
696 current_context = 0; 690 current_context = 0;
697 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); 691 for (URLRequestContextMap::iterator it = app_request_context_map_.begin();
698 it != app_request_context_map_.end(); ++it) { 692 it != app_request_context_map_.end(); ++it) {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // functions have been provided to assist in common operations. 980 // functions have been provided to assist in common operations.
987 DCHECK_CURRENTLY_ON(BrowserThread::IO); 981 DCHECK_CURRENTLY_ON(BrowserThread::IO);
988 DCHECK(!initialized_); 982 DCHECK(!initialized_);
989 DCHECK(profile_params_.get()); 983 DCHECK(profile_params_.get());
990 984
991 IOThread* const io_thread = profile_params_->io_thread; 985 IOThread* const io_thread = profile_params_->io_thread;
992 IOThread::Globals* const io_thread_globals = io_thread->globals(); 986 IOThread::Globals* const io_thread_globals = io_thread->globals();
993 const base::CommandLine& command_line = 987 const base::CommandLine& command_line =
994 *base::CommandLine::ForCurrentProcess(); 988 *base::CommandLine::ForCurrentProcess();
995 989
996 // Create the common request contexts. 990 // Create extension request context. Only used for cookies.
991 extensions_request_context_.reset(new net::URLRequestContext());
992 extensions_request_context_->set_name("extensions");
993
994 // Create the main request context.
997 main_request_context_.reset(new net::URLRequestContext()); 995 main_request_context_.reset(new net::URLRequestContext());
998 main_request_context_storage_.reset( 996 main_request_context_storage_.reset(
999 new net::URLRequestContextStorage(main_request_context_.get())); 997 new net::URLRequestContextStorage(main_request_context_.get()));
1000 extensions_request_context_.reset(new net::URLRequestContext());
1001 main_request_context_->set_name("main"); 998 main_request_context_->set_name("main");
1002 extensions_request_context_->set_name("extensions"); 999
1000 ApplyProfileParamsToContext(main_request_context_.get());
1001 main_request_context_->set_net_log(io_thread->net_log());
1003 1002
1004 main_request_context_->set_enable_brotli(io_thread_globals->enable_brotli); 1003 main_request_context_->set_enable_brotli(io_thread_globals->enable_brotli);
1005 1004
1006 std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate( 1005 std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate(
1007 new ChromeNetworkDelegate( 1006 new ChromeNetworkDelegate(
1008 #if BUILDFLAG(ENABLE_EXTENSIONS) 1007 #if BUILDFLAG(ENABLE_EXTENSIONS)
1009 io_thread_globals->extension_event_router_forwarder.get(), 1008 io_thread_globals->extension_event_router_forwarder.get(),
1010 #else 1009 #else
1011 NULL, 1010 NULL,
1012 #endif 1011 #endif
(...skipping 22 matching lines...) Expand all
1035 chrome_network_delegate->set_data_use_aggregator( 1034 chrome_network_delegate->set_data_use_aggregator(
1036 io_thread_globals->data_use_aggregator.get(), IsOffTheRecord()); 1035 io_thread_globals->data_use_aggregator.get(), IsOffTheRecord());
1037 1036
1038 std::unique_ptr<net::NetworkDelegate> network_delegate = 1037 std::unique_ptr<net::NetworkDelegate> network_delegate =
1039 ConfigureNetworkDelegate(profile_params_->io_thread, 1038 ConfigureNetworkDelegate(profile_params_->io_thread,
1040 std::move(chrome_network_delegate)); 1039 std::move(chrome_network_delegate));
1041 1040
1042 main_request_context_->set_host_resolver( 1041 main_request_context_->set_host_resolver(
1043 io_thread_globals->system_request_context->host_resolver()); 1042 io_thread_globals->system_request_context->host_resolver());
1044 1043
1045 // NOTE: Proxy service uses the default io thread network delegate, not the 1044 main_request_context_->set_http_auth_handler_factory(
1046 // delegate just created. 1045 io_thread_globals->system_request_context->http_auth_handler_factory());
1047 proxy_service_ = ProxyServiceFactory::CreateProxyService( 1046
1048 io_thread->net_log(), main_request_context_.get(), network_delegate.get(), 1047 main_request_context_storage_->set_proxy_service(
1049 std::move(profile_params_->proxy_config_service), command_line, 1048 ProxyServiceFactory::CreateProxyService(
1050 io_thread->WpadQuickCheckEnabled(), 1049 io_thread->net_log(), main_request_context_.get(),
1051 io_thread->PacHttpsUrlStrippingEnabled()); 1050 network_delegate.get(),
1051 std::move(profile_params_->proxy_config_service), command_line,
1052 io_thread->WpadQuickCheckEnabled(),
1053 io_thread->PacHttpsUrlStrippingEnabled()));
1052 1054
1053 main_request_context_storage_->set_network_delegate( 1055 main_request_context_storage_->set_network_delegate(
1054 std::move(network_delegate)); 1056 std::move(network_delegate));
1055 1057
1056 transport_security_state_.reset(new net::TransportSecurityState()); 1058 std::unique_ptr<net::TransportSecurityState> transport_security_state(
1059 base::MakeUnique<net::TransportSecurityState>());
1057 transport_security_persister_.reset(new net::TransportSecurityPersister( 1060 transport_security_persister_.reset(new net::TransportSecurityPersister(
1058 transport_security_state_.get(), profile_params_->path, 1061 transport_security_state.get(), profile_params_->path,
1059 base::CreateSequencedTaskRunnerWithTraits( 1062 base::CreateSequencedTaskRunnerWithTraits(
1060 {base::MayBlock(), base::TaskPriority::BACKGROUND, 1063 {base::MayBlock(), base::TaskPriority::BACKGROUND,
1061 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}), 1064 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}),
1062 IsOffTheRecord())); 1065 IsOffTheRecord()));
1063 1066
1064 net::NetworkTrafficAnnotationTag traffic_annotation = 1067 net::NetworkTrafficAnnotationTag traffic_annotation =
1065 net::DefineNetworkTrafficAnnotation("domain_security_policy", R"( 1068 net::DefineNetworkTrafficAnnotation("domain_security_policy", R"(
1066 semantics { 1069 semantics {
1067 sender: "Domain Security Policy" 1070 sender: "Domain Security Policy"
1068 description: 1071 description:
(...skipping 15 matching lines...) Expand all
1084 } 1087 }
1085 policy { 1088 policy {
1086 cookies_allowed: false 1089 cookies_allowed: false
1087 setting: "This feature cannot be disabled by settings." 1090 setting: "This feature cannot be disabled by settings."
1088 policy_exception_justification: 1091 policy_exception_justification:
1089 "Not implemented, this is a feature that websites can opt into and " 1092 "Not implemented, this is a feature that websites can opt into and "
1090 "thus there is no Chrome-wide policy to disable it." 1093 "thus there is no Chrome-wide policy to disable it."
1091 })"); 1094 })");
1092 certificate_report_sender_.reset( 1095 certificate_report_sender_.reset(
1093 new net::ReportSender(main_request_context_.get(), traffic_annotation)); 1096 new net::ReportSender(main_request_context_.get(), traffic_annotation));
1094 transport_security_state_->SetReportSender(certificate_report_sender_.get()); 1097 transport_security_state->SetReportSender(certificate_report_sender_.get());
1095 1098
1096 expect_ct_reporter_.reset( 1099 expect_ct_reporter_.reset(
1097 new ChromeExpectCTReporter(main_request_context_.get())); 1100 new ChromeExpectCTReporter(main_request_context_.get()));
1098 transport_security_state_->SetExpectCTReporter(expect_ct_reporter_.get()); 1101 transport_security_state->SetExpectCTReporter(expect_ct_reporter_.get());
1099 1102
1100 transport_security_state_->SetRequireCTDelegate( 1103 transport_security_state->SetRequireCTDelegate(
1101 ct_policy_manager_->GetDelegate()); 1104 ct_policy_manager_->GetDelegate());
1105 main_request_context_storage_->set_transport_security_state(
1106 std::move(transport_security_state));
1102 1107
1103 // Take ownership over these parameters. 1108 // Take ownership over these parameters.
1104 cookie_settings_ = profile_params_->cookie_settings; 1109 cookie_settings_ = profile_params_->cookie_settings;
1105 host_content_settings_map_ = profile_params_->host_content_settings_map; 1110 host_content_settings_map_ = profile_params_->host_content_settings_map;
1106 #if BUILDFLAG(ENABLE_EXTENSIONS) 1111 #if BUILDFLAG(ENABLE_EXTENSIONS)
1107 extension_info_map_ = profile_params_->extension_info_map; 1112 extension_info_map_ = profile_params_->extension_info_map;
1108 #endif 1113 #endif
1109 1114
1110 resource_context_->host_resolver_ = 1115 resource_context_->host_resolver_ =
1111 io_thread_globals->system_request_context->host_resolver(); 1116 io_thread_globals->system_request_context->host_resolver();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 1156
1152 // Install the New Tab Page Interceptor. 1157 // Install the New Tab Page Interceptor.
1153 if (profile_params_->new_tab_page_interceptor.get()) { 1158 if (profile_params_->new_tab_page_interceptor.get()) {
1154 request_interceptors.push_back( 1159 request_interceptors.push_back(
1155 std::move(profile_params_->new_tab_page_interceptor)); 1160 std::move(profile_params_->new_tab_page_interceptor));
1156 } 1161 }
1157 1162
1158 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier( 1163 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier(
1159 new net::MultiLogCTVerifier()); 1164 new net::MultiLogCTVerifier());
1160 ct_verifier->AddLogs(io_thread_globals->ct_logs); 1165 ct_verifier->AddLogs(io_thread_globals->ct_logs);
1161 main_request_context_->set_cert_transparency_verifier(ct_verifier.get());
1162 1166
1163 ct_tree_tracker_.reset(new certificate_transparency::TreeStateTracker( 1167 ct_tree_tracker_.reset(new certificate_transparency::TreeStateTracker(
1164 io_thread_globals->ct_logs, io_thread->net_log())); 1168 io_thread_globals->ct_logs, io_thread->net_log()));
1165 ct_verifier->SetObserver(ct_tree_tracker_.get()); 1169 ct_verifier->SetObserver(ct_tree_tracker_.get());
1166 1170
1167 cert_transparency_verifier_ = std::move(ct_verifier); 1171 main_request_context_storage_->set_cert_transparency_verifier(
1172 std::move(ct_verifier));
1173
1168 io_thread->RegisterSTHObserver(ct_tree_tracker_.get()); 1174 io_thread->RegisterSTHObserver(ct_tree_tracker_.get());
1169 ct_tree_tracker_unregistration_ = 1175 ct_tree_tracker_unregistration_ =
1170 base::Bind(&IOThread::UnregisterSTHObserver, base::Unretained(io_thread), 1176 base::Bind(&IOThread::UnregisterSTHObserver, base::Unretained(io_thread),
1171 ct_tree_tracker_.get()); 1177 ct_tree_tracker_.get());
1172 1178
1179 main_request_context_->set_ct_policy_enforcer(
1180 io_thread_globals->system_request_context->ct_policy_enforcer());
1181
1173 InitializeInternal(profile_params_.get(), protocol_handlers, 1182 InitializeInternal(profile_params_.get(), protocol_handlers,
1174 std::move(request_interceptors)); 1183 std::move(request_interceptors));
1175 1184
1176 profile_params_.reset(); 1185 profile_params_.reset();
1177 initialized_ = true; 1186 initialized_ = true;
1178 } 1187 }
1179 1188
1180 void ProfileIOData::ApplyProfileParamsToContext( 1189 void ProfileIOData::ApplyProfileParamsToContext(
1181 net::URLRequestContext* context) const { 1190 net::URLRequestContext* context) const {
1182 context->set_http_user_agent_settings( 1191 context->set_http_user_agent_settings(
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 void ProfileIOData::SetCookieSettingsForTesting( 1361 void ProfileIOData::SetCookieSettingsForTesting(
1353 content_settings::CookieSettings* cookie_settings) { 1362 content_settings::CookieSettings* cookie_settings) {
1354 DCHECK(!cookie_settings_.get()); 1363 DCHECK(!cookie_settings_.get());
1355 cookie_settings_ = cookie_settings; 1364 cookie_settings_ = cookie_settings;
1356 } 1365 }
1357 1366
1358 policy::URLBlacklist::URLBlacklistState ProfileIOData::GetURLBlacklistState( 1367 policy::URLBlacklist::URLBlacklistState ProfileIOData::GetURLBlacklistState(
1359 const GURL& url) const { 1368 const GURL& url) const {
1360 return url_blacklist_manager_->GetURLBlacklistState(url); 1369 return url_blacklist_manager_->GetURLBlacklistState(url);
1361 } 1370 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698