blob: 626e81b83580cce4cf7f8dbda86cb8b82fe625f6 [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]db0e86dd2011-03-16 14:47:2137#include "chrome/browser/net/proxy_service_factory.h"
sdefresne9fb67692015-08-03 18:48:2238#include "chrome/common/channel_info.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]bcefe0f2010-11-10 16:19:1041#include "chrome/common/pref_names.h"
megjablon3476e042014-10-14 19:21:5942#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
tbansaled0aecc2015-02-20 03:44:1843#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
[email protected]76b4b152013-12-08 21:10:0444#include "components/policy/core/common/policy_service.h"
abhishek.a2171c612852015-08-31 10:48:1945#include "components/proxy_config/pref_proxy_config_tracker.h"
[email protected]488a0e252014-06-25 04:37:4446#include "components/variations/variations_associated_data.h"
sdefresne9fb67692015-08-03 18:48:2247#include "components/version_info/version_info.h"
[email protected]c38831a12011-10-28 12:44:4948#include "content/public/browser/browser_thread.h"
[email protected]7c4b66b2014-01-04 12:28:1349#include "content/public/browser/cookie_store_factory.h"
rtenneti4d126a72015-06-23 17:32:0950#include "content/public/common/user_agent.h"
tbansal1c92d5b2015-08-14 20:14:4351#include "net/base/external_estimate_provider.h"
[email protected]c2dad292012-09-07 21:27:3552#include "net/base/host_mapping_rules.h"
[email protected]32eaa332010-02-08 22:15:5453#include "net/base/net_util.h"
tbansalea2fb8c2015-05-22 22:23:0054#include "net/base/network_quality_estimator.h"
rdsmith60e6e6fb2015-03-05 16:49:2055#include "net/base/sdch_manager.h"
eranm6571b2b2014-12-03 15:53:2356#include "net/cert/cert_policy_enforcer.h"
[email protected]6e7845ae2013-03-29 21:48:1157#include "net/cert/cert_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3958#include "net/cert/cert_verify_proc.h"
[email protected]284303b62013-11-28 15:11:5459#include "net/cert/ct_known_logs.h"
eranm6571b2b2014-12-03 15:53:2360#include "net/cert/ct_known_logs_static.h"
davidbeneb5f8ef32014-09-04 14:14:3261#include "net/cert/ct_log_verifier.h"
[email protected]284303b62013-11-28 15:11:5462#include "net/cert/ct_verifier.h"
davidbeneb5f8ef32014-09-04 14:14:3263#include "net/cert/multi_log_ct_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3964#include "net/cert/multi_threaded_cert_verifier.h"
[email protected]9a6c2aa2014-01-11 22:39:3965#include "net/cookies/cookie_store.h"
[email protected]bc71b8772013-04-10 20:55:1666#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5367#include "net/dns/host_resolver.h"
68#include "net/dns/mapped_host_resolver.h"
[email protected]b3ae2db2013-05-30 05:00:0569#include "net/ftp/ftp_network_layer.h"
[email protected]eb3cac72010-02-26 21:07:4570#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5071#include "net/http/http_auth_handler_factory.h"
[email protected]2fb629202010-12-23 23:52:5772#include "net/http/http_network_layer.h"
[email protected]17291a022011-10-10 07:32:5373#include "net/http/http_server_properties_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1274#include "net/proxy/proxy_config_service.h"
[email protected]86933612010-10-16 23:10:3375#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1276#include "net/proxy/proxy_service.h"
[email protected]648f81142014-08-15 21:38:4677#include "net/quic/crypto/crypto_protocol.h"
[email protected]6a31ca52013-12-23 00:44:3478#include "net/quic/quic_protocol.h"
mefcb6537c2014-11-12 19:38:5079#include "net/quic/quic_utils.h"
[email protected]717e4e22013-04-10 20:52:2380#include "net/socket/tcp_client_socket.h"
[email protected]77305422012-11-29 16:51:3981#include "net/spdy/spdy_session.h"
[email protected]6b8a3c742014-07-25 00:25:3582#include "net/ssl/channel_id_service.h"
83#include "net/ssl/default_channel_id_store.h"
[email protected]b3ae2db2013-05-30 05:00:0584#include "net/url_request/data_protocol_handler.h"
85#include "net/url_request/file_protocol_handler.h"
86#include "net/url_request/ftp_protocol_handler.h"
[email protected]aa051272014-03-10 05:56:5687#include "net/url_request/static_http_user_agent_settings.h"
[email protected]3dc1bc42012-06-19 08:20:5388#include "net/url_request/url_fetcher.h"
xunjieliaab07db2015-07-28 16:46:2389#include "net/url_request/url_request_backoff_manager.h"
[email protected]f9c8c7c2014-07-31 16:42:3190#include "net/url_request/url_request_context.h"
wjmacleanea309f72015-08-25 20:56:5991#include "net/url_request/url_request_context_builder.h"
[email protected]f9c8c7c2014-07-31 16:42:3192#include "net/url_request/url_request_context_getter.h"
[email protected]b3ae2db2013-05-30 05:00:0593#include "net/url_request/url_request_job_factory_impl.h"
[email protected]cca6f392014-05-28 21:32:2694#include "url/url_constants.h"
[email protected]77305422012-11-29 16:51:3995
96#if defined(ENABLE_CONFIGURATION_POLICY)
97#include "policy/policy_constants.h"
98#endif
[email protected]0ac83682010-01-22 17:46:2799
[email protected]84b7a552014-07-19 04:52:06100#if defined(ENABLE_EXTENSIONS)
101#include "chrome/browser/extensions/event_router_forwarder.h"
102#endif
103
davidben71f35ff2015-04-17 20:54:48104#if defined(USE_NSS_CERTS) || defined(OS_IOS)
eromaned744f32015-04-09 06:35:49105#include "net/cert_net/nss_ocsp.h"
[email protected]a592c0432012-12-01 18:10:29106#endif
[email protected]77feb462011-05-16 23:37:25107
jeremyimb6c97ae2015-01-05 22:57:14108#if defined(OS_ANDROID)
109#include "base/android/build_info.h"
tbansaldafbb3e2015-08-19 19:55:33110#include "chrome/browser/android/net/external_estimate_provider_android.h"
jeremyimb6c97ae2015-01-05 22:57:14111#endif
112
[email protected]f46f6d52014-02-08 04:00:39113#if defined(OS_CHROMEOS)
114#include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
[email protected]106ccd2c2014-06-17 09:21:00115#include "chromeos/network/host_resolver_impl_chromeos.h"
[email protected]f46f6d52014-02-08 04:00:39116#endif
117
[email protected]631bb742011-11-02 11:29:39118using content::BrowserThread;
119
[email protected]075c0322012-02-14 00:56:44120class SafeBrowsingURLRequestContext;
121
[email protected]21ee224e2011-11-21 02:17:53122// The IOThread object must outlive any tasks posted to the IO thread before the
123// Quit task, so base::Bind() calls are not refcounted.
124
[email protected]0ac83682010-01-22 17:46:27125namespace {
126
jrif9b4bec2014-09-15 15:46:54127const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen";
128const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled";
129
[email protected]903e63382013-06-01 00:40:58130const char kQuicFieldTrialName[] = "QUIC";
131const char kQuicFieldTrialEnabledGroupName[] = "Enabled";
[email protected]a64b213e2013-07-24 21:41:00132const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled";
[email protected]903e63382013-06-01 00:40:58133
[email protected]44a101422014-07-02 22:12:57134// The SPDY trial composes two different trial plus control groups:
135// * A "holdback" group with SPDY disabled, and corresponding control
136// (SPDY/3.1). The primary purpose of the holdback group is to encourage site
137// operators to do feature detection rather than UA-sniffing. As such, this
138// trial runs continuously.
139// * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and
140// eventual SPDY/4 deployment.
[email protected]aedfccd9b2013-10-02 03:24:46141const char kSpdyFieldTrialName[] = "SPDY";
bnce3553d92014-10-30 22:29:45142const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled";
bnce3553d92014-10-30 22:29:45143const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled";
144const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled";
bncbc0b05b2015-03-25 19:50:58145const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized";
[email protected]aedfccd9b2013-10-02 03:24:46146
tbansalb177b5392015-06-25 11:13:02147// Field trial for network quality estimator. Seeds RTT and downstream
148// throughput observations with values that correspond to the connection type
149// determined by the operating system.
150const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
151
[email protected]11f5e3a2012-09-27 00:30:13152#if defined(OS_MACOSX) && !defined(OS_IOS)
153void ObserveKeychainEvents() {
thestig00844cea2015-09-08 21:44:52154 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]11f5e3a2012-09-27 00:30:13155 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
156}
157#endif
158
[email protected]ee4c30d2012-11-07 15:08:43159// Used for the "system" URLRequestContext.
160class SystemURLRequestContext : public net::URLRequestContext {
[email protected]77feb462011-05-16 23:37:25161 public:
162 SystemURLRequestContext() {
davidben71f35ff2015-04-17 20:54:48163#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09164 net::SetURLRequestContextForNSSHttpIO(this);
[email protected]a592c0432012-12-01 18:10:29165#endif
[email protected]77feb462011-05-16 23:37:25166 }
167
168 private:
Daniel Chenga542fca2014-10-21 09:51:29169 ~SystemURLRequestContext() override {
[email protected]424559492014-07-22 00:27:40170 AssertNoURLRequests();
davidben71f35ff2015-04-17 20:54:48171#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09172 net::SetURLRequestContextForNSSHttpIO(NULL);
[email protected]a592c0432012-12-01 18:10:29173#endif
[email protected]77feb462011-05-16 23:37:25174 }
175};
176
[email protected]c54a8912012-10-22 22:09:43177scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
[email protected]d22f06e2013-06-11 16:01:17178 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
avi556c05022014-12-22 23:31:43179 const base::CommandLine& command_line =
180 *base::CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:51181
[email protected]c54a8912012-10-22 22:09:43182 net::HostResolver::Options options;
[email protected]962b98212010-07-17 03:37:51183
[email protected]06ef6d92011-05-19 04:24:58184 // Use the retry attempts override from the command-line, if any.
185 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
186 std::string s =
187 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
188 // Parse the switch (it should be a non-negative integer).
189 int n;
190 if (base::StringToInt(s, &n) && n >= 0) {
[email protected]c54a8912012-10-22 22:09:43191 options.max_retry_attempts = static_cast<size_t>(n);
[email protected]06ef6d92011-05-19 04:24:58192 } else {
193 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
194 }
195 }
196
[email protected]106ccd2c2014-06-17 09:21:00197 scoped_ptr<net::HostResolver> global_host_resolver;
198#if defined OS_CHROMEOS
199 global_host_resolver =
200 chromeos::HostResolverImplChromeOS::CreateSystemResolver(options,
201 net_log);
202#else
203 global_host_resolver =
204 net::HostResolver::CreateSystemResolver(options, net_log);
205#endif
[email protected]9087aa32010-02-18 08:03:38206
[email protected]3dc5d7ef2014-03-28 19:18:21207 // If hostname remappings were specified on the command-line, layer these
208 // rules on top of the real host resolver. This allows forwarding all requests
209 // through a designated test server.
210 if (!command_line.HasSwitch(switches::kHostResolverRules))
dcheng383ba8a2014-10-16 23:55:19211 return global_host_resolver.Pass();
[email protected]0ac83682010-01-22 17:46:27212
[email protected]3dc5d7ef2014-03-28 19:18:21213 scoped_ptr<net::MappedHostResolver> remapped_resolver(
214 new net::MappedHostResolver(global_host_resolver.Pass()));
215 remapped_resolver->SetRulesFromString(
216 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
dcheng383ba8a2014-10-16 23:55:19217 return remapped_resolver.Pass();
[email protected]0ac83682010-01-22 17:46:27218}
219
avi556c05022014-12-22 23:31:43220int GetSwitchValueAsInt(const base::CommandLine& command_line,
[email protected]f9cf5572012-12-04 15:52:09221 const std::string& switch_name) {
222 int value;
223 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
224 &value)) {
225 return 0;
226 }
227 return value;
[email protected]27c253802012-11-30 08:18:12228}
229
[email protected]488a0e252014-06-25 04:37:44230// Returns the value associated with |key| in |params| or "" if the
231// key is not present in the map.
232const std::string& GetVariationParam(
233 const std::map<std::string, std::string>& params,
234 const std::string& key) {
235 std::map<std::string, std::string>::const_iterator it = params.find(key);
236 if (it == params.end())
237 return base::EmptyString();
238
239 return it->second;
240}
241
bncbc0b05b2015-03-25 19:50:58242// Parse kUseSpdy command line flag options, which may contain the following:
243//
244// "off" : Disables SPDY support entirely.
bncbc0b05b2015-03-25 19:50:58245// "no-ping" : Disables SPDY ping connection testing.
246// "exclude=<host>" : Disables SPDY support for the host <host>.
247// "no-compress" : Disables SPDY header compression.
bncbc0b05b2015-03-25 19:50:58248// "init-max-streams=<limit>" : Specifies the maximum number of concurrent
249// streams for a SPDY session, unless the
250// specifies a different value via SETTINGS.
251void ConfigureSpdyGlobalsFromUseSpdyArgument(const std::string& mode,
252 IOThread::Globals* globals) {
253 static const char kOff[] = "off";
bncbc0b05b2015-03-25 19:50:58254 static const char kDisablePing[] = "no-ping";
255 static const char kExclude[] = "exclude"; // Hosts to exclude
256 static const char kDisableCompression[] = "no-compress";
bncbc0b05b2015-03-25 19:50:58257 static const char kInitialMaxConcurrentStreams[] = "init-max-streams";
258
brettwc6f82b12015-07-21 21:37:38259 for (const base::StringPiece& element : base::SplitStringPiece(
260 mode, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
261 std::vector<base::StringPiece> name_value = base::SplitStringPiece(
262 element, "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
263 const base::StringPiece option =
264 name_value.size() > 0 ? name_value[0] : base::StringPiece();
265 const base::StringPiece value =
266 name_value.size() > 1 ? name_value[1] : base::StringPiece();
bncbc0b05b2015-03-25 19:50:58267
268 if (option == kOff) {
269 net::HttpStreamFactory::set_spdy_enabled(false);
270 continue;
271 }
bncbc0b05b2015-03-25 19:50:58272 if (option == kDisablePing) {
273 globals->enable_spdy_ping_based_connection_checking.set(false);
274 continue;
275 }
276 if (option == kExclude) {
277 globals->forced_spdy_exclusions.insert(
brettwc6f82b12015-07-21 21:37:38278 net::HostPortPair::FromURL(GURL(value.as_string())));
bncbc0b05b2015-03-25 19:50:58279 continue;
280 }
281 if (option == kDisableCompression) {
282 globals->enable_spdy_compression.set(false);
283 continue;
284 }
bncbc0b05b2015-03-25 19:50:58285 if (option == kInitialMaxConcurrentStreams) {
286 int streams;
287 if (base::StringToInt(value, &streams)) {
288 globals->initial_max_spdy_concurrent_streams.set(streams);
289 continue;
290 }
291 }
brettwc6f82b12015-07-21 21:37:38292 LOG(DFATAL) << "Unrecognized spdy option: " << option.as_string();
bncbc0b05b2015-03-25 19:50:58293 }
294}
295
[email protected]0ac83682010-01-22 17:46:27296} // namespace
297
[email protected]e0845d5f2012-05-29 00:11:41298class IOThread::LoggingNetworkChangeObserver
[email protected]3d5aaad2012-10-27 12:31:28299 : public net::NetworkChangeNotifier::IPAddressObserver,
[email protected]03848872012-12-08 02:46:41300 public net::NetworkChangeNotifier::ConnectionTypeObserver,
301 public net::NetworkChangeNotifier::NetworkChangeObserver {
[email protected]e0845d5f2012-05-29 00:11:41302 public:
303 // |net_log| must remain valid throughout our lifetime.
304 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
305 : net_log_(net_log) {
306 net::NetworkChangeNotifier::AddIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28307 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41308 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41309 }
310
Daniel Chenga542fca2014-10-21 09:51:29311 ~LoggingNetworkChangeObserver() override {
[email protected]e0845d5f2012-05-29 00:11:41312 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28313 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41314 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41315 }
316
[email protected]03848872012-12-08 02:46:41317 // NetworkChangeNotifier::IPAddressObserver implementation.
Daniel Chenga542fca2014-10-21 09:51:29318 void OnIPAddressChanged() override {
[email protected]e0845d5f2012-05-29 00:11:41319 VLOG(1) << "Observed a change to the network IP addresses";
320
[email protected]2fa08912012-06-14 20:56:26321 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED);
[email protected]e0845d5f2012-05-29 00:11:41322 }
323
[email protected]03848872012-12-08 02:46:41324 // NetworkChangeNotifier::ConnectionTypeObserver implementation.
Daniel Chenga542fca2014-10-21 09:51:29325 void OnConnectionTypeChanged(
mostynb01d8b10e2014-10-13 09:44:44326 net::NetworkChangeNotifier::ConnectionType type) override {
[email protected]3d5aaad2012-10-27 12:31:28327 std::string type_as_string =
328 net::NetworkChangeNotifier::ConnectionTypeToString(type);
329
330 VLOG(1) << "Observed a change to network connectivity state "
331 << type_as_string;
332
333 net_log_->AddGlobalEntry(
334 net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED,
335 net::NetLog::StringCallback("new_connection_type", &type_as_string));
336 }
337
[email protected]03848872012-12-08 02:46:41338 // NetworkChangeNotifier::NetworkChangeObserver implementation.
Daniel Chenga542fca2014-10-21 09:51:29339 void OnNetworkChanged(
mostynb01d8b10e2014-10-13 09:44:44340 net::NetworkChangeNotifier::ConnectionType type) override {
[email protected]03848872012-12-08 02:46:41341 std::string type_as_string =
342 net::NetworkChangeNotifier::ConnectionTypeToString(type);
343
344 VLOG(1) << "Observed a network change to state " << type_as_string;
345
346 net_log_->AddGlobalEntry(
347 net::NetLog::TYPE_NETWORK_CHANGED,
348 net::NetLog::StringCallback("new_connection_type", &type_as_string));
349 }
350
[email protected]e0845d5f2012-05-29 00:11:41351 private:
352 net::NetLog* net_log_;
353 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
354};
355
[email protected]abe2c032011-03-31 18:49:34356class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
[email protected]db0e86dd2011-03-16 14:47:21357 public:
358 explicit SystemURLRequestContextGetter(IOThread* io_thread);
[email protected]db0e86dd2011-03-16 14:47:21359
[email protected]abe2c032011-03-31 18:49:34360 // Implementation for net::UrlRequestContextGetter.
Daniel Chenga542fca2014-10-21 09:51:29361 net::URLRequestContext* GetURLRequestContext() override;
362 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
363 const override;
[email protected]db0e86dd2011-03-16 14:47:21364
[email protected]13ed17f82012-04-06 02:27:18365 protected:
Daniel Chenga542fca2014-10-21 09:51:29366 ~SystemURLRequestContextGetter() override;
[email protected]13ed17f82012-04-06 02:27:18367
[email protected]db0e86dd2011-03-16 14:47:21368 private:
369 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
[email protected]4969b0122012-06-16 01:58:28370 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21371
372 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
373};
374
375SystemURLRequestContextGetter::SystemURLRequestContextGetter(
376 IOThread* io_thread)
377 : io_thread_(io_thread),
[email protected]4969b0122012-06-16 01:58:28378 network_task_runner_(
[email protected]2e5b60a22011-11-28 15:56:41379 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
[email protected]db0e86dd2011-03-16 14:47:21380}
381
382SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
383
384net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
thestig00844cea2015-09-08 21:44:52385 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]ef2bf422012-05-11 03:27:09386 DCHECK(io_thread_->globals()->system_request_context.get());
[email protected]db0e86dd2011-03-16 14:47:21387
[email protected]ef2bf422012-05-11 03:27:09388 return io_thread_->globals()->system_request_context.get();
[email protected]db0e86dd2011-03-16 14:47:21389}
390
[email protected]4969b0122012-06-16 01:58:28391scoped_refptr<base::SingleThreadTaskRunner>
392SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
393 return network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21394}
395
[email protected]c93123fa2012-04-19 02:49:48396IOThread::Globals::
397SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
398 Globals* globals)
399 : globals_(globals) {
400 DCHECK(globals_);
[email protected]7613faae2012-04-18 01:01:19401}
[email protected]1889dc1b2010-10-14 22:03:13402
[email protected]c93123fa2012-04-19 02:49:48403IOThread::Globals::
404SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {
405 if (globals_->system_request_context.get())
406 globals_->system_request_context->AssertNoURLRequests();
407}
408
409IOThread::Globals::Globals()
[email protected]9c009092013-05-01 03:14:09410 : system_request_context_leak_checker(this),
[email protected]c2dad292012-09-07 21:27:35411 ignore_certificate_errors(false),
[email protected]c2dad292012-09-07 21:27:35412 testing_fixed_http_port(0),
[email protected]c54c6962013-02-01 04:53:19413 testing_fixed_https_port(0),
414 enable_user_alternate_protocol_ports(false) {
415}
[email protected]c2dad292012-09-07 21:27:35416
[email protected]c93123fa2012-04-19 02:49:48417IOThread::Globals::~Globals() {}
418
[email protected]bcefe0f2010-11-10 16:19:10419// |local_state| is passed in explicitly in order to (1) reduce implicit
420// dependencies and (2) make IOThread more flexible for testing.
[email protected]3ce02412011-03-01 12:01:15421IOThread::IOThread(
[email protected]b1de2c72013-02-06 02:45:47422 PrefService* local_state,
[email protected]77305422012-11-29 16:51:39423 policy::PolicyService* policy_service,
[email protected]3ce02412011-03-01 12:01:15424 ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10425 extensions::EventRouterForwarder* extension_event_router_forwarder)
[email protected]2e5b60a22011-11-28 15:56:41426 : net_log_(net_log),
[email protected]84b7a552014-07-19 04:52:06427#if defined(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15428 extension_event_router_forwarder_(extension_event_router_forwarder),
[email protected]84b7a552014-07-19 04:52:06429#endif
[email protected]d13c3272010-02-04 00:24:51430 globals_(NULL),
[email protected]77305422012-11-29 16:51:39431 is_spdy_disabled_by_policy_(false),
peletskyi5df83d42015-04-30 16:37:46432 is_quic_allowed_by_policy_(true),
mohan.reddy14cb4ad42014-09-17 18:15:14433 creation_time_(base::TimeTicks::Now()),
434 weak_factory_(this) {
[email protected]bcefe0f2010-11-10 16:19:10435 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
436 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
437 prefs::kDisableAuthNegotiateCnameLookup);
438 negotiate_enable_port_ = local_state->GetBoolean(
439 prefs::kEnableAuthNegotiatePort);
440 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
441 auth_delegate_whitelist_ = local_state->GetString(
442 prefs::kAuthNegotiateDelegateWhitelist);
[email protected]ac7f3fdb2010-11-12 12:47:05443 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
aberentec894a52015-07-09 14:45:53444 auth_android_negotiate_account_type_ =
445 local_state->GetString(prefs::kAuthAndroidNegotiateAccountType);
[email protected]6f96cbcb2011-11-04 02:26:07446 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42447 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
448 local_state));
[email protected]9d8cfb682012-09-13 16:48:04449 ChromeNetworkDelegate::InitializePrefsOnUIThread(
450 &system_enable_referrers_,
451 NULL,
[email protected]d1208ba32012-11-08 11:10:33452 NULL,
treib4e26f6652014-12-01 14:34:18453 NULL,
[email protected]9d8cfb682012-09-13 16:48:04454 local_state);
[email protected]4d45a6de2011-05-13 05:20:18455 ssl_config_service_manager_.reset(
[email protected]e6d017652013-05-17 18:01:40456 SSLConfigServiceManager::CreateDefaultManager(local_state));
[email protected]2e5b60a22011-11-28 15:56:41457
[email protected]68a9b0d82013-03-08 07:05:07458 base::Value* dns_client_enabled_default = new base::FundamentalValue(
459 chrome_browser_net::ConfigureAsyncDnsFieldTrial());
460 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
461 dns_client_enabled_default);
ttuttle530184962015-01-13 00:24:07462 chrome_browser_net::LogAsyncDnsPrefSource(
463 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled));
[email protected]68a9b0d82013-03-08 07:05:07464
[email protected]fa4b6c32012-11-26 23:02:39465 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
466 local_state,
467 base::Bind(&IOThread::UpdateDnsClientEnabled,
468 base::Unretained(this)));
469 dns_client_enabled_.MoveToThread(
470 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
471
[email protected]67378142013-12-17 21:57:17472 quick_check_enabled_.Init(prefs::kQuickCheckEnabled,
473 local_state);
474 quick_check_enabled_.MoveToThread(
475 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
476
[email protected]77305422012-11-29 16:51:39477#if defined(ENABLE_CONFIGURATION_POLICY)
478 is_spdy_disabled_by_policy_ = policy_service->GetPolicies(
[email protected]2ccf83732013-02-04 20:19:02479 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get(
480 policy::key::kDisableSpdy) != NULL;
peletskyi5df83d42015-04-30 16:37:46481
482 const base::Value* value = policy_service->GetPolicies(
483 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
484 std::string())).GetValue(policy::key::kQuicAllowed);
485 if (value)
486 value->GetAsBoolean(&is_quic_allowed_by_policy_);
[email protected]77305422012-11-29 16:51:39487#endif // ENABLE_CONFIGURATION_POLICY
488
[email protected]2e5b60a22011-11-28 15:56:41489 BrowserThread::SetDelegate(BrowserThread::IO, this);
[email protected]bcefe0f2010-11-10 16:19:10490}
[email protected]0ac83682010-01-22 17:46:27491
492IOThread::~IOThread() {
[email protected]2e5b60a22011-11-28 15:56:41493 // This isn't needed for production code, but in tests, IOThread may
494 // be multiply constructed.
495 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
496
[email protected]d461ed22013-01-18 03:18:56497 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]d13c3272010-02-04 00:24:51498 DCHECK(!globals_);
[email protected]0ac83682010-01-22 17:46:27499}
500
[email protected]d13c3272010-02-04 00:24:51501IOThread::Globals* IOThread::globals() {
thestig00844cea2015-09-08 21:44:52502 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d13c3272010-02-04 00:24:51503 return globals_;
[email protected]0ac83682010-01-22 17:46:27504}
505
[email protected]37ac95b2013-07-23 23:39:35506void IOThread::SetGlobalsForTesting(Globals* globals) {
thestig00844cea2015-09-08 21:44:52507 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]37ac95b2013-07-23 23:39:35508 DCHECK(!globals || !globals_);
509 globals_ = globals;
510}
511
[email protected]b2fcd0e2010-12-01 15:19:40512ChromeNetLog* IOThread::net_log() {
513 return net_log_;
514}
515
[email protected]b09f76d62011-12-07 01:51:06516void IOThread::ChangedToOnTheRecord() {
thestig00844cea2015-09-08 21:44:52517 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]b09f76d62011-12-07 01:51:06518 BrowserThread::PostTask(
519 BrowserThread::IO,
520 FROM_HERE,
521 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
522 base::Unretained(this)));
523}
524
[email protected]abe2c032011-03-31 18:49:34525net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
thestig00844cea2015-09-08 21:44:52526 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5173de8b2013-06-02 21:16:02527 if (!system_url_request_context_getter_.get()) {
[email protected]addb3242011-06-13 21:39:16528 InitSystemRequestContext();
[email protected]db0e86dd2011-03-16 14:47:21529 }
[email protected]5173de8b2013-06-02 21:16:02530 return system_url_request_context_getter_.get();
[email protected]db0e86dd2011-03-16 14:47:21531}
532
[email protected]0ac83682010-01-22 17:46:27533void IOThread::Init() {
erikchendc7ecc412015-03-12 02:46:36534 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
535 // is fixed.
536 tracked_objects::ScopedTracker tracking_profile1(
537 FROM_HERE_WITH_EXPLICIT_FUNCTION("466432 IOThread::InitAsync::Start"));
[email protected]a5e73b82013-07-17 08:58:39538 TRACE_EVENT0("startup", "IOThread::InitAsync");
thestig00844cea2015-09-08 21:44:52539 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]70b92342010-10-12 05:54:06540
davidben71f35ff2015-04-17 20:54:48541#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09542 net::SetMessageLoopForNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29543#endif
[email protected]70b92342010-10-12 05:54:06544
erikchendc7ecc412015-03-12 02:46:36545 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
546 // is fixed.
547 tracked_objects::ScopedTracker tracking_profile2(
548 FROM_HERE_WITH_EXPLICIT_FUNCTION(
549 "466432 IOThread::InitAsync::CommandLineForCurrentProcess"));
avi556c05022014-12-22 23:31:43550 const base::CommandLine& command_line =
551 *base::CommandLine::ForCurrentProcess();
[email protected]c2dad292012-09-07 21:27:35552
[email protected]d13c3272010-02-04 00:24:51553 DCHECK(!globals_);
554 globals_ = new Globals;
555
[email protected]58bc7042010-07-07 18:04:14556 // Add an observer that will emit network change events to the ChromeNetLog.
557 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
558 // logging the network change before other IO thread consumers respond to it.
559 network_change_observer_.reset(
[email protected]b2fcd0e2010-12-01 15:19:40560 new LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14561
[email protected]cde8b3c2012-08-13 19:20:52562 // Setup the HistogramWatcher to run on the IO thread.
563 net::NetworkChangeNotifier::InitHistogramWatcher();
564
[email protected]84b7a552014-07-19 04:52:06565#if defined(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15566 globals_->extension_event_router_forwarder =
567 extension_event_router_forwarder_;
[email protected]84b7a552014-07-19 04:52:06568#endif
569
erikchendc7ecc412015-03-12 02:46:36570 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
571 // is fixed.
572 tracked_objects::ScopedTracker tracking_profile3(
573 FROM_HERE_WITH_EXPLICIT_FUNCTION(
574 "466432 IOThread::InitAsync::ChromeNetworkDelegate"));
megjablonc1751452014-12-09 19:46:47575 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate(
[email protected]84b7a552014-07-19 04:52:06576 new ChromeNetworkDelegate(extension_event_router_forwarder(),
megjablonc1751452014-12-09 19:46:47577 &system_enable_referrers_));
[email protected]84b7a552014-07-19 04:52:06578
erikchendc7ecc412015-03-12 02:46:36579 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
580 // is fixed.
581 tracked_objects::ScopedTracker tracking_profile4(
582 FROM_HERE_WITH_EXPLICIT_FUNCTION(
583 "466432 IOThread::InitAsync::CreateGlobalHostResolver"));
bengr9463b5772015-01-24 00:24:54584 globals_->system_network_delegate = chrome_network_delegate.Pass();
[email protected]c54a8912012-10-22 22:09:43585 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
tbansalea2fb8c2015-05-22 22:23:00586
tbansalb177b5392015-06-25 11:13:02587 std::map<std::string, std::string> network_quality_estimator_params;
588 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
589 &network_quality_estimator_params);
tbansal1c92d5b2015-08-14 20:14:43590
591 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider;
592#if defined(OS_ANDROID)
593 external_estimate_provider.reset(
tbansaldafbb3e2015-08-19 19:55:33594 new chrome::android::ExternalEstimateProviderAndroid());
tbansal1c92d5b2015-08-14 20:14:43595#endif
596 // Pass ownership.
597 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator(
598 external_estimate_provider.Pass(), network_quality_estimator_params));
tbansalea2fb8c2015-05-22 22:23:00599
erikchendc7ecc412015-03-12 02:46:36600 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
601 // is fixed.
602 tracked_objects::ScopedTracker tracking_profile5(
603 FROM_HERE_WITH_EXPLICIT_FUNCTION(
604 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::Start"));
[email protected]fa4b6c32012-11-26 23:02:39605 UpdateDnsClientEnabled();
erikchendc7ecc412015-03-12 02:46:36606 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
607 // is fixed.
608 tracked_objects::ScopedTracker tracking_profile6(
609 FROM_HERE_WITH_EXPLICIT_FUNCTION(
610 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::End"));
[email protected]f46f6d52014-02-08 04:00:39611#if defined(OS_CHROMEOS)
[email protected]f9357a442014-05-15 18:44:07612 // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
613 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
614 new chromeos::CertVerifyProcChromeOS()));
615#else
[email protected]84b7a552014-07-19 04:52:06616 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
617 net::CertVerifyProc::CreateDefault()));
[email protected]f9357a442014-05-15 18:44:07618#endif
619
davidbeneb5f8ef32014-09-04 14:14:32620 globals_->transport_security_state.reset(new net::TransportSecurityState());
621
erikchendc7ecc412015-03-12 02:46:36622 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
623 // is fixed.
erikchendc7ecc412015-03-12 02:46:36624 tracked_objects::ScopedTracker tracking_profile8(
625 FROM_HERE_WITH_EXPLICIT_FUNCTION(
626 "466432 IOThread::InitAsync::CreateLogVerifiers::Start"));
eranm03d454c2015-07-02 09:12:03627 std::vector<scoped_refptr<net::CTLogVerifier>> ct_logs(
628 net::ct::CreateLogVerifiersForKnownLogs());
[email protected]284303b62013-11-28 15:11:54629
630 // Add logs from command line
631 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
632 std::string switch_value = command_line.GetSwitchValueASCII(
633 switches::kCertificateTransparencyLog);
brettwc6f82b12015-07-21 21:37:38634 for (const base::StringPiece& curr_log : base::SplitStringPiece(
635 switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
636 std::vector<std::string> log_metadata = base::SplitString(
637 curr_log, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
eranmd2f0b872015-05-05 16:57:03638 CHECK_GE(log_metadata.size(), 3u)
639 << "CT log metadata missing: Switch format is "
640 << "'description:base64_key:url_without_schema'.";
641 std::string log_description(log_metadata[0]);
642 std::string log_url(std::string("https://") + log_metadata[2]);
[email protected]344bc952014-01-29 14:04:59643 std::string ct_public_key_data;
eranmd2f0b872015-05-05 16:57:03644 CHECK(base::Base64Decode(log_metadata[1], &ct_public_key_data))
[email protected]344bc952014-01-29 14:04:59645 << "Unable to decode CT public key.";
eranm03d454c2015-07-02 09:12:03646 scoped_refptr<net::CTLogVerifier> external_log_verifier(
eranmd2f0b872015-05-05 16:57:03647 net::CTLogVerifier::Create(ct_public_key_data, log_description,
648 log_url));
[email protected]344bc952014-01-29 14:04:59649 CHECK(external_log_verifier) << "Unable to parse CT public key.";
650 VLOG(1) << "Adding log with description " << log_description;
eranm03d454c2015-07-02 09:12:03651 ct_logs.push_back(external_log_verifier);
[email protected]344bc952014-01-29 14:04:59652 }
[email protected]284303b62013-11-28 15:11:54653 }
davidbeneb5f8ef32014-09-04 14:14:32654
erikchendc7ecc412015-03-12 02:46:36655 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
656 // is fixed.
eranm03d454c2015-07-02 09:12:03657 tracked_objects::ScopedTracker tracking_profile9(
658 FROM_HERE_WITH_EXPLICIT_FUNCTION(
659 "466432 IOThread::InitAsync::CreateLogVerifiers::End"));
660 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
661 // is fixed.
662 tracked_objects::ScopedTracker tracking_profile7(
663 FROM_HERE_WITH_EXPLICIT_FUNCTION(
664 "466432 IOThread::InitAsync::CreateMultiLogVerifier"));
665 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
666 globals_->cert_transparency_verifier.reset(ct_verifier);
667 // Add built-in logs
668 ct_verifier->AddLogs(ct_logs);
669
670 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
671 // is fixed.
erikchendc7ecc412015-03-12 02:46:36672 tracked_objects::ScopedTracker tracking_profile10(
673 FROM_HERE_WITH_EXPLICIT_FUNCTION(
674 "466432 IOThread::InitAsync::CertPolicyEnforcer"));
eranm9ca6c9a2015-05-06 19:10:00675 net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer;
eranm6571b2b2014-12-03 15:53:23676 globals_->cert_policy_enforcer.reset(policy_enforcer);
677
[email protected]4d45a6de2011-05-13 05:20:18678 globals_->ssl_config_service = GetSSLConfigService();
[email protected]f4bfa7672014-08-08 09:50:46679
[email protected]65d34382010-07-01 18:12:26680 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
[email protected]73c45322010-10-01 23:57:54681 globals_->host_resolver.get()));
[email protected]30d4c022013-07-18 22:58:16682 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
[email protected]2fb629202010-12-23 23:52:57683 // For the ProxyScriptFetcher, we use a direct ProxyService.
rdsmith82957ad2015-09-16 19:42:03684 globals_->proxy_script_fetcher_proxy_service =
685 net::ProxyService::CreateDirectWithNetLog(net_log_);
[email protected]273e37d2011-08-11 01:49:12686 // In-memory cookie store.
erikchendc7ecc412015-03-12 02:46:36687 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
688 // is fixed.
689 tracked_objects::ScopedTracker tracking_profile11(
690 FROM_HERE_WITH_EXPLICIT_FUNCTION(
691 "466432 IOThread::InitAsync::CreateCookieStore::Start"));
[email protected]9a6c2aa2014-01-11 22:39:39692 globals_->system_cookie_store =
693 content::CreateCookieStore(content::CookieStoreConfig());
erikchendc7ecc412015-03-12 02:46:36694 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
695 // is fixed.
696 tracked_objects::ScopedTracker tracking_profile12(
697 FROM_HERE_WITH_EXPLICIT_FUNCTION(
698 "466432 IOThread::InitAsync::CreateCookieStore::End"));
[email protected]6b8a3c742014-07-25 00:25:35699 // In-memory channel ID store.
700 globals_->system_channel_id_service.reset(
701 new net::ChannelIDService(
702 new net::DefaultChannelIDStore(NULL),
[email protected]5bab49ec2012-05-04 21:13:19703 base::WorkerPool::GetTaskRunner(true)));
erikchenb0357632015-04-22 00:36:50704 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
705 // is fixed.
706 tracked_objects::ScopedTracker tracking_profile12_1(
707 FROM_HERE_WITH_EXPLICIT_FUNCTION(
708 "466432 IOThread::InitAsync::CreateDnsProbeService"));
[email protected]4588b3d2012-11-14 00:37:38709 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
erikchenb0357632015-04-22 00:36:50710 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
711 // is fixed.
712 tracked_objects::ScopedTracker tracking_profile12_2(
713 FROM_HERE_WITH_EXPLICIT_FUNCTION(
714 "466432 IOThread::InitAsync::CreateHostMappingRules"));
[email protected]c2dad292012-09-07 21:27:35715 globals_->host_mapping_rules.reset(new net::HostMappingRules());
erikchenb0357632015-04-22 00:36:50716 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
717 // is fixed.
718 tracked_objects::ScopedTracker tracking_profile12_3(
719 FROM_HERE_WITH_EXPLICIT_FUNCTION(
720 "466432 IOThread::InitAsync::CreateHTTPUserAgentSettings"));
[email protected]ee4c30d2012-11-07 15:08:43721 globals_->http_user_agent_settings.reset(
[email protected]aa051272014-03-10 05:56:56722 new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
erikchenb0357632015-04-22 00:36:50723 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
724 // is fixed.
725 tracked_objects::ScopedTracker tracking_profile12_4(
726 FROM_HERE_WITH_EXPLICIT_FUNCTION(
727 "466432 IOThread::InitAsync::CommandLineConfiguration"));
[email protected]c2dad292012-09-07 21:27:35728 if (command_line.HasSwitch(switches::kHostRules)) {
[email protected]a5e73b82013-07-17 08:58:39729 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35730 globals_->host_mapping_rules->SetRulesFromString(
731 command_line.GetSwitchValueASCII(switches::kHostRules));
[email protected]a5e73b82013-07-17 08:58:39732 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35733 }
734 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
735 globals_->ignore_certificate_errors = true;
[email protected]c2dad292012-09-07 21:27:35736 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
[email protected]f9cf5572012-12-04 15:52:09737 globals_->testing_fixed_http_port =
738 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
[email protected]c2dad292012-09-07 21:27:35739 }
740 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
[email protected]f9cf5572012-12-04 15:52:09741 globals_->testing_fixed_https_port =
742 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
[email protected]c2dad292012-09-07 21:27:35743 }
erikchenb0357632015-04-22 00:36:50744 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
745 // is fixed.
746 tracked_objects::ScopedTracker tracking_profile12_5(
747 FROM_HERE_WITH_EXPLICIT_FUNCTION(
748 "466432 IOThread::InitAsync::QuicConfiguration"));
[email protected]256fe9b2013-11-27 01:58:02749 ConfigureQuic(command_line);
[email protected]c54c6962013-02-01 04:53:19750 if (command_line.HasSwitch(
751 switches::kEnableUserAlternateProtocolPorts)) {
752 globals_->enable_user_alternate_protocol_ports = true;
753 }
erikchendc7ecc412015-03-12 02:46:36754 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
755 // is fixed.
756 tracked_objects::ScopedTracker tracking_profile13(
757 FROM_HERE_WITH_EXPLICIT_FUNCTION(
758 "466432 IOThread::InitAsync::InitializeNetworkOptions"));
[email protected]f9cf5572012-12-04 15:52:09759 InitializeNetworkOptions(command_line);
760
wjmacleanea309f72015-08-25 20:56:59761 TRACE_EVENT_BEGIN0("startup",
762 "IOThread::Init:ProxyScriptFetcherRequestContext");
[email protected]ef2bf422012-05-11 03:27:09763 globals_->proxy_script_fetcher_context.reset(
764 ConstructProxyScriptFetcherContext(globals_, net_log_));
wjmacleanea309f72015-08-25 20:56:59765 TRACE_EVENT_END0("startup",
766 "IOThread::Init:ProxyScriptFetcherRequestContext");
[email protected]4a109492011-09-24 21:00:12767
sdefresne9fb67692015-08-03 18:48:22768 const version_info::Channel channel = chrome::GetChannel();
sdefresne6e883e42015-07-30 08:05:54769 if (channel == version_info::Channel::UNKNOWN ||
770 channel == version_info::Channel::CANARY ||
771 channel == version_info::Channel::DEV) {
xunjieliaab07db2015-07-28 16:46:23772 globals_->url_request_backoff_manager.reset(
773 new net::URLRequestBackoffManager());
774 }
775
[email protected]11f5e3a2012-09-27 00:30:13776#if defined(OS_MACOSX) && !defined(OS_IOS)
777 // Start observing Keychain events. This needs to be done on the UI thread,
778 // as Keychain services requires a CFRunLoop.
779 BrowserThread::PostTask(BrowserThread::UI,
780 FROM_HERE,
781 base::Bind(&ObserveKeychainEvents));
782#endif
783
[email protected]2e5b60a22011-11-28 15:56:41784 // InitSystemRequestContext turns right around and posts a task back
785 // to the IO thread, so we can't let it run until we know the IO
786 // thread has started.
787 //
788 // Note that since we are at BrowserThread::Init time, the UI thread
789 // is blocked waiting for the thread to start. Therefore, posting
790 // this task to the main thread's message loop here is guaranteed to
791 // get it onto the message loop while the IOThread object still
792 // exists. However, the message might not be processed on the UI
793 // thread until after IOThread is gone, so use a weak pointer.
794 BrowserThread::PostTask(BrowserThread::UI,
795 FROM_HERE,
796 base::Bind(&IOThread::InitSystemRequestContext,
797 weak_factory_.GetWeakPtr()));
[email protected]0ac83682010-01-22 17:46:27798}
799
[email protected]2a92cd92010-04-27 00:01:41800void IOThread::CleanUp() {
[email protected]075c0322012-02-14 00:56:44801 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
802
davidben71f35ff2015-04-17 20:54:48803#if defined(USE_NSS_CERTS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09804 net::ShutdownNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29805#endif
[email protected]59a3b362010-10-21 21:52:41806
[email protected]db0e86dd2011-03-16 14:47:21807 system_url_request_context_getter_ = NULL;
808
[email protected]af669932012-01-17 19:26:58809 // Release objects that the net::URLRequestContext could have been pointing
810 // to.
[email protected]0ee7a3b2010-11-09 06:13:40811
[email protected]7592b41f2014-04-01 01:44:43812 // Shutdown the HistogramWatcher on the IO thread.
813 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
814
[email protected]0ee7a3b2010-11-09 06:13:40815 // This must be reset before the ChromeNetLog is destroyed.
816 network_change_observer_.reset();
817
[email protected]db0e86dd2011-03-16 14:47:21818 system_proxy_config_service_.reset();
819
[email protected]d13c3272010-02-04 00:24:51820 delete globals_;
821 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27822
[email protected]db0e86dd2011-03-16 14:47:21823 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27824}
825
avi556c05022014-12-22 23:31:43826void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) {
[email protected]aedf781f2013-07-15 21:38:15827 // Only handle use-spdy command line flags if "spdy.disabled" preference is
828 // not disabled via policy.
[email protected]aedfccd9b2013-10-02 03:24:46829 if (is_spdy_disabled_by_policy_) {
830 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName);
831 if (trial)
832 trial->Disable();
833 } else {
bncbc0b05b2015-03-25 19:50:58834 std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
835 VariationParameters params;
836 if (!variations::GetVariationParams(kSpdyFieldTrialName, &params)) {
837 params.clear();
[email protected]aedf781f2013-07-15 21:38:15838 }
bncbc0b05b2015-03-25 19:50:58839 ConfigureSpdyGlobals(command_line, group, params, globals_);
[email protected]77305422012-11-29 16:51:39840 }
[email protected]717e4e22013-04-10 20:52:23841
jrif9b4bec2014-09-15 15:46:54842 ConfigureTCPFastOpen(command_line);
843
[email protected]717e4e22013-04-10 20:52:23844 // TODO(rch): Make the client socket factory a per-network session
845 // instance, constructed from a NetworkSession::Params, to allow us
846 // to move this option to IOThread::Globals &
847 // HttpNetworkSession::Params.
jrif9b4bec2014-09-15 15:46:54848}
jridcb4ae922014-09-12 23:52:39849
avi556c05022014-12-22 23:31:43850void IOThread::ConfigureTCPFastOpen(const base::CommandLine& command_line) {
jrif9b4bec2014-09-15 15:46:54851 const std::string trial_group =
852 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName);
853 if (trial_group == kTCPFastOpenHttpsEnabledGroupName)
854 globals_->enable_tcp_fast_open_for_ssl.set(true);
jridcb4ae922014-09-12 23:52:39855 bool always_enable_if_supported =
jrif9b4bec2014-09-15 15:46:54856 command_line.HasSwitch(switches::kEnableTcpFastOpen);
jridcb4ae922014-09-12 23:52:39857 // Check for OS support of TCP FastOpen, and turn it on for all connections
858 // if indicated by user.
859 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_if_supported);
[email protected]77305422012-11-29 16:51:39860}
861
bncbc0b05b2015-03-25 19:50:58862void IOThread::ConfigureSpdyGlobals(
863 const base::CommandLine& command_line,
864 base::StringPiece spdy_trial_group,
865 const VariationParameters& spdy_trial_params,
866 IOThread::Globals* globals) {
867 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
868 globals->trusted_spdy_proxy.set(
869 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy));
870 }
871 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
872 net::URLFetcher::SetIgnoreCertificateRequests(true);
873
874 if (command_line.HasSwitch(switches::kUseSpdy)) {
875 std::string spdy_mode =
876 command_line.GetSwitchValueASCII(switches::kUseSpdy);
877 ConfigureSpdyGlobalsFromUseSpdyArgument(spdy_mode, globals);
878 return;
879 }
880
881 globals->next_protos.clear();
882 globals->next_protos.push_back(net::kProtoHTTP11);
883 bool enable_quic = false;
884 globals->enable_quic.CopyToIfSet(&enable_quic);
885 if (enable_quic) {
886 globals->next_protos.push_back(net::kProtoQUIC1SPDY3);
887 }
888
bncbc0b05b2015-03-25 19:50:58889 // No SPDY command-line flags have been specified. Examine trial groups.
bnce3553d92014-10-30 22:29:45890 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) {
[email protected]44a101422014-07-02 22:12:57891 net::HttpStreamFactory::set_spdy_enabled(false);
bncbc0b05b2015-03-25 19:50:58892 return;
[email protected]44a101422014-07-02 22:12:57893 }
bncbc0b05b2015-03-25 19:50:58894 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy31GroupNamePrefix)) {
895 globals->next_protos.push_back(net::kProtoSPDY31);
bncbc0b05b2015-03-25 19:50:58896 return;
897 }
898 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy4GroupNamePrefix)) {
899 globals->next_protos.push_back(net::kProtoSPDY31);
bnc06d22432015-06-29 12:39:43900 globals->next_protos.push_back(net::kProtoHTTP2);
bncbc0b05b2015-03-25 19:50:58901 return;
902 }
903 if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) {
904 bool spdy_enabled = false;
brettwbc17d2c82015-06-09 22:39:08905 if (base::LowerCaseEqualsASCII(
bncbc0b05b2015-03-25 19:50:58906 GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) {
907 globals->next_protos.push_back(net::kProtoSPDY31);
908 spdy_enabled = true;
[email protected]443a30ed2012-11-30 02:56:46909 }
brettwbc17d2c82015-06-09 22:39:08910 if (base::LowerCaseEqualsASCII(
bncbc0b05b2015-03-25 19:50:58911 GetVariationParam(spdy_trial_params, "enable_http2"), "true")) {
bnc06d22432015-06-29 12:39:43912 globals->next_protos.push_back(net::kProtoHTTP2);
bncbc0b05b2015-03-25 19:50:58913 spdy_enabled = true;
914 }
915 // TODO(bnc): HttpStreamFactory::spdy_enabled_ is redundant with
916 // globals->next_protos, can it be eliminated?
917 net::HttpStreamFactory::set_spdy_enabled(spdy_enabled);
bncbc0b05b2015-03-25 19:50:58918 return;
[email protected]443a30ed2012-11-30 02:56:46919 }
bncbc0b05b2015-03-25 19:50:58920
921 // By default, enable HTTP/2.
922 globals->next_protos.push_back(net::kProtoSPDY31);
bnc06d22432015-06-29 12:39:43923 globals->next_protos.push_back(net::kProtoHTTP2);
[email protected]443a30ed2012-11-30 02:56:46924}
925
[email protected]b1de2c72013-02-06 02:45:47926void IOThread::RegisterPrefs(PrefRegistrySimple* registry) {
927 registry->RegisterStringPref(prefs::kAuthSchemes,
bengr70266e22015-06-12 19:38:17928 "basic,digest,ntlm,negotiate");
[email protected]68a9b0d82013-03-08 07:05:07929 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
[email protected]b1de2c72013-02-06 02:45:47930 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
[email protected]007b3f82013-04-09 08:46:45931 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
932 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
933 std::string());
934 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
aberentec894a52015-07-09 14:45:53935 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType,
936 std::string());
[email protected]a0a06932014-04-14 21:23:42937 registry->RegisterStringPref(
938 data_reduction_proxy::prefs::kDataReductionProxy, std::string());
[email protected]b1de2c72013-02-06 02:45:47939 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
[email protected]1575e3d2014-05-03 22:21:44940 data_reduction_proxy::RegisterPrefs(registry);
[email protected]68a9b0d82013-03-08 07:05:07941 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
[email protected]67378142013-12-17 21:57:17942 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
[email protected]bcefe0f2010-11-10 16:19:10943}
944
[email protected]65d34382010-07-01 18:12:26945net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
946 net::HostResolver* resolver) {
[email protected]9030a632010-11-19 20:12:09947 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL;
948 if (!auth_server_whitelist_.empty()) {
949 auth_filter_default_credentials =
950 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
951 }
952 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
953 if (!auth_delegate_whitelist_.empty()) {
954 auth_filter_delegate =
955 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_);
956 }
[email protected]b4955e7d2010-04-16 20:22:30957 globals_->url_security_manager.reset(
[email protected]d201b200e2010-08-27 17:35:02958 net::URLSecurityManager::Create(auth_filter_default_credentials,
959 auth_filter_delegate));
brettw83dc1612015-08-12 07:31:18960 std::vector<std::string> supported_schemes = base::SplitString(
961 auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
[email protected]b7304162010-08-23 17:42:29962
[email protected]ec44ee02012-09-28 21:31:51963 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory(
964 net::HttpAuthHandlerRegistryFactory::Create(
aberentec894a52015-07-09 14:45:53965 supported_schemes, globals_->url_security_manager.get(), resolver,
966 gssapi_library_name_, auth_android_negotiate_account_type_,
967 negotiate_disable_cname_lookup_, negotiate_enable_port_));
[email protected]ec44ee02012-09-28 21:31:51968 return registry_factory.release();
[email protected]eb3cac72010-02-26 21:07:45969}
970
[email protected]d6f37fc2011-02-13 23:58:41971void IOThread::ClearHostCache() {
thestig00844cea2015-09-08 21:44:52972 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d6f37fc2011-02-13 23:58:41973
[email protected]489d1a82011-10-12 03:09:11974 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
975 if (host_cache)
976 host_cache->clear();
[email protected]0ac83682010-01-22 17:46:27977}
[email protected]db0e86dd2011-03-16 14:47:21978
[email protected]f9cf5572012-12-04 15:52:09979void IOThread::InitializeNetworkSessionParams(
980 net::HttpNetworkSession::Params* params) {
[email protected]488a0e252014-06-25 04:37:44981 InitializeNetworkSessionParamsFromGlobals(*globals_, params);
982}
[email protected]f9cf5572012-12-04 15:52:09983
[email protected]488a0e252014-06-25 04:37:44984void IOThread::InitializeNetworkSessionParamsFromGlobals(
985 const IOThread::Globals& globals,
986 net::HttpNetworkSession::Params* params) {
wjmacleanea309f72015-08-25 20:56:59987 // The next two properties of the params don't seem to be
988 // elements of URLRequestContext, so they must be set here.
eranm6571b2b2014-12-03 15:53:23989 params->cert_policy_enforcer = globals.cert_policy_enforcer.get();
[email protected]488a0e252014-06-25 04:37:44990 params->host_mapping_rules = globals.host_mapping_rules.get();
wjmacleanea309f72015-08-25 20:56:59991
[email protected]488a0e252014-06-25 04:37:44992 params->ignore_certificate_errors = globals.ignore_certificate_errors;
993 params->testing_fixed_http_port = globals.testing_fixed_http_port;
994 params->testing_fixed_https_port = globals.testing_fixed_https_port;
jrif9b4bec2014-09-15 15:46:54995 globals.enable_tcp_fast_open_for_ssl.CopyToIfSet(
996 &params->enable_tcp_fast_open_for_ssl);
[email protected]488a0e252014-06-25 04:37:44997
998 globals.initial_max_spdy_concurrent_streams.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:09999 &params->spdy_initial_max_concurrent_streams);
[email protected]488a0e252014-06-25 04:37:441000 globals.enable_spdy_compression.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091001 &params->enable_spdy_compression);
[email protected]488a0e252014-06-25 04:37:441002 globals.enable_spdy_ping_based_connection_checking.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091003 &params->enable_spdy_ping_based_connection_checking);
[email protected]488a0e252014-06-25 04:37:441004 globals.spdy_default_protocol.CopyToIfSet(
[email protected]f9cf5572012-12-04 15:52:091005 &params->spdy_default_protocol);
[email protected]488a0e252014-06-25 04:37:441006 params->next_protos = globals.next_protos;
1007 globals.trusted_spdy_proxy.CopyToIfSet(&params->trusted_spdy_proxy);
[email protected]488a0e252014-06-25 04:37:441008 params->forced_spdy_exclusions = globals.forced_spdy_exclusions;
bnc55ff9da2015-08-19 18:42:351009 globals.use_alternative_services.CopyToIfSet(
1010 &params->use_alternative_services);
bnc62891a52015-04-27 14:14:121011 globals.alternative_service_probability_threshold.CopyToIfSet(
1012 &params->alternative_service_probability_threshold);
[email protected]d7599122014-05-24 03:37:231013
[email protected]488a0e252014-06-25 04:37:441014 globals.enable_quic.CopyToIfSet(&params->enable_quic);
rchff012122015-07-27 20:01:401015 globals.enable_insecure_quic.CopyToIfSet(&params->enable_insecure_quic);
tbansaled0aecc2015-02-20 03:44:181016 globals.enable_quic_for_proxies.CopyToIfSet(&params->enable_quic_for_proxies);
jri2b966f22014-09-02 22:25:361017 globals.quic_always_require_handshake_confirmation.CopyToIfSet(
1018 &params->quic_always_require_handshake_confirmation);
jri584002d12014-09-09 00:51:281019 globals.quic_disable_connection_pooling.CopyToIfSet(
1020 &params->quic_disable_connection_pooling);
rtenneti2912825c2015-01-06 01:19:461021 globals.quic_load_server_info_timeout_srtt_multiplier.CopyToIfSet(
1022 &params->quic_load_server_info_timeout_srtt_multiplier);
rtenneti4f809972015-02-11 19:38:341023 globals.quic_enable_connection_racing.CopyToIfSet(
1024 &params->quic_enable_connection_racing);
qyearsley3257b7de2015-02-28 06:59:031025 globals.quic_enable_non_blocking_io.CopyToIfSet(
1026 &params->quic_enable_non_blocking_io);
rch9976b0c2015-06-10 21:27:231027 globals.quic_prefer_aes.CopyToIfSet(&params->quic_prefer_aes);
rtenneti34dffe752015-02-24 23:27:321028 globals.quic_disable_disk_cache.CopyToIfSet(
1029 &params->quic_disable_disk_cache);
rtenneti374e56882015-03-28 13:49:541030 globals.quic_max_number_of_lossy_connections.CopyToIfSet(
1031 &params->quic_max_number_of_lossy_connections);
1032 globals.quic_packet_loss_threshold.CopyToIfSet(
1033 &params->quic_packet_loss_threshold);
rchc7433572015-02-27 18:16:511034 globals.quic_socket_receive_buffer_size.CopyToIfSet(
1035 &params->quic_socket_receive_buffer_size);
rtenneti8332ba52015-09-17 19:33:411036 globals.quic_delay_tcp_race.CopyToIfSet(&params->quic_delay_tcp_race);
[email protected]488a0e252014-06-25 04:37:441037 globals.enable_quic_port_selection.CopyToIfSet(
[email protected]376d38a2014-01-22 03:47:351038 &params->enable_quic_port_selection);
[email protected]488a0e252014-06-25 04:37:441039 globals.quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length);
1040 globals.quic_user_agent_id.CopyToIfSet(&params->quic_user_agent_id);
1041 globals.quic_supported_versions.CopyToIfSet(
[email protected]6a31ca52013-12-23 00:44:341042 &params->quic_supported_versions);
[email protected]488a0e252014-06-25 04:37:441043 params->quic_connection_options = globals.quic_connection_options;
1044
1045 globals.origin_to_force_quic_on.CopyToIfSet(
[email protected]49e85332013-06-04 04:18:031046 &params->origin_to_force_quic_on);
[email protected]c54c6962013-02-01 04:53:191047 params->enable_user_alternate_protocol_ports =
[email protected]488a0e252014-06-25 04:37:441048 globals.enable_user_alternate_protocol_ports;
[email protected]f9cf5572012-12-04 15:52:091049}
1050
[email protected]d827e112014-03-31 17:45:051051base::TimeTicks IOThread::creation_time() const {
1052 return creation_time_;
1053}
1054
[email protected]4d45a6de2011-05-13 05:20:181055net::SSLConfigService* IOThread::GetSSLConfigService() {
1056 return ssl_config_service_manager_->Get();
1057}
1058
[email protected]b09f76d62011-12-07 01:51:061059void IOThread::ChangedToOnTheRecordOnIOThread() {
thestig00844cea2015-09-08 21:44:521060 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]b09f76d62011-12-07 01:51:061061
1062 // Clear the host cache to avoid showing entries from the OTR session
1063 // in about:net-internals.
1064 ClearHostCache();
[email protected]b09f76d62011-12-07 01:51:061065}
1066
[email protected]db0e86dd2011-03-16 14:47:211067void IOThread::InitSystemRequestContext() {
[email protected]5173de8b2013-06-02 21:16:021068 if (system_url_request_context_getter_.get())
[email protected]addb3242011-06-13 21:39:161069 return;
[email protected]63e26822011-07-16 19:07:351070 // If we're in unit_tests, IOThread may not be run.
[email protected]dd483702011-12-02 14:47:421071 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
[email protected]63e26822011-07-16 19:07:351072 return;
[email protected]53c5b0f2013-07-22 10:54:111073 system_proxy_config_service_.reset(
1074 ProxyServiceFactory::CreateProxyConfigService(
1075 pref_proxy_config_tracker_.get()));
[email protected]addb3242011-06-13 21:39:161076 system_url_request_context_getter_ =
1077 new SystemURLRequestContextGetter(this);
[email protected]2e5b60a22011-11-28 15:56:411078 // Safe to post an unretained this pointer, since IOThread is
1079 // guaranteed to outlive the IO BrowserThread.
[email protected]dd483702011-12-02 14:47:421080 BrowserThread::PostTask(
1081 BrowserThread::IO,
1082 FROM_HERE,
1083 base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
1084 base::Unretained(this)));
[email protected]addb3242011-06-13 21:39:161085}
1086
1087void IOThread::InitSystemRequestContextOnIOThread() {
thestig00844cea2015-09-08 21:44:521088 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]6104ea5d2011-04-27 21:37:121089 DCHECK(!globals_->system_proxy_service.get());
[email protected]db0e86dd2011-03-16 14:47:211090 DCHECK(system_proxy_config_service_.get());
1091
avi556c05022014-12-22 23:31:431092 const base::CommandLine& command_line =
1093 *base::CommandLine::ForCurrentProcess();
rdsmith82957ad2015-09-16 19:42:031094 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
1095 net_log_, globals_->proxy_script_fetcher_context.get(),
1096 globals_->system_network_delegate.get(),
1097 system_proxy_config_service_.release(), command_line,
1098 quick_check_enabled_.GetValue());
[email protected]c2dad292012-09-07 21:27:351099
[email protected]ef2bf422012-05-11 03:27:091100 globals_->system_request_context.reset(
1101 ConstructSystemRequestContext(globals_, net_log_));
[email protected]db0e86dd2011-03-16 14:47:211102}
[email protected]fa4b6c32012-11-26 23:02:391103
1104void IOThread::UpdateDnsClientEnabled() {
1105 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
1106}
[email protected]903e63382013-06-01 00:40:581107
avi556c05022014-12-22 23:31:431108void IOThread::ConfigureQuic(const base::CommandLine& command_line) {
[email protected]903e63382013-06-01 00:40:581109 // Always fetch the field trial group to ensure it is reported correctly.
1110 // The command line flags will be associated with a group that is reported
1111 // so long as trial is actually queried.
[email protected]488a0e252014-06-25 04:37:441112 std::string group =
[email protected]903e63382013-06-01 00:40:581113 base::FieldTrialList::FindFullName(kQuicFieldTrialName);
[email protected]488a0e252014-06-25 04:37:441114 VariationParameters params;
[email protected]59b6f672014-07-26 18:35:471115 if (!variations::GetVariationParams(kQuicFieldTrialName, &params)) {
[email protected]488a0e252014-06-25 04:37:441116 params.clear();
1117 }
[email protected]903e63382013-06-01 00:40:581118
peletskyi5df83d42015-04-30 16:37:461119 ConfigureQuicGlobals(command_line, group, params, is_quic_allowed_by_policy_,
1120 globals_);
[email protected]488a0e252014-06-25 04:37:441121}
1122
[email protected]488a0e252014-06-25 04:37:441123void IOThread::ConfigureQuicGlobals(
1124 const base::CommandLine& command_line,
1125 base::StringPiece quic_trial_group,
1126 const VariationParameters& quic_trial_params,
peletskyi5df83d42015-04-30 16:37:461127 bool quic_allowed_by_policy,
[email protected]488a0e252014-06-25 04:37:441128 IOThread::Globals* globals) {
peletskyi5df83d42015-04-30 16:37:461129 bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group,
1130 quic_allowed_by_policy);
[email protected]488a0e252014-06-25 04:37:441131 globals->enable_quic.set(enable_quic);
peletskyi5df83d42015-04-30 16:37:461132 bool enable_quic_for_proxies = ShouldEnableQuicForProxies(
1133 command_line, quic_trial_group, quic_allowed_by_policy);
tbansaled0aecc2015-02-20 03:44:181134 globals->enable_quic_for_proxies.set(enable_quic_for_proxies);
bnc886e6d52015-09-15 15:33:301135 globals->use_alternative_services.set(
1136 ShouldQuicEnableAlternativeServices(command_line, quic_trial_params));
[email protected]256fe9b2013-11-27 01:58:021137 if (enable_quic) {
rchff012122015-07-27 20:01:401138 globals->enable_insecure_quic.set(
1139 ShouldEnableInsecureQuic(command_line, quic_trial_params));
jri2b966f22014-09-02 22:25:361140 globals->quic_always_require_handshake_confirmation.set(
1141 ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params));
jri584002d12014-09-09 00:51:281142 globals->quic_disable_connection_pooling.set(
1143 ShouldQuicDisableConnectionPooling(quic_trial_params));
rchc7433572015-02-27 18:16:511144 int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params);
1145 if (receive_buffer_size != 0) {
1146 globals->quic_socket_receive_buffer_size.set(receive_buffer_size);
1147 }
rtenneti8332ba52015-09-17 19:33:411148 globals->quic_delay_tcp_race.set(ShouldQuicDelayTcpRace(quic_trial_params));
rtenneti2912825c2015-01-06 01:19:461149 float load_server_info_timeout_srtt_multiplier =
1150 GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params);
1151 if (load_server_info_timeout_srtt_multiplier != 0) {
1152 globals->quic_load_server_info_timeout_srtt_multiplier.set(
1153 load_server_info_timeout_srtt_multiplier);
1154 }
rtenneti34dffe752015-02-24 23:27:321155 globals->quic_enable_connection_racing.set(
1156 ShouldQuicEnableConnectionRacing(quic_trial_params));
qyearsley3257b7de2015-02-28 06:59:031157 globals->quic_enable_non_blocking_io.set(
1158 ShouldQuicEnableNonBlockingIO(quic_trial_params));
rtenneti34dffe752015-02-24 23:27:321159 globals->quic_disable_disk_cache.set(
1160 ShouldQuicDisableDiskCache(quic_trial_params));
rch9976b0c2015-06-10 21:27:231161 globals->quic_prefer_aes.set(
1162 ShouldQuicPreferAes(quic_trial_params));
rtenneti374e56882015-03-28 13:49:541163 int max_number_of_lossy_connections = GetQuicMaxNumberOfLossyConnections(
1164 quic_trial_params);
1165 if (max_number_of_lossy_connections != 0) {
1166 globals->quic_max_number_of_lossy_connections.set(
1167 max_number_of_lossy_connections);
1168 }
1169 float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params);
1170 if (packet_loss_threshold != 0)
1171 globals->quic_packet_loss_threshold.set(packet_loss_threshold);
[email protected]488a0e252014-06-25 04:37:441172 globals->enable_quic_port_selection.set(
[email protected]376d38a2014-01-22 03:47:351173 ShouldEnableQuicPortSelection(command_line));
[email protected]488a0e252014-06-25 04:37:441174 globals->quic_connection_options =
1175 GetQuicConnectionOptions(command_line, quic_trial_params);
[email protected]256fe9b2013-11-27 01:58:021176 }
1177
1178 size_t max_packet_length = GetQuicMaxPacketLength(command_line,
[email protected]488a0e252014-06-25 04:37:441179 quic_trial_params);
[email protected]256fe9b2013-11-27 01:58:021180 if (max_packet_length != 0) {
[email protected]488a0e252014-06-25 04:37:441181 globals->quic_max_packet_length.set(max_packet_length);
[email protected]256fe9b2013-11-27 01:58:021182 }
1183
sdefresne9fb67692015-08-03 18:48:221184 std::string quic_user_agent_id = chrome::GetChannelString();
[email protected]adb9ded2014-07-25 08:31:441185 if (!quic_user_agent_id.empty())
1186 quic_user_agent_id.push_back(' ');
sdefresne9fb67692015-08-03 18:48:221187 quic_user_agent_id.append(
1188 version_info::GetProductNameAndVersionForUserAgent());
rtenneti4d126a72015-06-23 17:32:091189 quic_user_agent_id.push_back(' ');
1190 quic_user_agent_id.append(content::BuildOSCpuInfo());
[email protected]488a0e252014-06-25 04:37:441191 globals->quic_user_agent_id.set(quic_user_agent_id);
[email protected]0c4017ca2014-06-06 03:30:451192
[email protected]488a0e252014-06-25 04:37:441193 net::QuicVersion version = GetQuicVersion(command_line, quic_trial_params);
[email protected]6a31ca52013-12-23 00:44:341194 if (version != net::QUIC_VERSION_UNSUPPORTED) {
1195 net::QuicVersionVector supported_versions;
1196 supported_versions.push_back(version);
[email protected]488a0e252014-06-25 04:37:441197 globals->quic_supported_versions.set(supported_versions);
[email protected]6a31ca52013-12-23 00:44:341198 }
1199
bnc62891a52015-04-27 14:14:121200 double threshold = GetAlternativeProtocolProbabilityThreshold(
1201 command_line, quic_trial_params);
[email protected]287d9412014-07-08 23:01:001202 if (threshold >=0 && threshold <= 1) {
bnc62891a52015-04-27 14:14:121203 globals->alternative_service_probability_threshold.set(threshold);
1204 globals->http_server_properties->SetAlternativeServiceProbabilityThreshold(
[email protected]287d9412014-07-08 23:01:001205 threshold);
1206 }
1207
[email protected]256fe9b2013-11-27 01:58:021208 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
1209 net::HostPortPair quic_origin =
1210 net::HostPortPair::FromString(
1211 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
1212 if (!quic_origin.IsEmpty()) {
[email protected]488a0e252014-06-25 04:37:441213 globals->origin_to_force_quic_on.set(quic_origin);
[email protected]256fe9b2013-11-27 01:58:021214 }
1215 }
1216}
1217
avi556c05022014-12-22 23:31:431218bool IOThread::ShouldEnableQuic(const base::CommandLine& command_line,
peletskyi5df83d42015-04-30 16:37:461219 base::StringPiece quic_trial_group,
1220 bool quic_allowed_by_policy) {
1221 if (command_line.HasSwitch(switches::kDisableQuic) || !quic_allowed_by_policy)
[email protected]903e63382013-06-01 00:40:581222 return false;
1223
[email protected]a64b213e2013-07-24 21:41:001224 if (command_line.HasSwitch(switches::kEnableQuic))
[email protected]903e63382013-06-01 00:40:581225 return true;
1226
[email protected]256fe9b2013-11-27 01:58:021227 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) ||
1228 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
[email protected]a64b213e2013-07-24 21:41:001229}
1230
tbansaled0aecc2015-02-20 03:44:181231bool IOThread::ShouldEnableQuicForProxies(const base::CommandLine& command_line,
peletskyi5df83d42015-04-30 16:37:461232 base::StringPiece quic_trial_group,
1233 bool quic_allowed_by_policy) {
1234 return ShouldEnableQuic(
1235 command_line, quic_trial_group, quic_allowed_by_policy) ||
tbansaled0aecc2015-02-20 03:44:181236 ShouldEnableQuicForDataReductionProxy();
1237}
1238
tbansaled0aecc2015-02-20 03:44:181239bool IOThread::ShouldEnableQuicForDataReductionProxy() {
1240 const base::CommandLine& command_line =
1241 *base::CommandLine::ForCurrentProcess();
1242
1243 if (command_line.HasSwitch(switches::kDisableQuic))
1244 return false;
1245
jeremyim1c4e5b32015-06-18 19:10:481246 return data_reduction_proxy::params::IsIncludedInQuicFieldTrial();
tbansaled0aecc2015-02-20 03:44:181247}
1248
rchff012122015-07-27 20:01:401249bool IOThread::ShouldEnableInsecureQuic(
1250 const base::CommandLine& command_line,
rch405ed7a2015-05-12 01:10:161251 const VariationParameters& quic_trial_params) {
rchff012122015-07-27 20:01:401252 if (command_line.HasSwitch(switches::kEnableInsecureQuic))
1253 return true;
1254
brettwbc17d2c82015-06-09 22:39:081255 return base::LowerCaseEqualsASCII(
rchff012122015-07-27 20:01:401256 GetVariationParam(quic_trial_params, "enable_insecure_quic"),
rch405ed7a2015-05-12 01:10:161257 "true");
1258}
1259
[email protected]376d38a2014-01-22 03:47:351260bool IOThread::ShouldEnableQuicPortSelection(
avi556c05022014-12-22 23:31:431261 const base::CommandLine& command_line) {
[email protected]376d38a2014-01-22 03:47:351262 if (command_line.HasSwitch(switches::kDisableQuicPortSelection))
1263 return false;
1264
1265 if (command_line.HasSwitch(switches::kEnableQuicPortSelection))
1266 return true;
1267
[email protected]3273b3c2014-05-23 16:52:281268 return false; // Default to disabling port selection on all channels.
[email protected]376d38a2014-01-22 03:47:351269}
1270
[email protected]488a0e252014-06-25 04:37:441271net::QuicTagVector IOThread::GetQuicConnectionOptions(
avi556c05022014-12-22 23:31:431272 const base::CommandLine& command_line,
[email protected]488a0e252014-06-25 04:37:441273 const VariationParameters& quic_trial_params) {
1274 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) {
mefcb6537c2014-11-12 19:38:501275 return net::QuicUtils::ParseQuicConnectionOptions(
[email protected]488a0e252014-06-25 04:37:441276 command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions));
1277 }
1278
1279 VariationParameters::const_iterator it =
[email protected]8cc878112014-08-15 04:06:441280 quic_trial_params.find("connection_options");
1281 if (it == quic_trial_params.end()) {
rche9efff42015-01-12 17:58:191282 return net::QuicTagVector();
[email protected]8cc878112014-08-15 04:06:441283 }
[email protected]488a0e252014-06-25 04:37:441284
mefcb6537c2014-11-12 19:38:501285 return net::QuicUtils::ParseQuicConnectionOptions(it->second);
[email protected]488a0e252014-06-25 04:37:441286}
1287
bnc62891a52015-04-27 14:14:121288double IOThread::GetAlternativeProtocolProbabilityThreshold(
[email protected]287d9412014-07-08 23:01:001289 const base::CommandLine& command_line,
1290 const VariationParameters& quic_trial_params) {
1291 double value;
1292 if (command_line.HasSwitch(
bnc62891a52015-04-27 14:14:121293 switches::kAlternativeServiceProbabilityThreshold)) {
[email protected]287d9412014-07-08 23:01:001294 if (base::StringToDouble(
1295 command_line.GetSwitchValueASCII(
bnc62891a52015-04-27 14:14:121296 switches::kAlternativeServiceProbabilityThreshold),
[email protected]287d9412014-07-08 23:01:001297 &value)) {
1298 return value;
1299 }
1300 }
rch16642752014-09-18 00:29:161301 if (command_line.HasSwitch(switches::kEnableQuic)) {
1302 return 0;
1303 }
bnc62891a52015-04-27 14:14:121304 // TODO(bnc): Remove when new parameter name rolls out and server
1305 // configuration is changed.
[email protected]287d9412014-07-08 23:01:001306 if (base::StringToDouble(
1307 GetVariationParam(quic_trial_params,
1308 "alternate_protocol_probability_threshold"),
1309 &value)) {
1310 return value;
1311 }
bnc62891a52015-04-27 14:14:121312 if (base::StringToDouble(
1313 GetVariationParam(quic_trial_params,
1314 "alternative_service_probability_threshold"),
1315 &value)) {
1316 return value;
1317 }
[email protected]287d9412014-07-08 23:01:001318 return -1;
1319}
1320
jri2b966f22014-09-02 22:25:361321bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
1322 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081323 return base::LowerCaseEqualsASCII(
jri2b966f22014-09-02 22:25:361324 GetVariationParam(quic_trial_params,
1325 "always_require_handshake_confirmation"),
1326 "true");
1327}
1328
jri584002d12014-09-09 00:51:281329bool IOThread::ShouldQuicDisableConnectionPooling(
1330 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081331 return base::LowerCaseEqualsASCII(
jri584002d12014-09-09 00:51:281332 GetVariationParam(quic_trial_params, "disable_connection_pooling"),
1333 "true");
1334}
1335
rtenneti2912825c2015-01-06 01:19:461336float IOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier(
1337 const VariationParameters& quic_trial_params) {
1338 double value;
1339 if (base::StringToDouble(GetVariationParam(quic_trial_params,
1340 "load_server_info_time_to_srtt"),
1341 &value)) {
bnca580cbcf42015-08-17 17:21:191342 return static_cast<float>(value);
rtenneti2912825c2015-01-06 01:19:461343 }
1344 return 0.0f;
1345}
1346
rtenneti4f809972015-02-11 19:38:341347bool IOThread::ShouldQuicEnableConnectionRacing(
1348 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081349 return base::LowerCaseEqualsASCII(
rtenneti4f809972015-02-11 19:38:341350 GetVariationParam(quic_trial_params, "enable_connection_racing"),
1351 "true");
1352}
1353
qyearsley3257b7de2015-02-28 06:59:031354bool IOThread::ShouldQuicEnableNonBlockingIO(
1355 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081356 return base::LowerCaseEqualsASCII(
qyearsley3257b7de2015-02-28 06:59:031357 GetVariationParam(quic_trial_params, "enable_non_blocking_io"),
1358 "true");
1359}
1360
rtenneti34dffe752015-02-24 23:27:321361bool IOThread::ShouldQuicDisableDiskCache(
1362 const VariationParameters& quic_trial_params) {
brettwbc17d2c82015-06-09 22:39:081363 return base::LowerCaseEqualsASCII(
rtenneti34dffe752015-02-24 23:27:321364 GetVariationParam(quic_trial_params, "disable_disk_cache"), "true");
1365}
1366
rch9976b0c2015-06-10 21:27:231367bool IOThread::ShouldQuicPreferAes(
1368 const VariationParameters& quic_trial_params) {
1369 return base::LowerCaseEqualsASCII(
1370 GetVariationParam(quic_trial_params, "prefer_aes"), "true");
1371}
1372
bncd00793802015-08-27 19:18:171373bool IOThread::ShouldQuicEnableAlternativeServices(
bnc886e6d52015-09-15 15:33:301374 const base::CommandLine& command_line,
bncd00793802015-08-27 19:18:171375 const VariationParameters& quic_trial_params) {
bnc886e6d52015-09-15 15:33:301376 return command_line.HasSwitch(switches::kEnableAlternativeServices) ||
1377 base::LowerCaseEqualsASCII(
1378 GetVariationParam(quic_trial_params, "use_alternative_services"),
1379 "true");
bncd00793802015-08-27 19:18:171380}
1381
rtenneti374e56882015-03-28 13:49:541382int IOThread::GetQuicMaxNumberOfLossyConnections(
1383 const VariationParameters& quic_trial_params) {
1384 int value;
1385 if (base::StringToInt(GetVariationParam(quic_trial_params,
1386 "max_number_of_lossy_connections"),
1387 &value)) {
1388 return value;
1389 }
1390 return 0;
1391}
1392
rtenneti374e56882015-03-28 13:49:541393float IOThread::GetQuicPacketLossThreshold(
1394 const VariationParameters& quic_trial_params) {
1395 double value;
1396 if (base::StringToDouble(GetVariationParam(quic_trial_params,
1397 "packet_loss_threshold"),
1398 &value)) {
bnca580cbcf42015-08-17 17:21:191399 return static_cast<float>(value);
rtenneti374e56882015-03-28 13:49:541400 }
1401 return 0.0f;
1402}
1403
rchc7433572015-02-27 18:16:511404int IOThread::GetQuicSocketReceiveBufferSize(
1405 const VariationParameters& quic_trial_params) {
1406 int value;
1407 if (base::StringToInt(GetVariationParam(quic_trial_params,
1408 "receive_buffer_size"),
1409 &value)) {
1410 return value;
1411 }
1412 return 0;
1413}
1414
rtenneti8332ba52015-09-17 19:33:411415bool IOThread::ShouldQuicDelayTcpRace(
1416 const VariationParameters& quic_trial_params) {
1417 return base::LowerCaseEqualsASCII(
1418 GetVariationParam(quic_trial_params, "delay_tcp_race"), "true");
1419}
1420
[email protected]488a0e252014-06-25 04:37:441421size_t IOThread::GetQuicMaxPacketLength(
avi556c05022014-12-22 23:31:431422 const base::CommandLine& command_line,
[email protected]488a0e252014-06-25 04:37:441423 const VariationParameters& quic_trial_params) {
[email protected]256fe9b2013-11-27 01:58:021424 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
1425 unsigned value;
1426 if (!base::StringToUint(
1427 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
1428 &value)) {
1429 return 0;
1430 }
1431 return value;
1432 }
1433
[email protected]488a0e252014-06-25 04:37:441434 unsigned value;
1435 if (base::StringToUint(GetVariationParam(quic_trial_params,
1436 "max_packet_length"),
1437 &value)) {
1438 return value;
1439 }
rchcc4b8cf2014-12-05 20:24:381440 return 0;
[email protected]903e63382013-06-01 00:40:581441}
[email protected]6a31ca52013-12-23 00:44:341442
[email protected]488a0e252014-06-25 04:37:441443net::QuicVersion IOThread::GetQuicVersion(
avi556c05022014-12-22 23:31:431444 const base::CommandLine& command_line,
[email protected]488a0e252014-06-25 04:37:441445 const VariationParameters& quic_trial_params) {
1446 if (command_line.HasSwitch(switches::kQuicVersion)) {
1447 return ParseQuicVersion(
1448 command_line.GetSwitchValueASCII(switches::kQuicVersion));
[email protected]6a31ca52013-12-23 00:44:341449 }
[email protected]488a0e252014-06-25 04:37:441450
1451 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version"));
1452}
1453
1454net::QuicVersion IOThread::ParseQuicVersion(const std::string& quic_version) {
[email protected]6a31ca52013-12-23 00:44:341455 net::QuicVersionVector supported_versions = net::QuicSupportedVersions();
[email protected]6a31ca52013-12-23 00:44:341456 for (size_t i = 0; i < supported_versions.size(); ++i) {
1457 net::QuicVersion version = supported_versions[i];
[email protected]488a0e252014-06-25 04:37:441458 if (net::QuicVersionToString(version) == quic_version) {
[email protected]6a31ca52013-12-23 00:44:341459 return version;
1460 }
1461 }
[email protected]488a0e252014-06-25 04:37:441462
[email protected]6a31ca52013-12-23 00:44:341463 return net::QUIC_VERSION_UNSUPPORTED;
1464}
wjmacleanea309f72015-08-25 20:56:591465
1466net::URLRequestContext* IOThread::ConstructSystemRequestContext(
1467 IOThread::Globals* globals,
1468 net::NetLog* net_log) {
1469 net::URLRequestContext* context = new SystemURLRequestContext;
1470 context->set_net_log(net_log);
1471 context->set_host_resolver(globals->host_resolver.get());
1472 context->set_cert_verifier(globals->cert_verifier.get());
1473 context->set_transport_security_state(
1474 globals->transport_security_state.get());
1475 context->set_cert_transparency_verifier(
1476 globals->cert_transparency_verifier.get());
1477 context->set_ssl_config_service(globals->ssl_config_service.get());
1478 context->set_http_auth_handler_factory(
1479 globals->http_auth_handler_factory.get());
1480 context->set_proxy_service(globals->system_proxy_service.get());
1481
1482 globals->system_url_request_job_factory.reset(
1483 new net::URLRequestJobFactoryImpl());
1484 context->set_job_factory(globals->system_url_request_job_factory.get());
1485
1486 context->set_cookie_store(globals->system_cookie_store.get());
1487 context->set_channel_id_service(
1488 globals->system_channel_id_service.get());
1489 context->set_network_delegate(globals->system_network_delegate.get());
1490 context->set_http_user_agent_settings(
1491 globals->http_user_agent_settings.get());
1492 context->set_network_quality_estimator(
1493 globals->network_quality_estimator.get());
1494 context->set_backoff_manager(globals->url_request_backoff_manager.get());
1495
1496 context->set_http_server_properties(
1497 globals->http_server_properties->GetWeakPtr());
1498
1499 net::HttpNetworkSession::Params system_params;
1500 InitializeNetworkSessionParamsFromGlobals(*globals, &system_params);
1501 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1502 context, &system_params);
1503
1504 globals->system_http_transaction_factory.reset(
mmenke6b3af6e2015-09-12 02:06:061505 new net::HttpNetworkLayer(new net::HttpNetworkSession(system_params)));
wjmacleanea309f72015-08-25 20:56:591506 context->set_http_transaction_factory(
1507 globals->system_http_transaction_factory.get());
1508
1509 return context;
1510}
1511
1512net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext(
1513 IOThread::Globals* globals,
1514 net::NetLog* net_log) {
1515 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
1516 // is fixed.
1517 tracked_objects::ScopedTracker tracking_profile1(
1518 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1519 "466432 IOThread::ConstructProxyScriptFetcherContext1"));
1520 net::URLRequestContext* context = new net::URLRequestContext;
1521 context->set_net_log(net_log);
1522 context->set_host_resolver(globals->host_resolver.get());
1523 context->set_cert_verifier(globals->cert_verifier.get());
1524 context->set_transport_security_state(
1525 globals->transport_security_state.get());
1526 context->set_cert_transparency_verifier(
1527 globals->cert_transparency_verifier.get());
1528 context->set_ssl_config_service(globals->ssl_config_service.get());
1529 context->set_http_auth_handler_factory(
1530 globals->http_auth_handler_factory.get());
1531 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
1532
1533 context->set_job_factory(
1534 globals->proxy_script_fetcher_url_request_job_factory.get());
1535
1536 context->set_cookie_store(globals->system_cookie_store.get());
1537 context->set_channel_id_service(
1538 globals->system_channel_id_service.get());
1539 context->set_network_delegate(globals->system_network_delegate.get());
1540 context->set_http_user_agent_settings(
1541 globals->http_user_agent_settings.get());
1542 context->set_http_server_properties(
1543 globals->http_server_properties->GetWeakPtr());
1544
1545 net::HttpNetworkSession::Params session_params;
1546 InitializeNetworkSessionParamsFromGlobals(*globals, &session_params);
1547 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1548 context, &session_params);
1549
1550 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
1551 // is fixed.
1552 tracked_objects::ScopedTracker tracking_profile2(
1553 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1554 "466432 IOThread::ConstructProxyScriptFetcherContext2"));
mmenke6b3af6e2015-09-12 02:06:061555 scoped_refptr<net::HttpNetworkSession> network_session(
wjmacleanea309f72015-08-25 20:56:591556 new net::HttpNetworkSession(session_params));
1557 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
1558 // is fixed.
1559 tracked_objects::ScopedTracker tracking_profile3(
1560 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1561 "466432 IOThread::ConstructProxyScriptFetcherContext3"));
mmenke6b3af6e2015-09-12 02:06:061562 globals->proxy_script_fetcher_http_transaction_factory
1563 .reset(new net::HttpNetworkLayer(network_session.get()));
wjmacleanea309f72015-08-25 20:56:591564 context->set_http_transaction_factory(
1565 globals->proxy_script_fetcher_http_transaction_factory.get());
1566
1567 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
1568 new net::URLRequestJobFactoryImpl());
1569
1570 job_factory->SetProtocolHandler(
1571 url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler()));
1572 job_factory->SetProtocolHandler(
1573 url::kFileScheme,
1574 make_scoped_ptr(new net::FileProtocolHandler(
1575 content::BrowserThread::GetBlockingPool()
1576 ->GetTaskRunnerWithShutdownBehavior(
1577 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))));
1578#if !defined(DISABLE_FTP_SUPPORT)
1579 globals->proxy_script_fetcher_ftp_transaction_factory.reset(
1580 new net::FtpNetworkLayer(globals->host_resolver.get()));
1581 job_factory->SetProtocolHandler(
1582 url::kFtpScheme,
1583 make_scoped_ptr(new net::FtpProtocolHandler(
1584 globals->proxy_script_fetcher_ftp_transaction_factory.get())));
1585#endif
1586 globals->proxy_script_fetcher_url_request_job_factory = job_factory.Pass();
1587
1588 context->set_job_factory(
1589 globals->proxy_script_fetcher_url_request_job_factory.get());
1590
1591 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1592 // system URLRequestContext too. There's no reason this should be tied to a
1593 // profile.
1594 return context;
1595}