blob: 74e26ef37ee5646f122a084fda559da0b521511c [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]d22f06e2013-06-11 16:01:1715#include "base/debug/trace_event.h"
[email protected]0ac83682010-01-22 17:46:2716#include "base/logging.h"
[email protected]903e63382013-06-01 00:40:5817#include "base/metrics/field_trial.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_registry_simple.h"
19#include "base/prefs/pref_service.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"
[email protected]1988e1c2013-02-28 20:27:4222#include "base/strings/string_split.h"
[email protected]9c7ddc92013-06-11 01:40:5723#include "base/strings/string_util.h"
[email protected]255620da2013-08-19 13:14:2924#include "base/threading/sequenced_worker_pool.h"
[email protected]3fc40c142011-12-01 13:09:0425#include "base/threading/thread.h"
[email protected]5bab49ec2012-05-04 21:13:1926#include "base/threading/worker_pool.h"
[email protected]daae3462013-04-30 03:45:1427#include "base/time/default_tick_clock.h"
[email protected]d827e112014-03-31 17:45:0528#include "base/time/time.h"
[email protected]addb3242011-06-13 21:39:1629#include "build/build_config.h"
[email protected]df2840d2011-02-20 16:32:3230#include "chrome/browser/browser_process.h"
[email protected]5a38dfd2012-07-23 23:22:1031#include "chrome/browser/extensions/event_router_forwarder.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]0ee7a3b2010-11-09 06:13:4035#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]1889dc1b2010-10-14 22:03:1336#include "chrome/browser/net/connect_interceptor.h"
[email protected]4588b3d2012-11-14 00:37:3837#include "chrome/browser/net/dns_probe_service.h"
[email protected]7613faae2012-04-18 01:01:1938#include "chrome/browser/net/http_pipelining_compatibility_client.h"
[email protected]6f96cbcb2011-11-04 02:26:0739#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]db0e86dd2011-03-16 14:47:2140#include "chrome/browser/net/proxy_service_factory.h"
[email protected]3b543ab2011-09-17 21:47:0041#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]ec44ee02012-09-28 21:31:5142#include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h"
[email protected]aa051272014-03-10 05:56:5643#include "chrome/common/chrome_content_client.h"
[email protected]0ac83682010-01-22 17:46:2744#include "chrome/common/chrome_switches.h"
[email protected]376d38a2014-01-22 03:47:3545#include "chrome/common/chrome_version_info.h"
[email protected]bcefe0f2010-11-10 16:19:1046#include "chrome/common/pref_names.h"
[email protected]b3ae2db2013-05-30 05:00:0547#include "chrome/common/url_constants.h"
[email protected]76b4b152013-12-08 21:10:0448#include "components/policy/core/common/policy_service.h"
[email protected]c38831a12011-10-28 12:44:4949#include "content/public/browser/browser_thread.h"
[email protected]7c4b66b2014-01-04 12:28:1350#include "content/public/browser/cookie_store_factory.h"
[email protected]c2dad292012-09-07 21:27:3551#include "net/base/host_mapping_rules.h"
[email protected]32eaa332010-02-08 22:15:5452#include "net/base/net_util.h"
[email protected]daae3462013-04-30 03:45:1453#include "net/base/network_time_notifier.h"
[email protected]3b543ab2011-09-17 21:47:0054#include "net/base/sdch_manager.h"
[email protected]6e7845ae2013-03-29 21:48:1155#include "net/cert/cert_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3956#include "net/cert/cert_verify_proc.h"
[email protected]284303b62013-11-28 15:11:5457#include "net/cert/ct_known_logs.h"
58#include "net/cert/ct_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3959#include "net/cert/multi_threaded_cert_verifier.h"
[email protected]9a6c2aa2014-01-11 22:39:3960#include "net/cookies/cookie_store.h"
[email protected]bc71b8772013-04-10 20:55:1661#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5362#include "net/dns/host_resolver.h"
63#include "net/dns/mapped_host_resolver.h"
[email protected]b3ae2db2013-05-30 05:00:0564#include "net/ftp/ftp_network_layer.h"
[email protected]eb3cac72010-02-26 21:07:4565#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5066#include "net/http/http_auth_handler_factory.h"
[email protected]2fb629202010-12-23 23:52:5767#include "net/http/http_network_layer.h"
[email protected]17291a022011-10-10 07:32:5368#include "net/http/http_server_properties_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1269#include "net/proxy/proxy_config_service.h"
[email protected]86933612010-10-16 23:10:3370#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1271#include "net/proxy/proxy_service.h"
[email protected]6a31ca52013-12-23 00:44:3472#include "net/quic/quic_protocol.h"
[email protected]717e4e22013-04-10 20:52:2373#include "net/socket/tcp_client_socket.h"
[email protected]77305422012-11-29 16:51:3974#include "net/spdy/spdy_session.h"
[email protected]536fd0b2013-03-14 17:41:5775#include "net/ssl/default_server_bound_cert_store.h"
76#include "net/ssl/server_bound_cert_service.h"
[email protected]b3ae2db2013-05-30 05:00:0577#include "net/url_request/data_protocol_handler.h"
78#include "net/url_request/file_protocol_handler.h"
79#include "net/url_request/ftp_protocol_handler.h"
[email protected]aa051272014-03-10 05:56:5680#include "net/url_request/static_http_user_agent_settings.h"
[email protected]3dc1bc42012-06-19 08:20:5381#include "net/url_request/url_fetcher.h"
[email protected]b3ae2db2013-05-30 05:00:0582#include "net/url_request/url_request_job_factory_impl.h"
[email protected]a73a2802012-05-02 19:20:1583#include "net/url_request/url_request_throttler_manager.h"
[email protected]77305422012-11-29 16:51:3984#include "net/websockets/websocket_job.h"
85
[email protected]431ec412013-07-31 06:30:3186#if defined(OS_WIN)
87#include "win8/util/win8_util.h"
88#endif
89
[email protected]77305422012-11-29 16:51:3990#if defined(ENABLE_CONFIGURATION_POLICY)
91#include "policy/policy_constants.h"
92#endif
[email protected]0ac83682010-01-22 17:46:2793
[email protected]284303b62013-11-28 15:11:5494#if !defined(USE_OPENSSL)
95#include "net/cert/ct_log_verifier.h"
96#include "net/cert/multi_log_ct_verifier.h"
97#endif
98
[email protected]a592c0432012-12-01 18:10:2999#if defined(USE_NSS) || defined(OS_IOS)
[email protected]77feb462011-05-16 23:37:25100#include "net/ocsp/nss_ocsp.h"
[email protected]a592c0432012-12-01 18:10:29101#endif
[email protected]77feb462011-05-16 23:37:25102
[email protected]f3318752013-02-04 13:32:51103#if !defined(OS_IOS) && !defined(OS_ANDROID)
[email protected]a2c1b132013-02-01 12:28:47104#include "net/proxy/proxy_resolver_v8.h"
105#endif
106
[email protected]d0389f62013-11-08 06:06:13107#if defined(OS_ANDROID) || defined(OS_IOS)
108#include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h"
109#endif
110
[email protected]f46f6d52014-02-08 04:00:39111#if defined(OS_CHROMEOS)
[email protected]e456c742014-02-13 14:42:14112#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]f46f6d52014-02-08 04:00:39113#include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
114#endif
115
[email protected]631bb742011-11-02 11:29:39116using content::BrowserThread;
117
[email protected]075c0322012-02-14 00:56:44118class SafeBrowsingURLRequestContext;
119
[email protected]21ee224e2011-11-21 02:17:53120// The IOThread object must outlive any tasks posted to the IO thread before the
121// Quit task, so base::Bind() calls are not refcounted.
122
[email protected]0ac83682010-01-22 17:46:27123namespace {
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]256fe9b2013-11-27 01:58:02128const char kQuicFieldTrialPacketLengthSuffix[] = "BytePackets";
[email protected]c80f7c92014-02-27 13:12:02129const char kQuicFieldTrialPacingSuffix[] = "WithPacing";
[email protected]903e63382013-06-01 00:40:58130
[email protected]aedfccd9b2013-10-02 03:24:46131const char kSpdyFieldTrialName[] = "SPDY";
132const char kSpdyFieldTrialDisabledGroupName[] = "SpdyDisabled";
133
[email protected]11f5e3a2012-09-27 00:30:13134#if defined(OS_MACOSX) && !defined(OS_IOS)
135void ObserveKeychainEvents() {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
137 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
138}
139#endif
140
[email protected]ee4c30d2012-11-07 15:08:43141// Used for the "system" URLRequestContext.
142class SystemURLRequestContext : public net::URLRequestContext {
[email protected]77feb462011-05-16 23:37:25143 public:
144 SystemURLRequestContext() {
[email protected]a592c0432012-12-01 18:10:29145#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09146 net::SetURLRequestContextForNSSHttpIO(this);
[email protected]a592c0432012-12-01 18:10:29147#endif
[email protected]77feb462011-05-16 23:37:25148 }
149
150 private:
151 virtual ~SystemURLRequestContext() {
[email protected]a592c0432012-12-01 18:10:29152#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09153 net::SetURLRequestContextForNSSHttpIO(NULL);
[email protected]a592c0432012-12-01 18:10:29154#endif
[email protected]77feb462011-05-16 23:37:25155 }
156};
157
[email protected]c54a8912012-10-22 22:09:43158scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
[email protected]d22f06e2013-06-11 16:01:17159 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
[email protected]0ac83682010-01-22 17:46:27160 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:51161
[email protected]c54a8912012-10-22 22:09:43162 net::HostResolver::Options options;
[email protected]962b98212010-07-17 03:37:51163
164 // Use the concurrency override from the command-line, if any.
165 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
166 std::string s =
167 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism);
168
169 // Parse the switch (it should be a positive integer formatted as decimal).
170 int n;
[email protected]e83326f2010-07-31 17:29:25171 if (base::StringToInt(s, &n) && n > 0) {
[email protected]c54a8912012-10-22 22:09:43172 options.max_concurrent_resolves = static_cast<size_t>(n);
[email protected]962b98212010-07-17 03:37:51173 } else {
174 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s;
175 }
176 }
177
[email protected]06ef6d92011-05-19 04:24:58178 // Use the retry attempts override from the command-line, if any.
179 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
180 std::string s =
181 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
182 // Parse the switch (it should be a non-negative integer).
183 int n;
184 if (base::StringToInt(s, &n) && n >= 0) {
[email protected]c54a8912012-10-22 22:09:43185 options.max_retry_attempts = static_cast<size_t>(n);
[email protected]06ef6d92011-05-19 04:24:58186 } else {
187 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
188 }
189 }
190
[email protected]c54a8912012-10-22 22:09:43191 scoped_ptr<net::HostResolver> global_host_resolver(
192 net::HostResolver::CreateSystemResolver(options, net_log));
[email protected]9087aa32010-02-18 08:03:38193
[email protected]0f8f1b432010-03-16 19:06:03194 // Determine if we should disable IPv6 support.
[email protected]23330db72013-07-18 03:32:11195 if (command_line.HasSwitch(switches::kEnableIPv6)) {
196 // Disable IPv6 probing.
197 global_host_resolver->SetDefaultAddressFamily(
198 net::ADDRESS_FAMILY_UNSPECIFIED);
199 } else if (command_line.HasSwitch(switches::kDisableIPv6)) {
200 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
[email protected]9087aa32010-02-18 08:03:38201 }
202
[email protected]3dc5d7ef2014-03-28 19:18:21203 // If hostname remappings were specified on the command-line, layer these
204 // rules on top of the real host resolver. This allows forwarding all requests
205 // through a designated test server.
206 if (!command_line.HasSwitch(switches::kHostResolverRules))
207 return global_host_resolver.PassAs<net::HostResolver>();
[email protected]0ac83682010-01-22 17:46:27208
[email protected]3dc5d7ef2014-03-28 19:18:21209 scoped_ptr<net::MappedHostResolver> remapped_resolver(
210 new net::MappedHostResolver(global_host_resolver.Pass()));
211 remapped_resolver->SetRulesFromString(
212 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
213 return remapped_resolver.PassAs<net::HostResolver>();
[email protected]0ac83682010-01-22 17:46:27214}
215
[email protected]ef2bf422012-05-11 03:27:09216// TODO(willchan): Remove proxy script fetcher context since it's not necessary
217// now that I got rid of refcounting URLRequestContexts.
[email protected]77feb462011-05-16 23:37:25218// See IOThread::Globals for details.
[email protected]ef2bf422012-05-11 03:27:09219net::URLRequestContext*
[email protected]2fb629202010-12-23 23:52:57220ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
221 net::NetLog* net_log) {
[email protected]ee4c30d2012-11-07 15:08:43222 net::URLRequestContext* context = new net::URLRequestContext;
[email protected]2fb629202010-12-23 23:52:57223 context->set_net_log(net_log);
224 context->set_host_resolver(globals->host_resolver.get());
225 context->set_cert_verifier(globals->cert_verifier.get());
[email protected]a2a41972011-12-07 17:47:27226 context->set_transport_security_state(
227 globals->transport_security_state.get());
[email protected]284303b62013-11-28 15:11:54228 context->set_cert_transparency_verifier(
229 globals->cert_transparency_verifier.get());
[email protected]2fb629202010-12-23 23:52:57230 context->set_http_auth_handler_factory(
231 globals->http_auth_handler_factory.get());
232 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
233 context->set_http_transaction_factory(
[email protected]52617df2010-12-24 07:30:01234 globals->proxy_script_fetcher_http_transaction_factory.get());
[email protected]b3ae2db2013-05-30 05:00:05235 context->set_job_factory(
236 globals->proxy_script_fetcher_url_request_job_factory.get());
[email protected]273e37d2011-08-11 01:49:12237 context->set_cookie_store(globals->system_cookie_store.get());
[email protected]9c4eff22012-03-20 22:42:29238 context->set_server_bound_cert_service(
239 globals->system_server_bound_cert_service.get());
[email protected]3ce02412011-03-01 12:01:15240 context->set_network_delegate(globals->system_network_delegate.get());
[email protected]ee4c30d2012-11-07 15:08:43241 context->set_http_user_agent_settings(
242 globals->http_user_agent_settings.get());
[email protected]db96a882011-10-09 02:01:54243 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
244 // system URLRequestContext too. There's no reason this should be tied to a
245 // profile.
[email protected]2fb629202010-12-23 23:52:57246 return context;
247}
248
[email protected]ef2bf422012-05-11 03:27:09249net::URLRequestContext*
[email protected]db0e86dd2011-03-16 14:47:21250ConstructSystemRequestContext(IOThread::Globals* globals,
251 net::NetLog* net_log) {
[email protected]ef2bf422012-05-11 03:27:09252 net::URLRequestContext* context = new SystemURLRequestContext;
[email protected]db0e86dd2011-03-16 14:47:21253 context->set_net_log(net_log);
254 context->set_host_resolver(globals->host_resolver.get());
255 context->set_cert_verifier(globals->cert_verifier.get());
[email protected]a2a41972011-12-07 17:47:27256 context->set_transport_security_state(
257 globals->transport_security_state.get());
[email protected]284303b62013-11-28 15:11:54258 context->set_cert_transparency_verifier(
259 globals->cert_transparency_verifier.get());
[email protected]db0e86dd2011-03-16 14:47:21260 context->set_http_auth_handler_factory(
261 globals->http_auth_handler_factory.get());
262 context->set_proxy_service(globals->system_proxy_service.get());
263 context->set_http_transaction_factory(
264 globals->system_http_transaction_factory.get());
[email protected]273e37d2011-08-11 01:49:12265 context->set_cookie_store(globals->system_cookie_store.get());
[email protected]9c4eff22012-03-20 22:42:29266 context->set_server_bound_cert_service(
267 globals->system_server_bound_cert_service.get());
[email protected]a73a2802012-05-02 19:20:15268 context->set_throttler_manager(globals->throttler_manager.get());
[email protected]815c69cf2012-06-30 00:52:08269 context->set_network_delegate(globals->system_network_delegate.get());
[email protected]ee4c30d2012-11-07 15:08:43270 context->set_http_user_agent_settings(
271 globals->http_user_agent_settings.get());
[email protected]db0e86dd2011-03-16 14:47:21272 return context;
273}
274
[email protected]f9cf5572012-12-04 15:52:09275int GetSwitchValueAsInt(const CommandLine& command_line,
276 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]0ac83682010-01-22 17:46:27285} // namespace
286
[email protected]e0845d5f2012-05-29 00:11:41287class IOThread::LoggingNetworkChangeObserver
[email protected]3d5aaad2012-10-27 12:31:28288 : public net::NetworkChangeNotifier::IPAddressObserver,
[email protected]03848872012-12-08 02:46:41289 public net::NetworkChangeNotifier::ConnectionTypeObserver,
290 public net::NetworkChangeNotifier::NetworkChangeObserver {
[email protected]e0845d5f2012-05-29 00:11:41291 public:
292 // |net_log| must remain valid throughout our lifetime.
293 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
294 : net_log_(net_log) {
295 net::NetworkChangeNotifier::AddIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28296 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41297 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41298 }
299
[email protected]b94584a2013-02-07 03:02:08300 virtual ~LoggingNetworkChangeObserver() {
[email protected]e0845d5f2012-05-29 00:11:41301 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28302 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41303 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41304 }
305
[email protected]03848872012-12-08 02:46:41306 // NetworkChangeNotifier::IPAddressObserver implementation.
[email protected]3d5aaad2012-10-27 12:31:28307 virtual void OnIPAddressChanged() OVERRIDE {
[email protected]e0845d5f2012-05-29 00:11:41308 VLOG(1) << "Observed a change to the network IP addresses";
309
[email protected]2fa08912012-06-14 20:56:26310 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED);
[email protected]e0845d5f2012-05-29 00:11:41311 }
312
[email protected]03848872012-12-08 02:46:41313 // NetworkChangeNotifier::ConnectionTypeObserver implementation.
[email protected]3d5aaad2012-10-27 12:31:28314 virtual void OnConnectionTypeChanged(
315 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
316 std::string type_as_string =
317 net::NetworkChangeNotifier::ConnectionTypeToString(type);
318
319 VLOG(1) << "Observed a change to network connectivity state "
320 << type_as_string;
321
322 net_log_->AddGlobalEntry(
323 net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED,
324 net::NetLog::StringCallback("new_connection_type", &type_as_string));
325 }
326
[email protected]03848872012-12-08 02:46:41327 // NetworkChangeNotifier::NetworkChangeObserver implementation.
328 virtual void OnNetworkChanged(
329 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
330 std::string type_as_string =
331 net::NetworkChangeNotifier::ConnectionTypeToString(type);
332
333 VLOG(1) << "Observed a network change to state " << type_as_string;
334
335 net_log_->AddGlobalEntry(
336 net::NetLog::TYPE_NETWORK_CHANGED,
337 net::NetLog::StringCallback("new_connection_type", &type_as_string));
338 }
339
[email protected]e0845d5f2012-05-29 00:11:41340 private:
341 net::NetLog* net_log_;
342 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
343};
344
[email protected]abe2c032011-03-31 18:49:34345class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
[email protected]db0e86dd2011-03-16 14:47:21346 public:
347 explicit SystemURLRequestContextGetter(IOThread* io_thread);
[email protected]db0e86dd2011-03-16 14:47:21348
[email protected]abe2c032011-03-31 18:49:34349 // Implementation for net::UrlRequestContextGetter.
[email protected]4969b0122012-06-16 01:58:28350 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
351 virtual scoped_refptr<base::SingleThreadTaskRunner>
352 GetNetworkTaskRunner() const OVERRIDE;
[email protected]db0e86dd2011-03-16 14:47:21353
[email protected]13ed17f82012-04-06 02:27:18354 protected:
355 virtual ~SystemURLRequestContextGetter();
356
[email protected]db0e86dd2011-03-16 14:47:21357 private:
358 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
[email protected]4969b0122012-06-16 01:58:28359 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21360
361 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
362};
363
364SystemURLRequestContextGetter::SystemURLRequestContextGetter(
365 IOThread* io_thread)
366 : io_thread_(io_thread),
[email protected]4969b0122012-06-16 01:58:28367 network_task_runner_(
[email protected]2e5b60a22011-11-28 15:56:41368 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
[email protected]db0e86dd2011-03-16 14:47:21369}
370
371SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
372
373net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]ef2bf422012-05-11 03:27:09375 DCHECK(io_thread_->globals()->system_request_context.get());
[email protected]db0e86dd2011-03-16 14:47:21376
[email protected]ef2bf422012-05-11 03:27:09377 return io_thread_->globals()->system_request_context.get();
[email protected]db0e86dd2011-03-16 14:47:21378}
379
[email protected]4969b0122012-06-16 01:58:28380scoped_refptr<base::SingleThreadTaskRunner>
381SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
382 return network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21383}
384
[email protected]c93123fa2012-04-19 02:49:48385IOThread::Globals::
386SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
387 Globals* globals)
388 : globals_(globals) {
389 DCHECK(globals_);
[email protected]7613faae2012-04-18 01:01:19390}
[email protected]1889dc1b2010-10-14 22:03:13391
[email protected]c93123fa2012-04-19 02:49:48392IOThread::Globals::
393SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {
394 if (globals_->system_request_context.get())
395 globals_->system_request_context->AssertNoURLRequests();
396}
397
398IOThread::Globals::Globals()
[email protected]9c009092013-05-01 03:14:09399 : system_request_context_leak_checker(this),
[email protected]c2dad292012-09-07 21:27:35400 ignore_certificate_errors(false),
401 http_pipelining_enabled(false),
402 testing_fixed_http_port(0),
[email protected]c54c6962013-02-01 04:53:19403 testing_fixed_https_port(0),
404 enable_user_alternate_protocol_ports(false) {
405}
[email protected]c2dad292012-09-07 21:27:35406
[email protected]c93123fa2012-04-19 02:49:48407IOThread::Globals::~Globals() {}
408
[email protected]bcefe0f2010-11-10 16:19:10409// |local_state| is passed in explicitly in order to (1) reduce implicit
410// dependencies and (2) make IOThread more flexible for testing.
[email protected]3ce02412011-03-01 12:01:15411IOThread::IOThread(
[email protected]b1de2c72013-02-06 02:45:47412 PrefService* local_state,
[email protected]77305422012-11-29 16:51:39413 policy::PolicyService* policy_service,
[email protected]3ce02412011-03-01 12:01:15414 ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10415 extensions::EventRouterForwarder* extension_event_router_forwarder)
[email protected]2e5b60a22011-11-28 15:56:41416 : net_log_(net_log),
[email protected]3ce02412011-03-01 12:01:15417 extension_event_router_forwarder_(extension_event_router_forwarder),
[email protected]d13c3272010-02-04 00:24:51418 globals_(NULL),
[email protected]4a109492011-09-24 21:00:12419 sdch_manager_(NULL),
[email protected]77305422012-11-29 16:51:39420 is_spdy_disabled_by_policy_(false),
[email protected]d827e112014-03-31 17:45:05421 weak_factory_(this),
422 creation_time_(base::TimeTicks::Now()) {
[email protected]f3318752013-02-04 13:32:51423#if !defined(OS_IOS) && !defined(OS_ANDROID)
[email protected]431ec412013-07-31 06:30:31424#if defined(OS_WIN)
425 if (!win8::IsSingleWindowMetroMode())
426 net::ProxyResolverV8::RememberDefaultIsolate();
427 else
428 net::ProxyResolverV8::CreateIsolate();
429#else
[email protected]a2c1b132013-02-01 12:28:47430 net::ProxyResolverV8::RememberDefaultIsolate();
431#endif
[email protected]431ec412013-07-31 06:30:31432#endif
[email protected]bcefe0f2010-11-10 16:19:10433 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
434 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
435 prefs::kDisableAuthNegotiateCnameLookup);
436 negotiate_enable_port_ = local_state->GetBoolean(
437 prefs::kEnableAuthNegotiatePort);
438 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
439 auth_delegate_whitelist_ = local_state->GetString(
440 prefs::kAuthNegotiateDelegateWhitelist);
[email protected]ac7f3fdb2010-11-12 12:47:05441 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
[email protected]6f96cbcb2011-11-04 02:26:07442 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42443 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
444 local_state));
[email protected]9d8cfb682012-09-13 16:48:04445 ChromeNetworkDelegate::InitializePrefsOnUIThread(
446 &system_enable_referrers_,
447 NULL,
[email protected]d1208ba32012-11-08 11:10:33448 NULL,
[email protected]9d8cfb682012-09-13 16:48:04449 local_state);
[email protected]4d45a6de2011-05-13 05:20:18450 ssl_config_service_manager_.reset(
[email protected]e6d017652013-05-17 18:01:40451 SSLConfigServiceManager::CreateDefaultManager(local_state));
[email protected]2e5b60a22011-11-28 15:56:41452
[email protected]68a9b0d82013-03-08 07:05:07453 base::Value* dns_client_enabled_default = new base::FundamentalValue(
454 chrome_browser_net::ConfigureAsyncDnsFieldTrial());
455 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
456 dns_client_enabled_default);
457
[email protected]fa4b6c32012-11-26 23:02:39458 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
459 local_state,
460 base::Bind(&IOThread::UpdateDnsClientEnabled,
461 base::Unretained(this)));
462 dns_client_enabled_.MoveToThread(
463 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
464
[email protected]67378142013-12-17 21:57:17465 quick_check_enabled_.Init(prefs::kQuickCheckEnabled,
466 local_state);
467 quick_check_enabled_.MoveToThread(
468 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
469
[email protected]77305422012-11-29 16:51:39470#if defined(ENABLE_CONFIGURATION_POLICY)
471 is_spdy_disabled_by_policy_ = policy_service->GetPolicies(
[email protected]2ccf83732013-02-04 20:19:02472 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get(
473 policy::key::kDisableSpdy) != NULL;
[email protected]77305422012-11-29 16:51:39474#endif // ENABLE_CONFIGURATION_POLICY
475
[email protected]2e5b60a22011-11-28 15:56:41476 BrowserThread::SetDelegate(BrowserThread::IO, this);
[email protected]bcefe0f2010-11-10 16:19:10477}
[email protected]0ac83682010-01-22 17:46:27478
479IOThread::~IOThread() {
[email protected]2e5b60a22011-11-28 15:56:41480 // This isn't needed for production code, but in tests, IOThread may
481 // be multiply constructed.
482 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
483
[email protected]d461ed22013-01-18 03:18:56484 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]d13c3272010-02-04 00:24:51485 DCHECK(!globals_);
[email protected]0ac83682010-01-22 17:46:27486}
487
[email protected]d13c3272010-02-04 00:24:51488IOThread::Globals* IOThread::globals() {
[email protected]f8b3ef82010-10-11 02:45:52489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d13c3272010-02-04 00:24:51490 return globals_;
[email protected]0ac83682010-01-22 17:46:27491}
492
[email protected]37ac95b2013-07-23 23:39:35493void IOThread::SetGlobalsForTesting(Globals* globals) {
494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
495 DCHECK(!globals || !globals_);
496 globals_ = globals;
497}
498
[email protected]b2fcd0e2010-12-01 15:19:40499ChromeNetLog* IOThread::net_log() {
500 return net_log_;
501}
502
[email protected]b09f76d62011-12-07 01:51:06503void IOThread::ChangedToOnTheRecord() {
504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
505 BrowserThread::PostTask(
506 BrowserThread::IO,
507 FROM_HERE,
508 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
509 base::Unretained(this)));
510}
511
[email protected]abe2c032011-03-31 18:49:34512net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
[email protected]db0e86dd2011-03-16 14:47:21513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]5173de8b2013-06-02 21:16:02514 if (!system_url_request_context_getter_.get()) {
[email protected]addb3242011-06-13 21:39:16515 InitSystemRequestContext();
[email protected]db0e86dd2011-03-16 14:47:21516 }
[email protected]5173de8b2013-06-02 21:16:02517 return system_url_request_context_getter_.get();
[email protected]db0e86dd2011-03-16 14:47:21518}
519
[email protected]0ac83682010-01-22 17:46:27520void IOThread::Init() {
[email protected]a5e73b82013-07-17 08:58:39521 // Prefer to use InitAsync unless you need initialization to block
522 // the UI thread
523}
524
525void IOThread::InitAsync() {
526 TRACE_EVENT0("startup", "IOThread::InitAsync");
[email protected]2e5b60a22011-11-28 15:56:41527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]70b92342010-10-12 05:54:06528
[email protected]a592c0432012-12-01 18:10:29529#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09530 net::SetMessageLoopForNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29531#endif
[email protected]70b92342010-10-12 05:54:06532
[email protected]c2dad292012-09-07 21:27:35533 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
534
[email protected]d13c3272010-02-04 00:24:51535 DCHECK(!globals_);
536 globals_ = new Globals;
537
[email protected]58bc7042010-07-07 18:04:14538 // Add an observer that will emit network change events to the ChromeNetLog.
539 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
540 // logging the network change before other IO thread consumers respond to it.
541 network_change_observer_.reset(
[email protected]b2fcd0e2010-12-01 15:19:40542 new LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14543
[email protected]cde8b3c2012-08-13 19:20:52544 // Setup the HistogramWatcher to run on the IO thread.
545 net::NetworkChangeNotifier::InitHistogramWatcher();
546
[email protected]3ce02412011-03-01 12:01:15547 globals_->extension_event_router_forwarder =
548 extension_event_router_forwarder_;
[email protected]a09159a2012-11-29 12:51:48549 ChromeNetworkDelegate* network_delegate =
550 new ChromeNetworkDelegate(extension_event_router_forwarder_,
551 &system_enable_referrers_);
[email protected]3620bbc2013-10-05 05:07:23552 if (command_line.HasSwitch(switches::kEnableClientHints))
553 network_delegate->SetEnableClientHints();
[email protected]c2dad292012-09-07 21:27:35554 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling))
[email protected]a1d4ab072012-06-07 13:21:15555 network_delegate->NeverThrottleRequests();
[email protected]a1d4ab072012-06-07 13:21:15556 globals_->system_network_delegate.reset(network_delegate);
[email protected]c54a8912012-10-22 22:09:43557 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
[email protected]fa4b6c32012-11-26 23:02:39558 UpdateDnsClientEnabled();
[email protected]f46f6d52014-02-08 04:00:39559#if defined(OS_CHROMEOS)
[email protected]e456c742014-02-13 14:42:14560 if (chromeos::UserManager::IsMultipleProfilesAllowed()) {
561 // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
562 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
563 new chromeos::CertVerifyProcChromeOS()));
564 } else // NOLINT Fallthrough to normal verifier if multiprofiles not allowed.
[email protected]f46f6d52014-02-08 04:00:39565#endif
[email protected]e456c742014-02-13 14:42:14566 {
567 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
568 net::CertVerifyProc::CreateDefault()));
569 }
[email protected]f43b89f32012-05-01 19:39:48570 globals_->transport_security_state.reset(new net::TransportSecurityState());
[email protected]284303b62013-11-28 15:11:54571#if !defined(USE_OPENSSL)
572 // For now, Certificate Transparency is only implemented for platforms
573 // that use NSS.
574 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
575 globals_->cert_transparency_verifier.reset(ct_verifier);
576
577 // Add built-in logs
578 ct_verifier->AddLog(net::ct::CreateGooglePilotLogVerifier().Pass());
579 ct_verifier->AddLog(net::ct::CreateGoogleAviatorLogVerifier().Pass());
580 ct_verifier->AddLog(net::ct::CreateGoogleRocketeerLogVerifier().Pass());
581
582 // Add logs from command line
583 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
584 std::string switch_value = command_line.GetSwitchValueASCII(
585 switches::kCertificateTransparencyLog);
[email protected]344bc952014-01-29 14:04:59586 std::vector<std::string> logs;
587 base::SplitString(switch_value, ',', &logs);
588 for (std::vector<std::string>::iterator it = logs.begin(); it != logs.end();
589 ++it) {
590 const std::string& curr_log = *it;
591 size_t delim_pos = curr_log.find(":");
592 CHECK(delim_pos != std::string::npos)
593 << "CT log description not provided (switch format"
594 " is 'description:base64_key')";
595 std::string log_description(curr_log.substr(0, delim_pos));
596 std::string ct_public_key_data;
597 CHECK(base::Base64Decode(curr_log.substr(delim_pos + 1),
598 &ct_public_key_data))
599 << "Unable to decode CT public key.";
600 scoped_ptr<net::CTLogVerifier> external_log_verifier(
601 net::CTLogVerifier::Create(ct_public_key_data, log_description));
602 CHECK(external_log_verifier) << "Unable to parse CT public key.";
603 VLOG(1) << "Adding log with description " << log_description;
604 ct_verifier->AddLog(external_log_verifier.Pass());
605 }
[email protected]284303b62013-11-28 15:11:54606 }
607#else
608 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
609 LOG(DFATAL) << "Certificate Transparency is not yet supported in Chrome "
610 "builds using OpenSSL.";
611 }
612#endif
[email protected]4d45a6de2011-05-13 05:20:18613 globals_->ssl_config_service = GetSSLConfigService();
[email protected]d0389f62013-11-08 06:06:13614#if defined(OS_ANDROID) || defined(OS_IOS)
615 if (DataReductionProxySettings::IsDataReductionProxyAllowed()) {
616 spdyproxy_auth_origins_ =
617 DataReductionProxySettings::GetDataReductionProxies();
[email protected]ec44ee02012-09-28 21:31:51618 }
[email protected]d0389f62013-11-08 06:06:13619#endif // defined(OS_ANDROID) || defined(OS_IOS)
[email protected]65d34382010-07-01 18:12:26620 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
[email protected]73c45322010-10-01 23:57:54621 globals_->host_resolver.get()));
[email protected]30d4c022013-07-18 22:58:16622 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
[email protected]2fb629202010-12-23 23:52:57623 // For the ProxyScriptFetcher, we use a direct ProxyService.
[email protected]6104ea5d2011-04-27 21:37:12624 globals_->proxy_script_fetcher_proxy_service.reset(
625 net::ProxyService::CreateDirectWithNetLog(net_log_));
[email protected]273e37d2011-08-11 01:49:12626 // In-memory cookie store.
[email protected]9a6c2aa2014-01-11 22:39:39627 globals_->system_cookie_store =
628 content::CreateCookieStore(content::CookieStoreConfig());
[email protected]9c4eff22012-03-20 22:42:29629 // In-memory server bound cert store.
630 globals_->system_server_bound_cert_service.reset(
631 new net::ServerBoundCertService(
[email protected]5bab49ec2012-05-04 21:13:19632 new net::DefaultServerBoundCertStore(NULL),
633 base::WorkerPool::GetTaskRunner(true)));
[email protected]4588b3d2012-11-14 00:37:38634 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
[email protected]c2dad292012-09-07 21:27:35635 globals_->host_mapping_rules.reset(new net::HostMappingRules());
[email protected]ee4c30d2012-11-07 15:08:43636 globals_->http_user_agent_settings.reset(
[email protected]aa051272014-03-10 05:56:56637 new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
[email protected]c2dad292012-09-07 21:27:35638 if (command_line.HasSwitch(switches::kHostRules)) {
[email protected]a5e73b82013-07-17 08:58:39639 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35640 globals_->host_mapping_rules->SetRulesFromString(
641 command_line.GetSwitchValueASCII(switches::kHostRules));
[email protected]a5e73b82013-07-17 08:58:39642 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35643 }
644 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
645 globals_->ignore_certificate_errors = true;
[email protected]c2dad292012-09-07 21:27:35646 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
[email protected]f9cf5572012-12-04 15:52:09647 globals_->testing_fixed_http_port =
648 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
[email protected]c2dad292012-09-07 21:27:35649 }
650 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
[email protected]f9cf5572012-12-04 15:52:09651 globals_->testing_fixed_https_port =
652 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
[email protected]c2dad292012-09-07 21:27:35653 }
[email protected]256fe9b2013-11-27 01:58:02654 ConfigureQuic(command_line);
[email protected]c54c6962013-02-01 04:53:19655 if (command_line.HasSwitch(
656 switches::kEnableUserAlternateProtocolPorts)) {
657 globals_->enable_user_alternate_protocol_ports = true;
658 }
[email protected]f9cf5572012-12-04 15:52:09659 InitializeNetworkOptions(command_line);
660
[email protected]9e1bdd32011-02-03 21:48:34661 net::HttpNetworkSession::Params session_params;
[email protected]f9cf5572012-12-04 15:52:09662 InitializeNetworkSessionParams(&session_params);
[email protected]27c253802012-11-30 08:18:12663 session_params.net_log = net_log_;
[email protected]9e1bdd32011-02-03 21:48:34664 session_params.proxy_service =
665 globals_->proxy_script_fetcher_proxy_service.get();
[email protected]c2dad292012-09-07 21:27:35666
[email protected]a5e73b82013-07-17 08:58:39667 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:HttpNetworkSession");
[email protected]57cb0f72011-01-28 06:33:58668 scoped_refptr<net::HttpNetworkSession> network_session(
[email protected]9e1bdd32011-02-03 21:48:34669 new net::HttpNetworkSession(session_params));
[email protected]5173de8b2013-06-02 21:16:02670 globals_->proxy_script_fetcher_http_transaction_factory
671 .reset(new net::HttpNetworkLayer(network_session.get()));
[email protected]a5e73b82013-07-17 08:58:39672 TRACE_EVENT_END0("startup", "IOThread::InitAsync:HttpNetworkSession");
[email protected]b3ae2db2013-05-30 05:00:05673 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
674 new net::URLRequestJobFactoryImpl());
[email protected]44495c482014-01-26 10:15:06675 job_factory->SetProtocolHandler(content::kDataScheme,
[email protected]b3ae2db2013-05-30 05:00:05676 new net::DataProtocolHandler());
[email protected]255620da2013-08-19 13:14:29677 job_factory->SetProtocolHandler(
[email protected]3e99baf2013-12-30 06:32:11678 content::kFileScheme,
[email protected]255620da2013-08-19 13:14:29679 new net::FileProtocolHandler(
680 content::BrowserThread::GetBlockingPool()->
681 GetTaskRunnerWithShutdownBehavior(
682 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
[email protected]b3ae2db2013-05-30 05:00:05683#if !defined(DISABLE_FTP_SUPPORT)
684 globals_->proxy_script_fetcher_ftp_transaction_factory.reset(
685 new net::FtpNetworkLayer(globals_->host_resolver.get()));
686 job_factory->SetProtocolHandler(
[email protected]72aa4c22013-12-01 15:09:35687 content::kFtpScheme,
[email protected]b3ae2db2013-05-30 05:00:05688 new net::FtpProtocolHandler(
689 globals_->proxy_script_fetcher_ftp_transaction_factory.get()));
690#endif
691 globals_->proxy_script_fetcher_url_request_job_factory =
692 job_factory.PassAs<net::URLRequestJobFactory>();
[email protected]2fb629202010-12-23 23:52:57693
[email protected]a73a2802012-05-02 19:20:15694 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager());
[email protected]a1d4ab072012-06-07 13:21:15695 globals_->throttler_manager->set_net_log(net_log_);
[email protected]332a8c962013-07-17 22:31:23696 // Always done in production, disabled only for unit tests.
697 globals_->throttler_manager->set_enable_thread_checks(true);
[email protected]a73a2802012-05-02 19:20:15698
[email protected]ef2bf422012-05-11 03:27:09699 globals_->proxy_script_fetcher_context.reset(
700 ConstructProxyScriptFetcherContext(globals_, net_log_));
[email protected]4a109492011-09-24 21:00:12701
[email protected]daae3462013-04-30 03:45:14702 globals_->network_time_notifier.reset(
703 new net::NetworkTimeNotifier(
704 scoped_ptr<base::TickClock>(new base::DefaultTickClock())));
705
[email protected]4a109492011-09-24 21:00:12706 sdch_manager_ = new net::SdchManager();
[email protected]2e5b60a22011-11-28 15:56:41707
[email protected]11f5e3a2012-09-27 00:30:13708#if defined(OS_MACOSX) && !defined(OS_IOS)
709 // Start observing Keychain events. This needs to be done on the UI thread,
710 // as Keychain services requires a CFRunLoop.
711 BrowserThread::PostTask(BrowserThread::UI,
712 FROM_HERE,
713 base::Bind(&ObserveKeychainEvents));
714#endif
715
[email protected]2e5b60a22011-11-28 15:56:41716 // InitSystemRequestContext turns right around and posts a task back
717 // to the IO thread, so we can't let it run until we know the IO
718 // thread has started.
719 //
720 // Note that since we are at BrowserThread::Init time, the UI thread
721 // is blocked waiting for the thread to start. Therefore, posting
722 // this task to the main thread's message loop here is guaranteed to
723 // get it onto the message loop while the IOThread object still
724 // exists. However, the message might not be processed on the UI
725 // thread until after IOThread is gone, so use a weak pointer.
726 BrowserThread::PostTask(BrowserThread::UI,
727 FROM_HERE,
728 base::Bind(&IOThread::InitSystemRequestContext,
729 weak_factory_.GetWeakPtr()));
[email protected]0ac83682010-01-22 17:46:27730}
731
[email protected]2a92cd92010-04-27 00:01:41732void IOThread::CleanUp() {
[email protected]075c0322012-02-14 00:56:44733 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
734
[email protected]4a109492011-09-24 21:00:12735 delete sdch_manager_;
736 sdch_manager_ = NULL;
737
[email protected]a592c0432012-12-01 18:10:29738#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09739 net::ShutdownNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29740#endif
[email protected]59a3b362010-10-21 21:52:41741
[email protected]db0e86dd2011-03-16 14:47:21742 system_url_request_context_getter_ = NULL;
743
[email protected]af669932012-01-17 19:26:58744 // Release objects that the net::URLRequestContext could have been pointing
745 // to.
[email protected]0ee7a3b2010-11-09 06:13:40746
747 // This must be reset before the ChromeNetLog is destroyed.
748 network_change_observer_.reset();
749
[email protected]db0e86dd2011-03-16 14:47:21750 system_proxy_config_service_.reset();
751
[email protected]d13c3272010-02-04 00:24:51752 delete globals_;
753 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27754
[email protected]db0e86dd2011-03-16 14:47:21755 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27756}
757
[email protected]f9cf5572012-12-04 15:52:09758void IOThread::InitializeNetworkOptions(const CommandLine& command_line) {
[email protected]aedf781f2013-07-15 21:38:15759 // Only handle use-spdy command line flags if "spdy.disabled" preference is
760 // not disabled via policy.
[email protected]aedfccd9b2013-10-02 03:24:46761 if (is_spdy_disabled_by_policy_) {
762 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName);
763 if (trial)
764 trial->Disable();
765 } else {
766 std::string spdy_trial_group =
767 base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
768
[email protected]aedf781f2013-07-15 21:38:15769 if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) {
770 // Enable WebSocket over SPDY.
771 net::WebSocketJob::set_websocket_over_spdy_enabled(true);
772 }
[email protected]aedfccd9b2013-10-02 03:24:46773
[email protected]aedf781f2013-07-15 21:38:15774 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
775 globals_->trusted_spdy_proxy.set(
776 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy));
777 }
778 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
779 net::URLFetcher::SetIgnoreCertificateRequests(true);
[email protected]77305422012-11-29 16:51:39780
[email protected]aedf781f2013-07-15 21:38:15781 if (command_line.HasSwitch(switches::kUseSpdy)) {
782 std::string spdy_mode =
783 command_line.GetSwitchValueASCII(switches::kUseSpdy);
784 EnableSpdy(spdy_mode);
[email protected]88a332622013-07-30 07:13:32785 } else if (command_line.HasSwitch(switches::kEnableHttp2Draft04)) {
786 net::HttpStreamFactory::EnableNpnHttp2Draft04();
[email protected]aedf781f2013-07-15 21:38:15787 } else if (command_line.HasSwitch(switches::kEnableSpdy4a2)) {
788 net::HttpStreamFactory::EnableNpnSpdy4a2();
789 } else if (command_line.HasSwitch(switches::kDisableSpdy31)) {
790 net::HttpStreamFactory::EnableNpnSpdy3();
[email protected]aedf781f2013-07-15 21:38:15791 } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) {
792 net::HttpStreamFactory::EnableNpnHttpOnly();
793 } else {
[email protected]aedfccd9b2013-10-02 03:24:46794 if (spdy_trial_group == kSpdyFieldTrialDisabledGroupName &&
795 !command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) {
796 net::HttpStreamFactory::set_spdy_enabled(false);
797 } else {
798 // Use SPDY/3.1 by default.
[email protected]11011522013-11-19 02:18:15799 net::HttpStreamFactory::EnableNpnSpdy31();
[email protected]aedfccd9b2013-10-02 03:24:46800 }
[email protected]aedf781f2013-07-15 21:38:15801 }
[email protected]77305422012-11-29 16:51:39802 }
[email protected]717e4e22013-04-10 20:52:23803
804 // TODO(rch): Make the client socket factory a per-network session
805 // instance, constructed from a NetworkSession::Params, to allow us
806 // to move this option to IOThread::Globals &
807 // HttpNetworkSession::Params.
808 if (command_line.HasSwitch(switches::kEnableTcpFastOpen))
809 net::SetTCPFastOpenEnabled(true);
[email protected]77305422012-11-29 16:51:39810}
811
[email protected]443a30ed2012-11-30 02:56:46812void IOThread::EnableSpdy(const std::string& mode) {
813 static const char kOff[] = "off";
814 static const char kSSL[] = "ssl";
815 static const char kDisableSSL[] = "no-ssl";
816 static const char kDisablePing[] = "no-ping";
817 static const char kExclude[] = "exclude"; // Hosts to exclude
818 static const char kDisableCompression[] = "no-compress";
819 static const char kDisableAltProtocols[] = "no-alt-protocols";
820 static const char kForceAltProtocols[] = "force-alt-protocols";
821 static const char kSingleDomain[] = "single-domain";
822
823 static const char kInitialMaxConcurrentStreams[] = "init-max-streams";
824
825 std::vector<std::string> spdy_options;
826 base::SplitString(mode, ',', &spdy_options);
827
828 for (std::vector<std::string>::iterator it = spdy_options.begin();
829 it != spdy_options.end(); ++it) {
830 const std::string& element = *it;
831 std::vector<std::string> name_value;
832 base::SplitString(element, '=', &name_value);
[email protected]007b3f82013-04-09 08:46:45833 const std::string& option =
834 name_value.size() > 0 ? name_value[0] : std::string();
835 const std::string value =
836 name_value.size() > 1 ? name_value[1] : std::string();
[email protected]443a30ed2012-11-30 02:56:46837
838 if (option == kOff) {
839 net::HttpStreamFactory::set_spdy_enabled(false);
840 } else if (option == kDisableSSL) {
[email protected]b05bcaa32013-10-06 05:26:02841 globals_->spdy_default_protocol.set(net::kProtoSPDY3);
[email protected]443a30ed2012-11-30 02:56:46842 net::HttpStreamFactory::set_force_spdy_over_ssl(false);
843 net::HttpStreamFactory::set_force_spdy_always(true);
844 } else if (option == kSSL) {
[email protected]b05bcaa32013-10-06 05:26:02845 globals_->spdy_default_protocol.set(net::kProtoSPDY3);
[email protected]443a30ed2012-11-30 02:56:46846 net::HttpStreamFactory::set_force_spdy_over_ssl(true);
847 net::HttpStreamFactory::set_force_spdy_always(true);
848 } else if (option == kDisablePing) {
[email protected]f9cf5572012-12-04 15:52:09849 globals_->enable_spdy_ping_based_connection_checking.set(false);
[email protected]443a30ed2012-11-30 02:56:46850 } else if (option == kExclude) {
851 net::HttpStreamFactory::add_forced_spdy_exclusion(value);
852 } else if (option == kDisableCompression) {
[email protected]f9cf5572012-12-04 15:52:09853 globals_->enable_spdy_compression.set(false);
[email protected]443a30ed2012-11-30 02:56:46854 } else if (option == kDisableAltProtocols) {
855 net::HttpStreamFactory::set_use_alternate_protocols(false);
856 } else if (option == kForceAltProtocols) {
857 net::PortAlternateProtocolPair pair;
858 pair.port = 443;
[email protected]b05bcaa32013-10-06 05:26:02859 pair.protocol = net::NPN_SPDY_3;
[email protected]443a30ed2012-11-30 02:56:46860 net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair);
861 } else if (option == kSingleDomain) {
[email protected]256fe9b2013-11-27 01:58:02862 DVLOG(1) << "FORCING SINGLE DOMAIN";
[email protected]f9cf5572012-12-04 15:52:09863 globals_->force_spdy_single_domain.set(true);
[email protected]443a30ed2012-11-30 02:56:46864 } else if (option == kInitialMaxConcurrentStreams) {
865 int streams;
[email protected]f9cf5572012-12-04 15:52:09866 if (base::StringToInt(value, &streams))
867 globals_->initial_max_spdy_concurrent_streams.set(streams);
[email protected]443a30ed2012-11-30 02:56:46868 } else if (option.empty() && it == spdy_options.begin()) {
869 continue;
870 } else {
871 LOG(DFATAL) << "Unrecognized spdy option: " << option;
872 }
873 }
874}
875
[email protected]bcefe0f2010-11-10 16:19:10876// static
[email protected]b1de2c72013-02-06 02:45:47877void IOThread::RegisterPrefs(PrefRegistrySimple* registry) {
878 registry->RegisterStringPref(prefs::kAuthSchemes,
879 "basic,digest,ntlm,negotiate,"
880 "spdyproxy");
[email protected]68a9b0d82013-03-08 07:05:07881 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
[email protected]b1de2c72013-02-06 02:45:47882 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
[email protected]007b3f82013-04-09 08:46:45883 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
884 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
885 std::string());
886 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
887 registry->RegisterStringPref(prefs::kSpdyProxyAuthOrigin, std::string());
[email protected]b1de2c72013-02-06 02:45:47888 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
889 registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0);
890 registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0);
[email protected]eac11e12013-03-19 22:04:32891#if defined(OS_ANDROID) || defined(OS_IOS)
892 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
893 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
[email protected]2db93e42013-08-07 17:40:41894 registry->RegisterListPref(
[email protected]0d36d1e2013-09-24 04:25:28895 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled);
[email protected]2db93e42013-08-07 17:40:41896 registry->RegisterListPref(
[email protected]0d36d1e2013-09-24 04:25:28897 prefs::kDailyContentLengthWithDataReductionProxyEnabled);
898 registry->RegisterListPref(
[email protected]828eab22013-12-10 22:42:38899 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled);
900 registry->RegisterListPref(
901 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled);
902 registry->RegisterListPref(
903 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled);
904 registry->RegisterListPref(
905 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled);
906 registry->RegisterListPref(
[email protected]0d36d1e2013-09-24 04:25:28907 prefs::kDailyOriginalContentLengthViaDataReductionProxy);
908 registry->RegisterListPref(
909 prefs::kDailyContentLengthViaDataReductionProxy);
[email protected]eac11e12013-03-19 22:04:32910 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
911#endif
[email protected]68a9b0d82013-03-08 07:05:07912 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
[email protected]67378142013-12-17 21:57:17913 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
[email protected]bcefe0f2010-11-10 16:19:10914}
915
[email protected]65d34382010-07-01 18:12:26916net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
917 net::HostResolver* resolver) {
[email protected]9030a632010-11-19 20:12:09918 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL;
919 if (!auth_server_whitelist_.empty()) {
920 auth_filter_default_credentials =
921 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
922 }
923 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
924 if (!auth_delegate_whitelist_.empty()) {
925 auth_filter_delegate =
926 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_);
927 }
[email protected]b4955e7d2010-04-16 20:22:30928 globals_->url_security_manager.reset(
[email protected]d201b200e2010-08-27 17:35:02929 net::URLSecurityManager::Create(auth_filter_default_credentials,
930 auth_filter_delegate));
[email protected]b7304162010-08-23 17:42:29931 std::vector<std::string> supported_schemes;
[email protected]bcefe0f2010-11-10 16:19:10932 base::SplitString(auth_schemes_, ',', &supported_schemes);
[email protected]b7304162010-08-23 17:42:29933
[email protected]ec44ee02012-09-28 21:31:51934 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory(
935 net::HttpAuthHandlerRegistryFactory::Create(
936 supported_schemes, globals_->url_security_manager.get(),
937 resolver, gssapi_library_name_, negotiate_disable_cname_lookup_,
938 negotiate_enable_port_));
939
[email protected]d0389f62013-11-08 06:06:13940 if (!spdyproxy_auth_origins_.empty()) {
941 registry_factory->RegisterSchemeFactory(
942 "spdyproxy",
943 new spdyproxy::HttpAuthHandlerSpdyProxy::Factory(
944 spdyproxy_auth_origins_));
[email protected]ec44ee02012-09-28 21:31:51945 }
946
947 return registry_factory.release();
[email protected]eb3cac72010-02-26 21:07:45948}
949
[email protected]d6f37fc2011-02-13 23:58:41950void IOThread::ClearHostCache() {
951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
952
[email protected]489d1a82011-10-12 03:09:11953 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
954 if (host_cache)
955 host_cache->clear();
[email protected]0ac83682010-01-22 17:46:27956}
[email protected]db0e86dd2011-03-16 14:47:21957
[email protected]f9cf5572012-12-04 15:52:09958void IOThread::InitializeNetworkSessionParams(
959 net::HttpNetworkSession::Params* params) {
960 params->host_resolver = globals_->host_resolver.get();
961 params->cert_verifier = globals_->cert_verifier.get();
962 params->server_bound_cert_service =
963 globals_->system_server_bound_cert_service.get();
964 params->transport_security_state = globals_->transport_security_state.get();
965 params->ssl_config_service = globals_->ssl_config_service.get();
966 params->http_auth_handler_factory = globals_->http_auth_handler_factory.get();
[email protected]30d4c022013-07-18 22:58:16967 params->http_server_properties =
968 globals_->http_server_properties->GetWeakPtr();
[email protected]f9cf5572012-12-04 15:52:09969 params->network_delegate = globals_->system_network_delegate.get();
970 params->host_mapping_rules = globals_->host_mapping_rules.get();
971 params->ignore_certificate_errors = globals_->ignore_certificate_errors;
972 params->http_pipelining_enabled = globals_->http_pipelining_enabled;
973 params->testing_fixed_http_port = globals_->testing_fixed_http_port;
974 params->testing_fixed_https_port = globals_->testing_fixed_https_port;
975
[email protected]f9cf5572012-12-04 15:52:09976 globals_->initial_max_spdy_concurrent_streams.CopyToIfSet(
977 &params->spdy_initial_max_concurrent_streams);
[email protected]f9cf5572012-12-04 15:52:09978 globals_->force_spdy_single_domain.CopyToIfSet(
979 &params->force_spdy_single_domain);
[email protected]f9cf5572012-12-04 15:52:09980 globals_->enable_spdy_compression.CopyToIfSet(
981 &params->enable_spdy_compression);
982 globals_->enable_spdy_ping_based_connection_checking.CopyToIfSet(
983 &params->enable_spdy_ping_based_connection_checking);
984 globals_->spdy_default_protocol.CopyToIfSet(
985 &params->spdy_default_protocol);
[email protected]26615ae2013-06-13 17:50:59986 globals_->trusted_spdy_proxy.CopyToIfSet(
987 &params->trusted_spdy_proxy);
[email protected]b559b132013-01-29 22:13:32988 globals_->enable_quic.CopyToIfSet(&params->enable_quic);
[email protected]eb8f88e2013-07-15 09:52:17989 globals_->enable_quic_https.CopyToIfSet(&params->enable_quic_https);
[email protected]c80f7c92014-02-27 13:12:02990 globals_->enable_quic_pacing.CopyToIfSet(
991 &params->enable_quic_pacing);
[email protected]d412ef72014-03-03 21:13:14992 globals_->enable_quic_persist_server_info.CopyToIfSet(
993 &params->enable_quic_persist_server_info);
[email protected]376d38a2014-01-22 03:47:35994 globals_->enable_quic_port_selection.CopyToIfSet(
995 &params->enable_quic_port_selection);
[email protected]256fe9b2013-11-27 01:58:02996 globals_->quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length);
[email protected]6a31ca52013-12-23 00:44:34997 globals_->quic_supported_versions.CopyToIfSet(
998 &params->quic_supported_versions);
[email protected]49e85332013-06-04 04:18:03999 globals_->origin_to_force_quic_on.CopyToIfSet(
1000 &params->origin_to_force_quic_on);
[email protected]c54c6962013-02-01 04:53:191001 params->enable_user_alternate_protocol_ports =
1002 globals_->enable_user_alternate_protocol_ports;
[email protected]f9cf5572012-12-04 15:52:091003}
1004
[email protected]d827e112014-03-31 17:45:051005base::TimeTicks IOThread::creation_time() const {
1006 return creation_time_;
1007}
1008
[email protected]4d45a6de2011-05-13 05:20:181009net::SSLConfigService* IOThread::GetSSLConfigService() {
1010 return ssl_config_service_manager_->Get();
1011}
1012
[email protected]b09f76d62011-12-07 01:51:061013void IOThread::ChangedToOnTheRecordOnIOThread() {
1014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1015
1016 // Clear the host cache to avoid showing entries from the OTR session
1017 // in about:net-internals.
1018 ClearHostCache();
[email protected]b09f76d62011-12-07 01:51:061019}
1020
[email protected]db0e86dd2011-03-16 14:47:211021void IOThread::InitSystemRequestContext() {
[email protected]5173de8b2013-06-02 21:16:021022 if (system_url_request_context_getter_.get())
[email protected]addb3242011-06-13 21:39:161023 return;
[email protected]63e26822011-07-16 19:07:351024 // If we're in unit_tests, IOThread may not be run.
[email protected]dd483702011-12-02 14:47:421025 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
[email protected]63e26822011-07-16 19:07:351026 return;
[email protected]53c5b0f2013-07-22 10:54:111027 system_proxy_config_service_.reset(
1028 ProxyServiceFactory::CreateProxyConfigService(
1029 pref_proxy_config_tracker_.get()));
[email protected]addb3242011-06-13 21:39:161030 system_url_request_context_getter_ =
1031 new SystemURLRequestContextGetter(this);
[email protected]2e5b60a22011-11-28 15:56:411032 // Safe to post an unretained this pointer, since IOThread is
1033 // guaranteed to outlive the IO BrowserThread.
[email protected]dd483702011-12-02 14:47:421034 BrowserThread::PostTask(
1035 BrowserThread::IO,
1036 FROM_HERE,
1037 base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
1038 base::Unretained(this)));
[email protected]addb3242011-06-13 21:39:161039}
1040
1041void IOThread::InitSystemRequestContextOnIOThread() {
[email protected]db0e86dd2011-03-16 14:47:211042 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]6104ea5d2011-04-27 21:37:121043 DCHECK(!globals_->system_proxy_service.get());
[email protected]db0e86dd2011-03-16 14:47:211044 DCHECK(system_proxy_config_service_.get());
1045
1046 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]6104ea5d2011-04-27 21:37:121047 globals_->system_proxy_service.reset(
[email protected]db0e86dd2011-03-16 14:47:211048 ProxyServiceFactory::CreateProxyService(
1049 net_log_,
[email protected]ef2bf422012-05-11 03:27:091050 globals_->proxy_script_fetcher_context.get(),
[email protected]8def32a02013-03-11 19:13:231051 globals_->system_network_delegate.get(),
[email protected]db0e86dd2011-03-16 14:47:211052 system_proxy_config_service_.release(),
[email protected]67378142013-12-17 21:57:171053 command_line,
1054 quick_check_enabled_.GetValue()));
[email protected]c2dad292012-09-07 21:27:351055
[email protected]db0e86dd2011-03-16 14:47:211056 net::HttpNetworkSession::Params system_params;
[email protected]f9cf5572012-12-04 15:52:091057 InitializeNetworkSessionParams(&system_params);
[email protected]db0e86dd2011-03-16 14:47:211058 system_params.net_log = net_log_;
[email protected]27c253802012-11-30 08:18:121059 system_params.proxy_service = globals_->system_proxy_service.get();
[email protected]c2dad292012-09-07 21:27:351060
[email protected]db0e86dd2011-03-16 14:47:211061 globals_->system_http_transaction_factory.reset(
1062 new net::HttpNetworkLayer(
1063 new net::HttpNetworkSession(system_params)));
[email protected]ef2bf422012-05-11 03:27:091064 globals_->system_request_context.reset(
1065 ConstructSystemRequestContext(globals_, net_log_));
[email protected]d24fc3a02012-02-11 02:08:341066
1067 sdch_manager_->set_sdch_fetcher(
1068 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
[email protected]db0e86dd2011-03-16 14:47:211069}
[email protected]fa4b6c32012-11-26 23:02:391070
1071void IOThread::UpdateDnsClientEnabled() {
1072 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
1073}
[email protected]903e63382013-06-01 00:40:581074
[email protected]256fe9b2013-11-27 01:58:021075void IOThread::ConfigureQuic(const CommandLine& command_line) {
[email protected]903e63382013-06-01 00:40:581076 // Always fetch the field trial group to ensure it is reported correctly.
1077 // The command line flags will be associated with a group that is reported
1078 // so long as trial is actually queried.
1079 std::string quic_trial_group =
1080 base::FieldTrialList::FindFullName(kQuicFieldTrialName);
1081
[email protected]256fe9b2013-11-27 01:58:021082 bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group);
1083 globals_->enable_quic.set(enable_quic);
1084 if (enable_quic) {
1085 globals_->enable_quic_https.set(
1086 ShouldEnableQuicHttps(command_line, quic_trial_group));
[email protected]c80f7c92014-02-27 13:12:021087 globals_->enable_quic_pacing.set(
1088 ShouldEnableQuicPacing(command_line, quic_trial_group));
[email protected]d412ef72014-03-03 21:13:141089 globals_->enable_quic_persist_server_info.set(
1090 ShouldEnableQuicPersistServerInfo(command_line));
[email protected]376d38a2014-01-22 03:47:351091 globals_->enable_quic_port_selection.set(
1092 ShouldEnableQuicPortSelection(command_line));
[email protected]256fe9b2013-11-27 01:58:021093 }
1094
1095 size_t max_packet_length = GetQuicMaxPacketLength(command_line,
1096 quic_trial_group);
1097 if (max_packet_length != 0) {
1098 globals_->quic_max_packet_length.set(max_packet_length);
1099 }
1100
[email protected]6a31ca52013-12-23 00:44:341101 net::QuicVersion version = GetQuicVersion(command_line);
1102 if (version != net::QUIC_VERSION_UNSUPPORTED) {
1103 net::QuicVersionVector supported_versions;
1104 supported_versions.push_back(version);
1105 globals_->quic_supported_versions.set(supported_versions);
1106 }
1107
[email protected]256fe9b2013-11-27 01:58:021108 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
1109 net::HostPortPair quic_origin =
1110 net::HostPortPair::FromString(
1111 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
1112 if (!quic_origin.IsEmpty()) {
1113 globals_->origin_to_force_quic_on.set(quic_origin);
1114 }
1115 }
1116}
1117
1118bool IOThread::ShouldEnableQuic(const CommandLine& command_line,
1119 base::StringPiece quic_trial_group) {
[email protected]903e63382013-06-01 00:40:581120 if (command_line.HasSwitch(switches::kDisableQuic))
1121 return false;
1122
[email protected]a64b213e2013-07-24 21:41:001123 if (command_line.HasSwitch(switches::kEnableQuic))
[email protected]903e63382013-06-01 00:40:581124 return true;
1125
[email protected]256fe9b2013-11-27 01:58:021126 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) ||
1127 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
[email protected]a64b213e2013-07-24 21:41:001128}
1129
[email protected]256fe9b2013-11-27 01:58:021130bool IOThread::ShouldEnableQuicHttps(const CommandLine& command_line,
1131 base::StringPiece quic_trial_group) {
[email protected]a64b213e2013-07-24 21:41:001132 if (command_line.HasSwitch(switches::kDisableQuicHttps))
1133 return false;
1134
1135 if (command_line.HasSwitch(switches::kEnableQuicHttps))
1136 return true;
1137
[email protected]256fe9b2013-11-27 01:58:021138 return quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
1139}
1140
[email protected]376d38a2014-01-22 03:47:351141bool IOThread::ShouldEnableQuicPortSelection(
1142 const CommandLine& command_line) {
1143 if (command_line.HasSwitch(switches::kDisableQuicPortSelection))
1144 return false;
1145
1146 if (command_line.HasSwitch(switches::kEnableQuicPortSelection))
1147 return true;
1148
1149#if defined(OS_WIN)
1150 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
1151 // Avoid picking ports (which might induce a security dialog) when we have a
1152 // beta or stable release. Allow in all other cases, including when we do a
1153 // developer build (CHANNEL_UNKNOWN).
1154 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
1155 channel == chrome::VersionInfo::CHANNEL_BETA) {
1156 // TODO(grt) bug=329255: Detect presence of rule on Windows that allows us
1157 // to do port selection without inducing a dialog.
1158 // When we have an API to see if the administrative security manager will
1159 // allow port selection without a security dialog, we may return true if
1160 // we're sure there will be no security dialog.
1161 return false;
1162 }
1163 return true;
1164#else
1165 return true;
1166#endif
1167}
1168
[email protected]c80f7c92014-02-27 13:12:021169bool IOThread::ShouldEnableQuicPacing(const CommandLine& command_line,
1170 base::StringPiece quic_trial_group) {
1171 if (command_line.HasSwitch(switches::kEnableQuicPacing))
1172 return true;
1173
1174 if (command_line.HasSwitch(switches::kDisableQuicPacing))
1175 return false;
1176
1177 return quic_trial_group.ends_with(kQuicFieldTrialPacingSuffix);
1178}
1179
[email protected]d412ef72014-03-03 21:13:141180bool IOThread::ShouldEnableQuicPersistServerInfo(
1181 const CommandLine& command_line) {
1182 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
1183 // Avoid persisting of Quic server config information to disk cache when we
1184 // have a beta or stable release. Allow in all other cases, including when we
1185 // do a developer build (CHANNEL_UNKNOWN).
1186 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
1187 channel == chrome::VersionInfo::CHANNEL_BETA) {
1188 return false;
1189 }
1190 return true;
1191}
1192
[email protected]256fe9b2013-11-27 01:58:021193size_t IOThread::GetQuicMaxPacketLength(const CommandLine& command_line,
1194 base::StringPiece quic_trial_group) {
1195 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
1196 unsigned value;
1197 if (!base::StringToUint(
1198 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
1199 &value)) {
1200 return 0;
1201 }
1202 return value;
1203 }
1204
1205 // Format of the packet length group names is:
1206 // (Https)?Enabled<length>BytePackets.
1207 base::StringPiece length_str(quic_trial_group);
1208 if (length_str.starts_with(kQuicFieldTrialEnabledGroupName)) {
1209 length_str.remove_prefix(strlen(kQuicFieldTrialEnabledGroupName));
1210 } else if (length_str.starts_with(kQuicFieldTrialHttpsEnabledGroupName)) {
1211 length_str.remove_prefix(strlen(kQuicFieldTrialHttpsEnabledGroupName));
1212 } else {
1213 return 0;
1214 }
1215 if (!length_str.ends_with(kQuicFieldTrialPacketLengthSuffix)) {
1216 return 0;
1217 }
1218 length_str.remove_suffix(strlen(kQuicFieldTrialPacketLengthSuffix));
1219 unsigned value;
1220 if (!base::StringToUint(length_str, &value)) {
1221 return 0;
1222 }
1223 return value;
[email protected]903e63382013-06-01 00:40:581224}
[email protected]6a31ca52013-12-23 00:44:341225
1226net::QuicVersion IOThread::GetQuicVersion(const CommandLine& command_line) {
1227 if (!command_line.HasSwitch(switches::kQuicVersion)) {
1228 return net::QUIC_VERSION_UNSUPPORTED;
1229 }
1230 net::QuicVersionVector supported_versions = net::QuicSupportedVersions();
1231 std::string version_flag =
1232 command_line.GetSwitchValueASCII(switches::kQuicVersion);
1233 for (size_t i = 0; i < supported_versions.size(); ++i) {
1234 net::QuicVersion version = supported_versions[i];
1235 if (net::QuicVersionToString(version) == version_flag) {
1236 return version;
1237 }
1238 }
1239 return net::QUIC_VERSION_UNSUPPORTED;
1240}