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

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

Powered by Google App Engine
This is Rietveld 408576698