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

Side by Side Diff: ios/chrome/browser/ios_chrome_io_thread.mm

Issue 1892123003: Add components/network_session_configurator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on https://crrev.com/1945513002. Created 4 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
« no previous file with comments | « ios/chrome/browser/ios_chrome_io_thread.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ios/chrome/browser/ios_chrome_io_thread.h" 5 #include "ios/chrome/browser/ios_chrome_io_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/debug/leak_tracker.h" 16 #include "base/debug/leak_tracker.h"
17 #include "base/environment.h" 17 #include "base/environment.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/field_trial.h" 21 #include "base/metrics/field_trial.h"
22 #include "base/stl_util.h" 22 #include "base/stl_util.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_piece.h"
25 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
26 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
27 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
28 #include "base/threading/thread.h" 27 #include "base/threading/thread.h"
29 #include "base/threading/worker_pool.h" 28 #include "base/threading/worker_pool.h"
30 #include "base/time/time.h" 29 #include "base/time/time.h"
31 #include "base/trace_event/trace_event.h" 30 #include "base/trace_event/trace_event.h"
32 #include "components/net_log/chrome_net_log.h" 31 #include "components/net_log/chrome_net_log.h"
32 #include "components/network_session_configurator/network_session_configurator.h "
33 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
34 #include "components/proxy_config/pref_proxy_config_tracker.h" 34 #include "components/proxy_config/pref_proxy_config_tracker.h"
35 #include "components/variations/variations_associated_data.h" 35 #include "components/variations/variations_associated_data.h"
36 #include "components/version_info/version_info.h" 36 #include "components/version_info/version_info.h"
37 #include "ios/chrome/browser/chrome_switches.h" 37 #include "ios/chrome/browser/chrome_switches.h"
38 #include "ios/chrome/browser/net/cookie_util.h" 38 #include "ios/chrome/browser/net/cookie_util.h"
39 #include "ios/chrome/browser/net/ios_chrome_network_delegate.h" 39 #include "ios/chrome/browser/net/ios_chrome_network_delegate.h"
40 #include "ios/chrome/browser/net/proxy_service_factory.h" 40 #include "ios/chrome/browser/net/proxy_service_factory.h"
41 #include "ios/chrome/common/channel_info.h" 41 #include "ios/chrome/common/channel_info.h"
42 #include "ios/web/public/user_agent.h" 42 #include "ios/web/public/user_agent.h"
(...skipping 10 matching lines...) Expand all
53 #include "net/cert/multi_threaded_cert_verifier.h" 53 #include "net/cert/multi_threaded_cert_verifier.h"
54 #include "net/cookies/cookie_monster.h" 54 #include "net/cookies/cookie_monster.h"
55 #include "net/cookies/cookie_store.h" 55 #include "net/cookies/cookie_store.h"
56 #include "net/dns/host_cache.h" 56 #include "net/dns/host_cache.h"
57 #include "net/dns/host_resolver.h" 57 #include "net/dns/host_resolver.h"
58 #include "net/dns/mapped_host_resolver.h" 58 #include "net/dns/mapped_host_resolver.h"
59 #include "net/http/http_auth_filter.h" 59 #include "net/http/http_auth_filter.h"
60 #include "net/http/http_auth_handler_factory.h" 60 #include "net/http/http_auth_handler_factory.h"
61 #include "net/http/http_auth_preferences.h" 61 #include "net/http/http_auth_preferences.h"
62 #include "net/http/http_network_layer.h" 62 #include "net/http/http_network_layer.h"
63 #include "net/http/http_network_session.h"
64 #include "net/http/http_server_properties_impl.h" 63 #include "net/http/http_server_properties_impl.h"
65 #include "net/nqe/external_estimate_provider.h" 64 #include "net/nqe/external_estimate_provider.h"
66 #include "net/nqe/network_quality_estimator.h" 65 #include "net/nqe/network_quality_estimator.h"
67 #include "net/proxy/proxy_config_service.h" 66 #include "net/proxy/proxy_config_service.h"
68 #include "net/proxy/proxy_script_fetcher_impl.h" 67 #include "net/proxy/proxy_script_fetcher_impl.h"
69 #include "net/proxy/proxy_service.h" 68 #include "net/proxy/proxy_service.h"
70 #include "net/quic/crypto/crypto_protocol.h"
71 #include "net/quic/quic_protocol.h"
72 #include "net/quic/quic_utils.h"
73 #include "net/socket/tcp_client_socket.h" 69 #include "net/socket/tcp_client_socket.h"
74 #include "net/spdy/spdy_session.h" 70 #include "net/spdy/spdy_session.h"
75 #include "net/ssl/channel_id_service.h" 71 #include "net/ssl/channel_id_service.h"
76 #include "net/ssl/default_channel_id_store.h" 72 #include "net/ssl/default_channel_id_store.h"
77 #include "net/url_request/data_protocol_handler.h" 73 #include "net/url_request/data_protocol_handler.h"
78 #include "net/url_request/file_protocol_handler.h" 74 #include "net/url_request/file_protocol_handler.h"
79 #include "net/url_request/static_http_user_agent_settings.h" 75 #include "net/url_request/static_http_user_agent_settings.h"
80 #include "net/url_request/url_request_backoff_manager.h" 76 #include "net/url_request/url_request_backoff_manager.h"
81 #include "net/url_request/url_request_context.h" 77 #include "net/url_request/url_request_context.h"
82 #include "net/url_request/url_request_context_builder.h" 78 #include "net/url_request/url_request_context_builder.h"
83 #include "net/url_request/url_request_context_getter.h" 79 #include "net/url_request/url_request_context_getter.h"
84 #include "net/url_request/url_request_job_factory_impl.h" 80 #include "net/url_request/url_request_job_factory_impl.h"
85 #include "url/url_constants.h" 81 #include "url/url_constants.h"
86 82
87 // The IOSChromeIOThread object must outlive any tasks posted to the IO thread 83 // The IOSChromeIOThread object must outlive any tasks posted to the IO thread
88 // before the Quit task, so base::Bind() calls are not refcounted. 84 // before the Quit task, so base::Bind() calls are not refcounted.
89 85
90 namespace { 86 namespace {
91 87
92 const char kSupportedAuthSchemes[] = "basic,digest,ntlm"; 88 const char kSupportedAuthSchemes[] = "basic,digest,ntlm";
93 89
94 const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen";
95 const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled";
96
97 const char kQuicFieldTrialName[] = "QUIC";
98 const char kQuicFieldTrialEnabledGroupName[] = "Enabled";
99 const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled";
100
101 // The SPDY trial composes two different trial plus control groups:
102 // * A "holdback" group with SPDY disabled, and corresponding control
103 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site
104 // operators to do feature detection rather than UA-sniffing. As such, this
105 // trial runs continuously.
106 // * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and
107 // eventual SPDY/4 deployment.
108 const char kSpdyFieldTrialName[] = "SPDY";
109 const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled";
110 const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled";
111 const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled";
112 const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized";
113
114 // The AltSvc trial controls whether Alt-Svc headers are parsed.
115 // Disabled:
116 // Alt-Svc headers are not parsed.
117 // Alternate-Protocol headers are parsed.
118 // Enabled:
119 // Alt-Svc headers are parsed, but only same-host entries are used by
120 // default. (Use "enable_alternative_service_with_different_host" QUIC
121 // parameter to enable entries with different hosts.)
122 // Alternate-Protocol headers are ignored for responses that have an Alt-Svc
123 // header.
124 const char kAltSvcFieldTrialName[] = "ParseAltSvc";
125 const char kAltSvcFieldTrialDisabledPrefix[] = "AltSvcDisabled";
126 const char kAltSvcFieldTrialEnabledPrefix[] = "AltSvcEnabled";
127
128 // Field trial for network quality estimator. Seeds RTT and downstream 90 // Field trial for network quality estimator. Seeds RTT and downstream
129 // throughput observations with values that correspond to the connection type 91 // throughput observations with values that correspond to the connection type
130 // determined by the operating system. 92 // determined by the operating system.
131 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; 93 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
132 94
133 // Field trial for NPN.
134 const char kNpnTrialName[] = "NPN";
135 const char kNpnTrialEnabledGroupNamePrefix[] = "Enable";
136 const char kNpnTrialDisabledGroupNamePrefix[] = "Disable";
137
138 // Field trial for priority dependencies.
139 const char kSpdyDependenciesFieldTrial[] = "SpdyEnableDependencies";
140 const char kSpdyDependenciesFieldTrialEnable[] = "Enable";
141 const char kSpdyDepencenciesFieldTrialDisable[] = "Disable";
142
143 // Used for the "system" URLRequestContext. 95 // Used for the "system" URLRequestContext.
144 class SystemURLRequestContext : public net::URLRequestContext { 96 class SystemURLRequestContext : public net::URLRequestContext {
145 public: 97 public:
146 SystemURLRequestContext() { 98 SystemURLRequestContext() {
147 } 99 }
148 100
149 private: 101 private:
150 ~SystemURLRequestContext() override { 102 ~SystemURLRequestContext() override {
151 AssertNoURLRequests(); 103 AssertNoURLRequests();
152 } 104 }
(...skipping 25 matching lines...) Expand all
178 int GetSwitchValueAsInt(const base::CommandLine& command_line, 130 int GetSwitchValueAsInt(const base::CommandLine& command_line,
179 const std::string& switch_name) { 131 const std::string& switch_name) {
180 int value; 132 int value;
181 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), 133 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
182 &value)) { 134 &value)) {
183 return 0; 135 return 0;
184 } 136 }
185 return value; 137 return value;
186 } 138 }
187 139
188 // Returns the value associated with |key| in |params| or "" if the
189 // key is not present in the map.
190 const std::string& GetVariationParam(
191 const std::map<std::string, std::string>& params,
192 const std::string& key) {
193 std::map<std::string, std::string>::const_iterator it = params.find(key);
194 if (it == params.end())
195 return base::EmptyString();
196
197 return it->second;
198 }
199
200 } // namespace 140 } // namespace
201 141
202 class IOSChromeIOThread::LoggingNetworkChangeObserver 142 class IOSChromeIOThread::LoggingNetworkChangeObserver
203 : public net::NetworkChangeNotifier::IPAddressObserver, 143 : public net::NetworkChangeNotifier::IPAddressObserver,
204 public net::NetworkChangeNotifier::ConnectionTypeObserver, 144 public net::NetworkChangeNotifier::ConnectionTypeObserver,
205 public net::NetworkChangeNotifier::NetworkChangeObserver { 145 public net::NetworkChangeNotifier::NetworkChangeObserver {
206 public: 146 public:
207 // |net_log| must remain valid throughout our lifetime. 147 // |net_log| must remain valid throughout our lifetime.
208 explicit LoggingNetworkChangeObserver(net::NetLog* net_log) 148 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
209 : net_log_(net_log) { 149 : net_log_(net_log) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 DCHECK(globals_); 243 DCHECK(globals_);
304 } 244 }
305 245
306 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: 246 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
307 ~SystemRequestContextLeakChecker() { 247 ~SystemRequestContextLeakChecker() {
308 if (globals_->system_request_context.get()) 248 if (globals_->system_request_context.get())
309 globals_->system_request_context->AssertNoURLRequests(); 249 globals_->system_request_context->AssertNoURLRequests();
310 } 250 }
311 251
312 IOSChromeIOThread::Globals::Globals() 252 IOSChromeIOThread::Globals::Globals()
313 : system_request_context_leak_checker(this), 253 : system_request_context_leak_checker(this) {}
314 testing_fixed_http_port(0),
315 testing_fixed_https_port(0) {}
316 254
317 IOSChromeIOThread::Globals::~Globals() {} 255 IOSChromeIOThread::Globals::~Globals() {}
318 256
319 // |local_state| is passed in explicitly in order to (1) reduce implicit 257 // |local_state| is passed in explicitly in order to (1) reduce implicit
320 // dependencies and (2) make IOSChromeIOThread more flexible for testing. 258 // dependencies and (2) make IOSChromeIOThread more flexible for testing.
321 IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state, 259 IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state,
322 net_log::ChromeNetLog* net_log) 260 net_log::ChromeNetLog* net_log)
323 : net_log_(net_log), 261 : net_log_(net_log),
324 globals_(nullptr), 262 globals_(nullptr),
325 creation_time_(base::TimeTicks::Now()), 263 creation_time_(base::TimeTicks::Now()),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 globals_->transport_security_state.reset(new net::TransportSecurityState()); 354 globals_->transport_security_state.reset(new net::TransportSecurityState());
417 355
418 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs( 356 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs(
419 net::ct::CreateLogVerifiersForKnownLogs()); 357 net::ct::CreateLogVerifiersForKnownLogs());
420 358
421 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); 359 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
422 globals_->cert_transparency_verifier.reset(ct_verifier); 360 globals_->cert_transparency_verifier.reset(ct_verifier);
423 // Add built-in logs 361 // Add built-in logs
424 ct_verifier->AddLogs(ct_logs); 362 ct_verifier->AddLogs(ct_logs);
425 363
426 net::CTPolicyEnforcer* policy_enforcer = new net::CTPolicyEnforcer; 364 params_.ct_policy_enforcer = new net::CTPolicyEnforcer;
427 globals_->ct_policy_enforcer.reset(policy_enforcer);
428 365
429 globals_->ssl_config_service = GetSSLConfigService(); 366 globals_->ssl_config_service = GetSSLConfigService();
430 367
431 CreateDefaultAuthHandlerFactory(); 368 CreateDefaultAuthHandlerFactory();
432 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); 369 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
433 // In-memory cookie store. 370 // In-memory cookie store.
434 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr)); 371 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr));
435 // In-memory channel ID store. 372 // In-memory channel ID store.
436 globals_->system_channel_id_service.reset( 373 globals_->system_channel_id_service.reset(
437 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr), 374 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr),
438 base::WorkerPool::GetTaskRunner(true))); 375 base::WorkerPool::GetTaskRunner(true)));
439 globals_->system_cookie_store->SetChannelIDServiceID( 376 globals_->system_cookie_store->SetChannelIDServiceID(
440 globals_->system_channel_id_service->GetUniqueID()); 377 globals_->system_channel_id_service->GetUniqueID());
441 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings( 378 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings(
442 std::string(), web::GetWebClient()->GetUserAgent(false))); 379 std::string(), web::GetWebClient()->GetUserAgent(false)));
443 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpPort)) { 380 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpPort)) {
444 globals_->testing_fixed_http_port = 381 params_.testing_fixed_http_port =
445 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpPort); 382 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpPort);
446 } 383 }
447 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpsPort)) { 384 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpsPort)) {
448 globals_->testing_fixed_https_port = 385 params_.testing_fixed_https_port =
449 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpsPort); 386 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpsPort);
450 } 387 }
451 ConfigureAltSvcGlobals(
452 base::FieldTrialList::FindFullName(kAltSvcFieldTrialName), globals_);
453 ConfigureQuic();
454 ConfigurePriorityDependencies();
455 InitializeNetworkOptions();
456 388
389 params_.ignore_certificate_errors = false;
390 params_.enable_quic_port_selection = false;
391 params_.enable_user_alternate_protocol_ports = false;
392
393 std::string quic_user_agent_id = ::GetChannelString();
394 if (!quic_user_agent_id.empty())
395 quic_user_agent_id.push_back(' ');
396 quic_user_agent_id.append(
397 version_info::GetProductNameAndVersionForUserAgent());
398 quic_user_agent_id.push_back(' ');
399 quic_user_agent_id.append(web::BuildOSCpuInfo());
400
401 network_session_configurator::ParseFieldTrials(true, true, quic_user_agent_id,
402 &params_);
457 const version_info::Channel channel = ::GetChannel(); 403 const version_info::Channel channel = ::GetChannel();
458 if (channel == version_info::Channel::UNKNOWN || 404 if (channel == version_info::Channel::UNKNOWN ||
459 channel == version_info::Channel::CANARY || 405 channel == version_info::Channel::CANARY ||
460 channel == version_info::Channel::DEV) { 406 channel == version_info::Channel::DEV) {
461 globals_->url_request_backoff_manager.reset( 407 globals_->url_request_backoff_manager.reset(
462 new net::URLRequestBackoffManager()); 408 new net::URLRequestBackoffManager());
463 } 409 }
464 410
465 // InitSystemRequestContext turns right around and posts a task back 411 // InitSystemRequestContext turns right around and posts a task back
466 // to the IO thread, so we can't let it run until we know the IO 412 // to the IO thread, so we can't let it run until we know the IO
(...skipping 24 matching lines...) Expand all
491 network_change_observer_.reset(); 437 network_change_observer_.reset();
492 438
493 system_proxy_config_service_.reset(); 439 system_proxy_config_service_.reset();
494 440
495 delete globals_; 441 delete globals_;
496 globals_ = nullptr; 442 globals_ = nullptr;
497 443
498 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 444 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
499 } 445 }
500 446
501 void IOSChromeIOThread::InitializeNetworkOptions() {
502 std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
503 VariationParameters params;
504 if (!variations::GetVariationParams(kSpdyFieldTrialName, &params)) {
505 params.clear();
506 }
507 ConfigureSpdyGlobals(group, params, globals_);
508
509 ConfigureSSLTCPFastOpen();
510
511 ConfigureNPNGlobals(base::FieldTrialList::FindFullName(kNpnTrialName),
512 globals_);
513
514 // TODO(rch): Make the client socket factory a per-network session
515 // instance, constructed from a NetworkSession::Params, to allow us
516 // to move this option to IOSChromeIOThread::Globals &
517 // HttpNetworkSession::Params.
518 }
519
520 void IOSChromeIOThread::ConfigureSSLTCPFastOpen() {
521 const std::string trial_group =
522 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName);
523 if (trial_group == kTCPFastOpenHttpsEnabledGroupName)
524 globals_->enable_tcp_fast_open_for_ssl.set(true);
525 }
526
527 // static
528 void IOSChromeIOThread::ConfigureSpdyGlobals(
529 base::StringPiece spdy_trial_group,
530 const VariationParameters& spdy_trial_params,
531 IOSChromeIOThread::Globals* globals) {
532 // No SPDY command-line flags have been specified. Examine trial groups.
533 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) {
534 net::HttpStreamFactory::set_spdy_enabled(false);
535 return;
536 }
537 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy31GroupNamePrefix)) {
538 globals->enable_spdy31.set(true);
539 globals->enable_http2.set(false);
540 return;
541 }
542 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy4GroupNamePrefix)) {
543 globals->enable_spdy31.set(true);
544 globals->enable_http2.set(true);
545 return;
546 }
547 if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) {
548 bool spdy_enabled = false;
549 globals->enable_spdy31.set(false);
550 globals->enable_http2.set(false);
551 if (base::LowerCaseEqualsASCII(
552 GetVariationParam(spdy_trial_params, "enable_http2"), "true")) {
553 spdy_enabled = true;
554 globals->enable_http2.set(true);
555 }
556 if (base::LowerCaseEqualsASCII(
557 GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) {
558 spdy_enabled = true;
559 globals->enable_spdy31.set(true);
560 }
561 // TODO(bnc): https://crbug.com/521597
562 // HttpStreamFactory::spdy_enabled_ is redundant with globals->enable_http2
563 // and enable_spdy31, can it be eliminated?
564 net::HttpStreamFactory::set_spdy_enabled(spdy_enabled);
565 return;
566 }
567
568 // By default, enable HTTP/2.
569 globals->enable_spdy31.set(true);
570 globals->enable_http2.set(true);
571 }
572
573 // static
574 void IOSChromeIOThread::ConfigureAltSvcGlobals(
575 base::StringPiece altsvc_trial_group,
576 IOSChromeIOThread::Globals* globals) {
577 if (altsvc_trial_group.starts_with(kAltSvcFieldTrialEnabledPrefix)) {
578 globals->parse_alternative_services.set(true);
579 return;
580 }
581 if (altsvc_trial_group.starts_with(kAltSvcFieldTrialDisabledPrefix)) {
582 globals->parse_alternative_services.set(false);
583 }
584 }
585
586 // static
587 void IOSChromeIOThread::ConfigureNPNGlobals(
588 base::StringPiece npn_trial_group,
589 IOSChromeIOThread::Globals* globals) {
590 if (npn_trial_group.starts_with(kNpnTrialEnabledGroupNamePrefix)) {
591 globals->enable_npn.set(true);
592 } else if (npn_trial_group.starts_with(kNpnTrialDisabledGroupNamePrefix)) {
593 globals->enable_npn.set(false);
594 }
595 }
596
597 void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() { 447 void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() {
598 std::vector<std::string> supported_schemes = 448 std::vector<std::string> supported_schemes =
599 base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE, 449 base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE,
600 base::SPLIT_WANT_NONEMPTY); 450 base::SPLIT_WANT_NONEMPTY);
601 globals_->http_auth_preferences.reset( 451 globals_->http_auth_preferences.reset(
602 new net::HttpAuthPreferences(supported_schemes, std::string())); 452 new net::HttpAuthPreferences(supported_schemes, std::string()));
603 globals_->http_auth_handler_factory = 453 globals_->http_auth_handler_factory =
604 net::HttpAuthHandlerRegistryFactory::Create( 454 net::HttpAuthHandlerRegistryFactory::Create(
605 globals_->http_auth_preferences.get(), globals_->host_resolver.get()); 455 globals_->http_auth_preferences.get(), globals_->host_resolver.get());
606 } 456 }
607 457
608 void IOSChromeIOThread::ClearHostCache() { 458 void IOSChromeIOThread::ClearHostCache() {
609 DCHECK_CURRENTLY_ON(web::WebThread::IO); 459 DCHECK_CURRENTLY_ON(web::WebThread::IO);
610 460
611 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); 461 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
612 if (host_cache) 462 if (host_cache)
613 host_cache->clear(); 463 host_cache->clear();
614 } 464 }
615 465
616 void IOSChromeIOThread::InitializeNetworkSessionParams( 466 const net::HttpNetworkSession::Params& IOSChromeIOThread::NetworkSessionParams()
617 net::HttpNetworkSession::Params* params) { 467 const {
618 InitializeNetworkSessionParamsFromGlobals(*globals_, params); 468 return params_;
619 }
620
621 void IOSChromeIOThread::InitializeNetworkSessionParamsFromGlobals(
622 const IOSChromeIOThread::Globals& globals,
623 net::HttpNetworkSession::Params* params) {
624 // The next two properties of the params don't seem to be
625 // elements of URLRequestContext, so they must be set here.
626 params->ct_policy_enforcer = globals.ct_policy_enforcer.get();
627
628 params->ignore_certificate_errors = false;
629 params->testing_fixed_http_port = globals.testing_fixed_http_port;
630 params->testing_fixed_https_port = globals.testing_fixed_https_port;
631 globals.enable_tcp_fast_open_for_ssl.CopyToIfSet(
632 &params->enable_tcp_fast_open_for_ssl);
633
634 globals.enable_spdy31.CopyToIfSet(&params->enable_spdy31);
635 globals.enable_http2.CopyToIfSet(&params->enable_http2);
636 globals.parse_alternative_services.CopyToIfSet(
637 &params->parse_alternative_services);
638 globals.enable_alternative_service_with_different_host.CopyToIfSet(
639 &params->enable_alternative_service_with_different_host);
640
641 globals.enable_npn.CopyToIfSet(&params->enable_npn);
642
643 globals.enable_priority_dependencies.CopyToIfSet(
644 &params->enable_priority_dependencies);
645
646 globals.enable_quic.CopyToIfSet(&params->enable_quic);
647 globals.quic_always_require_handshake_confirmation.CopyToIfSet(
648 &params->quic_always_require_handshake_confirmation);
649 globals.quic_disable_connection_pooling.CopyToIfSet(
650 &params->quic_disable_connection_pooling);
651 globals.quic_load_server_info_timeout_srtt_multiplier.CopyToIfSet(
652 &params->quic_load_server_info_timeout_srtt_multiplier);
653 globals.quic_enable_connection_racing.CopyToIfSet(
654 &params->quic_enable_connection_racing);
655 globals.quic_enable_non_blocking_io.CopyToIfSet(
656 &params->quic_enable_non_blocking_io);
657 globals.quic_prefer_aes.CopyToIfSet(&params->quic_prefer_aes);
658 globals.quic_disable_disk_cache.CopyToIfSet(&params->quic_disable_disk_cache);
659 globals.quic_max_number_of_lossy_connections.CopyToIfSet(
660 &params->quic_max_number_of_lossy_connections);
661 globals.quic_packet_loss_threshold.CopyToIfSet(
662 &params->quic_packet_loss_threshold);
663 globals.quic_socket_receive_buffer_size.CopyToIfSet(
664 &params->quic_socket_receive_buffer_size);
665 globals.quic_delay_tcp_race.CopyToIfSet(&params->quic_delay_tcp_race);
666 params->enable_quic_port_selection = false;
667 globals.quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length);
668 globals.quic_user_agent_id.CopyToIfSet(&params->quic_user_agent_id);
669 globals.quic_supported_versions.CopyToIfSet(&params->quic_supported_versions);
670 params->quic_connection_options = globals.quic_connection_options;
671 globals.quic_close_sessions_on_ip_change.CopyToIfSet(
672 &params->quic_close_sessions_on_ip_change);
673
674 params->enable_user_alternate_protocol_ports = false;
675 } 469 }
676 470
677 base::TimeTicks IOSChromeIOThread::creation_time() const { 471 base::TimeTicks IOSChromeIOThread::creation_time() const {
678 return creation_time_; 472 return creation_time_;
679 } 473 }
680 474
681 net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() { 475 net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() {
682 return ssl_config_service_manager_->Get(); 476 return ssl_config_service_manager_->Get();
683 } 477 }
684 478
(...skipping 27 matching lines...) Expand all
712 void IOSChromeIOThread::InitSystemRequestContextOnIOThread() { 506 void IOSChromeIOThread::InitSystemRequestContextOnIOThread() {
713 DCHECK_CURRENTLY_ON(web::WebThread::IO); 507 DCHECK_CURRENTLY_ON(web::WebThread::IO);
714 DCHECK(!globals_->system_proxy_service.get()); 508 DCHECK(!globals_->system_proxy_service.get());
715 DCHECK(system_proxy_config_service_.get()); 509 DCHECK(system_proxy_config_service_.get());
716 510
717 globals_->system_proxy_service = ios::ProxyServiceFactory::CreateProxyService( 511 globals_->system_proxy_service = ios::ProxyServiceFactory::CreateProxyService(
718 net_log_, nullptr, globals_->system_network_delegate.get(), 512 net_log_, nullptr, globals_->system_network_delegate.get(),
719 std::move(system_proxy_config_service_), true /* quick_check_enabled */); 513 std::move(system_proxy_config_service_), true /* quick_check_enabled */);
720 514
721 globals_->system_request_context.reset( 515 globals_->system_request_context.reset(
722 ConstructSystemRequestContext(globals_, net_log_)); 516 ConstructSystemRequestContext(globals_, params_, net_log_));
723 }
724
725 void IOSChromeIOThread::ConfigurePriorityDependencies() {
726 std::string group =
727 base::FieldTrialList::FindFullName(kSpdyDependenciesFieldTrial);
728 if (group == kSpdyDependenciesFieldTrialEnable) {
729 globals_->enable_priority_dependencies.set(true);
730 } else if (group == kSpdyDepencenciesFieldTrialDisable) {
731 globals_->enable_priority_dependencies.set(false);
732 }
733 }
734
735 void IOSChromeIOThread::ConfigureQuic() {
736 // Always fetch the field trial group to ensure it is reported correctly.
737 // The command line flags will be associated with a group that is reported
738 // so long as trial is actually queried.
739 std::string group = base::FieldTrialList::FindFullName(kQuicFieldTrialName);
740 VariationParameters params;
741 if (!variations::GetVariationParams(kQuicFieldTrialName, &params)) {
742 params.clear();
743 }
744
745 ConfigureQuicGlobals(group, params, globals_);
746 }
747
748 void IOSChromeIOThread::ConfigureQuicGlobals(
749 base::StringPiece quic_trial_group,
750 const VariationParameters& quic_trial_params,
751 IOSChromeIOThread::Globals* globals) {
752 bool enable_quic = ShouldEnableQuic(quic_trial_group);
753 globals->enable_quic.set(enable_quic);
754
755 if (ShouldQuicEnableAlternativeServicesForDifferentHost(quic_trial_params)) {
756 globals->enable_alternative_service_with_different_host.set(true);
757 globals->parse_alternative_services.set(true);
758 } else {
759 globals->enable_alternative_service_with_different_host.set(false);
760 }
761
762 if (enable_quic) {
763 globals->quic_always_require_handshake_confirmation.set(
764 ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params));
765 globals->quic_disable_connection_pooling.set(
766 ShouldQuicDisableConnectionPooling(quic_trial_params));
767 int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params);
768 if (receive_buffer_size != 0) {
769 globals->quic_socket_receive_buffer_size.set(receive_buffer_size);
770 }
771 globals->quic_delay_tcp_race.set(ShouldQuicDelayTcpRace(quic_trial_params));
772 float load_server_info_timeout_srtt_multiplier =
773 GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params);
774 if (load_server_info_timeout_srtt_multiplier != 0) {
775 globals->quic_load_server_info_timeout_srtt_multiplier.set(
776 load_server_info_timeout_srtt_multiplier);
777 }
778 globals->quic_enable_connection_racing.set(
779 ShouldQuicEnableConnectionRacing(quic_trial_params));
780 globals->quic_enable_non_blocking_io.set(
781 ShouldQuicEnableNonBlockingIO(quic_trial_params));
782 globals->quic_disable_disk_cache.set(
783 ShouldQuicDisableDiskCache(quic_trial_params));
784 globals->quic_prefer_aes.set(ShouldQuicPreferAes(quic_trial_params));
785 int max_number_of_lossy_connections =
786 GetQuicMaxNumberOfLossyConnections(quic_trial_params);
787 if (max_number_of_lossy_connections != 0) {
788 globals->quic_max_number_of_lossy_connections.set(
789 max_number_of_lossy_connections);
790 }
791 float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params);
792 if (packet_loss_threshold != 0)
793 globals->quic_packet_loss_threshold.set(packet_loss_threshold);
794 globals->quic_connection_options =
795 GetQuicConnectionOptions(quic_trial_params);
796 globals->quic_close_sessions_on_ip_change.set(
797 ShouldQuicCloseSessionsOnIpChange(quic_trial_params));
798 }
799
800 size_t max_packet_length = GetQuicMaxPacketLength(quic_trial_params);
801 if (max_packet_length != 0) {
802 globals->quic_max_packet_length.set(max_packet_length);
803 }
804
805 std::string quic_user_agent_id = ::GetChannelString();
806 if (!quic_user_agent_id.empty())
807 quic_user_agent_id.push_back(' ');
808 quic_user_agent_id.append(
809 version_info::GetProductNameAndVersionForUserAgent());
810 quic_user_agent_id.push_back(' ');
811 quic_user_agent_id.append(web::BuildOSCpuInfo());
812 globals->quic_user_agent_id.set(quic_user_agent_id);
813
814 net::QuicVersion version = GetQuicVersion(quic_trial_params);
815 if (version != net::QUIC_VERSION_UNSUPPORTED) {
816 net::QuicVersionVector supported_versions;
817 supported_versions.push_back(version);
818 globals->quic_supported_versions.set(supported_versions);
819 }
820 }
821
822 bool IOSChromeIOThread::ShouldEnableQuic(base::StringPiece quic_trial_group) {
823 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) ||
824 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
825 }
826
827 net::QuicTagVector IOSChromeIOThread::GetQuicConnectionOptions(
828 const VariationParameters& quic_trial_params) {
829 VariationParameters::const_iterator it =
830 quic_trial_params.find("connection_options");
831 if (it == quic_trial_params.end()) {
832 return net::QuicTagVector();
833 }
834
835 return net::QuicUtils::ParseQuicConnectionOptions(it->second);
836 }
837
838 bool IOSChromeIOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
839 const VariationParameters& quic_trial_params) {
840 return base::LowerCaseEqualsASCII(
841 GetVariationParam(quic_trial_params,
842 "always_require_handshake_confirmation"),
843 "true");
844 }
845
846 bool IOSChromeIOThread::ShouldQuicDisableConnectionPooling(
847 const VariationParameters& quic_trial_params) {
848 return base::LowerCaseEqualsASCII(
849 GetVariationParam(quic_trial_params, "disable_connection_pooling"),
850 "true");
851 }
852
853 float IOSChromeIOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier(
854 const VariationParameters& quic_trial_params) {
855 double value;
856 if (base::StringToDouble(
857 GetVariationParam(quic_trial_params, "load_server_info_time_to_srtt"),
858 &value)) {
859 return static_cast<float>(value);
860 }
861 return 0.0f;
862 }
863
864 bool IOSChromeIOThread::ShouldQuicEnableConnectionRacing(
865 const VariationParameters& quic_trial_params) {
866 return base::LowerCaseEqualsASCII(
867 GetVariationParam(quic_trial_params, "enable_connection_racing"), "true");
868 }
869
870 bool IOSChromeIOThread::ShouldQuicEnableNonBlockingIO(
871 const VariationParameters& quic_trial_params) {
872 return base::LowerCaseEqualsASCII(
873 GetVariationParam(quic_trial_params, "enable_non_blocking_io"), "true");
874 }
875
876 bool IOSChromeIOThread::ShouldQuicDisableDiskCache(
877 const VariationParameters& quic_trial_params) {
878 return base::LowerCaseEqualsASCII(
879 GetVariationParam(quic_trial_params, "disable_disk_cache"), "true");
880 }
881
882 bool IOSChromeIOThread::ShouldQuicPreferAes(
883 const VariationParameters& quic_trial_params) {
884 return base::LowerCaseEqualsASCII(
885 GetVariationParam(quic_trial_params, "prefer_aes"), "true");
886 }
887
888 bool IOSChromeIOThread::ShouldQuicEnableAlternativeServicesForDifferentHost(
889 const VariationParameters& quic_trial_params) {
890 // TODO(bnc): Remove inaccurately named "use_alternative_services" parameter.
891 return base::LowerCaseEqualsASCII(
892 GetVariationParam(quic_trial_params, "use_alternative_services"),
893 "true") ||
894 base::LowerCaseEqualsASCII(
895 GetVariationParam(
896 quic_trial_params,
897 "enable_alternative_service_with_different_host"),
898 "true");
899 }
900
901 int IOSChromeIOThread::GetQuicMaxNumberOfLossyConnections(
902 const VariationParameters& quic_trial_params) {
903 int value;
904 if (base::StringToInt(GetVariationParam(quic_trial_params,
905 "max_number_of_lossy_connections"),
906 &value)) {
907 return value;
908 }
909 return 0;
910 }
911
912 float IOSChromeIOThread::GetQuicPacketLossThreshold(
913 const VariationParameters& quic_trial_params) {
914 double value;
915 if (base::StringToDouble(
916 GetVariationParam(quic_trial_params, "packet_loss_threshold"),
917 &value)) {
918 return static_cast<float>(value);
919 }
920 return 0.0f;
921 }
922
923 int IOSChromeIOThread::GetQuicSocketReceiveBufferSize(
924 const VariationParameters& quic_trial_params) {
925 int value;
926 if (base::StringToInt(
927 GetVariationParam(quic_trial_params, "receive_buffer_size"),
928 &value)) {
929 return value;
930 }
931 return 0;
932 }
933
934 bool IOSChromeIOThread::ShouldQuicDelayTcpRace(
935 const VariationParameters& quic_trial_params) {
936 return base::LowerCaseEqualsASCII(
937 GetVariationParam(quic_trial_params, "delay_tcp_race"), "true");
938 }
939
940 bool IOSChromeIOThread::ShouldQuicCloseSessionsOnIpChange(
941 const VariationParameters& quic_trial_params) {
942 return base::LowerCaseEqualsASCII(
943 GetVariationParam(quic_trial_params, "close_sessions_on_ip_change"),
944 "true");
945 }
946
947 size_t IOSChromeIOThread::GetQuicMaxPacketLength(
948 const VariationParameters& quic_trial_params) {
949 unsigned value;
950 if (base::StringToUint(
951 GetVariationParam(quic_trial_params, "max_packet_length"), &value)) {
952 return value;
953 }
954 return 0;
955 }
956
957 net::QuicVersion IOSChromeIOThread::GetQuicVersion(
958 const VariationParameters& quic_trial_params) {
959 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version"));
960 }
961
962 net::QuicVersion IOSChromeIOThread::ParseQuicVersion(
963 const std::string& quic_version) {
964 net::QuicVersionVector supported_versions = net::QuicSupportedVersions();
965 for (size_t i = 0; i < supported_versions.size(); ++i) {
966 net::QuicVersion version = supported_versions[i];
967 if (net::QuicVersionToString(version) == quic_version) {
968 return version;
969 }
970 }
971
972 return net::QUIC_VERSION_UNSUPPORTED;
973 } 517 }
974 518
975 net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext( 519 net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext(
976 IOSChromeIOThread::Globals* globals, 520 IOSChromeIOThread::Globals* globals,
521 const net::HttpNetworkSession::Params& params,
977 net::NetLog* net_log) { 522 net::NetLog* net_log) {
978 net::URLRequestContext* context = new SystemURLRequestContext; 523 net::URLRequestContext* context = new SystemURLRequestContext;
979 context->set_net_log(net_log); 524 context->set_net_log(net_log);
980 context->set_host_resolver(globals->host_resolver.get()); 525 context->set_host_resolver(globals->host_resolver.get());
981 context->set_cert_verifier(globals->cert_verifier.get()); 526 context->set_cert_verifier(globals->cert_verifier.get());
982 context->set_transport_security_state( 527 context->set_transport_security_state(
983 globals->transport_security_state.get()); 528 globals->transport_security_state.get());
984 context->set_cert_transparency_verifier( 529 context->set_cert_transparency_verifier(
985 globals->cert_transparency_verifier.get()); 530 globals->cert_transparency_verifier.get());
986 context->set_ssl_config_service(globals->ssl_config_service.get()); 531 context->set_ssl_config_service(globals->ssl_config_service.get());
(...skipping 16 matching lines...) Expand all
1003 context->set_network_delegate(globals->system_network_delegate.get()); 548 context->set_network_delegate(globals->system_network_delegate.get());
1004 context->set_http_user_agent_settings( 549 context->set_http_user_agent_settings(
1005 globals->http_user_agent_settings.get()); 550 globals->http_user_agent_settings.get());
1006 context->set_network_quality_estimator( 551 context->set_network_quality_estimator(
1007 globals->network_quality_estimator.get()); 552 globals->network_quality_estimator.get());
1008 context->set_backoff_manager(globals->url_request_backoff_manager.get()); 553 context->set_backoff_manager(globals->url_request_backoff_manager.get());
1009 554
1010 context->set_http_server_properties( 555 context->set_http_server_properties(
1011 globals->http_server_properties->GetWeakPtr()); 556 globals->http_server_properties->GetWeakPtr());
1012 557
1013 net::HttpNetworkSession::Params system_params; 558 net::HttpNetworkSession::Params system_params(params);
1014 InitializeNetworkSessionParamsFromGlobals(*globals, &system_params);
1015 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents( 559 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1016 context, &system_params); 560 context, &system_params);
1017 561
1018 globals->system_http_network_session.reset( 562 globals->system_http_network_session.reset(
1019 new net::HttpNetworkSession(system_params)); 563 new net::HttpNetworkSession(system_params));
1020 globals->system_http_transaction_factory.reset( 564 globals->system_http_transaction_factory.reset(
1021 new net::HttpNetworkLayer(globals->system_http_network_session.get())); 565 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
1022 context->set_http_transaction_factory( 566 context->set_http_transaction_factory(
1023 globals->system_http_transaction_factory.get()); 567 globals->system_http_transaction_factory.get());
1024 568
1025 return context; 569 return context;
1026 } 570 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ios_chrome_io_thread.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698