OLD | NEW |
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 ~SystemURLRequestContext() override { | 163 ~SystemURLRequestContext() override { |
164 AssertNoURLRequests(); | 164 AssertNoURLRequests(); |
165 #if defined(USE_NSS) || defined(OS_IOS) | 165 #if defined(USE_NSS) || defined(OS_IOS) |
166 net::SetURLRequestContextForNSSHttpIO(NULL); | 166 net::SetURLRequestContextForNSSHttpIO(NULL); |
167 #endif | 167 #endif |
168 } | 168 } |
169 }; | 169 }; |
170 | 170 |
171 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { | 171 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { |
172 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); | 172 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); |
173 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 173 const base::CommandLine& command_line = |
| 174 *base::CommandLine::ForCurrentProcess(); |
174 | 175 |
175 net::HostResolver::Options options; | 176 net::HostResolver::Options options; |
176 | 177 |
177 // Use the concurrency override from the command-line, if any. | 178 // Use the concurrency override from the command-line, if any. |
178 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { | 179 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
179 std::string s = | 180 std::string s = |
180 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); | 181 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
181 | 182 |
182 // Parse the switch (it should be a positive integer formatted as decimal). | 183 // Parse the switch (it should be a positive integer formatted as decimal). |
183 int n; | 184 int n; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 context->set_cookie_store(globals->system_cookie_store.get()); | 287 context->set_cookie_store(globals->system_cookie_store.get()); |
287 context->set_channel_id_service( | 288 context->set_channel_id_service( |
288 globals->system_channel_id_service.get()); | 289 globals->system_channel_id_service.get()); |
289 context->set_throttler_manager(globals->throttler_manager.get()); | 290 context->set_throttler_manager(globals->throttler_manager.get()); |
290 context->set_network_delegate(globals->system_network_delegate.get()); | 291 context->set_network_delegate(globals->system_network_delegate.get()); |
291 context->set_http_user_agent_settings( | 292 context->set_http_user_agent_settings( |
292 globals->http_user_agent_settings.get()); | 293 globals->http_user_agent_settings.get()); |
293 return context; | 294 return context; |
294 } | 295 } |
295 | 296 |
296 int GetSwitchValueAsInt(const CommandLine& command_line, | 297 int GetSwitchValueAsInt(const base::CommandLine& command_line, |
297 const std::string& switch_name) { | 298 const std::string& switch_name) { |
298 int value; | 299 int value; |
299 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), | 300 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
300 &value)) { | 301 &value)) { |
301 return 0; | 302 return 0; |
302 } | 303 } |
303 return value; | 304 return value; |
304 } | 305 } |
305 | 306 |
306 // Returns the value associated with |key| in |params| or "" if the | 307 // Returns the value associated with |key| in |params| or "" if the |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 } | 571 } |
571 | 572 |
572 void IOThread::InitAsync() { | 573 void IOThread::InitAsync() { |
573 TRACE_EVENT0("startup", "IOThread::InitAsync"); | 574 TRACE_EVENT0("startup", "IOThread::InitAsync"); |
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
575 | 576 |
576 #if defined(USE_NSS) || defined(OS_IOS) | 577 #if defined(USE_NSS) || defined(OS_IOS) |
577 net::SetMessageLoopForNSSHttpIO(); | 578 net::SetMessageLoopForNSSHttpIO(); |
578 #endif | 579 #endif |
579 | 580 |
580 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 581 const base::CommandLine& command_line = |
| 582 *base::CommandLine::ForCurrentProcess(); |
581 | 583 |
582 DCHECK(!globals_); | 584 DCHECK(!globals_); |
583 globals_ = new Globals; | 585 globals_ = new Globals; |
584 | 586 |
585 // Add an observer that will emit network change events to the ChromeNetLog. | 587 // Add an observer that will emit network change events to the ChromeNetLog. |
586 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 588 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
587 // logging the network change before other IO thread consumers respond to it. | 589 // logging the network change before other IO thread consumers respond to it. |
588 network_change_observer_.reset( | 590 network_change_observer_.reset( |
589 new LoggingNetworkChangeObserver(net_log_)); | 591 new LoggingNetworkChangeObserver(net_log_)); |
590 | 592 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 network_change_observer_.reset(); | 803 network_change_observer_.reset(); |
802 | 804 |
803 system_proxy_config_service_.reset(); | 805 system_proxy_config_service_.reset(); |
804 | 806 |
805 delete globals_; | 807 delete globals_; |
806 globals_ = NULL; | 808 globals_ = NULL; |
807 | 809 |
808 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | 810 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
809 } | 811 } |
810 | 812 |
811 void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { | 813 void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { |
812 // Only handle use-spdy command line flags if "spdy.disabled" preference is | 814 // Only handle use-spdy command line flags if "spdy.disabled" preference is |
813 // not disabled via policy. | 815 // not disabled via policy. |
814 if (is_spdy_disabled_by_policy_) { | 816 if (is_spdy_disabled_by_policy_) { |
815 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); | 817 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); |
816 if (trial) | 818 if (trial) |
817 trial->Disable(); | 819 trial->Disable(); |
818 } else { | 820 } else { |
819 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { | 821 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
820 globals_->trusted_spdy_proxy.set( | 822 globals_->trusted_spdy_proxy.set( |
821 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); | 823 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); |
(...skipping 19 matching lines...) Expand all Loading... |
841 } | 843 } |
842 | 844 |
843 ConfigureTCPFastOpen(command_line); | 845 ConfigureTCPFastOpen(command_line); |
844 | 846 |
845 // TODO(rch): Make the client socket factory a per-network session | 847 // TODO(rch): Make the client socket factory a per-network session |
846 // instance, constructed from a NetworkSession::Params, to allow us | 848 // instance, constructed from a NetworkSession::Params, to allow us |
847 // to move this option to IOThread::Globals & | 849 // to move this option to IOThread::Globals & |
848 // HttpNetworkSession::Params. | 850 // HttpNetworkSession::Params. |
849 } | 851 } |
850 | 852 |
851 void IOThread::ConfigureTCPFastOpen(const CommandLine& command_line) { | 853 void IOThread::ConfigureTCPFastOpen(const base::CommandLine& command_line) { |
852 const std::string trial_group = | 854 const std::string trial_group = |
853 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); | 855 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); |
854 if (trial_group == kTCPFastOpenHttpsEnabledGroupName) | 856 if (trial_group == kTCPFastOpenHttpsEnabledGroupName) |
855 globals_->enable_tcp_fast_open_for_ssl.set(true); | 857 globals_->enable_tcp_fast_open_for_ssl.set(true); |
856 bool always_enable_if_supported = | 858 bool always_enable_if_supported = |
857 command_line.HasSwitch(switches::kEnableTcpFastOpen); | 859 command_line.HasSwitch(switches::kEnableTcpFastOpen); |
858 // Check for OS support of TCP FastOpen, and turn it on for all connections | 860 // Check for OS support of TCP FastOpen, and turn it on for all connections |
859 // if indicated by user. | 861 // if indicated by user. |
860 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_if_supported); | 862 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_if_supported); |
861 } | 863 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 FROM_HERE, | 1113 FROM_HERE, |
1112 base::Bind(&IOThread::InitSystemRequestContextOnIOThread, | 1114 base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
1113 base::Unretained(this))); | 1115 base::Unretained(this))); |
1114 } | 1116 } |
1115 | 1117 |
1116 void IOThread::InitSystemRequestContextOnIOThread() { | 1118 void IOThread::InitSystemRequestContextOnIOThread() { |
1117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1118 DCHECK(!globals_->system_proxy_service.get()); | 1120 DCHECK(!globals_->system_proxy_service.get()); |
1119 DCHECK(system_proxy_config_service_.get()); | 1121 DCHECK(system_proxy_config_service_.get()); |
1120 | 1122 |
1121 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1123 const base::CommandLine& command_line = |
| 1124 *base::CommandLine::ForCurrentProcess(); |
1122 globals_->system_proxy_service.reset( | 1125 globals_->system_proxy_service.reset( |
1123 ProxyServiceFactory::CreateProxyService( | 1126 ProxyServiceFactory::CreateProxyService( |
1124 net_log_, | 1127 net_log_, |
1125 globals_->proxy_script_fetcher_context.get(), | 1128 globals_->proxy_script_fetcher_context.get(), |
1126 globals_->system_network_delegate.get(), | 1129 globals_->system_network_delegate.get(), |
1127 system_proxy_config_service_.release(), | 1130 system_proxy_config_service_.release(), |
1128 command_line, | 1131 command_line, |
1129 quick_check_enabled_.GetValue())); | 1132 quick_check_enabled_.GetValue())); |
1130 DCHECK(globals_->data_reduction_proxy_params); | 1133 DCHECK(globals_->data_reduction_proxy_params); |
1131 | 1134 |
(...skipping 12 matching lines...) Expand all Loading... |
1144 globals_->system_request_context->set_ssl_config_service( | 1147 globals_->system_request_context->set_ssl_config_service( |
1145 globals_->ssl_config_service.get()); | 1148 globals_->ssl_config_service.get()); |
1146 globals_->system_request_context->set_http_server_properties( | 1149 globals_->system_request_context->set_http_server_properties( |
1147 globals_->http_server_properties->GetWeakPtr()); | 1150 globals_->http_server_properties->GetWeakPtr()); |
1148 } | 1151 } |
1149 | 1152 |
1150 void IOThread::UpdateDnsClientEnabled() { | 1153 void IOThread::UpdateDnsClientEnabled() { |
1151 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); | 1154 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
1152 } | 1155 } |
1153 | 1156 |
1154 void IOThread::ConfigureQuic(const CommandLine& command_line) { | 1157 void IOThread::ConfigureQuic(const base::CommandLine& command_line) { |
1155 // Always fetch the field trial group to ensure it is reported correctly. | 1158 // Always fetch the field trial group to ensure it is reported correctly. |
1156 // The command line flags will be associated with a group that is reported | 1159 // The command line flags will be associated with a group that is reported |
1157 // so long as trial is actually queried. | 1160 // so long as trial is actually queried. |
1158 std::string group = | 1161 std::string group = |
1159 base::FieldTrialList::FindFullName(kQuicFieldTrialName); | 1162 base::FieldTrialList::FindFullName(kQuicFieldTrialName); |
1160 VariationParameters params; | 1163 VariationParameters params; |
1161 if (!variations::GetVariationParams(kQuicFieldTrialName, ¶ms)) { | 1164 if (!variations::GetVariationParams(kQuicFieldTrialName, ¶ms)) { |
1162 params.clear(); | 1165 params.clear(); |
1163 } | 1166 } |
1164 | 1167 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { | 1260 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { |
1258 net::HostPortPair quic_origin = | 1261 net::HostPortPair quic_origin = |
1259 net::HostPortPair::FromString( | 1262 net::HostPortPair::FromString( |
1260 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn)); | 1263 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn)); |
1261 if (!quic_origin.IsEmpty()) { | 1264 if (!quic_origin.IsEmpty()) { |
1262 globals->origin_to_force_quic_on.set(quic_origin); | 1265 globals->origin_to_force_quic_on.set(quic_origin); |
1263 } | 1266 } |
1264 } | 1267 } |
1265 } | 1268 } |
1266 | 1269 |
1267 bool IOThread::ShouldEnableQuic(const CommandLine& command_line, | 1270 bool IOThread::ShouldEnableQuic(const base::CommandLine& command_line, |
1268 base::StringPiece quic_trial_group) { | 1271 base::StringPiece quic_trial_group) { |
1269 if (command_line.HasSwitch(switches::kDisableQuic)) | 1272 if (command_line.HasSwitch(switches::kDisableQuic)) |
1270 return false; | 1273 return false; |
1271 | 1274 |
1272 if (command_line.HasSwitch(switches::kEnableQuic)) | 1275 if (command_line.HasSwitch(switches::kEnableQuic)) |
1273 return true; | 1276 return true; |
1274 | 1277 |
1275 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || | 1278 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || |
1276 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); | 1279 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
1277 } | 1280 } |
1278 | 1281 |
1279 bool IOThread::ShouldEnableQuicPortSelection( | 1282 bool IOThread::ShouldEnableQuicPortSelection( |
1280 const CommandLine& command_line) { | 1283 const base::CommandLine& command_line) { |
1281 if (command_line.HasSwitch(switches::kDisableQuicPortSelection)) | 1284 if (command_line.HasSwitch(switches::kDisableQuicPortSelection)) |
1282 return false; | 1285 return false; |
1283 | 1286 |
1284 if (command_line.HasSwitch(switches::kEnableQuicPortSelection)) | 1287 if (command_line.HasSwitch(switches::kEnableQuicPortSelection)) |
1285 return true; | 1288 return true; |
1286 | 1289 |
1287 return false; // Default to disabling port selection on all channels. | 1290 return false; // Default to disabling port selection on all channels. |
1288 } | 1291 } |
1289 | 1292 |
1290 bool IOThread::ShouldEnableQuicPacing( | 1293 bool IOThread::ShouldEnableQuicPacing( |
1291 const CommandLine& command_line, | 1294 const base::CommandLine& command_line, |
1292 base::StringPiece quic_trial_group, | 1295 base::StringPiece quic_trial_group, |
1293 const VariationParameters& quic_trial_params) { | 1296 const VariationParameters& quic_trial_params) { |
1294 if (command_line.HasSwitch(switches::kEnableQuicPacing)) | 1297 if (command_line.HasSwitch(switches::kEnableQuicPacing)) |
1295 return true; | 1298 return true; |
1296 | 1299 |
1297 if (command_line.HasSwitch(switches::kDisableQuicPacing)) | 1300 if (command_line.HasSwitch(switches::kDisableQuicPacing)) |
1298 return false; | 1301 return false; |
1299 | 1302 |
1300 return LowerCaseEqualsASCII( | 1303 return LowerCaseEqualsASCII( |
1301 GetVariationParam(quic_trial_params, "enable_pacing"), | 1304 GetVariationParam(quic_trial_params, "enable_pacing"), |
1302 "true"); | 1305 "true"); |
1303 } | 1306 } |
1304 | 1307 |
1305 net::QuicTagVector IOThread::GetQuicConnectionOptions( | 1308 net::QuicTagVector IOThread::GetQuicConnectionOptions( |
1306 const CommandLine& command_line, | 1309 const base::CommandLine& command_line, |
1307 const VariationParameters& quic_trial_params) { | 1310 const VariationParameters& quic_trial_params) { |
1308 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) { | 1311 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) { |
1309 return net::QuicUtils::ParseQuicConnectionOptions( | 1312 return net::QuicUtils::ParseQuicConnectionOptions( |
1310 command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions)); | 1313 command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions)); |
1311 } | 1314 } |
1312 | 1315 |
1313 VariationParameters::const_iterator it = | 1316 VariationParameters::const_iterator it = |
1314 quic_trial_params.find("connection_options"); | 1317 quic_trial_params.find("connection_options"); |
1315 if (it == quic_trial_params.end()) { | 1318 if (it == quic_trial_params.end()) { |
1316 // TODO(rch): remove support for deprecated congestion_options. | 1319 // TODO(rch): remove support for deprecated congestion_options. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 bool IOThread::ShouldDisableLoadingServerInfoForNewServers( | 1384 bool IOThread::ShouldDisableLoadingServerInfoForNewServers( |
1382 const VariationParameters& quic_trial_params) { | 1385 const VariationParameters& quic_trial_params) { |
1383 return LowerCaseEqualsASCII( | 1386 return LowerCaseEqualsASCII( |
1384 GetVariationParam(quic_trial_params, | 1387 GetVariationParam(quic_trial_params, |
1385 "disable_loading_server_info_for_new_servers"), | 1388 "disable_loading_server_info_for_new_servers"), |
1386 "true"); | 1389 "true"); |
1387 } | 1390 } |
1388 | 1391 |
1389 // static | 1392 // static |
1390 size_t IOThread::GetQuicMaxPacketLength( | 1393 size_t IOThread::GetQuicMaxPacketLength( |
1391 const CommandLine& command_line, | 1394 const base::CommandLine& command_line, |
1392 base::StringPiece quic_trial_group, | 1395 base::StringPiece quic_trial_group, |
1393 const VariationParameters& quic_trial_params) { | 1396 const VariationParameters& quic_trial_params) { |
1394 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) { | 1397 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) { |
1395 unsigned value; | 1398 unsigned value; |
1396 if (!base::StringToUint( | 1399 if (!base::StringToUint( |
1397 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength), | 1400 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength), |
1398 &value)) { | 1401 &value)) { |
1399 return 0; | 1402 return 0; |
1400 } | 1403 } |
1401 return value; | 1404 return value; |
1402 } | 1405 } |
1403 | 1406 |
1404 unsigned value; | 1407 unsigned value; |
1405 if (base::StringToUint(GetVariationParam(quic_trial_params, | 1408 if (base::StringToUint(GetVariationParam(quic_trial_params, |
1406 "max_packet_length"), | 1409 "max_packet_length"), |
1407 &value)) { | 1410 &value)) { |
1408 return value; | 1411 return value; |
1409 } | 1412 } |
1410 return 0; | 1413 return 0; |
1411 } | 1414 } |
1412 | 1415 |
1413 // static | 1416 // static |
1414 net::QuicVersion IOThread::GetQuicVersion( | 1417 net::QuicVersion IOThread::GetQuicVersion( |
1415 const CommandLine& command_line, | 1418 const base::CommandLine& command_line, |
1416 const VariationParameters& quic_trial_params) { | 1419 const VariationParameters& quic_trial_params) { |
1417 if (command_line.HasSwitch(switches::kQuicVersion)) { | 1420 if (command_line.HasSwitch(switches::kQuicVersion)) { |
1418 return ParseQuicVersion( | 1421 return ParseQuicVersion( |
1419 command_line.GetSwitchValueASCII(switches::kQuicVersion)); | 1422 command_line.GetSwitchValueASCII(switches::kQuicVersion)); |
1420 } | 1423 } |
1421 | 1424 |
1422 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version")); | 1425 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version")); |
1423 } | 1426 } |
1424 | 1427 |
1425 // static | 1428 // static |
1426 net::QuicVersion IOThread::ParseQuicVersion(const std::string& quic_version) { | 1429 net::QuicVersion IOThread::ParseQuicVersion(const std::string& quic_version) { |
1427 net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); | 1430 net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); |
1428 for (size_t i = 0; i < supported_versions.size(); ++i) { | 1431 for (size_t i = 0; i < supported_versions.size(); ++i) { |
1429 net::QuicVersion version = supported_versions[i]; | 1432 net::QuicVersion version = supported_versions[i]; |
1430 if (net::QuicVersionToString(version) == quic_version) { | 1433 if (net::QuicVersionToString(version) == quic_version) { |
1431 return version; | 1434 return version; |
1432 } | 1435 } |
1433 } | 1436 } |
1434 | 1437 |
1435 return net::QUIC_VERSION_UNSUPPORTED; | 1438 return net::QUIC_VERSION_UNSUPPORTED; |
1436 } | 1439 } |
OLD | NEW |