blob: d2fcf3909fee7a2246f84c9d3bbff1745102182e [file] [log] [blame]
[email protected]d24fc3a02012-02-11 02:08:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0ac83682010-01-22 17:46:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/io_thread.h"
[email protected]e83326f2010-07-31 17:29:256
[email protected]bcefe0f2010-11-10 16:19:107#include <vector>
8
[email protected]284303b62013-11-28 15:11:549#include "base/base64.h"
[email protected]21ee224e2011-11-21 02:17:5310#include "base/bind.h"
11#include "base/bind_helpers.h"
[email protected]aa84a7e2012-03-15 21:29:0612#include "base/command_line.h"
[email protected]c93123fa2012-04-19 02:49:4813#include "base/compiler_specific.h"
[email protected]58580352010-10-26 04:07:5014#include "base/debug/leak_tracker.h"
[email protected]0ac83682010-01-22 17:46:2715#include "base/logging.h"
[email protected]903e63382013-06-01 00:40:5816#include "base/metrics/field_trial.h"
[email protected]3853a4c2013-02-11 17:15:5717#include "base/prefs/pref_registry_simple.h"
18#include "base/prefs/pref_service.h"
michaeln3e5bced2015-02-09 22:58:2319#include "base/profiler/scoped_tracker.h"
[email protected]7286e3fc2011-07-19 22:13:2420#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
bnce3553d92014-10-30 22:29:4522#include "base/strings/string_piece.h"
[email protected]1988e1c2013-02-28 20:27:4223#include "base/strings/string_split.h"
[email protected]9c7ddc92013-06-11 01:40:5724#include "base/strings/string_util.h"
[email protected]255620da2013-08-19 13:14:2925#include "base/threading/sequenced_worker_pool.h"
[email protected]3fc40c142011-12-01 13:09:0426#include "base/threading/thread.h"
[email protected]5bab49ec2012-05-04 21:13:1927#include "base/threading/worker_pool.h"
[email protected]d827e112014-03-31 17:45:0528#include "base/time/time.h"
primiano6221e572015-01-28 12:14:3429#include "base/trace_event/trace_event.h"
[email protected]addb3242011-06-13 21:39:1630#include "build/build_config.h"
[email protected]df2840d2011-02-20 16:32:3231#include "chrome/browser/browser_process.h"
[email protected]026876f32012-08-22 23:53:4032#include "chrome/browser/net/async_dns_field_trial.h"
[email protected]9e743cd2010-03-16 07:03:5333#include "chrome/browser/net/chrome_net_log.h"
[email protected]c38831a12011-10-28 12:44:4934#include "chrome/browser/net/chrome_network_delegate.h"
[email protected]1889dc1b2010-10-14 22:03:1335#include "chrome/browser/net/connect_interceptor.h"
[email protected]4588b3d2012-11-14 00:37:3836#include "chrome/browser/net/dns_probe_service.h"
[email protected]6f96cbcb2011-11-04 02:26:0737#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]db0e86dd2011-03-16 14:47:2138#include "chrome/browser/net/proxy_service_factory.h"
[email protected]aa051272014-03-10 05:56:5639#include "chrome/common/chrome_content_client.h"
[email protected]0ac83682010-01-22 17:46:2740#include "chrome/common/chrome_switches.h"
[email protected]0c4017ca2014-06-06 03:30:4541#include "chrome/common/chrome_version_info.h"
[email protected]bcefe0f2010-11-10 16:19:1042#include "chrome/common/pref_names.h"
megjablon3476e042014-10-14 19:21:5943#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
tbansaled0aecc2015-02-20 03:44:1844#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
[email protected]76b4b152013-12-08 21:10:0445#include "components/policy/core/common/policy_service.h"
[email protected]488a0e252014-06-25 04:37:4446#include "components/variations/variations_associated_data.h"
[email protected]c38831a12011-10-28 12:44:4947#include "content/public/browser/browser_thread.h"
[email protected]7c4b66b2014-01-04 12:28:1348#include "content/public/browser/cookie_store_factory.h"
[email protected]c2dad292012-09-07 21:27:3549#include "net/base/host_mapping_rules.h"
[email protected]32eaa332010-02-08 22:15:5450#include "net/base/net_util.h"
tbansalea2fb8c2015-05-22 22:23:0051#include "net/base/network_quality_estimator.h"
rdsmith60e6e6fb2015-03-05 16:49:2052#include "net/base/sdch_manager.h"
eranm6571b2b2014-12-03 15:53:2353#include "net/cert/cert_policy_enforcer.h"
[email protected]6e7845ae2013-03-29 21:48:1154#include "net/cert/cert_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3955#include "net/cert/cert_verify_proc.h"
[email protected]284303b62013-11-28 15:11:5456#include "net/cert/ct_known_logs.h"
eranm6571b2b2014-12-03 15:53:2357#include "net/cert/ct_known_logs_static.h"
davidbeneb5f8ef32014-09-04 14:14:3258#include "net/cert/ct_log_verifier.h"
[email protected]284303b62013-11-28 15:11:5459#include "net/cert/ct_verifier.h"
davidbeneb5f8ef32014-09-04 14:14:3260#include "net/cert/multi_log_ct_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3961#include "net/cert/multi_threaded_cert_verifier.h"
[email protected]9a6c2aa2014-01-11 22:39:3962#include "net/cookies/cookie_store.h"
[email protected]bc71b8772013-04-10 20:55:1663#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5364#include "net/dns/host_resolver.h"
65#include "net/dns/mapped_host_resolver.h"
[email protected]b3ae2db2013-05-30 05:00:0566#include "net/ftp/ftp_network_layer.h"
[email protected]eb3cac72010-02-26 21:07:4567#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5068#include "net/http/http_auth_handler_factory.h"
[email protected]2fb629202010-12-23 23:52:5769#include "net/http/http_network_layer.h"
[email protected]17291a022011-10-10 07:32:5370#include "net/http/http_server_properties_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1271#include "net/proxy/proxy_config_service.h"
[email protected]86933612010-10-16 23:10:3372#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1273#include "net/proxy/proxy_service.h"
[email protected]648f81142014-08-15 21:38:4674#include "net/quic/crypto/crypto_protocol.h"
[email protected]6a31ca52013-12-23 00:44:3475#include "net/quic/quic_protocol.h"
mefcb6537c2014-11-12 19:38:5076#include "net/quic/quic_utils.h"
[email protected]717e4e22013-04-10 20:52:2377#include "net/socket/tcp_client_socket.h"
[email protected]77305422012-11-29 16:51:3978#include "net/spdy/spdy_session.h"
[email protected]6b8a3c742014-07-25 00:25:3579#include "net/ssl/channel_id_service.h"
80#include "net/ssl/default_channel_id_store.h"
[email protected]b3ae2db2013-05-30 05:00:0581#include "net/url_request/data_protocol_handler.h"
82#include "net/url_request/file_protocol_handler.h"
83#include "net/url_request/ftp_protocol_handler.h"
[email protected]aa051272014-03-10 05:56:5684#include "net/url_request/static_http_user_agent_settings.h"
[email protected]3dc1bc42012-06-19 08:20:5385#include "net/url_request/url_fetcher.h"
[email protected]f9c8c7c2014-07-31 16:42:3186#include "net/url_request/url_request_context.h"
87#include "net/url_request/url_request_context_getter.h"
[email protected]b3ae2db2013-05-30 05:00:0588#include "net/url_request/url_request_job_factory_impl.h"
[email protected]a73a2802012-05-02 19:20:1589#include "net/url_request/url_request_throttler_manager.h"
[email protected]cca6f392014-05-28 21:32:2690#include "url/url_constants.h"
[email protected]77305422012-11-29 16:51:3991
92#if defined(ENABLE_CONFIGURATION_POLICY)
93#include "policy/policy_constants.h"
94#endif
[email protected]0ac83682010-01-22 17:46:2795
[email protected]84b7a552014-07-19 04:52:0696#if defined(ENABLE_EXTENSIONS)
97#include "chrome/browser/extensions/event_router_forwarder.h"
98#endif
99
davidben71f35ff2015-04-17 20:54:48100#if defined(USE_NSS_CERTS) || defined(OS_IOS)
eromaned744f32015-04-09 06:35:49101#include "net/cert_net/nss_ocsp.h"
[email protected]a592c0432012-12-01 18:10:29102#endif
[email protected]77feb462011-05-16 23:37:25103
jeremyimb6c97ae2015-01-05 22:57:14104#if defined(OS_ANDROID)
105#include "base/android/build_info.h"
106#endif
107
[email protected]f46f6d52014-02-08 04:00:39108#if defined(OS_CHROMEOS)
109#include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
[email protected]106ccd2c2014-06-17 09:21:00110#include "chromeos/network/host_resolver_impl_chromeos.h"
[email protected]f46f6d52014-02-08 04:00:39111#endif
112
[email protected]631bb742011-11-02 11:29:39113using content::BrowserThread;
114
[email protected]075c0322012-02-14 00:56:44115class SafeBrowsingURLRequestContext;
116
[email protected]21ee224e2011-11-21 02:17:53117// The IOThread object must outlive any tasks posted to the IO thread before the
118// Quit task, so base::Bind() calls are not refcounted.
119
[email protected]0ac83682010-01-22 17:46:27120namespace {
121
jrif9b4bec2014-09-15 15:46:54122const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen";
123const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled";
124
[email protected]903e63382013-06-01 00:40:58125const char kQuicFieldTrialName[] = "QUIC";
126const char kQuicFieldTrialEnabledGroupName[] = "Enabled";
[email protected]a64b213e2013-07-24 21:41:00127const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled";
[email protected]903e63382013-06-01 00:40:58128
[email protected]44a101422014-07-02 22:12:57129// The SPDY trial composes two different trial plus control groups:
130// * A "holdback" group with SPDY disabled, and corresponding control
131// (SPDY/3.1). The primary purpose of the holdback group is to encourage site
132// operators to do feature detection rather than UA-sniffing. As such, this
133// trial runs continuously.
134// * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and
135// eventual SPDY/4 deployment.
[email protected]aedfccd9b2013-10-02 03:24:46136const char kSpdyFieldTrialName[] = "SPDY";
bnce3553d92014-10-30 22:29:45137const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled";
bnce3553d92014-10-30 22:29:45138const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled";
139const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled";
bncbc0b05b2015-03-25 19:50:58140const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized";
[email protected]aedfccd9b2013-10-02 03:24:46141
ricea64c07d792014-10-08 03:37:00142// Field trial for Cache-Control: stale-while-revalidate directive.
143const char kStaleWhileRevalidateFieldTrialName[] = "StaleWhileRevalidate";
144
[email protected]11f5e3a2012-09-27 00:30:13145#if defined(OS_MACOSX) && !defined(OS_IOS)
146void ObserveKeychainEvents() {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
149}
150#endif
151
[email protected]ee4c30d2012-11-07 15:08:43152// Used for the "system" URLRequestContext.
153class SystemURLRequestContext : public net::URLRequestContext {
[email protected]77feb462011-05-16 23:37:25154 public:
155 SystemURLRequestContext() {
davidben71f35ff2015-04-17 20:54:48156#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09157 net::SetURLRequestContextForNSSHttpIO(this);
[email protected]a592c0432012-12-01 18:10:29158#endif
[email protected]77feb462011-05-16 23:37:25159 }
160
161 private:
Daniel Chenga542fca2014-10-21 09:51:29162 ~SystemURLRequestContext() override {
[email protected]424559492014-07-22 00:27:40163 AssertNoURLRequests();
davidben71f35ff2015-04-17 20:54:48164#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09165 net::SetURLRequestContextForNSSHttpIO(NULL);
[email protected]a592c0432012-12-01 18:10:29166#endif
[email protected]77feb462011-05-16 23:37:25167 }
168};
169
[email protected]c54a8912012-10-22 22:09:43170scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
[email protected]d22f06e2013-06-11 16:01:17171 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
avi556c05022014-12-22 23:31:43172 const base::CommandLine& command_line =
173 *base::CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:51174
[email protected]c54a8912012-10-22 22:09:43175 net::HostResolver::Options options;
[email protected]962b98212010-07-17 03:37:51176
[email protected]06ef6d92011-05-19 04:24:58177 // Use the retry attempts override from the command-line, if any.
178 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
179 std::string s =
180 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
181 // Parse the switch (it should be a non-negative integer).
182 int n;
183 if (base::StringToInt(s, &n) && n >= 0) {
[email protected]c54a8912012-10-22 22:09:43184 options.max_retry_attempts = static_cast<size_t>(n);
[email protected]06ef6d92011-05-19 04:24:58185 } else {
186 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
187 }
188 }
189
[email protected]106ccd2c2014-06-17 09:21:00190 scoped_ptr<net::HostResolver> global_host_resolver;
191#if defined OS_CHROMEOS
192 global_host_resolver =
193 chromeos::HostResolverImplChromeOS::CreateSystemResolver(options,
194 net_log);
195#else
196 global_host_resolver =
197 net::HostResolver::CreateSystemResolver(options, net_log);
198#endif
[email protected]9087aa32010-02-18 08:03:38199
[email protected]3dc5d7ef2014-03-28 19:18:21200 // If hostname remappings were specified on the command-line, layer these
201 // rules on top of the real host resolver. This allows forwarding all requests
202 // through a designated test server.
203 if (!command_line.HasSwitch(switches::kHostResolverRules))
dcheng383ba8a2014-10-16 23:55:19204 return global_host_resolver.Pass();
[email protected]0ac83682010-01-22 17:46:27205
[email protected]3dc5d7ef2014-03-28 19:18:21206 scoped_ptr<net::MappedHostResolver> remapped_resolver(
207 new net::MappedHostResolver(global_host_resolver.Pass()));
208 remapped_resolver->SetRulesFromString(
209 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
dcheng383ba8a2014-10-16 23:55:19210 return remapped_resolver.Pass();
[email protected]0ac83682010-01-22 17:46:27211}
212
[email protected]ef2bf422012-05-11 03:27:09213// TODO(willchan): Remove proxy script fetcher context since it's not necessary
214// now that I got rid of refcounting URLRequestContexts.
[email protected]77feb462011-05-16 23:37:25215// See IOThread::Globals for details.
[email protected]ef2bf422012-05-11 03:27:09216net::URLRequestContext*
[email protected]2fb629202010-12-23 23:52:57217ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
218 net::NetLog* net_log) {
[email protected]ee4c30d2012-11-07 15:08:43219 net::URLRequestContext* context = new net::URLRequestContext;
[email protected]2fb629202010-12-23 23:52:57220 context->set_net_log(net_log);
221 context->set_host_resolver(globals->host_resolver.get());
222 context->set_cert_verifier(globals->cert_verifier.get());
[email protected]a2a41972011-12-07 17:47:27223 context->set_transport_security_state(
224 globals->transport_security_state.get());
[email protected]284303b62013-11-28 15:11:54225 context->set_cert_transparency_verifier(
226 globals->cert_transparency_verifier.get());
[email protected]2fb629202010-12-23 23:52:57227 context->set_http_auth_handler_factory(
228 globals->http_auth_handler_factory.get());
229 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
230 context->set_http_transaction_factory(
[email protected]52617df2010-12-24 07:30:01231 globals->proxy_script_fetcher_http_transaction_factory.get());
[email protected]b3ae2db2013-05-30 05:00:05232 context->set_job_factory(
233 globals->proxy_script_fetcher_url_request_job_factory.get());
[email protected]273e37d2011-08-11 01:49:12234 context->set_cookie_store(globals->system_cookie_store.get());
[email protected]6b8a3c742014-07-25 00:25:35235 context->set_channel_id_service(
236 globals->system_channel_id_service.get());
[email protected]3ce02412011-03-01 12:01:15237 context->set_network_delegate(globals->system_network_delegate.get());
[email protected]ee4c30d2012-11-07 15:08:43238 context->set_http_user_agent_settings(
239 globals->http_user_agent_settings.get());
[email protected]db96a882011-10-09 02:01:54240 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
241 // system URLRequestContext too. There's no reason this should be tied to a
242 // profile.
[email protected]2fb629202010-12-23 23:52:57243 return context;
244}
245
[email protected]ef2bf422012-05-11 03:27:09246net::URLRequestContext*
[email protected]db0e86dd2011-03-16 14:47:21247ConstructSystemRequestContext(IOThread::Globals* globals,
248 net::NetLog* net_log) {
[email protected]ef2bf422012-05-11 03:27:09249 net::URLRequestContext* context = new SystemURLRequestContext;
[email protected]db0e86dd2011-03-16 14:47:21250 context->set_net_log(net_log);
251 context->set_host_resolver(globals->host_resolver.get());
252 context->set_cert_verifier(globals->cert_verifier.get());
[email protected]a2a41972011-12-07 17:47:27253 context->set_transport_security_state(
254 globals->transport_security_state.get());
[email protected]284303b62013-11-28 15:11:54255 context->set_cert_transparency_verifier(
256 globals->cert_transparency_verifier.get());
[email protected]db0e86dd2011-03-16 14:47:21257 context->set_http_auth_handler_factory(
258 globals->http_auth_handler_factory.get());
259 context->set_proxy_service(globals->system_proxy_service.get());
260 context->set_http_transaction_factory(
261 globals->system_http_transaction_factory.get());
[email protected]2944afa2014-06-13 00:41:29262 context->set_job_factory(globals->system_url_request_job_factory.get());
[email protected]273e37d2011-08-11 01:49:12263 context->set_cookie_store(globals->system_cookie_store.get());
[email protected]6b8a3c742014-07-25 00:25:35264 context->set_channel_id_service(
265 globals->system_channel_id_service.get());
[email protected]a73a2802012-05-02 19:20:15266 context->set_throttler_manager(globals->throttler_manager.get());
[email protected]815c69cf2012-06-30 00:52:08267 context->set_network_delegate(globals->system_network_delegate.get());
[email protected]ee4c30d2012-11-07 15:08:43268 context->set_http_user_agent_settings(
269 globals->http_user_agent_settings.get());
tbansalea2fb8c2015-05-22 22:23:00270 context->set_network_quality_estimator(
271 globals->network_quality_estimator.get());
[email protected]db0e86dd2011-03-16 14:47:21272 return context;
273}
274
avi556c05022014-12-22 23:31:43275int GetSwitchValueAsInt(const base::CommandLine& command_line,
[email protected]f9cf5572012-12-04 15:52:09276 const std::string& switch_name) {
277 int value;
278 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
279 &value)) {
280 return 0;
281 }
282 return value;
[email protected]27c253802012-11-30 08:18:12283}
284
[email protected]488a0e252014-06-25 04:37:44285// Returns the value associated with |key| in |params| or "" if the
286// key is not present in the map.
287const std::string& GetVariationParam(
288 const std::map<std::string, std::string>& params,
289 const std::string& key) {
290 std::map<std::string, std::string>::const_iterator it = params.find(key);
291 if (it == params.end())
292 return base::EmptyString();
293
294 return it->second;
295}
296
ricea43736982014-10-30 09:15:48297// Return true if stale-while-revalidate support should be enabled.
298bool IsStaleWhileRevalidateEnabled(const base::CommandLine& command_line) {
299 if (command_line.HasSwitch(switches::kEnableStaleWhileRevalidate))
300 return true;
301 const std::string group_name =
302 base::FieldTrialList::FindFullName(kStaleWhileRevalidateFieldTrialName);
303 return group_name == "Enabled";
304}
305
bncbc0b05b2015-03-25 19:50:58306// Parse kUseSpdy command line flag options, which may contain the following:
307//
308// "off" : Disables SPDY support entirely.
bncbc0b05b2015-03-25 19:50:58309// "no-ping" : Disables SPDY ping connection testing.
310// "exclude=<host>" : Disables SPDY support for the host <host>.
311// "no-compress" : Disables SPDY header compression.
312// "no-alt-protocols : Disables alternate protocol support.
bncbc0b05b2015-03-25 19:50:58313// "init-max-streams=<limit>" : Specifies the maximum number of concurrent
314// streams for a SPDY session, unless the
315// specifies a different value via SETTINGS.
316void ConfigureSpdyGlobalsFromUseSpdyArgument(const std::string& mode,
317 IOThread::Globals* globals) {
318 static const char kOff[] = "off";
bncbc0b05b2015-03-25 19:50:58319 static const char kDisablePing[] = "no-ping";
320 static const char kExclude[] = "exclude"; // Hosts to exclude
321 static const char kDisableCompression[] = "no-compress";
322 static const char kDisableAltProtocols[] = "no-alt-protocols";
bncbc0b05b2015-03-25 19:50:58323 static const char kInitialMaxConcurrentStreams[] = "init-max-streams";
324
325 std::vector<std::string> spdy_options;
326 base::SplitString(mode, ',', &spdy_options);
327
328 for (const std::string& element : spdy_options) {
329 std::vector<std::string> name_value;
330 base::SplitString(element, '=', &name_value);
331 const std::string& option =
332 name_value.size() > 0 ? name_value[0] : std::string();
333 const std::string value =
334 name_value.size() > 1 ? name_value[1] : std::string();
335
336 if (option == kOff) {
337 net::HttpStreamFactory::set_spdy_enabled(false);
338 continue;
339 }
bncbc0b05b2015-03-25 19:50:58340 if (option == kDisablePing) {
341 globals->enable_spdy_ping_based_connection_checking.set(false);
342 continue;
343 }
344 if (option == kExclude) {
345 globals->forced_spdy_exclusions.insert(
346 net::HostPortPair::FromURL(GURL(value)));
347 continue;
348 }
349 if (option == kDisableCompression) {
350 globals->enable_spdy_compression.set(false);
351 continue;
352 }
353 if (option == kDisableAltProtocols) {
354 globals->use_alternate_protocols.set(false);
355 continue;
356 }
bncbc0b05b2015-03-25 19:50:58357 if (option == kInitialMaxConcurrentStreams) {
358 int streams;
359 if (base::StringToInt(value, &streams)) {
360 globals->initial_max_spdy_concurrent_streams.set(streams);
361 continue;
362 }
363 }
364 LOG(DFATAL) << "Unrecognized spdy option: " << option;
365 }
366}
367
[email protected]0ac83682010-01-22 17:46:27368} // namespace
369
[email protected]e0845d5f2012-05-29 00:11:41370class IOThread::LoggingNetworkChangeObserver
[email protected]3d5aaad2012-10-27 12:31:28371 : public net::NetworkChangeNotifier::IPAddressObserver,
[email protected]03848872012-12-08 02:46:41372 public net::NetworkChangeNotifier::ConnectionTypeObserver,
373 public net::NetworkChangeNotifier::NetworkChangeObserver {
[email protected]e0845d5f2012-05-29 00:11:41374 public:
375 // |net_log| must remain valid throughout our lifetime.
376 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
377 : net_log_(net_log) {
378 net::NetworkChangeNotifier::AddIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28379 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41380 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41381 }
382
Daniel Chenga542fca2014-10-21 09:51:29383 ~LoggingNetworkChangeObserver() override {
[email protected]e0845d5f2012-05-29 00:11:41384 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28385 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41386 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41387 }
388
[email protected]03848872012-12-08 02:46:41389 // NetworkChangeNotifier::IPAddressObserver implementation.
Daniel Chenga542fca2014-10-21 09:51:29390 void OnIPAddressChanged() override {
[email protected]e0845d5f2012-05-29 00:11:41391 VLOG(1) << "Observed a change to the network IP addresses";
392
[email protected]2fa08912012-06-14 20:56:26393 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED);
[email protected]e0845d5f2012-05-29 00:11:41394 }
395
[email protected]03848872012-12-08 02:46:41396 // NetworkChangeNotifier::ConnectionTypeObserver implementation.
Daniel Chenga542fca2014-10-21 09:51:29397 void OnConnectionTypeChanged(
mostynb01d8b10e2014-10-13 09:44:44398 net::NetworkChangeNotifier::ConnectionType type) override {
[email protected]3d5aaad2012-10-27 12:31:28399 std::string type_as_string =
400 net::NetworkChangeNotifier::ConnectionTypeToString(type);
401
402 VLOG(1) << "Observed a change to network connectivity state "
403 << type_as_string;
404
405 net_log_->AddGlobalEntry(
406 net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED,
407 net::NetLog::StringCallback("new_connection_type", &type_as_string));
408 }
409
[email protected]03848872012-12-08 02:46:41410 // NetworkChangeNotifier::NetworkChangeObserver implementation.
Daniel Chenga542fca2014-10-21 09:51:29411 void OnNetworkChanged(
mostynb01d8b10e2014-10-13 09:44:44412 net::NetworkChangeNotifier::ConnectionType type) override {
[email protected]03848872012-12-08 02:46:41413 std::string type_as_string =
414 net::NetworkChangeNotifier::ConnectionTypeToString(type);
415
416 VLOG(1) << "Observed a network change to state " << type_as_string;
417
418 net_log_->AddGlobalEntry(
419 net::NetLog::TYPE_NETWORK_CHANGED,
420 net::NetLog::StringCallback("new_connection_type", &type_as_string));
421 }
422
[email protected]e0845d5f2012-05-29 00:11:41423 private:
424 net::NetLog* net_log_;
425 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
426};
427
[email protected]abe2c032011-03-31 18:49:34428class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
[email protected]db0e86dd2011-03-16 14:47:21429 public:
430 explicit SystemURLRequestContextGetter(IOThread* io_thread);
[email protected]db0e86dd2011-03-16 14:47:21431
[email protected]abe2c032011-03-31 18:49:34432 // Implementation for net::UrlRequestContextGetter.
Daniel Chenga542fca2014-10-21 09:51:29433 net::URLRequestContext* GetURLRequestContext() override;
434 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
435 const override;
[email protected]db0e86dd2011-03-16 14:47:21436
[email protected]13ed17f82012-04-06 02:27:18437 protected:
Daniel Chenga542fca2014-10-21 09:51:29438 ~SystemURLRequestContextGetter() override;
[email protected]13ed17f82012-04-06 02:27:18439
[email protected]db0e86dd2011-03-16 14:47:21440 private:
441 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
[email protected]4969b0122012-06-16 01:58:28442 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21443
444 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
445};
446
447SystemURLRequestContextGetter::SystemURLRequestContextGetter(
448 IOThread* io_thread)
449 : io_thread_(io_thread),
[email protected]4969b0122012-06-16 01:58:28450 network_task_runner_(
[email protected]2e5b60a22011-11-28 15:56:41451 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
[email protected]db0e86dd2011-03-16 14:47:21452}
453
454SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
455
456net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]ef2bf422012-05-11 03:27:09458 DCHECK(io_thread_->globals()->system_request_context.get());
[email protected]db0e86dd2011-03-16 14:47:21459
[email protected]ef2bf422012-05-11 03:27:09460 return io_thread_->globals()->system_request_context.get();
[email protected]db0e86dd2011-03-16 14:47:21461}
462
[email protected]4969b0122012-06-16 01:58:28463scoped_refptr<base::SingleThreadTaskRunner>
464SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
465 return network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21466}
467
[email protected]c93123fa2012-04-19 02:49:48468IOThread::Globals::
469SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
470 Globals* globals)
471 : globals_(globals) {
472 DCHECK(globals_);
[email protected]7613faae2012-04-18 01:01:19473}
[email protected]1889dc1b2010-10-14 22:03:13474
[email protected]c93123fa2012-04-19 02:49:48475IOThread::Globals::
476SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {
477 if (globals_->system_request_context.get())
478 globals_->system_request_context->AssertNoURLRequests();
479}
480
481IOThread::Globals::Globals()
[email protected]9c009092013-05-01 03:14:09482 : system_request_context_leak_checker(this),
[email protected]c2dad292012-09-07 21:27:35483 ignore_certificate_errors(false),
ricea64c07d792014-10-08 03:37:00484 use_stale_while_revalidate(false),
[email protected]c2dad292012-09-07 21:27:35485 testing_fixed_http_port(0),
[email protected]c54c6962013-02-01 04:53:19486 testing_fixed_https_port(0),
487 enable_user_alternate_protocol_ports(false) {
488}
[email protected]c2dad292012-09-07 21:27:35489
[email protected]c93123fa2012-04-19 02:49:48490IOThread::Globals::~Globals() {}
491
[email protected]bcefe0f2010-11-10 16:19:10492// |local_state| is passed in explicitly in order to (1) reduce implicit
493// dependencies and (2) make IOThread more flexible for testing.
[email protected]3ce02412011-03-01 12:01:15494IOThread::IOThread(
[email protected]b1de2c72013-02-06 02:45:47495 PrefService* local_state,
[email protected]77305422012-11-29 16:51:39496 policy::PolicyService* policy_service,
[email protected]3ce02412011-03-01 12:01:15497 ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10498 extensions::EventRouterForwarder* extension_event_router_forwarder)
[email protected]2e5b60a22011-11-28 15:56:41499 : net_log_(net_log),
[email protected]84b7a552014-07-19 04:52:06500#if defined(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15501 extension_event_router_forwarder_(extension_event_router_forwarder),
[email protected]84b7a552014-07-19 04:52:06502#endif
[email protected]d13c3272010-02-04 00:24:51503 globals_(NULL),
[email protected]77305422012-11-29 16:51:39504 is_spdy_disabled_by_policy_(false),
peletskyi5df83d42015-04-30 16:37:46505 is_quic_allowed_by_policy_(true),
mohan.reddy14cb4ad42014-09-17 18:15:14506 creation_time_(base::TimeTicks::Now()),
507 weak_factory_(this) {
[email protected]bcefe0f2010-11-10 16:19:10508 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
509 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
510 prefs::kDisableAuthNegotiateCnameLookup);
511 negotiate_enable_port_ = local_state->GetBoolean(
512 prefs::kEnableAuthNegotiatePort);
513 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
514 auth_delegate_whitelist_ = local_state->GetString(
515 prefs::kAuthNegotiateDelegateWhitelist);
[email protected]ac7f3fdb2010-11-12 12:47:05516 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
[email protected]6f96cbcb2011-11-04 02:26:07517 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42518 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
519 local_state));
[email protected]9d8cfb682012-09-13 16:48:04520 ChromeNetworkDelegate::InitializePrefsOnUIThread(
521 &system_enable_referrers_,
522 NULL,
[email protected]d1208ba32012-11-08 11:10:33523 NULL,
treib4e26f6652014-12-01 14:34:18524 NULL,
[email protected]9d8cfb682012-09-13 16:48:04525 local_state);
[email protected]4d45a6de2011-05-13 05:20:18526 ssl_config_service_manager_.reset(
[email protected]e6d017652013-05-17 18:01:40527 SSLConfigServiceManager::CreateDefaultManager(local_state));
[email protected]2e5b60a22011-11-28 15:56:41528
[email protected]68a9b0d82013-03-08 07:05:07529 base::Value* dns_client_enabled_default = new base::FundamentalValue(
530 chrome_browser_net::ConfigureAsyncDnsFieldTrial());
531 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
532 dns_client_enabled_default);
ttuttle530184962015-01-13 00:24:07533 chrome_browser_net::LogAsyncDnsPrefSource(
534 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled));
[email protected]68a9b0d82013-03-08 07:05:07535
[email protected]fa4b6c32012-11-26 23:02:39536 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
537 local_state,
538 base::Bind(&IOThread::UpdateDnsClientEnabled,
539 base::Unretained(this)));
540 dns_client_enabled_.MoveToThread(
541 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
542
[email protected]67378142013-12-17 21:57:17543 quick_check_enabled_.Init(prefs::kQuickCheckEnabled,
544 local_state);
545 quick_check_enabled_.MoveToThread(
546 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
547
[email protected]77305422012-11-29 16:51:39548#if defined(ENABLE_CONFIGURATION_POLICY)
549 is_spdy_disabled_by_policy_ = policy_service->GetPolicies(
[email protected]2ccf83732013-02-04 20:19:02550 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get(
551 policy::key::kDisableSpdy) != NULL;
peletskyi5df83d42015-04-30 16:37:46552
553 const base::Value* value = policy_service->GetPolicies(
554 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
555 std::string())).GetValue(policy::key::kQuicAllowed);
556 if (value)
557 value->GetAsBoolean(&is_quic_allowed_by_policy_);
[email protected]77305422012-11-29 16:51:39558#endif // ENABLE_CONFIGURATION_POLICY
559
[email protected]2e5b60a22011-11-28 15:56:41560 BrowserThread::SetDelegate(BrowserThread::IO, this);
[email protected]bcefe0f2010-11-10 16:19:10561}
[email protected]0ac83682010-01-22 17:46:27562
563IOThread::~IOThread() {
[email protected]2e5b60a22011-11-28 15:56:41564 // This isn't needed for production code, but in tests, IOThread may
565 // be multiply constructed.
566 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
567
[email protected]d461ed22013-01-18 03:18:56568 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]d13c3272010-02-04 00:24:51569 DCHECK(!globals_);
[email protected]0ac83682010-01-22 17:46:27570}
571
[email protected]d13c3272010-02-04 00:24:51572IOThread::Globals* IOThread::globals() {
[email protected]f8b3ef82010-10-11 02:45:52573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d13c3272010-02-04 00:24:51574 return globals_;
[email protected]0ac83682010-01-22 17:46:27575}
576
[email protected]37ac95b2013-07-23 23:39:35577void IOThread::SetGlobalsForTesting(Globals* globals) {
578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
579 DCHECK(!globals || !globals_);
580 globals_ = globals;
581}
582
[email protected]b2fcd0e2010-12-01 15:19:40583ChromeNetLog* IOThread::net_log() {
584 return net_log_;
585}
586
[email protected]b09f76d62011-12-07 01:51:06587void IOThread::ChangedToOnTheRecord() {
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
589 BrowserThread::PostTask(
590 BrowserThread::IO,
591 FROM_HERE,
592 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
593 base::Unretained(this)));
594}
595
[email protected]abe2c032011-03-31 18:49:34596net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
[email protected]db0e86dd2011-03-16 14:47:21597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]5173de8b2013-06-02 21:16:02598 if (!system_url_request_context_getter_.get()) {
[email protected]addb3242011-06-13 21:39:16599 InitSystemRequestContext();
[email protected]db0e86dd2011-03-16 14:47:21600 }
[email protected]5173de8b2013-06-02 21:16:02601 return system_url_request_context_getter_.get();
[email protected]db0e86dd2011-03-16 14:47:21602}
603
[email protected]0ac83682010-01-22 17:46:27604void IOThread::Init() {
erikchendc7ecc412015-03-12 02:46:36605 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
606 // is fixed.
607 tracked_objects::ScopedTracker tracking_profile1(
608 FROM_HERE_WITH_EXPLICIT_FUNCTION("466432 IOThread::InitAsync::Start"));
[email protected]a5e73b82013-07-17 08:58:39609 TRACE_EVENT0("startup", "IOThread::InitAsync");
[email protected]2e5b60a22011-11-28 15:56:41610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]70b92342010-10-12 05:54:06611
davidben71f35ff2015-04-17 20:54:48612#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09613 net::SetMessageLoopForNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29614#endif
[email protected]70b92342010-10-12 05:54:06615
erikchendc7ecc412015-03-12 02:46:36616 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
617 // is fixed.
618 tracked_objects::ScopedTracker tracking_profile2(
619 FROM_HERE_WITH_EXPLICIT_FUNCTION(
620 "466432 IOThread::InitAsync::CommandLineForCurrentProcess"));
avi556c05022014-12-22 23:31:43621 const base::CommandLine& command_line =
622 *base::CommandLine::ForCurrentProcess();
[email protected]c2dad292012-09-07 21:27:35623
[email protected]d13c3272010-02-04 00:24:51624 DCHECK(!globals_);
625 globals_ = new Globals;
626
[email protected]58bc7042010-07-07 18:04:14627 // Add an observer that will emit network change events to the ChromeNetLog.
628 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
629 // logging the network change before other IO thread consumers respond to it.
630 network_change_observer_.reset(
[email protected]b2fcd0e2010-12-01 15:19:40631 new LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14632
[email protected]cde8b3c2012-08-13 19:20:52633 // Setup the HistogramWatcher to run on the IO thread.
634 net::NetworkChangeNotifier::InitHistogramWatcher();
635
[email protected]84b7a552014-07-19 04:52:06636#if defined(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15637 globals_->extension_event_router_forwarder =
638 extension_event_router_forwarder_;
[email protected]84b7a552014-07-19 04:52:06639#endif
640
erikchendc7ecc412015-03-12 02:46:36641 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
642 // is fixed.
643 tracked_objects::ScopedTracker tracking_profile3(
644 FROM_HERE_WITH_EXPLICIT_FUNCTION(
645 "466432 IOThread::InitAsync::ChromeNetworkDelegate"));
megjablonc1751452014-12-09 19:46:47646 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate(
[email protected]84b7a552014-07-19 04:52:06647 new ChromeNetworkDelegate(extension_event_router_forwarder(),
megjablonc1751452014-12-09 19:46:47648 &system_enable_referrers_));
[email protected]84b7a552014-07-19 04:52:06649
[email protected]84b7a552014-07-19 04:52:06650#if defined(ENABLE_EXTENSIONS)
[email protected]c2dad292012-09-07 21:27:35651 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling))
megjablonc1751452014-12-09 19:46:47652 chrome_network_delegate->NeverThrottleRequests();
[email protected]84b7a552014-07-19 04:52:06653#endif
654
erikchendc7ecc412015-03-12 02:46:36655 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
656 // is fixed.
657 tracked_objects::ScopedTracker tracking_profile4(
658 FROM_HERE_WITH_EXPLICIT_FUNCTION(
659 "466432 IOThread::InitAsync::CreateGlobalHostResolver"));
bengr9463b5772015-01-24 00:24:54660 globals_->system_network_delegate = chrome_network_delegate.Pass();
[email protected]c54a8912012-10-22 22:09:43661 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
tbansalea2fb8c2015-05-22 22:23:00662
663 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator());
664
erikchendc7ecc412015-03-12 02:46:36665 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
666 // is fixed.
667 tracked_objects::ScopedTracker tracking_profile5(
668 FROM_HERE_WITH_EXPLICIT_FUNCTION(
669 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::Start"));
[email protected]fa4b6c32012-11-26 23:02:39670 UpdateDnsClientEnabled();
erikchendc7ecc412015-03-12 02:46:36671 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
672 // is fixed.
673 tracked_objects::ScopedTracker tracking_profile6(
674 FROM_HERE_WITH_EXPLICIT_FUNCTION(
675 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::End"));
[email protected]f46f6d52014-02-08 04:00:39676#if defined(OS_CHROMEOS)
[email protected]f9357a442014-05-15 18:44:07677 // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
678 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
679 new chromeos::CertVerifyProcChromeOS()));
680#else
[email protected]84b7a552014-07-19 04:52:06681 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
682 net::CertVerifyProc::CreateDefault()));
[email protected]f9357a442014-05-15 18:44:07683#endif
684
davidbeneb5f8ef32014-09-04 14:14:32685 globals_->transport_security_state.reset(new net::TransportSecurityState());
686
erikchendc7ecc412015-03-12 02:46:36687 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
688 // is fixed.
689 tracked_objects::ScopedTracker tracking_profile7(
690 FROM_HERE_WITH_EXPLICIT_FUNCTION(
691 "466432 IOThread::InitAsync::CreateMultiLogVerifier"));
[email protected]284303b62013-11-28 15:11:54692 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
693 globals_->cert_transparency_verifier.reset(ct_verifier);
694
erikchendc7ecc412015-03-12 02:46:36695 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
696 // is fixed.
697 tracked_objects::ScopedTracker tracking_profile8(
698 FROM_HERE_WITH_EXPLICIT_FUNCTION(
699 "466432 IOThread::InitAsync::CreateLogVerifiers::Start"));
[email protected]284303b62013-11-28 15:11:54700 // Add built-in logs
[email protected]c78b21a2014-06-24 17:47:51701 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs());
erikchendc7ecc412015-03-12 02:46:36702 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
703 // is fixed.
704 tracked_objects::ScopedTracker tracking_profile9(
705 FROM_HERE_WITH_EXPLICIT_FUNCTION(
706 "466432 IOThread::InitAsync::CreateLogVerifiers::End"));
[email protected]284303b62013-11-28 15:11:54707
708 // Add logs from command line
709 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
710 std::string switch_value = command_line.GetSwitchValueASCII(
711 switches::kCertificateTransparencyLog);
[email protected]344bc952014-01-29 14:04:59712 std::vector<std::string> logs;
713 base::SplitString(switch_value, ',', &logs);
714 for (std::vector<std::string>::iterator it = logs.begin(); it != logs.end();
715 ++it) {
716 const std::string& curr_log = *it;
eranmd2f0b872015-05-05 16:57:03717 std::vector<std::string> log_metadata;
718 base::SplitString(curr_log, ':', &log_metadata);
719 CHECK_GE(log_metadata.size(), 3u)
720 << "CT log metadata missing: Switch format is "
721 << "'description:base64_key:url_without_schema'.";
722 std::string log_description(log_metadata[0]);
723 std::string log_url(std::string("https://") + log_metadata[2]);
[email protected]344bc952014-01-29 14:04:59724 std::string ct_public_key_data;
eranmd2f0b872015-05-05 16:57:03725 CHECK(base::Base64Decode(log_metadata[1], &ct_public_key_data))
[email protected]344bc952014-01-29 14:04:59726 << "Unable to decode CT public key.";
727 scoped_ptr<net::CTLogVerifier> external_log_verifier(
eranmd2f0b872015-05-05 16:57:03728 net::CTLogVerifier::Create(ct_public_key_data, log_description,
729 log_url));
[email protected]344bc952014-01-29 14:04:59730 CHECK(external_log_verifier) << "Unable to parse CT public key.";
731 VLOG(1) << "Adding log with description " << log_description;
732 ct_verifier->AddLog(external_log_verifier.Pass());
733 }
[email protected]284303b62013-11-28 15:11:54734 }
davidbeneb5f8ef32014-09-04 14:14:32735
erikchendc7ecc412015-03-12 02:46:36736 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
737 // is fixed.
738 tracked_objects::ScopedTracker tracking_profile10(
739 FROM_HERE_WITH_EXPLICIT_FUNCTION(
740 "466432 IOThread::InitAsync::CertPolicyEnforcer"));
eranm9ca6c9a2015-05-06 19:10:00741 net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer;
eranm6571b2b2014-12-03 15:53:23742 globals_->cert_policy_enforcer.reset(policy_enforcer);
743
[email protected]4d45a6de2011-05-13 05:20:18744 globals_->ssl_config_service = GetSSLConfigService();
[email protected]f4bfa7672014-08-08 09:50:46745
[email protected]65d34382010-07-01 18:12:26746 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
[email protected]73c45322010-10-01 23:57:54747 globals_->host_resolver.get()));
[email protected]30d4c022013-07-18 22:58:16748 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
[email protected]2fb629202010-12-23 23:52:57749 // For the ProxyScriptFetcher, we use a direct ProxyService.
[email protected]6104ea5d2011-04-27 21:37:12750 globals_->proxy_script_fetcher_proxy_service.reset(
751 net::ProxyService::CreateDirectWithNetLog(net_log_));
[email protected]273e37d2011-08-11 01:49:12752 // In-memory cookie store.
erikchendc7ecc412015-03-12 02:46:36753 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
754 // is fixed.
755 tracked_objects::ScopedTracker tracking_profile11(
756 FROM_HERE_WITH_EXPLICIT_FUNCTION(
757 "466432 IOThread::InitAsync::CreateCookieStore::Start"));
[email protected]9a6c2aa2014-01-11 22:39:39758 globals_->system_cookie_store =
759 content::CreateCookieStore(content::CookieStoreConfig());
erikchendc7ecc412015-03-12 02:46:36760 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
761 // is fixed.
762 tracked_objects::ScopedTracker tracking_profile12(
763 FROM_HERE_WITH_EXPLICIT_FUNCTION(
764 "466432 IOThread::InitAsync::CreateCookieStore::End"));
[email protected]6b8a3c742014-07-25 00:25:35765 // In-memory channel ID store.
766 globals_->system_channel_id_service.reset(
767 new net::ChannelIDService(
768 new net::DefaultChannelIDStore(NULL),
[email protected]5bab49ec2012-05-04 21:13:19769 base::WorkerPool::GetTaskRunner(true)));
erikchenb0357632015-04-22 00:36:50770 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
771 // is fixed.
772 tracked_objects::ScopedTracker tracking_profile12_1(
773 FROM_HERE_WITH_EXPLICIT_FUNCTION(
774 "466432 IOThread::InitAsync::CreateDnsProbeService"));
[email protected]4588b3d2012-11-14 00:37:38775 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
erikchenb0357632015-04-22 00:36:50776 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
777 // is fixed.
778 tracked_objects::ScopedTracker tracking_profile12_2(
779 FROM_HERE_WITH_EXPLICIT_FUNCTION(
780 "466432 IOThread::InitAsync::CreateHostMappingRules"));
[email protected]c2dad292012-09-07 21:27:35781 globals_->host_mapping_rules.reset(new net::HostMappingRules());
erikchenb0357632015-04-22 00:36:50782 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
783 // is fixed.
784 tracked_objects::ScopedTracker tracking_profile12_3(
785 FROM_HERE_WITH_EXPLICIT_FUNCTION(
786 "466432 IOThread::InitAsync::CreateHTTPUserAgentSettings"));
[email protected]ee4c30d2012-11-07 15:08:43787 globals_->http_user_agent_settings.reset(
[email protected]aa051272014-03-10 05:56:56788 new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
erikchenb0357632015-04-22 00:36:50789 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
790 // is fixed.
791 tracked_objects::ScopedTracker tracking_profile12_4(
792 FROM_HERE_WITH_EXPLICIT_FUNCTION(
793 "466432 IOThread::InitAsync::CommandLineConfiguration"));
[email protected]c2dad292012-09-07 21:27:35794 if (command_line.HasSwitch(switches::kHostRules)) {
[email protected]a5e73b82013-07-17 08:58:39795 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35796 globals_->host_mapping_rules->SetRulesFromString(
797 command_line.GetSwitchValueASCII(switches::kHostRules));
[email protected]a5e73b82013-07-17 08:58:39798 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35799 }
800 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
801 globals_->ignore_certificate_errors = true;
ricea43736982014-10-30 09:15:48802 globals_->use_stale_while_revalidate =
803 IsStaleWhileRevalidateEnabled(command_line);
[email protected]c2dad292012-09-07 21:27:35804 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
[email protected]f9cf5572012-12-04 15:52:09805 globals_->testing_fixed_http_port =
806 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
[email protected]c2dad292012-09-07 21:27:35807 }
808 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
[email protected]f9cf5572012-12-04 15:52:09809 globals_->testing_fixed_https_port =
810 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
[email protected]c2dad292012-09-07 21:27:35811 }
erikchenb0357632015-04-22 00:36:50812 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
813 // is fixed.
814 tracked_objects::ScopedTracker tracking_profile12_5(
815 FROM_HERE_WITH_EXPLICIT_FUNCTION(
816 "466432 IOThread::InitAsync::QuicConfiguration"));
[email protected]256fe9b2013-11-27 01:58:02817 ConfigureQuic(command_line);
[email protected]c54c6962013-02-01 04:53:19818 if (command_line.HasSwitch(
819 switches::kEnableUserAlternateProtocolPorts)) {
820 globals_->enable_user_alternate_protocol_ports = true;
821 }
erikchendc7ecc412015-03-12 02:46:36822 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
823 // is fixed.
824 tracked_objects::ScopedTracker tracking_profile13(
825 FROM_HERE_WITH_EXPLICIT_FUNCTION(
826 "466432 IOThread::InitAsync::InitializeNetworkOptions"));
[email protected]f9cf5572012-12-04 15:52:09827 InitializeNetworkOptions(command_line);
828
[email protected]9e1bdd32011-02-03 21:48:34829 net::HttpNetworkSession::Params session_params;
[email protected]f9cf5572012-12-04 15:52:09830 InitializeNetworkSessionParams(&session_params);
[email protected]27c253802012-11-30 08:18:12831 session_params.net_log = net_log_;
[email protected]9e1bdd32011-02-03 21:48:34832 session_params.proxy_service =
833 globals_->proxy_script_fetcher_proxy_service.get();
[email protected]c2dad292012-09-07 21:27:35834
erikchendc7ecc412015-03-12 02:46:36835 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
836 // is fixed.
837 tracked_objects::ScopedTracker tracking_profile14(
838 FROM_HERE_WITH_EXPLICIT_FUNCTION(
839 "466432 IOThread::InitAsync::HttpNetorkSession::Start"));
[email protected]a5e73b82013-07-17 08:58:39840 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:HttpNetworkSession");
[email protected]57cb0f72011-01-28 06:33:58841 scoped_refptr<net::HttpNetworkSession> network_session(
[email protected]9e1bdd32011-02-03 21:48:34842 new net::HttpNetworkSession(session_params));
erikchendc7ecc412015-03-12 02:46:36843 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
844 // is fixed.
845 tracked_objects::ScopedTracker tracking_profile15(
846 FROM_HERE_WITH_EXPLICIT_FUNCTION(
847 "466432 IOThread::InitAsync::HttpNetorkSession::End"));
[email protected]5173de8b2013-06-02 21:16:02848 globals_->proxy_script_fetcher_http_transaction_factory
849 .reset(new net::HttpNetworkLayer(network_session.get()));
[email protected]a5e73b82013-07-17 08:58:39850 TRACE_EVENT_END0("startup", "IOThread::InitAsync:HttpNetworkSession");
[email protected]b3ae2db2013-05-30 05:00:05851 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
852 new net::URLRequestJobFactoryImpl());
erikchendc7ecc412015-03-12 02:46:36853
854 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
855 // is fixed.
856 tracked_objects::ScopedTracker tracking_profile16(
857 FROM_HERE_WITH_EXPLICIT_FUNCTION(
858 "466432 IOThread::InitAsync::SetProtocolHandler"));
[email protected]cca6f392014-05-28 21:32:26859 job_factory->SetProtocolHandler(url::kDataScheme,
[email protected]b3ae2db2013-05-30 05:00:05860 new net::DataProtocolHandler());
[email protected]255620da2013-08-19 13:14:29861 job_factory->SetProtocolHandler(
[email protected]cca6f392014-05-28 21:32:26862 url::kFileScheme,
[email protected]255620da2013-08-19 13:14:29863 new net::FileProtocolHandler(
864 content::BrowserThread::GetBlockingPool()->
865 GetTaskRunnerWithShutdownBehavior(
866 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
[email protected]b3ae2db2013-05-30 05:00:05867#if !defined(DISABLE_FTP_SUPPORT)
868 globals_->proxy_script_fetcher_ftp_transaction_factory.reset(
869 new net::FtpNetworkLayer(globals_->host_resolver.get()));
870 job_factory->SetProtocolHandler(
[email protected]cca6f392014-05-28 21:32:26871 url::kFtpScheme,
[email protected]b3ae2db2013-05-30 05:00:05872 new net::FtpProtocolHandler(
873 globals_->proxy_script_fetcher_ftp_transaction_factory.get()));
874#endif
dcheng383ba8a2014-10-16 23:55:19875 globals_->proxy_script_fetcher_url_request_job_factory = job_factory.Pass();
[email protected]2fb629202010-12-23 23:52:57876
[email protected]a73a2802012-05-02 19:20:15877 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager());
[email protected]a1d4ab072012-06-07 13:21:15878 globals_->throttler_manager->set_net_log(net_log_);
[email protected]332a8c962013-07-17 22:31:23879 // Always done in production, disabled only for unit tests.
880 globals_->throttler_manager->set_enable_thread_checks(true);
[email protected]a73a2802012-05-02 19:20:15881
[email protected]ef2bf422012-05-11 03:27:09882 globals_->proxy_script_fetcher_context.reset(
883 ConstructProxyScriptFetcherContext(globals_, net_log_));
[email protected]4a109492011-09-24 21:00:12884
[email protected]11f5e3a2012-09-27 00:30:13885#if defined(OS_MACOSX) && !defined(OS_IOS)
886 // Start observing Keychain events. This needs to be done on the UI thread,
887 // as Keychain services requires a CFRunLoop.
888 BrowserThread::PostTask(BrowserThread::UI,
889 FROM_HERE,
890 base::Bind(&ObserveKeychainEvents));
891#endif
892
[email protected]2e5b60a22011-11-28 15:56:41893 // InitSystemRequestContext turns right around and posts a task back
894 // to the IO thread, so we can't let it run until we know the IO
895 // thread has started.
896 //
897 // Note that since we are at BrowserThread::Init time, the UI thread
898 // is blocked waiting for the thread to start. Therefore, posting
899 // this task to the main thread's message loop here is guaranteed to
900 // get it onto the message loop while the IOThread object still
901 // exists. However, the message might not be processed on the UI
902 // thread until after IOThread is gone, so use a weak pointer.
903 BrowserThread::PostTask(BrowserThread::UI,
904 FROM_HERE,
905 base::Bind(&IOThread::InitSystemRequestContext,
906 weak_factory_.GetWeakPtr()));
[email protected]0ac83682010-01-22 17:46:27907}
908
[email protected]2a92cd92010-04-27 00:01:41909void IOThread::CleanUp() {
[email protected]075c0322012-02-14 00:56:44910 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
911
davidben71f35ff2015-04-17 20:54:48912#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09913 net::ShutdownNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29914#endif
[email protected]59a3b362010-10-21 21:52:41915
[email protected]db0e86dd2011-03-16 14:47:21916 system_url_request_context_getter_ = NULL;
917
[email protected]af669932012-01-17 19:26:58918 // Release objects that the net::URLRequestContext could have been pointing
919 // to.
[email protected]0ee7a3b2010-11-09 06:13:40920
[email protected]7592b41f2014-04-01 01:44:43921 // Shutdown the HistogramWatcher on the IO thread.
922 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
923
[email protected]0ee7a3b2010-11-09 06:13:40924 // This must be reset before the ChromeNetLog is destroyed.
925 network_change_observer_.reset();
926
[email protected]db0e86dd2011-03-16 14:47:21927 system_proxy_config_service_.reset();
928
[email protected]d13c3272010-02-04 00:24:51929 delete globals_;
930 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27931
[email protected]db0e86dd2011-03-16 14:47:21932 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27933}
934
avi556c05022014-12-22 23:31:43935void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) {
[email protected]aedf781f2013-07-15 21:38:15936 // Only handle use-spdy command line flags if "spdy.disabled" preference is
937 // not disabled via policy.
[email protected]aedfccd9b2013-10-02 03:24:46938 if (is_spdy_disabled_by_policy_) {
939 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName);
940 if (trial)
941 trial->Disable();
942 } else {
bncbc0b05b2015-03-25 19:50:58943 std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
944 VariationParameters params;
945 if (!variations::GetVariationParams(kSpdyFieldTrialName, &params)) {
946 params.clear();
[email protected]aedf781f2013-07-15 21:38:15947 }
bncbc0b05b2015-03-25 19:50:58948 ConfigureSpdyGlobals(command_line, group, params, globals_);
[email protected]77305422012-11-29 16:51:39949 }
[email protected]717e4e22013-04-10 20:52:23950
jrif9b4bec2014-09-15 15:46:54951 ConfigureTCPFastOpen(command_line);
jrif9b4bec2014-09-15 15:46:54952
[email protected]717e4e22013-04-10 20:52:23953 // TODO(rch): Make the client socket factory a per-network session
954 // instance, constructed from a NetworkSession::Params, to allow us
955 // to move this option to IOThread::Globals &
956 // HttpNetworkSession::Params.
jrif9b4bec2014-09-15 15:46:54957}
jridcb4ae922014-09-12 23:52:39958
avi556c05022014-12-22 23:31:43959void IOThread::ConfigureTCPFastOpen(const base::CommandLine& command_line) {
jrif9b4bec2014-09-15 15:46:54960 const std::string trial_group =
961 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName);
962 if (trial_group == kTCPFastOpenHttpsEnabledGroupName)
963 globals_->enable_tcp_fast_open_for_ssl.set(true);
jridcb4ae922014-09-12 23:52:39964 bool always_enable_if_supported =
jrif9b4bec2014-09-15 15:46:54965 command_line.HasSwitch(switches::kEnableTcpFastOpen);
jridcb4ae922014-09-12 23:52:39966 // Check for OS support of TCP FastOpen, and turn it on for all connections
967 // if indicated by user.
968 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_if_supported);
[email protected]77305422012-11-29 16:51:39969}
970
bncbc0b05b2015-03-25 19:50:58971// static
972void IOThread::ConfigureSpdyGlobals(
973 const base::CommandLine& command_line,
974 base::StringPiece spdy_trial_group,
975 const VariationParameters& spdy_trial_params,
976 IOThread::Globals* globals) {
977 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
978 globals->trusted_spdy_proxy.set(
979 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy));
980 }
981 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
982 net::URLFetcher::SetIgnoreCertificateRequests(true);
983
984 if (command_line.HasSwitch(switches::kUseSpdy)) {
985 std::string spdy_mode =
986 command_line.GetSwitchValueASCII(switches::kUseSpdy);
987 ConfigureSpdyGlobalsFromUseSpdyArgument(spdy_mode, globals);
988 return;
989 }
990
991 globals->next_protos.clear();
992 globals->next_protos.push_back(net::kProtoHTTP11);
993 bool enable_quic = false;
994 globals->enable_quic.CopyToIfSet(&enable_quic);
995 if (enable_quic) {
996 globals->next_protos.push_back(net::kProtoQUIC1SPDY3);
997 }
998
bncbc0b05b2015-03-25 19:50:58999 // No SPDY command-line flags have been specified. Examine trial groups.
bnce3553d92014-10-30 22:29:451000 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) {
[email protected]44a101422014-07-02 22:12:571001 net::HttpStreamFactory::set_spdy_enabled(false);
bncbc0b05b2015-03-25 19:50:581002 return;
[email protected]44a101422014-07-02 22:12:571003 }
bncbc0b05b2015-03-25 19:50:581004 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy31GroupNamePrefix)) {
1005 globals->next_protos.push_back(net::kProtoSPDY31);
1006 globals->use_alternate_protocols.set(true);
1007 return;
1008 }
1009 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy4GroupNamePrefix)) {
1010 globals->next_protos.push_back(net::kProtoSPDY31);
1011 globals->next_protos.push_back(net::kProtoSPDY4_14);
1012 globals->next_protos.push_back(net::kProtoSPDY4);
1013 globals->use_alternate_protocols.set(true);
1014 return;
1015 }
1016 if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) {
1017 bool spdy_enabled = false;
brettwbc17d2c82015-06-09 22:39:081018 if (base::LowerCaseEqualsASCII(
bncbc0b05b2015-03-25 19:50:581019 GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) {
1020 globals->next_protos.push_back(net::kProtoSPDY31);
1021 spdy_enabled = true;
[email protected]443a30ed2012-11-30 02:56:461022 }
brettwbc17d2c82015-06-09 22:39:081023 if (base::LowerCaseEqualsASCII(
bncbc0b05b2015-03-25 19:50:581024 GetVariationParam(spdy_trial_params, "enable_http2_14"), "true")) {
1025 globals->next_protos.push_back(net::kProtoSPDY4_14);
1026 spdy_enabled = true;
1027 }
brettwbc17d2c82015-06-09 22:39:081028 if (base::LowerCaseEqualsASCII(
bncbc0b05b2015-03-25 19:50:581029 GetVariationParam(spdy_trial_params, "enable_http2"), "true")) {
1030 globals->next_protos.push_back(net::kProtoSPDY4);
1031 spdy_enabled = true;
1032 }
1033 // TODO(bnc): HttpStreamFactory::spdy_enabled_ is redundant with
1034 // globals->next_protos, can it be eliminated?
1035 net::HttpStreamFactory::set_spdy_enabled(spdy_enabled);
1036 globals->use_alternate_protocols.set(true);
1037 return;
[email protected]443a30ed2012-11-30 02:56:461038 }
bncbc0b05b2015-03-25 19:50:581039
1040 // By default, enable HTTP/2.
1041 globals->next_protos.push_back(net::kProtoSPDY31);
1042 globals->next_protos.push_back(net::kProtoSPDY4_14);
1043 globals->next_protos.push_back(net::kProtoSPDY4);
1044 globals->use_alternate_protocols.set(true);
[email protected]443a30ed2012-11-30 02:56:461045}
1046
[email protected]bcefe0f2010-11-10 16:19:101047// static
[email protected]b1de2c72013-02-06 02:45:471048void IOThread::RegisterPrefs(PrefRegistrySimple* registry) {
1049 registry->RegisterStringPref(prefs::kAuthSchemes,
bengr70266e22015-06-12 19:38:171050 "basic,digest,ntlm,negotiate");
[email protected]68a9b0d82013-03-08 07:05:071051 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
[email protected]b1de2c72013-02-06 02:45:471052 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
[email protected]007b3f82013-04-09 08:46:451053 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
1054 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
1055 std::string());
1056 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
[email protected]a0a06932014-04-14 21:23:421057 registry->RegisterStringPref(
1058 data_reduction_proxy::prefs::kDataReductionProxy, std::string());
[email protected]b1de2c72013-02-06 02:45:471059 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
[email protected]1575e3d2014-05-03 22:21:441060 data_reduction_proxy::RegisterPrefs(registry);
[email protected]68a9b0d82013-03-08 07:05:071061 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
[email protected]67378142013-12-17 21:57:171062 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
[email protected]bcefe0f2010-11-10 16:19:101063}
1064
[email protected]65d34382010-07-01 18:12:261065net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
1066 net::HostResolver* resolver) {
[email protected]9030a632010-11-19 20:12:091067 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL;
1068 if (!auth_server_whitelist_.empty()) {
1069 auth_filter_default_credentials =
1070 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
1071 }
1072 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
1073 if (!auth_delegate_whitelist_.empty()) {
1074 auth_filter_delegate =
1075 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_);
1076 }
[email protected]b4955e7d2010-04-16 20:22:301077 globals_->url_security_manager.reset(
[email protected]d201b200e2010-08-27 17:35:021078 net::URLSecurityManager::Create(auth_filter_default_credentials,
1079 auth_filter_delegate));
[email protected]b7304162010-08-23 17:42:291080 std::vector<std::string> supported_schemes;
[email protected]bcefe0f2010-11-10 16:19:101081 base::SplitString(auth_schemes_, ',', &supported_schemes);
[email protected]b7304162010-08-23 17:42:291082
[email protected]ec44ee02012-09-28 21:31:511083 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory(
1084 net::HttpAuthHandlerRegistryFactory::Create(
1085 supported_schemes, globals_->url_security_manager.get(),
1086 resolver, gssapi_library_name_, negotiate_disable_cname_lookup_,
1087 negotiate_enable_port_));
[email protected]ec44ee02012-09-28 21:31:511088 return registry_factory.release();
[email protected]eb3cac72010-02-26 21:07:451089}
1090
[email protected]d6f37fc2011-02-13 23:58:411091void IOThread::ClearHostCache() {
1092 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1093
[email protected]489d1a82011-10-12 03:09:111094 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
1095 if (host_cache)
1096 host_cache->clear();
[email protected]0ac83682010-01-22 17:46:271097}
[email protected]db0e86dd2011-03-16 14:47:211098
[email protected]f9cf5572012-12-04 15:52:091099void IOThread::InitializeNetworkSessionParams(
1100 net::HttpNetworkSession::Params* params) {
[email protected]488a0e252014-06-25 04:37:441101 InitializeNetworkSessionParamsFromGlobals(*globals_, params);
1102}
[email protected]f9cf5572012-12-04 15:52:091103
[email protected]488a0e252014-06-25 04:37:441104// static
1105void IOThread::InitializeNetworkSessionParamsFromGlobals(
1106 const IOThread::Globals& globals,
1107 net::HttpNetworkSession::Params* params) {
1108 params->host_resolver = globals.host_resolver.get();
1109 params->cert_verifier = globals.cert_verifier.get();
eranm6571b2b2014-12-03 15:53:231110 params->cert_policy_enforcer = globals.cert_policy_enforcer.get();
[email protected]6b8a3c742014-07-25 00:25:351111 params->channel_id_service = globals.system_channel_id_service.get();
[email protected]488a0e252014-06-25 04:37:441112 params->transport_security_state = globals.transport_security_state.get();
1113 params->ssl_config_service = globals.ssl_config_service.get();
1114 params->http_auth_handler_factory = globals.http_auth_handler_factory.get();
1115 params->http_server_properties =
1116 globals.http_server_properties->GetWeakPtr();
1117 params->network_delegate = globals.system_network_delegate.get();
1118 params->host_mapping_rules = globals.host_mapping_rules.get();
1119 params->ignore_certificate_errors = globals.ignore_certificate_errors;
ricea64c07d792014-10-08 03:37:001120 params->use_stale_while_revalidate = globals.use_stale_while_revalidate;
[email protected]488a0e252014-06-25 04:37:441121 params->testing_fixed_http_port = globals.testing_fixed_http_port;
1122 params->testing_fixed_https_port = globals.testing_fixed_https_port;
jrif9b4bec2014-09-15 15:46:541123 globals.enable_tcp_fast_open_for_ssl.CopyToIfSet(
1124 &params->enable_tcp_fast_open_for_ssl);
[email protected]488a0e252014-06-25 04:37:441125
1126 globals.initial_max_spdy_concurrent_streams.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091127 &params->spdy_initial_max_concurrent_streams);
[email protected]488a0e252014-06-25 04:37:441128 globals.enable_spdy_compression.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091129 &params->enable_spdy_compression);
[email protected]488a0e252014-06-25 04:37:441130 globals.enable_spdy_ping_based_connection_checking.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091131 &params->enable_spdy_ping_based_connection_checking);
[email protected]488a0e252014-06-25 04:37:441132 globals.spdy_default_protocol.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091133 &params->spdy_default_protocol);
[email protected]488a0e252014-06-25 04:37:441134 params->next_protos = globals.next_protos;
1135 globals.trusted_spdy_proxy.CopyToIfSet(&params->trusted_spdy_proxy);
[email protected]488a0e252014-06-25 04:37:441136 params->forced_spdy_exclusions = globals.forced_spdy_exclusions;
1137 globals.use_alternate_protocols.CopyToIfSet(
[email protected]d7599122014-05-24 03:37:231138 &params->use_alternate_protocols);
bnc62891a52015-04-27 14:14:121139 globals.alternative_service_probability_threshold.CopyToIfSet(
1140 &params->alternative_service_probability_threshold);
[email protected]d7599122014-05-24 03:37:231141
[email protected]488a0e252014-06-25 04:37:441142 globals.enable_quic.CopyToIfSet(&params->enable_quic);
rch405ed7a2015-05-12 01:10:161143 globals.disable_insecure_quic.CopyToIfSet(&params->disable_insecure_quic);
tbansaled0aecc2015-02-20 03:44:181144 globals.enable_quic_for_proxies.CopyToIfSet(&params->enable_quic_for_proxies);
jri2b966f22014-09-02 22:25:361145 globals.quic_always_require_handshake_confirmation.CopyToIfSet(
1146 &params->quic_always_require_handshake_confirmation);
jri584002d12014-09-09 00:51:281147 globals.quic_disable_connection_pooling.CopyToIfSet(
1148 &params->quic_disable_connection_pooling);
rtenneti2912825c2015-01-06 01:19:461149 globals.quic_load_server_info_timeout_srtt_multiplier.CopyToIfSet(
1150 &params->quic_load_server_info_timeout_srtt_multiplier);
rtenneti4f809972015-02-11 19:38:341151 globals.quic_enable_connection_racing.CopyToIfSet(
1152 &params->quic_enable_connection_racing);
qyearsley3257b7de2015-02-28 06:59:031153 globals.quic_enable_non_blocking_io.CopyToIfSet(
1154 &params->quic_enable_non_blocking_io);
rch9976b0c2015-06-10 21:27:231155 globals.quic_prefer_aes.CopyToIfSet(&params->quic_prefer_aes);
rtenneti34dffe752015-02-24 23:27:321156 globals.quic_disable_disk_cache.CopyToIfSet(
1157 &params->quic_disable_disk_cache);
rtenneti374e56882015-03-28 13:49:541158 globals.quic_max_number_of_lossy_connections.CopyToIfSet(
1159 &params->quic_max_number_of_lossy_connections);
1160 globals.quic_packet_loss_threshold.CopyToIfSet(
1161 &params->quic_packet_loss_threshold);
rchc7433572015-02-27 18:16:511162 globals.quic_socket_receive_buffer_size.CopyToIfSet(
1163 &params->quic_socket_receive_buffer_size);
[email protected]488a0e252014-06-25 04:37:441164 globals.enable_quic_port_selection.CopyToIfSet(
[email protected]376d38a2014-01-22 03:47:351165 &params->enable_quic_port_selection);
[email protected]488a0e252014-06-25 04:37:441166 globals.quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length);
1167 globals.quic_user_agent_id.CopyToIfSet(&params->quic_user_agent_id);
1168 globals.quic_supported_versions.CopyToIfSet(
[email protected]6a31ca52013-12-23 00:44:341169 &params->quic_supported_versions);
[email protected]488a0e252014-06-25 04:37:441170 params->quic_connection_options = globals.quic_connection_options;
1171
1172 globals.origin_to_force_quic_on.CopyToIfSet(
[email protected]49e85332013-06-04 04:18:031173 &params->origin_to_force_quic_on);
[email protected]c54c6962013-02-01 04:53:191174 params->enable_user_alternate_protocol_ports =
[email protected]488a0e252014-06-25 04:37:441175 globals.enable_user_alternate_protocol_ports;
[email protected]f9cf5572012-12-04 15:52:091176}
1177
[email protected]d827e112014-03-31 17:45:051178base::TimeTicks IOThread::creation_time() const {
1179 return creation_time_;
1180}
1181
[email protected]4d45a6de2011-05-13 05:20:181182net::SSLConfigService* IOThread::GetSSLConfigService() {
1183 return ssl_config_service_manager_->Get();
1184}
1185
[email protected]b09f76d62011-12-07 01:51:061186void IOThread::ChangedToOnTheRecordOnIOThread() {
1187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1188
1189 // Clear the host cache to avoid showing entries from the OTR session
1190 // in about:net-internals.
1191 ClearHostCache();
[email protected]b09f76d62011-12-07 01:51:061192}
1193
[email protected]db0e86dd2011-03-16 14:47:211194void IOThread::InitSystemRequestContext() {
[email protected]5173de8b2013-06-02 21:16:021195 if (system_url_request_context_getter_.get())
[email protected]addb3242011-06-13 21:39:161196 return;
[email protected]63e26822011-07-16 19:07:351197 // If we're in unit_tests, IOThread may not be run.
[email protected]dd483702011-12-02 14:47:421198 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
[email protected]63e26822011-07-16 19:07:351199 return;
[email protected]53c5b0f2013-07-22 10:54:111200 system_proxy_config_service_.reset(
1201 ProxyServiceFactory::CreateProxyConfigService(
1202 pref_proxy_config_tracker_.get()));
[email protected]addb3242011-06-13 21:39:161203 system_url_request_context_getter_ =
1204 new SystemURLRequestContextGetter(this);
[email protected]2e5b60a22011-11-28 15:56:411205 // Safe to post an unretained this pointer, since IOThread is
1206 // guaranteed to outlive the IO BrowserThread.
[email protected]dd483702011-12-02 14:47:421207 BrowserThread::PostTask(
1208 BrowserThread::IO,
1209 FROM_HERE,
1210 base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
1211 base::Unretained(this)));
[email protected]addb3242011-06-13 21:39:161212}
1213
1214void IOThread::InitSystemRequestContextOnIOThread() {
[email protected]db0e86dd2011-03-16 14:47:211215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]6104ea5d2011-04-27 21:37:121216 DCHECK(!globals_->system_proxy_service.get());
[email protected]db0e86dd2011-03-16 14:47:211217 DCHECK(system_proxy_config_service_.get());
1218
avi556c05022014-12-22 23:31:431219 const base::CommandLine& command_line =
1220 *base::CommandLine::ForCurrentProcess();
[email protected]6104ea5d2011-04-27 21:37:121221 globals_->system_proxy_service.reset(
[email protected]db0e86dd2011-03-16 14:47:211222 ProxyServiceFactory::CreateProxyService(
1223 net_log_,
[email protected]ef2bf422012-05-11 03:27:091224 globals_->proxy_script_fetcher_context.get(),
[email protected]8def32a02013-03-11 19:13:231225 globals_->system_network_delegate.get(),
[email protected]db0e86dd2011-03-16 14:47:211226 system_proxy_config_service_.release(),
[email protected]67378142013-12-17 21:57:171227 command_line,
1228 quick_check_enabled_.GetValue()));
[email protected]c2dad292012-09-07 21:27:351229
[email protected]db0e86dd2011-03-16 14:47:211230 net::HttpNetworkSession::Params system_params;
[email protected]f9cf5572012-12-04 15:52:091231 InitializeNetworkSessionParams(&system_params);
[email protected]db0e86dd2011-03-16 14:47:211232 system_params.net_log = net_log_;
[email protected]27c253802012-11-30 08:18:121233 system_params.proxy_service = globals_->system_proxy_service.get();
[email protected]c2dad292012-09-07 21:27:351234
michaelne2fd577c2015-02-27 02:10:131235 globals_->system_http_transaction_factory.reset(
1236 new net::HttpNetworkLayer(
1237 new net::HttpNetworkSession(system_params)));
[email protected]2944afa2014-06-13 00:41:291238 globals_->system_url_request_job_factory.reset(
1239 new net::URLRequestJobFactoryImpl());
[email protected]ef2bf422012-05-11 03:27:091240 globals_->system_request_context.reset(
1241 ConstructSystemRequestContext(globals_, net_log_));
[email protected]db8bf052014-06-25 11:53:101242 globals_->system_request_context->set_ssl_config_service(
dcheng319a21952014-08-26 22:52:401243 globals_->ssl_config_service.get());
[email protected]db8bf052014-06-25 11:53:101244 globals_->system_request_context->set_http_server_properties(
1245 globals_->http_server_properties->GetWeakPtr());
[email protected]db0e86dd2011-03-16 14:47:211246}
[email protected]fa4b6c32012-11-26 23:02:391247
1248void IOThread::UpdateDnsClientEnabled() {
1249 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
1250}
[email protected]903e63382013-06-01 00:40:581251
avi556c05022014-12-22 23:31:431252void IOThread::ConfigureQuic(const base::CommandLine& command_line) {
[email protected]903e63382013-06-01 00:40:581253 // Always fetch the field trial group to ensure it is reported correctly.
1254 // The command line flags will be associated with a group that is reported
1255 // so long as trial is actually queried.
[email protected]488a0e252014-06-25 04:37:441256 std::string group =
[email protected]903e63382013-06-01 00:40:581257 base::FieldTrialList::FindFullName(kQuicFieldTrialName);
[email protected]488a0e252014-06-25 04:37:441258 VariationParameters params;
[email protected]59b6f672014-07-26 18:35:471259 if (!variations::GetVariationParams(kQuicFieldTrialName, &params)) {
[email protected]488a0e252014-06-25 04:37:441260 params.clear();
1261 }
[email protected]903e63382013-06-01 00:40:581262
peletskyi5df83d42015-04-30 16:37:461263 ConfigureQuicGlobals(command_line, group, params, is_quic_allowed_by_policy_,
1264 globals_);
[email protected]488a0e252014-06-25 04:37:441265}
1266
1267// static
1268void IOThread::ConfigureQuicGlobals(
1269 const base::CommandLine& command_line,
1270 base::StringPiece quic_trial_group,
1271 const VariationParameters& quic_trial_params,
peletskyi5df83d42015-04-30 16:37:461272 bool quic_allowed_by_policy,
[email protected]488a0e252014-06-25 04:37:441273 IOThread::Globals* globals) {
peletskyi5df83d42015-04-30 16:37:461274 bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group,
1275 quic_allowed_by_policy);
[email protected]488a0e252014-06-25 04:37:441276 globals->enable_quic.set(enable_quic);
peletskyi5df83d42015-04-30 16:37:461277 bool enable_quic_for_proxies = ShouldEnableQuicForProxies(
1278 command_line, quic_trial_group, quic_allowed_by_policy);
tbansaled0aecc2015-02-20 03:44:181279 globals->enable_quic_for_proxies.set(enable_quic_for_proxies);
[email protected]256fe9b2013-11-27 01:58:021280 if (enable_quic) {
rch405ed7a2015-05-12 01:10:161281 globals->disable_insecure_quic.set(
1282 ShouldDisableInsecureQuic(quic_trial_params));
jri2b966f22014-09-02 22:25:361283 globals->quic_always_require_handshake_confirmation.set(
1284 ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params));
jri584002d12014-09-09 00:51:281285 globals->quic_disable_connection_pooling.set(
1286 ShouldQuicDisableConnectionPooling(quic_trial_params));
rchc7433572015-02-27 18:16:511287 int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params);
1288 if (receive_buffer_size != 0) {
1289 globals->quic_socket_receive_buffer_size.set(receive_buffer_size);
1290 }
rtenneti2912825c2015-01-06 01:19:461291 float load_server_info_timeout_srtt_multiplier =
1292 GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params);
1293 if (load_server_info_timeout_srtt_multiplier != 0) {
1294 globals->quic_load_server_info_timeout_srtt_multiplier.set(
1295 load_server_info_timeout_srtt_multiplier);
1296 }
rtenneti34dffe752015-02-24 23:27:321297 globals->quic_enable_connection_racing.set(
1298 ShouldQuicEnableConnectionRacing(quic_trial_params));
qyearsley3257b7de2015-02-28 06:59:031299 globals->quic_enable_non_blocking_io.set(
1300 ShouldQuicEnableNonBlockingIO(quic_trial_params));
rtenneti34dffe752015-02-24 23:27:321301 globals->quic_disable_disk_cache.set(
1302 ShouldQuicDisableDiskCache(quic_trial_params));
rch9976b0c2015-06-10 21:27:231303 globals->quic_prefer_aes.set(
1304 ShouldQuicPreferAes(quic_trial_params));
rtenneti374e56882015-03-28 13:49:541305 int max_number_of_lossy_connections = GetQuicMaxNumberOfLossyConnections(
1306 quic_trial_params);
1307 if (max_number_of_lossy_connections != 0) {
1308 globals->quic_max_number_of_lossy_connections.set(
1309 max_number_of_lossy_connections);
1310 }
1311 float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params);
1312 if (packet_loss_threshold != 0)
1313 globals->quic_packet_loss_threshold.set(packet_loss_threshold);
[email protected]488a0e252014-06-25 04:37:441314 globals->enable_quic_port_selection.set(
[email protected]376d38a2014-01-22 03:47:351315 ShouldEnableQuicPortSelection(command_line));
[email protected]488a0e252014-06-25 04:37:441316 globals->quic_connection_options =
1317 GetQuicConnectionOptions(command_line, quic_trial_params);
[email protected]256fe9b2013-11-27 01:58:021318 }
1319
1320 size_t max_packet_length = GetQuicMaxPacketLength(command_line,
[email protected]488a0e252014-06-25 04:37:441321 quic_trial_params);
[email protected]256fe9b2013-11-27 01:58:021322 if (max_packet_length != 0) {
[email protected]488a0e252014-06-25 04:37:441323 globals->quic_max_packet_length.set(max_packet_length);
[email protected]256fe9b2013-11-27 01:58:021324 }
1325
[email protected]0c4017ca2014-06-06 03:30:451326 std::string quic_user_agent_id =
1327 chrome::VersionInfo::GetVersionStringModifier();
[email protected]adb9ded2014-07-25 08:31:441328 if (!quic_user_agent_id.empty())
1329 quic_user_agent_id.push_back(' ');
[email protected]0c4017ca2014-06-06 03:30:451330 chrome::VersionInfo version_info;
1331 quic_user_agent_id.append(version_info.ProductNameAndVersionForUserAgent());
[email protected]488a0e252014-06-25 04:37:441332 globals->quic_user_agent_id.set(quic_user_agent_id);
[email protected]0c4017ca2014-06-06 03:30:451333
[email protected]488a0e252014-06-25 04:37:441334 net::QuicVersion version = GetQuicVersion(command_line, quic_trial_params);
[email protected]6a31ca52013-12-23 00:44:341335 if (version != net::QUIC_VERSION_UNSUPPORTED) {
1336 net::QuicVersionVector supported_versions;
1337 supported_versions.push_back(version);
[email protected]488a0e252014-06-25 04:37:441338 globals->quic_supported_versions.set(supported_versions);
[email protected]6a31ca52013-12-23 00:44:341339 }
1340
bnc62891a52015-04-27 14:14:121341 double threshold = GetAlternativeProtocolProbabilityThreshold(
1342 command_line, quic_trial_params);
[email protected]287d9412014-07-08 23:01:001343 if (threshold >=0 && threshold <= 1) {
bnc62891a52015-04-27 14:14:121344 globals->alternative_service_probability_threshold.set(threshold);
1345 globals->http_server_properties->SetAlternativeServiceProbabilityThreshold(
[email protected]287d9412014-07-08 23:01:001346 threshold);
1347 }
1348
[email protected]256fe9b2013-11-27 01:58:021349 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
1350 net::HostPortPair quic_origin =
1351 net::HostPortPair::FromString(
1352 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
1353 if (!quic_origin.IsEmpty()) {
[email protected]488a0e252014-06-25 04:37:441354 globals->origin_to_force_quic_on.set(quic_origin);
[email protected]256fe9b2013-11-27 01:58:021355 }
1356 }
1357}
1358
avi556c05022014-12-22 23:31:431359bool IOThread::ShouldEnableQuic(const base::CommandLine& command_line,
peletskyi5df83d42015-04-30 16:37:461360 base::StringPiece quic_trial_group,
1361 bool quic_allowed_by_policy) {
1362 if (command_line.HasSwitch(switches::kDisableQuic) || !quic_allowed_by_policy)
[email protected]903e63382013-06-01 00:40:581363 return false;
1364
[email protected]a64b213e2013-07-24 21:41:001365 if (command_line.HasSwitch(switches::kEnableQuic))
[email protected]903e63382013-06-01 00:40:581366 return true;
1367
[email protected]256fe9b2013-11-27 01:58:021368 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) ||
1369 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
[email protected]a64b213e2013-07-24 21:41:001370}
1371
tbansaled0aecc2015-02-20 03:44:181372// static
1373bool IOThread::ShouldEnableQuicForProxies(const base::CommandLine& command_line,
peletskyi5df83d42015-04-30 16:37:461374 base::StringPiece quic_trial_group,
1375 bool quic_allowed_by_policy) {
1376 return ShouldEnableQuic(
1377 command_line, quic_trial_group, quic_allowed_by_policy) ||
tbansaled0aecc2015-02-20 03:44:181378 ShouldEnableQuicForDataReductionProxy();
1379}
1380
1381// static
1382bool IOThread::ShouldEnableQuicForDataReductionProxy() {
1383 const base::CommandLine& command_line =
1384 *base::CommandLine::ForCurrentProcess();
1385
1386 if (command_line.HasSwitch(switches::kDisableQuic))
1387 return false;
1388
1389 return data_reduction_proxy::DataReductionProxyParams::
1390 IsIncludedInQuicFieldTrial();
1391}
1392
rch405ed7a2015-05-12 01:10:161393// static
1394bool IOThread::ShouldDisableInsecureQuic(
1395 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081396 return base::LowerCaseEqualsASCII(
rch405ed7a2015-05-12 01:10:161397 GetVariationParam(quic_trial_params, "disable_insecure_quic"),
1398 "true");
1399}
1400
[email protected]376d38a2014-01-22 03:47:351401bool IOThread::ShouldEnableQuicPortSelection(
avi556c05022014-12-22 23:31:431402 const base::CommandLine& command_line) {
[email protected]376d38a2014-01-22 03:47:351403 if (command_line.HasSwitch(switches::kDisableQuicPortSelection))
1404 return false;
1405
1406 if (command_line.HasSwitch(switches::kEnableQuicPortSelection))
1407 return true;
1408
[email protected]3273b3c2014-05-23 16:52:281409 return false; // Default to disabling port selection on all channels.
[email protected]376d38a2014-01-22 03:47:351410}
1411
[email protected]488a0e252014-06-25 04:37:441412net::QuicTagVector IOThread::GetQuicConnectionOptions(
avi556c05022014-12-22 23:31:431413 const base::CommandLine& command_line,
[email protected]488a0e252014-06-25 04:37:441414 const VariationParameters& quic_trial_params) {
1415 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) {
mefcb6537c2014-11-12 19:38:501416 return net::QuicUtils::ParseQuicConnectionOptions(
[email protected]488a0e252014-06-25 04:37:441417 command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions));
1418 }
1419
1420 VariationParameters::const_iterator it =
[email protected]8cc878112014-08-15 04:06:441421 quic_trial_params.find("connection_options");
1422 if (it == quic_trial_params.end()) {
rche9efff42015-01-12 17:58:191423 return net::QuicTagVector();
[email protected]8cc878112014-08-15 04:06:441424 }
[email protected]488a0e252014-06-25 04:37:441425
mefcb6537c2014-11-12 19:38:501426 return net::QuicUtils::ParseQuicConnectionOptions(it->second);
[email protected]488a0e252014-06-25 04:37:441427}
1428
[email protected]287d9412014-07-08 23:01:001429// static
bnc62891a52015-04-27 14:14:121430double IOThread::GetAlternativeProtocolProbabilityThreshold(
[email protected]287d9412014-07-08 23:01:001431 const base::CommandLine& command_line,
1432 const VariationParameters& quic_trial_params) {
1433 double value;
1434 if (command_line.HasSwitch(
bnc62891a52015-04-27 14:14:121435 switches::kAlternativeServiceProbabilityThreshold)) {
[email protected]287d9412014-07-08 23:01:001436 if (base::StringToDouble(
1437 command_line.GetSwitchValueASCII(
bnc62891a52015-04-27 14:14:121438 switches::kAlternativeServiceProbabilityThreshold),
[email protected]287d9412014-07-08 23:01:001439 &value)) {
1440 return value;
1441 }
1442 }
rch16642752014-09-18 00:29:161443 if (command_line.HasSwitch(switches::kEnableQuic)) {
1444 return 0;
1445 }
bnc62891a52015-04-27 14:14:121446 // TODO(bnc): Remove when new parameter name rolls out and server
1447 // configuration is changed.
[email protected]287d9412014-07-08 23:01:001448 if (base::StringToDouble(
1449 GetVariationParam(quic_trial_params,
1450 "alternate_protocol_probability_threshold"),
1451 &value)) {
1452 return value;
1453 }
bnc62891a52015-04-27 14:14:121454 if (base::StringToDouble(
1455 GetVariationParam(quic_trial_params,
1456 "alternative_service_probability_threshold"),
1457 &value)) {
1458 return value;
1459 }
[email protected]287d9412014-07-08 23:01:001460 return -1;
1461}
1462
1463// static
jri2b966f22014-09-02 22:25:361464bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
1465 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081466 return base::LowerCaseEqualsASCII(
jri2b966f22014-09-02 22:25:361467 GetVariationParam(quic_trial_params,
1468 "always_require_handshake_confirmation"),
1469 "true");
1470}
1471
1472// static
jri584002d12014-09-09 00:51:281473bool IOThread::ShouldQuicDisableConnectionPooling(
1474 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081475 return base::LowerCaseEqualsASCII(
jri584002d12014-09-09 00:51:281476 GetVariationParam(quic_trial_params, "disable_connection_pooling"),
1477 "true");
1478}
1479
1480// static
rtenneti2912825c2015-01-06 01:19:461481float IOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier(
1482 const VariationParameters& quic_trial_params) {
1483 double value;
1484 if (base::StringToDouble(GetVariationParam(quic_trial_params,
1485 "load_server_info_time_to_srtt"),
1486 &value)) {
1487 return (float)value;
1488 }
1489 return 0.0f;
1490}
1491
1492// static
rtenneti4f809972015-02-11 19:38:341493bool IOThread::ShouldQuicEnableConnectionRacing(
1494 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081495 return base::LowerCaseEqualsASCII(
rtenneti4f809972015-02-11 19:38:341496 GetVariationParam(quic_trial_params, "enable_connection_racing"),
1497 "true");
1498}
1499
1500// static
qyearsley3257b7de2015-02-28 06:59:031501bool IOThread::ShouldQuicEnableNonBlockingIO(
1502 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081503 return base::LowerCaseEqualsASCII(
qyearsley3257b7de2015-02-28 06:59:031504 GetVariationParam(quic_trial_params, "enable_non_blocking_io"),
1505 "true");
1506}
1507
1508// static
rtenneti34dffe752015-02-24 23:27:321509bool IOThread::ShouldQuicDisableDiskCache(
1510 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081511 return base::LowerCaseEqualsASCII(
rtenneti34dffe752015-02-24 23:27:321512 GetVariationParam(quic_trial_params, "disable_disk_cache"), "true");
1513}
1514
1515// static
rch9976b0c2015-06-10 21:27:231516bool IOThread::ShouldQuicPreferAes(
1517 const VariationParameters& quic_trial_params) {
1518 return base::LowerCaseEqualsASCII(
1519 GetVariationParam(quic_trial_params, "prefer_aes"), "true");
1520}
1521
1522// static
rtenneti374e56882015-03-28 13:49:541523int IOThread::GetQuicMaxNumberOfLossyConnections(
1524 const VariationParameters& quic_trial_params) {
1525 int value;
1526 if (base::StringToInt(GetVariationParam(quic_trial_params,
1527 "max_number_of_lossy_connections"),
1528 &value)) {
1529 return value;
1530 }
1531 return 0;
1532}
1533
1534// static
1535float IOThread::GetQuicPacketLossThreshold(
1536 const VariationParameters& quic_trial_params) {
1537 double value;
1538 if (base::StringToDouble(GetVariationParam(quic_trial_params,
1539 "packet_loss_threshold"),
1540 &value)) {
1541 return (float)value;
1542 }
1543 return 0.0f;
1544}
1545
1546// static
rchc7433572015-02-27 18:16:511547int IOThread::GetQuicSocketReceiveBufferSize(
1548 const VariationParameters& quic_trial_params) {
1549 int value;
1550 if (base::StringToInt(GetVariationParam(quic_trial_params,
1551 "receive_buffer_size"),
1552 &value)) {
1553 return value;
1554 }
1555 return 0;
1556}
1557
1558// static
[email protected]488a0e252014-06-25 04:37:441559size_t IOThread::GetQuicMaxPacketLength(
avi556c05022014-12-22 23:31:431560 const base::CommandLine& command_line,
[email protected]488a0e252014-06-25 04:37:441561 const VariationParameters& quic_trial_params) {
[email protected]256fe9b2013-11-27 01:58:021562 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
1563 unsigned value;
1564 if (!base::StringToUint(
1565 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
1566 &value)) {
1567 return 0;
1568 }
1569 return value;
1570 }
1571
[email protected]488a0e252014-06-25 04:37:441572 unsigned value;
1573 if (base::StringToUint(GetVariationParam(quic_trial_params,
1574 "max_packet_length"),
1575 &value)) {
1576 return value;
1577 }
rchcc4b8cf2014-12-05 20:24:381578 return 0;
[email protected]903e63382013-06-01 00:40:581579}
[email protected]6a31ca52013-12-23 00:44:341580
[email protected]287d9412014-07-08 23:01:001581// static
[email protected]488a0e252014-06-25 04:37:441582net::QuicVersion IOThread::GetQuicVersion(
avi556c05022014-12-22 23:31:431583 const base::CommandLine& command_line,
[email protected]488a0e252014-06-25 04:37:441584 const VariationParameters& quic_trial_params) {
1585 if (command_line.HasSwitch(switches::kQuicVersion)) {
1586 return ParseQuicVersion(
1587 command_line.GetSwitchValueASCII(switches::kQuicVersion));
[email protected]6a31ca52013-12-23 00:44:341588 }
[email protected]488a0e252014-06-25 04:37:441589
1590 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version"));
1591}
1592
[email protected]287d9412014-07-08 23:01:001593// static
[email protected]488a0e252014-06-25 04:37:441594net::QuicVersion IOThread::ParseQuicVersion(const std::string& quic_version) {
[email protected]6a31ca52013-12-23 00:44:341595 net::QuicVersionVector supported_versions = net::QuicSupportedVersions();
[email protected]6a31ca52013-12-23 00:44:341596 for (size_t i = 0; i < supported_versions.size(); ++i) {
1597 net::QuicVersion version = supported_versions[i];
[email protected]488a0e252014-06-25 04:37:441598 if (net::QuicVersionToString(version) == quic_version) {
[email protected]6a31ca52013-12-23 00:44:341599 return version;
1600 }
1601 }
[email protected]488a0e252014-06-25 04:37:441602
[email protected]6a31ca52013-12-23 00:44:341603 return net::QUIC_VERSION_UNSUPPORTED;
1604}