blob: eab893506955713eeb4a6cffd6c06e0a3afaaf12 [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]addb3242011-06-13 21:39:1628#include "build/build_config.h"
[email protected]df2840d2011-02-20 16:32:3229#include "chrome/browser/browser_process.h"
[email protected]5a38dfd2012-07-23 23:22:1030#include "chrome/browser/extensions/event_router_forwarder.h"
[email protected]026876f32012-08-22 23:53:4031#include "chrome/browser/net/async_dns_field_trial.h"
[email protected]ee4c30d2012-11-07 15:08:4332#include "chrome/browser/net/basic_http_user_agent_settings.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]a9e0d1412012-08-20 22:13:0139#include "chrome/browser/net/load_time_stats.h"
[email protected]6f96cbcb2011-11-04 02:26:0740#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]db0e86dd2011-03-16 14:47:2141#include "chrome/browser/net/proxy_service_factory.h"
[email protected]3b543ab2011-09-17 21:47:0042#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]ec44ee02012-09-28 21:31:5143#include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h"
[email protected]77305422012-11-29 16:51:3944#include "chrome/browser/policy/policy_service.h"
[email protected]0ac83682010-01-22 17:46:2745#include "chrome/common/chrome_switches.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]c38831a12011-10-28 12:44:4948#include "content/public/browser/browser_thread.h"
[email protected]c2dad292012-09-07 21:27:3549#include "net/base/host_mapping_rules.h"
[email protected]32eaa332010-02-08 22:15:5450#include "net/base/net_util.h"
[email protected]daae3462013-04-30 03:45:1451#include "net/base/network_time_notifier.h"
[email protected]3b543ab2011-09-17 21:47:0052#include "net/base/sdch_manager.h"
[email protected]6e7845ae2013-03-29 21:48:1153#include "net/cert/cert_verifier.h"
[email protected]284303b62013-11-28 15:11:5454#include "net/cert/ct_known_logs.h"
55#include "net/cert/ct_verifier.h"
[email protected]33ad6ce92013-08-27 14:39:0856#include "net/cookies/cookie_monster.h"
[email protected]bc71b8772013-04-10 20:55:1657#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5358#include "net/dns/host_resolver.h"
59#include "net/dns/mapped_host_resolver.h"
[email protected]b3ae2db2013-05-30 05:00:0560#include "net/ftp/ftp_network_layer.h"
[email protected]eb3cac72010-02-26 21:07:4561#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5062#include "net/http/http_auth_handler_factory.h"
[email protected]2fb629202010-12-23 23:52:5763#include "net/http/http_network_layer.h"
[email protected]17291a022011-10-10 07:32:5364#include "net/http/http_server_properties_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1265#include "net/proxy/proxy_config_service.h"
[email protected]86933612010-10-16 23:10:3366#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1267#include "net/proxy/proxy_service.h"
[email protected]717e4e22013-04-10 20:52:2368#include "net/socket/tcp_client_socket.h"
[email protected]77305422012-11-29 16:51:3969#include "net/spdy/spdy_session.h"
[email protected]536fd0b2013-03-14 17:41:5770#include "net/ssl/default_server_bound_cert_store.h"
71#include "net/ssl/server_bound_cert_service.h"
[email protected]b3ae2db2013-05-30 05:00:0572#include "net/url_request/data_protocol_handler.h"
73#include "net/url_request/file_protocol_handler.h"
74#include "net/url_request/ftp_protocol_handler.h"
[email protected]3dc1bc42012-06-19 08:20:5375#include "net/url_request/url_fetcher.h"
[email protected]b3ae2db2013-05-30 05:00:0576#include "net/url_request/url_request_job_factory_impl.h"
[email protected]a73a2802012-05-02 19:20:1577#include "net/url_request/url_request_throttler_manager.h"
[email protected]77305422012-11-29 16:51:3978#include "net/websockets/websocket_job.h"
79
[email protected]431ec412013-07-31 06:30:3180#if defined(OS_WIN)
81#include "win8/util/win8_util.h"
82#endif
83
[email protected]77305422012-11-29 16:51:3984#if defined(ENABLE_CONFIGURATION_POLICY)
85#include "policy/policy_constants.h"
86#endif
[email protected]0ac83682010-01-22 17:46:2787
[email protected]284303b62013-11-28 15:11:5488#if !defined(USE_OPENSSL)
89#include "net/cert/ct_log_verifier.h"
90#include "net/cert/multi_log_ct_verifier.h"
91#endif
92
[email protected]a592c0432012-12-01 18:10:2993#if defined(USE_NSS) || defined(OS_IOS)
[email protected]77feb462011-05-16 23:37:2594#include "net/ocsp/nss_ocsp.h"
[email protected]a592c0432012-12-01 18:10:2995#endif
[email protected]77feb462011-05-16 23:37:2596
[email protected]f3318752013-02-04 13:32:5197#if !defined(OS_IOS) && !defined(OS_ANDROID)
[email protected]a2c1b132013-02-01 12:28:4798#include "net/proxy/proxy_resolver_v8.h"
99#endif
100
[email protected]d0389f62013-11-08 06:06:13101#if defined(OS_ANDROID) || defined(OS_IOS)
102#include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h"
103#endif
104
[email protected]631bb742011-11-02 11:29:39105using content::BrowserThread;
106
[email protected]075c0322012-02-14 00:56:44107class SafeBrowsingURLRequestContext;
108
[email protected]21ee224e2011-11-21 02:17:53109// The IOThread object must outlive any tasks posted to the IO thread before the
110// Quit task, so base::Bind() calls are not refcounted.
111
[email protected]0ac83682010-01-22 17:46:27112namespace {
113
[email protected]903e63382013-06-01 00:40:58114const char kQuicFieldTrialName[] = "QUIC";
115const char kQuicFieldTrialEnabledGroupName[] = "Enabled";
[email protected]a64b213e2013-07-24 21:41:00116const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled";
[email protected]256fe9b2013-11-27 01:58:02117const char kQuicFieldTrialPacketLengthSuffix[] = "BytePackets";
[email protected]903e63382013-06-01 00:40:58118
[email protected]aedfccd9b2013-10-02 03:24:46119const char kSpdyFieldTrialName[] = "SPDY";
120const char kSpdyFieldTrialDisabledGroupName[] = "SpdyDisabled";
121
[email protected]11f5e3a2012-09-27 00:30:13122#if defined(OS_MACOSX) && !defined(OS_IOS)
123void ObserveKeychainEvents() {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
126}
127#endif
128
[email protected]ee4c30d2012-11-07 15:08:43129// Used for the "system" URLRequestContext.
130class SystemURLRequestContext : public net::URLRequestContext {
[email protected]77feb462011-05-16 23:37:25131 public:
132 SystemURLRequestContext() {
[email protected]a592c0432012-12-01 18:10:29133#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09134 net::SetURLRequestContextForNSSHttpIO(this);
[email protected]a592c0432012-12-01 18:10:29135#endif
[email protected]77feb462011-05-16 23:37:25136 }
137
138 private:
139 virtual ~SystemURLRequestContext() {
[email protected]a592c0432012-12-01 18:10:29140#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09141 net::SetURLRequestContextForNSSHttpIO(NULL);
[email protected]a592c0432012-12-01 18:10:29142#endif
[email protected]77feb462011-05-16 23:37:25143 }
144};
145
[email protected]c54a8912012-10-22 22:09:43146scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
[email protected]d22f06e2013-06-11 16:01:17147 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
[email protected]0ac83682010-01-22 17:46:27148 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:51149
[email protected]c54a8912012-10-22 22:09:43150 net::HostResolver::Options options;
[email protected]962b98212010-07-17 03:37:51151
152 // Use the concurrency override from the command-line, if any.
153 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
154 std::string s =
155 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism);
156
157 // Parse the switch (it should be a positive integer formatted as decimal).
158 int n;
[email protected]e83326f2010-07-31 17:29:25159 if (base::StringToInt(s, &n) && n > 0) {
[email protected]c54a8912012-10-22 22:09:43160 options.max_concurrent_resolves = static_cast<size_t>(n);
[email protected]962b98212010-07-17 03:37:51161 } else {
162 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s;
163 }
164 }
165
[email protected]06ef6d92011-05-19 04:24:58166 // Use the retry attempts override from the command-line, if any.
167 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
168 std::string s =
169 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
170 // Parse the switch (it should be a non-negative integer).
171 int n;
172 if (base::StringToInt(s, &n) && n >= 0) {
[email protected]c54a8912012-10-22 22:09:43173 options.max_retry_attempts = static_cast<size_t>(n);
[email protected]06ef6d92011-05-19 04:24:58174 } else {
175 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
176 }
177 }
178
[email protected]c54a8912012-10-22 22:09:43179 scoped_ptr<net::HostResolver> global_host_resolver(
180 net::HostResolver::CreateSystemResolver(options, net_log));
[email protected]9087aa32010-02-18 08:03:38181
[email protected]0f8f1b432010-03-16 19:06:03182 // Determine if we should disable IPv6 support.
[email protected]23330db72013-07-18 03:32:11183 if (command_line.HasSwitch(switches::kEnableIPv6)) {
184 // Disable IPv6 probing.
185 global_host_resolver->SetDefaultAddressFamily(
186 net::ADDRESS_FAMILY_UNSPECIFIED);
187 } else if (command_line.HasSwitch(switches::kDisableIPv6)) {
188 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
[email protected]9087aa32010-02-18 08:03:38189 }
190
[email protected]9087aa32010-02-18 08:03:38191 // If hostname remappings were specified on the command-line, layer these
192 // rules on top of the real host resolver. This allows forwarding all requests
193 // through a designated test server.
[email protected]0f8f1b432010-03-16 19:06:03194 if (!command_line.HasSwitch(switches::kHostResolverRules))
[email protected]c54a8912012-10-22 22:09:43195 return global_host_resolver.PassAs<net::HostResolver>();
[email protected]0ac83682010-01-22 17:46:27196
[email protected]c54a8912012-10-22 22:09:43197 scoped_ptr<net::MappedHostResolver> remapped_resolver(
198 new net::MappedHostResolver(global_host_resolver.Pass()));
[email protected]0f8f1b432010-03-16 19:06:03199 remapped_resolver->SetRulesFromString(
200 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
[email protected]c54a8912012-10-22 22:09:43201 return remapped_resolver.PassAs<net::HostResolver>();
[email protected]0ac83682010-01-22 17:46:27202}
203
[email protected]ef2bf422012-05-11 03:27:09204// TODO(willchan): Remove proxy script fetcher context since it's not necessary
205// now that I got rid of refcounting URLRequestContexts.
[email protected]77feb462011-05-16 23:37:25206// See IOThread::Globals for details.
[email protected]ef2bf422012-05-11 03:27:09207net::URLRequestContext*
[email protected]2fb629202010-12-23 23:52:57208ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
209 net::NetLog* net_log) {
[email protected]ee4c30d2012-11-07 15:08:43210 net::URLRequestContext* context = new net::URLRequestContext;
[email protected]2fb629202010-12-23 23:52:57211 context->set_net_log(net_log);
212 context->set_host_resolver(globals->host_resolver.get());
213 context->set_cert_verifier(globals->cert_verifier.get());
[email protected]a2a41972011-12-07 17:47:27214 context->set_transport_security_state(
215 globals->transport_security_state.get());
[email protected]284303b62013-11-28 15:11:54216 context->set_cert_transparency_verifier(
217 globals->cert_transparency_verifier.get());
[email protected]2fb629202010-12-23 23:52:57218 context->set_http_auth_handler_factory(
219 globals->http_auth_handler_factory.get());
220 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
221 context->set_http_transaction_factory(
[email protected]52617df2010-12-24 07:30:01222 globals->proxy_script_fetcher_http_transaction_factory.get());
[email protected]b3ae2db2013-05-30 05:00:05223 context->set_job_factory(
224 globals->proxy_script_fetcher_url_request_job_factory.get());
[email protected]273e37d2011-08-11 01:49:12225 context->set_cookie_store(globals->system_cookie_store.get());
[email protected]9c4eff22012-03-20 22:42:29226 context->set_server_bound_cert_service(
227 globals->system_server_bound_cert_service.get());
[email protected]3ce02412011-03-01 12:01:15228 context->set_network_delegate(globals->system_network_delegate.get());
[email protected]ee4c30d2012-11-07 15:08:43229 context->set_http_user_agent_settings(
230 globals->http_user_agent_settings.get());
[email protected]db96a882011-10-09 02:01:54231 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
232 // system URLRequestContext too. There's no reason this should be tied to a
233 // profile.
[email protected]2fb629202010-12-23 23:52:57234 return context;
235}
236
[email protected]ef2bf422012-05-11 03:27:09237net::URLRequestContext*
[email protected]db0e86dd2011-03-16 14:47:21238ConstructSystemRequestContext(IOThread::Globals* globals,
239 net::NetLog* net_log) {
[email protected]ef2bf422012-05-11 03:27:09240 net::URLRequestContext* context = new SystemURLRequestContext;
[email protected]db0e86dd2011-03-16 14:47:21241 context->set_net_log(net_log);
242 context->set_host_resolver(globals->host_resolver.get());
243 context->set_cert_verifier(globals->cert_verifier.get());
[email protected]a2a41972011-12-07 17:47:27244 context->set_transport_security_state(
245 globals->transport_security_state.get());
[email protected]284303b62013-11-28 15:11:54246 context->set_cert_transparency_verifier(
247 globals->cert_transparency_verifier.get());
[email protected]db0e86dd2011-03-16 14:47:21248 context->set_http_auth_handler_factory(
249 globals->http_auth_handler_factory.get());
250 context->set_proxy_service(globals->system_proxy_service.get());
251 context->set_http_transaction_factory(
252 globals->system_http_transaction_factory.get());
[email protected]273e37d2011-08-11 01:49:12253 context->set_cookie_store(globals->system_cookie_store.get());
[email protected]9c4eff22012-03-20 22:42:29254 context->set_server_bound_cert_service(
255 globals->system_server_bound_cert_service.get());
[email protected]a73a2802012-05-02 19:20:15256 context->set_throttler_manager(globals->throttler_manager.get());
[email protected]815c69cf2012-06-30 00:52:08257 context->set_network_delegate(globals->system_network_delegate.get());
[email protected]ee4c30d2012-11-07 15:08:43258 context->set_http_user_agent_settings(
259 globals->http_user_agent_settings.get());
[email protected]db0e86dd2011-03-16 14:47:21260 return context;
261}
262
[email protected]f9cf5572012-12-04 15:52:09263int GetSwitchValueAsInt(const CommandLine& command_line,
264 const std::string& switch_name) {
265 int value;
266 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
267 &value)) {
268 return 0;
269 }
270 return value;
[email protected]27c253802012-11-30 08:18:12271}
272
[email protected]0ac83682010-01-22 17:46:27273} // namespace
274
[email protected]e0845d5f2012-05-29 00:11:41275class IOThread::LoggingNetworkChangeObserver
[email protected]3d5aaad2012-10-27 12:31:28276 : public net::NetworkChangeNotifier::IPAddressObserver,
[email protected]03848872012-12-08 02:46:41277 public net::NetworkChangeNotifier::ConnectionTypeObserver,
278 public net::NetworkChangeNotifier::NetworkChangeObserver {
[email protected]e0845d5f2012-05-29 00:11:41279 public:
280 // |net_log| must remain valid throughout our lifetime.
281 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
282 : net_log_(net_log) {
283 net::NetworkChangeNotifier::AddIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28284 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41285 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41286 }
287
[email protected]b94584a2013-02-07 03:02:08288 virtual ~LoggingNetworkChangeObserver() {
[email protected]e0845d5f2012-05-29 00:11:41289 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
[email protected]3d5aaad2012-10-27 12:31:28290 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
[email protected]03848872012-12-08 02:46:41291 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
[email protected]e0845d5f2012-05-29 00:11:41292 }
293
[email protected]03848872012-12-08 02:46:41294 // NetworkChangeNotifier::IPAddressObserver implementation.
[email protected]3d5aaad2012-10-27 12:31:28295 virtual void OnIPAddressChanged() OVERRIDE {
[email protected]e0845d5f2012-05-29 00:11:41296 VLOG(1) << "Observed a change to the network IP addresses";
297
[email protected]2fa08912012-06-14 20:56:26298 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED);
[email protected]e0845d5f2012-05-29 00:11:41299 }
300
[email protected]03848872012-12-08 02:46:41301 // NetworkChangeNotifier::ConnectionTypeObserver implementation.
[email protected]3d5aaad2012-10-27 12:31:28302 virtual void OnConnectionTypeChanged(
303 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
304 std::string type_as_string =
305 net::NetworkChangeNotifier::ConnectionTypeToString(type);
306
307 VLOG(1) << "Observed a change to network connectivity state "
308 << type_as_string;
309
310 net_log_->AddGlobalEntry(
311 net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED,
312 net::NetLog::StringCallback("new_connection_type", &type_as_string));
313 }
314
[email protected]03848872012-12-08 02:46:41315 // NetworkChangeNotifier::NetworkChangeObserver implementation.
316 virtual void OnNetworkChanged(
317 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
318 std::string type_as_string =
319 net::NetworkChangeNotifier::ConnectionTypeToString(type);
320
321 VLOG(1) << "Observed a network change to state " << type_as_string;
322
323 net_log_->AddGlobalEntry(
324 net::NetLog::TYPE_NETWORK_CHANGED,
325 net::NetLog::StringCallback("new_connection_type", &type_as_string));
326 }
327
[email protected]e0845d5f2012-05-29 00:11:41328 private:
329 net::NetLog* net_log_;
330 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
331};
332
[email protected]abe2c032011-03-31 18:49:34333class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
[email protected]db0e86dd2011-03-16 14:47:21334 public:
335 explicit SystemURLRequestContextGetter(IOThread* io_thread);
[email protected]db0e86dd2011-03-16 14:47:21336
[email protected]abe2c032011-03-31 18:49:34337 // Implementation for net::UrlRequestContextGetter.
[email protected]4969b0122012-06-16 01:58:28338 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
339 virtual scoped_refptr<base::SingleThreadTaskRunner>
340 GetNetworkTaskRunner() const OVERRIDE;
[email protected]db0e86dd2011-03-16 14:47:21341
[email protected]13ed17f82012-04-06 02:27:18342 protected:
343 virtual ~SystemURLRequestContextGetter();
344
[email protected]db0e86dd2011-03-16 14:47:21345 private:
346 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
[email protected]4969b0122012-06-16 01:58:28347 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21348
349 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
350};
351
352SystemURLRequestContextGetter::SystemURLRequestContextGetter(
353 IOThread* io_thread)
354 : io_thread_(io_thread),
[email protected]4969b0122012-06-16 01:58:28355 network_task_runner_(
[email protected]2e5b60a22011-11-28 15:56:41356 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
[email protected]db0e86dd2011-03-16 14:47:21357}
358
359SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
360
361net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]ef2bf422012-05-11 03:27:09363 DCHECK(io_thread_->globals()->system_request_context.get());
[email protected]db0e86dd2011-03-16 14:47:21364
[email protected]ef2bf422012-05-11 03:27:09365 return io_thread_->globals()->system_request_context.get();
[email protected]db0e86dd2011-03-16 14:47:21366}
367
[email protected]4969b0122012-06-16 01:58:28368scoped_refptr<base::SingleThreadTaskRunner>
369SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
370 return network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21371}
372
[email protected]c93123fa2012-04-19 02:49:48373IOThread::Globals::
374SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
375 Globals* globals)
376 : globals_(globals) {
377 DCHECK(globals_);
[email protected]7613faae2012-04-18 01:01:19378}
[email protected]1889dc1b2010-10-14 22:03:13379
[email protected]c93123fa2012-04-19 02:49:48380IOThread::Globals::
381SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {
382 if (globals_->system_request_context.get())
383 globals_->system_request_context->AssertNoURLRequests();
384}
385
386IOThread::Globals::Globals()
[email protected]9c009092013-05-01 03:14:09387 : system_request_context_leak_checker(this),
[email protected]c2dad292012-09-07 21:27:35388 ignore_certificate_errors(false),
389 http_pipelining_enabled(false),
390 testing_fixed_http_port(0),
[email protected]c54c6962013-02-01 04:53:19391 testing_fixed_https_port(0),
392 enable_user_alternate_protocol_ports(false) {
393}
[email protected]c2dad292012-09-07 21:27:35394
[email protected]c93123fa2012-04-19 02:49:48395IOThread::Globals::~Globals() {}
396
[email protected]bcefe0f2010-11-10 16:19:10397// |local_state| is passed in explicitly in order to (1) reduce implicit
398// dependencies and (2) make IOThread more flexible for testing.
[email protected]3ce02412011-03-01 12:01:15399IOThread::IOThread(
[email protected]b1de2c72013-02-06 02:45:47400 PrefService* local_state,
[email protected]77305422012-11-29 16:51:39401 policy::PolicyService* policy_service,
[email protected]3ce02412011-03-01 12:01:15402 ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10403 extensions::EventRouterForwarder* extension_event_router_forwarder)
[email protected]2e5b60a22011-11-28 15:56:41404 : net_log_(net_log),
[email protected]3ce02412011-03-01 12:01:15405 extension_event_router_forwarder_(extension_event_router_forwarder),
[email protected]d13c3272010-02-04 00:24:51406 globals_(NULL),
[email protected]4a109492011-09-24 21:00:12407 sdch_manager_(NULL),
[email protected]77305422012-11-29 16:51:39408 is_spdy_disabled_by_policy_(false),
[email protected]9c009092013-05-01 03:14:09409 weak_factory_(this) {
[email protected]f3318752013-02-04 13:32:51410#if !defined(OS_IOS) && !defined(OS_ANDROID)
[email protected]431ec412013-07-31 06:30:31411#if defined(OS_WIN)
412 if (!win8::IsSingleWindowMetroMode())
413 net::ProxyResolverV8::RememberDefaultIsolate();
414 else
415 net::ProxyResolverV8::CreateIsolate();
416#else
[email protected]a2c1b132013-02-01 12:28:47417 net::ProxyResolverV8::RememberDefaultIsolate();
418#endif
[email protected]431ec412013-07-31 06:30:31419#endif
[email protected]bcefe0f2010-11-10 16:19:10420 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
421 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
422 prefs::kDisableAuthNegotiateCnameLookup);
423 negotiate_enable_port_ = local_state->GetBoolean(
424 prefs::kEnableAuthNegotiatePort);
425 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
426 auth_delegate_whitelist_ = local_state->GetString(
427 prefs::kAuthNegotiateDelegateWhitelist);
[email protected]ac7f3fdb2010-11-12 12:47:05428 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
[email protected]6f96cbcb2011-11-04 02:26:07429 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42430 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
431 local_state));
[email protected]9d8cfb682012-09-13 16:48:04432 ChromeNetworkDelegate::InitializePrefsOnUIThread(
433 &system_enable_referrers_,
434 NULL,
[email protected]d1208ba32012-11-08 11:10:33435 NULL,
[email protected]9d8cfb682012-09-13 16:48:04436 local_state);
[email protected]4d45a6de2011-05-13 05:20:18437 ssl_config_service_manager_.reset(
[email protected]e6d017652013-05-17 18:01:40438 SSLConfigServiceManager::CreateDefaultManager(local_state));
[email protected]2e5b60a22011-11-28 15:56:41439
[email protected]68a9b0d82013-03-08 07:05:07440 base::Value* dns_client_enabled_default = new base::FundamentalValue(
441 chrome_browser_net::ConfigureAsyncDnsFieldTrial());
442 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
443 dns_client_enabled_default);
444
[email protected]fa4b6c32012-11-26 23:02:39445 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
446 local_state,
447 base::Bind(&IOThread::UpdateDnsClientEnabled,
448 base::Unretained(this)));
449 dns_client_enabled_.MoveToThread(
450 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
451
[email protected]77305422012-11-29 16:51:39452#if defined(ENABLE_CONFIGURATION_POLICY)
453 is_spdy_disabled_by_policy_ = policy_service->GetPolicies(
[email protected]2ccf83732013-02-04 20:19:02454 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get(
455 policy::key::kDisableSpdy) != NULL;
[email protected]77305422012-11-29 16:51:39456#endif // ENABLE_CONFIGURATION_POLICY
457
[email protected]2e5b60a22011-11-28 15:56:41458 BrowserThread::SetDelegate(BrowserThread::IO, this);
[email protected]bcefe0f2010-11-10 16:19:10459}
[email protected]0ac83682010-01-22 17:46:27460
461IOThread::~IOThread() {
[email protected]2e5b60a22011-11-28 15:56:41462 // This isn't needed for production code, but in tests, IOThread may
463 // be multiply constructed.
464 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
465
[email protected]d461ed22013-01-18 03:18:56466 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]d13c3272010-02-04 00:24:51467 DCHECK(!globals_);
[email protected]0ac83682010-01-22 17:46:27468}
469
[email protected]d13c3272010-02-04 00:24:51470IOThread::Globals* IOThread::globals() {
[email protected]f8b3ef82010-10-11 02:45:52471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d13c3272010-02-04 00:24:51472 return globals_;
[email protected]0ac83682010-01-22 17:46:27473}
474
[email protected]37ac95b2013-07-23 23:39:35475void IOThread::SetGlobalsForTesting(Globals* globals) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
477 DCHECK(!globals || !globals_);
478 globals_ = globals;
479}
480
[email protected]b2fcd0e2010-12-01 15:19:40481ChromeNetLog* IOThread::net_log() {
482 return net_log_;
483}
484
[email protected]b09f76d62011-12-07 01:51:06485void IOThread::ChangedToOnTheRecord() {
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487 BrowserThread::PostTask(
488 BrowserThread::IO,
489 FROM_HERE,
490 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
491 base::Unretained(this)));
492}
493
[email protected]abe2c032011-03-31 18:49:34494net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
[email protected]db0e86dd2011-03-16 14:47:21495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]5173de8b2013-06-02 21:16:02496 if (!system_url_request_context_getter_.get()) {
[email protected]addb3242011-06-13 21:39:16497 InitSystemRequestContext();
[email protected]db0e86dd2011-03-16 14:47:21498 }
[email protected]5173de8b2013-06-02 21:16:02499 return system_url_request_context_getter_.get();
[email protected]db0e86dd2011-03-16 14:47:21500}
501
[email protected]0ac83682010-01-22 17:46:27502void IOThread::Init() {
[email protected]a5e73b82013-07-17 08:58:39503 // Prefer to use InitAsync unless you need initialization to block
504 // the UI thread
505}
506
507void IOThread::InitAsync() {
508 TRACE_EVENT0("startup", "IOThread::InitAsync");
[email protected]2e5b60a22011-11-28 15:56:41509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]70b92342010-10-12 05:54:06510
[email protected]a592c0432012-12-01 18:10:29511#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09512 net::SetMessageLoopForNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29513#endif
[email protected]70b92342010-10-12 05:54:06514
[email protected]c2dad292012-09-07 21:27:35515 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
516
[email protected]d13c3272010-02-04 00:24:51517 DCHECK(!globals_);
518 globals_ = new Globals;
519
[email protected]58bc7042010-07-07 18:04:14520 // Add an observer that will emit network change events to the ChromeNetLog.
521 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
522 // logging the network change before other IO thread consumers respond to it.
523 network_change_observer_.reset(
[email protected]b2fcd0e2010-12-01 15:19:40524 new LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14525
[email protected]cde8b3c2012-08-13 19:20:52526 // Setup the HistogramWatcher to run on the IO thread.
527 net::NetworkChangeNotifier::InitHistogramWatcher();
528
[email protected]3ce02412011-03-01 12:01:15529 globals_->extension_event_router_forwarder =
530 extension_event_router_forwarder_;
[email protected]a09159a2012-11-29 12:51:48531 ChromeNetworkDelegate* network_delegate =
532 new ChromeNetworkDelegate(extension_event_router_forwarder_,
533 &system_enable_referrers_);
[email protected]3620bbc2013-10-05 05:07:23534 if (command_line.HasSwitch(switches::kEnableClientHints))
535 network_delegate->SetEnableClientHints();
[email protected]c2dad292012-09-07 21:27:35536 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling))
[email protected]a1d4ab072012-06-07 13:21:15537 network_delegate->NeverThrottleRequests();
[email protected]a1d4ab072012-06-07 13:21:15538 globals_->system_network_delegate.reset(network_delegate);
[email protected]c54a8912012-10-22 22:09:43539 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
[email protected]fa4b6c32012-11-26 23:02:39540 UpdateDnsClientEnabled();
[email protected]9f59fac2012-03-21 23:18:11541 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault());
[email protected]f43b89f32012-05-01 19:39:48542 globals_->transport_security_state.reset(new net::TransportSecurityState());
[email protected]284303b62013-11-28 15:11:54543#if !defined(USE_OPENSSL)
544 // For now, Certificate Transparency is only implemented for platforms
545 // that use NSS.
546 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
547 globals_->cert_transparency_verifier.reset(ct_verifier);
548
549 // Add built-in logs
550 ct_verifier->AddLog(net::ct::CreateGooglePilotLogVerifier().Pass());
551 ct_verifier->AddLog(net::ct::CreateGoogleAviatorLogVerifier().Pass());
552 ct_verifier->AddLog(net::ct::CreateGoogleRocketeerLogVerifier().Pass());
553
554 // Add logs from command line
555 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
556 std::string switch_value = command_line.GetSwitchValueASCII(
557 switches::kCertificateTransparencyLog);
558 size_t delim_pos = switch_value.find(":");
559 CHECK(delim_pos != std::string::npos)
560 << "CT log description not provided (switch format"
561 " is 'description:base64_key')";
562 std::string log_description(switch_value.substr(0, delim_pos));
563 std::string ct_public_key_data;
564 CHECK(base::Base64Decode(
565 switch_value.substr(delim_pos + 1),
566 &ct_public_key_data)) << "Unable to decode CT public key.";
567 scoped_ptr<net::CTLogVerifier> external_log_verifier(
568 net::CTLogVerifier::Create(ct_public_key_data, log_description));
569 CHECK(external_log_verifier) << "Unable to parse CT public key.";
570 ct_verifier->AddLog(external_log_verifier.Pass());
571 }
572#else
573 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
574 LOG(DFATAL) << "Certificate Transparency is not yet supported in Chrome "
575 "builds using OpenSSL.";
576 }
577#endif
[email protected]4d45a6de2011-05-13 05:20:18578 globals_->ssl_config_service = GetSSLConfigService();
[email protected]d0389f62013-11-08 06:06:13579#if defined(OS_ANDROID) || defined(OS_IOS)
580 if (DataReductionProxySettings::IsDataReductionProxyAllowed()) {
581 spdyproxy_auth_origins_ =
582 DataReductionProxySettings::GetDataReductionProxies();
[email protected]ec44ee02012-09-28 21:31:51583 }
[email protected]d0389f62013-11-08 06:06:13584#endif // defined(OS_ANDROID) || defined(OS_IOS)
[email protected]65d34382010-07-01 18:12:26585 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
[email protected]73c45322010-10-01 23:57:54586 globals_->host_resolver.get()));
[email protected]30d4c022013-07-18 22:58:16587 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
[email protected]2fb629202010-12-23 23:52:57588 // For the ProxyScriptFetcher, we use a direct ProxyService.
[email protected]6104ea5d2011-04-27 21:37:12589 globals_->proxy_script_fetcher_proxy_service.reset(
590 net::ProxyService::CreateDirectWithNetLog(net_log_));
[email protected]273e37d2011-08-11 01:49:12591 // In-memory cookie store.
[email protected]33ad6ce92013-08-27 14:39:08592 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL);
[email protected]9c4eff22012-03-20 22:42:29593 // In-memory server bound cert store.
594 globals_->system_server_bound_cert_service.reset(
595 new net::ServerBoundCertService(
[email protected]5bab49ec2012-05-04 21:13:19596 new net::DefaultServerBoundCertStore(NULL),
597 base::WorkerPool::GetTaskRunner(true)));
[email protected]4588b3d2012-11-14 00:37:38598 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
[email protected]a9e0d1412012-08-20 22:13:01599 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats());
[email protected]c2dad292012-09-07 21:27:35600 globals_->host_mapping_rules.reset(new net::HostMappingRules());
[email protected]ee4c30d2012-11-07 15:08:43601 globals_->http_user_agent_settings.reset(
[email protected]84f05432013-03-15 01:00:12602 new BasicHttpUserAgentSettings(std::string()));
[email protected]c2dad292012-09-07 21:27:35603 if (command_line.HasSwitch(switches::kHostRules)) {
[email protected]a5e73b82013-07-17 08:58:39604 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35605 globals_->host_mapping_rules->SetRulesFromString(
606 command_line.GetSwitchValueASCII(switches::kHostRules));
[email protected]a5e73b82013-07-17 08:58:39607 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35608 }
609 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
610 globals_->ignore_certificate_errors = true;
[email protected]c2dad292012-09-07 21:27:35611 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
[email protected]f9cf5572012-12-04 15:52:09612 globals_->testing_fixed_http_port =
613 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
[email protected]c2dad292012-09-07 21:27:35614 }
615 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
[email protected]f9cf5572012-12-04 15:52:09616 globals_->testing_fixed_https_port =
617 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
[email protected]c2dad292012-09-07 21:27:35618 }
[email protected]256fe9b2013-11-27 01:58:02619 ConfigureQuic(command_line);
[email protected]c54c6962013-02-01 04:53:19620 if (command_line.HasSwitch(
621 switches::kEnableUserAlternateProtocolPorts)) {
622 globals_->enable_user_alternate_protocol_ports = true;
623 }
[email protected]f9cf5572012-12-04 15:52:09624 InitializeNetworkOptions(command_line);
625
[email protected]9e1bdd32011-02-03 21:48:34626 net::HttpNetworkSession::Params session_params;
[email protected]f9cf5572012-12-04 15:52:09627 InitializeNetworkSessionParams(&session_params);
[email protected]27c253802012-11-30 08:18:12628 session_params.net_log = net_log_;
[email protected]9e1bdd32011-02-03 21:48:34629 session_params.proxy_service =
630 globals_->proxy_script_fetcher_proxy_service.get();
[email protected]c2dad292012-09-07 21:27:35631
[email protected]a5e73b82013-07-17 08:58:39632 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:HttpNetworkSession");
[email protected]57cb0f72011-01-28 06:33:58633 scoped_refptr<net::HttpNetworkSession> network_session(
[email protected]9e1bdd32011-02-03 21:48:34634 new net::HttpNetworkSession(session_params));
[email protected]5173de8b2013-06-02 21:16:02635 globals_->proxy_script_fetcher_http_transaction_factory
636 .reset(new net::HttpNetworkLayer(network_session.get()));
[email protected]a5e73b82013-07-17 08:58:39637 TRACE_EVENT_END0("startup", "IOThread::InitAsync:HttpNetworkSession");
[email protected]b3ae2db2013-05-30 05:00:05638 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
639 new net::URLRequestJobFactoryImpl());
640 job_factory->SetProtocolHandler(chrome::kDataScheme,
641 new net::DataProtocolHandler());
[email protected]255620da2013-08-19 13:14:29642 job_factory->SetProtocolHandler(
643 chrome::kFileScheme,
644 new net::FileProtocolHandler(
645 content::BrowserThread::GetBlockingPool()->
646 GetTaskRunnerWithShutdownBehavior(
647 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
[email protected]b3ae2db2013-05-30 05:00:05648#if !defined(DISABLE_FTP_SUPPORT)
649 globals_->proxy_script_fetcher_ftp_transaction_factory.reset(
650 new net::FtpNetworkLayer(globals_->host_resolver.get()));
651 job_factory->SetProtocolHandler(
652 chrome::kFtpScheme,
653 new net::FtpProtocolHandler(
654 globals_->proxy_script_fetcher_ftp_transaction_factory.get()));
655#endif
656 globals_->proxy_script_fetcher_url_request_job_factory =
657 job_factory.PassAs<net::URLRequestJobFactory>();
[email protected]2fb629202010-12-23 23:52:57658
[email protected]a73a2802012-05-02 19:20:15659 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager());
[email protected]a1d4ab072012-06-07 13:21:15660 globals_->throttler_manager->set_net_log(net_log_);
[email protected]332a8c962013-07-17 22:31:23661 // Always done in production, disabled only for unit tests.
662 globals_->throttler_manager->set_enable_thread_checks(true);
[email protected]a73a2802012-05-02 19:20:15663
[email protected]ef2bf422012-05-11 03:27:09664 globals_->proxy_script_fetcher_context.reset(
665 ConstructProxyScriptFetcherContext(globals_, net_log_));
[email protected]4a109492011-09-24 21:00:12666
[email protected]daae3462013-04-30 03:45:14667 globals_->network_time_notifier.reset(
668 new net::NetworkTimeNotifier(
669 scoped_ptr<base::TickClock>(new base::DefaultTickClock())));
670
[email protected]4a109492011-09-24 21:00:12671 sdch_manager_ = new net::SdchManager();
[email protected]2e5b60a22011-11-28 15:56:41672
[email protected]11f5e3a2012-09-27 00:30:13673#if defined(OS_MACOSX) && !defined(OS_IOS)
674 // Start observing Keychain events. This needs to be done on the UI thread,
675 // as Keychain services requires a CFRunLoop.
676 BrowserThread::PostTask(BrowserThread::UI,
677 FROM_HERE,
678 base::Bind(&ObserveKeychainEvents));
679#endif
680
[email protected]2e5b60a22011-11-28 15:56:41681 // InitSystemRequestContext turns right around and posts a task back
682 // to the IO thread, so we can't let it run until we know the IO
683 // thread has started.
684 //
685 // Note that since we are at BrowserThread::Init time, the UI thread
686 // is blocked waiting for the thread to start. Therefore, posting
687 // this task to the main thread's message loop here is guaranteed to
688 // get it onto the message loop while the IOThread object still
689 // exists. However, the message might not be processed on the UI
690 // thread until after IOThread is gone, so use a weak pointer.
691 BrowserThread::PostTask(BrowserThread::UI,
692 FROM_HERE,
693 base::Bind(&IOThread::InitSystemRequestContext,
694 weak_factory_.GetWeakPtr()));
[email protected]0ac83682010-01-22 17:46:27695}
696
[email protected]2a92cd92010-04-27 00:01:41697void IOThread::CleanUp() {
[email protected]075c0322012-02-14 00:56:44698 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
699
[email protected]4a109492011-09-24 21:00:12700 delete sdch_manager_;
701 sdch_manager_ = NULL;
702
[email protected]a592c0432012-12-01 18:10:29703#if defined(USE_NSS) || defined(OS_IOS)
[email protected]8c434cbc2012-03-14 14:25:09704 net::ShutdownNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29705#endif
[email protected]59a3b362010-10-21 21:52:41706
[email protected]db0e86dd2011-03-16 14:47:21707 system_url_request_context_getter_ = NULL;
708
[email protected]af669932012-01-17 19:26:58709 // Release objects that the net::URLRequestContext could have been pointing
710 // to.
[email protected]0ee7a3b2010-11-09 06:13:40711
712 // This must be reset before the ChromeNetLog is destroyed.
713 network_change_observer_.reset();
714
[email protected]db0e86dd2011-03-16 14:47:21715 system_proxy_config_service_.reset();
716
[email protected]d13c3272010-02-04 00:24:51717 delete globals_;
718 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27719
[email protected]db0e86dd2011-03-16 14:47:21720 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27721}
722
[email protected]f9cf5572012-12-04 15:52:09723void IOThread::InitializeNetworkOptions(const CommandLine& command_line) {
[email protected]33ad6ce92013-08-27 14:39:08724 if (command_line.HasSwitch(switches::kEnableFileCookies)) {
725 // Enable cookie storage for file:// URLs. Must do this before the first
726 // Profile (and therefore the first CookieMonster) is created.
727 net::CookieMonster::EnableFileScheme();
728 }
729
[email protected]aedf781f2013-07-15 21:38:15730 // Only handle use-spdy command line flags if "spdy.disabled" preference is
731 // not disabled via policy.
[email protected]aedfccd9b2013-10-02 03:24:46732 if (is_spdy_disabled_by_policy_) {
733 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName);
734 if (trial)
735 trial->Disable();
736 } else {
737 std::string spdy_trial_group =
738 base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
739
[email protected]aedf781f2013-07-15 21:38:15740 if (command_line.HasSwitch(switches::kEnableIPPooling))
741 globals_->enable_spdy_ip_pooling.set(true);
[email protected]77305422012-11-29 16:51:39742
[email protected]aedf781f2013-07-15 21:38:15743 if (command_line.HasSwitch(switches::kDisableIPPooling))
744 globals_->enable_spdy_ip_pooling.set(false);
[email protected]77305422012-11-29 16:51:39745
[email protected]aedf781f2013-07-15 21:38:15746 if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) {
747 // Enable WebSocket over SPDY.
748 net::WebSocketJob::set_websocket_over_spdy_enabled(true);
749 }
[email protected]aedfccd9b2013-10-02 03:24:46750
[email protected]aedf781f2013-07-15 21:38:15751 if (command_line.HasSwitch(switches::kMaxSpdyConcurrentStreams)) {
752 globals_->max_spdy_concurrent_streams_limit.set(
753 GetSwitchValueAsInt(command_line,
754 switches::kMaxSpdyConcurrentStreams));
755 }
756 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
757 globals_->trusted_spdy_proxy.set(
758 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy));
759 }
760 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
761 net::URLFetcher::SetIgnoreCertificateRequests(true);
[email protected]77305422012-11-29 16:51:39762
[email protected]aedf781f2013-07-15 21:38:15763 if (command_line.HasSwitch(switches::kUseSpdy)) {
764 std::string spdy_mode =
765 command_line.GetSwitchValueASCII(switches::kUseSpdy);
766 EnableSpdy(spdy_mode);
[email protected]88a332622013-07-30 07:13:32767 } else if (command_line.HasSwitch(switches::kEnableHttp2Draft04)) {
768 net::HttpStreamFactory::EnableNpnHttp2Draft04();
[email protected]aedf781f2013-07-15 21:38:15769 } else if (command_line.HasSwitch(switches::kEnableSpdy4a2)) {
770 net::HttpStreamFactory::EnableNpnSpdy4a2();
771 } else if (command_line.HasSwitch(switches::kDisableSpdy31)) {
772 net::HttpStreamFactory::EnableNpnSpdy3();
[email protected]11011522013-11-19 02:18:15773 } else if (command_line.HasSwitch(switches::kEnableSpdy2)) {
774 net::HttpStreamFactory::EnableNpnSpdy31WithSpdy2();
[email protected]aedf781f2013-07-15 21:38:15775 } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) {
776 net::HttpStreamFactory::EnableNpnHttpOnly();
777 } else {
[email protected]aedfccd9b2013-10-02 03:24:46778 if (spdy_trial_group == kSpdyFieldTrialDisabledGroupName &&
779 !command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) {
780 net::HttpStreamFactory::set_spdy_enabled(false);
781 } else {
782 // Use SPDY/3.1 by default.
[email protected]11011522013-11-19 02:18:15783 net::HttpStreamFactory::EnableNpnSpdy31();
[email protected]aedfccd9b2013-10-02 03:24:46784 }
[email protected]aedf781f2013-07-15 21:38:15785 }
[email protected]77305422012-11-29 16:51:39786 }
[email protected]717e4e22013-04-10 20:52:23787
788 // TODO(rch): Make the client socket factory a per-network session
789 // instance, constructed from a NetworkSession::Params, to allow us
790 // to move this option to IOThread::Globals &
791 // HttpNetworkSession::Params.
792 if (command_line.HasSwitch(switches::kEnableTcpFastOpen))
793 net::SetTCPFastOpenEnabled(true);
[email protected]77305422012-11-29 16:51:39794}
795
[email protected]443a30ed2012-11-30 02:56:46796void IOThread::EnableSpdy(const std::string& mode) {
797 static const char kOff[] = "off";
798 static const char kSSL[] = "ssl";
799 static const char kDisableSSL[] = "no-ssl";
800 static const char kDisablePing[] = "no-ping";
801 static const char kExclude[] = "exclude"; // Hosts to exclude
802 static const char kDisableCompression[] = "no-compress";
803 static const char kDisableAltProtocols[] = "no-alt-protocols";
804 static const char kForceAltProtocols[] = "force-alt-protocols";
805 static const char kSingleDomain[] = "single-domain";
806
807 static const char kInitialMaxConcurrentStreams[] = "init-max-streams";
808
809 std::vector<std::string> spdy_options;
810 base::SplitString(mode, ',', &spdy_options);
811
812 for (std::vector<std::string>::iterator it = spdy_options.begin();
813 it != spdy_options.end(); ++it) {
814 const std::string& element = *it;
815 std::vector<std::string> name_value;
816 base::SplitString(element, '=', &name_value);
[email protected]007b3f82013-04-09 08:46:45817 const std::string& option =
818 name_value.size() > 0 ? name_value[0] : std::string();
819 const std::string value =
820 name_value.size() > 1 ? name_value[1] : std::string();
[email protected]443a30ed2012-11-30 02:56:46821
822 if (option == kOff) {
823 net::HttpStreamFactory::set_spdy_enabled(false);
824 } else if (option == kDisableSSL) {
[email protected]b05bcaa32013-10-06 05:26:02825 globals_->spdy_default_protocol.set(net::kProtoSPDY3);
[email protected]443a30ed2012-11-30 02:56:46826 net::HttpStreamFactory::set_force_spdy_over_ssl(false);
827 net::HttpStreamFactory::set_force_spdy_always(true);
828 } else if (option == kSSL) {
[email protected]b05bcaa32013-10-06 05:26:02829 globals_->spdy_default_protocol.set(net::kProtoSPDY3);
[email protected]443a30ed2012-11-30 02:56:46830 net::HttpStreamFactory::set_force_spdy_over_ssl(true);
831 net::HttpStreamFactory::set_force_spdy_always(true);
832 } else if (option == kDisablePing) {
[email protected]f9cf5572012-12-04 15:52:09833 globals_->enable_spdy_ping_based_connection_checking.set(false);
[email protected]443a30ed2012-11-30 02:56:46834 } else if (option == kExclude) {
835 net::HttpStreamFactory::add_forced_spdy_exclusion(value);
836 } else if (option == kDisableCompression) {
[email protected]f9cf5572012-12-04 15:52:09837 globals_->enable_spdy_compression.set(false);
[email protected]443a30ed2012-11-30 02:56:46838 } else if (option == kDisableAltProtocols) {
839 net::HttpStreamFactory::set_use_alternate_protocols(false);
840 } else if (option == kForceAltProtocols) {
841 net::PortAlternateProtocolPair pair;
842 pair.port = 443;
[email protected]b05bcaa32013-10-06 05:26:02843 pair.protocol = net::NPN_SPDY_3;
[email protected]443a30ed2012-11-30 02:56:46844 net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair);
845 } else if (option == kSingleDomain) {
[email protected]256fe9b2013-11-27 01:58:02846 DVLOG(1) << "FORCING SINGLE DOMAIN";
[email protected]f9cf5572012-12-04 15:52:09847 globals_->force_spdy_single_domain.set(true);
[email protected]443a30ed2012-11-30 02:56:46848 } else if (option == kInitialMaxConcurrentStreams) {
849 int streams;
[email protected]f9cf5572012-12-04 15:52:09850 if (base::StringToInt(value, &streams))
851 globals_->initial_max_spdy_concurrent_streams.set(streams);
[email protected]443a30ed2012-11-30 02:56:46852 } else if (option.empty() && it == spdy_options.begin()) {
853 continue;
854 } else {
855 LOG(DFATAL) << "Unrecognized spdy option: " << option;
856 }
857 }
858}
859
[email protected]bcefe0f2010-11-10 16:19:10860// static
[email protected]b1de2c72013-02-06 02:45:47861void IOThread::RegisterPrefs(PrefRegistrySimple* registry) {
862 registry->RegisterStringPref(prefs::kAuthSchemes,
863 "basic,digest,ntlm,negotiate,"
864 "spdyproxy");
[email protected]68a9b0d82013-03-08 07:05:07865 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
[email protected]b1de2c72013-02-06 02:45:47866 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
[email protected]007b3f82013-04-09 08:46:45867 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
868 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
869 std::string());
870 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
871 registry->RegisterStringPref(prefs::kSpdyProxyAuthOrigin, std::string());
[email protected]b1de2c72013-02-06 02:45:47872 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
873 registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0);
874 registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0);
[email protected]eac11e12013-03-19 22:04:32875#if defined(OS_ANDROID) || defined(OS_IOS)
876 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
877 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
[email protected]2db93e42013-08-07 17:40:41878 registry->RegisterListPref(
[email protected]0d36d1e2013-09-24 04:25:28879 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled);
[email protected]2db93e42013-08-07 17:40:41880 registry->RegisterListPref(
[email protected]0d36d1e2013-09-24 04:25:28881 prefs::kDailyContentLengthWithDataReductionProxyEnabled);
882 registry->RegisterListPref(
883 prefs::kDailyOriginalContentLengthViaDataReductionProxy);
884 registry->RegisterListPref(
885 prefs::kDailyContentLengthViaDataReductionProxy);
[email protected]eac11e12013-03-19 22:04:32886 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
887#endif
[email protected]68a9b0d82013-03-08 07:05:07888 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
[email protected]bcefe0f2010-11-10 16:19:10889}
890
[email protected]65d34382010-07-01 18:12:26891net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
892 net::HostResolver* resolver) {
[email protected]9030a632010-11-19 20:12:09893 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL;
894 if (!auth_server_whitelist_.empty()) {
895 auth_filter_default_credentials =
896 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
897 }
898 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
899 if (!auth_delegate_whitelist_.empty()) {
900 auth_filter_delegate =
901 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_);
902 }
[email protected]b4955e7d2010-04-16 20:22:30903 globals_->url_security_manager.reset(
[email protected]d201b200e2010-08-27 17:35:02904 net::URLSecurityManager::Create(auth_filter_default_credentials,
905 auth_filter_delegate));
[email protected]b7304162010-08-23 17:42:29906 std::vector<std::string> supported_schemes;
[email protected]bcefe0f2010-11-10 16:19:10907 base::SplitString(auth_schemes_, ',', &supported_schemes);
[email protected]b7304162010-08-23 17:42:29908
[email protected]ec44ee02012-09-28 21:31:51909 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory(
910 net::HttpAuthHandlerRegistryFactory::Create(
911 supported_schemes, globals_->url_security_manager.get(),
912 resolver, gssapi_library_name_, negotiate_disable_cname_lookup_,
913 negotiate_enable_port_));
914
[email protected]d0389f62013-11-08 06:06:13915 if (!spdyproxy_auth_origins_.empty()) {
916 registry_factory->RegisterSchemeFactory(
917 "spdyproxy",
918 new spdyproxy::HttpAuthHandlerSpdyProxy::Factory(
919 spdyproxy_auth_origins_));
[email protected]ec44ee02012-09-28 21:31:51920 }
921
922 return registry_factory.release();
[email protected]eb3cac72010-02-26 21:07:45923}
924
[email protected]d6f37fc2011-02-13 23:58:41925void IOThread::ClearHostCache() {
926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
927
[email protected]489d1a82011-10-12 03:09:11928 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
929 if (host_cache)
930 host_cache->clear();
[email protected]0ac83682010-01-22 17:46:27931}
[email protected]db0e86dd2011-03-16 14:47:21932
[email protected]f9cf5572012-12-04 15:52:09933void IOThread::InitializeNetworkSessionParams(
934 net::HttpNetworkSession::Params* params) {
935 params->host_resolver = globals_->host_resolver.get();
936 params->cert_verifier = globals_->cert_verifier.get();
937 params->server_bound_cert_service =
938 globals_->system_server_bound_cert_service.get();
939 params->transport_security_state = globals_->transport_security_state.get();
940 params->ssl_config_service = globals_->ssl_config_service.get();
941 params->http_auth_handler_factory = globals_->http_auth_handler_factory.get();
[email protected]30d4c022013-07-18 22:58:16942 params->http_server_properties =
943 globals_->http_server_properties->GetWeakPtr();
[email protected]f9cf5572012-12-04 15:52:09944 params->network_delegate = globals_->system_network_delegate.get();
945 params->host_mapping_rules = globals_->host_mapping_rules.get();
946 params->ignore_certificate_errors = globals_->ignore_certificate_errors;
947 params->http_pipelining_enabled = globals_->http_pipelining_enabled;
948 params->testing_fixed_http_port = globals_->testing_fixed_http_port;
949 params->testing_fixed_https_port = globals_->testing_fixed_https_port;
950
[email protected]f9cf5572012-12-04 15:52:09951 globals_->initial_max_spdy_concurrent_streams.CopyToIfSet(
952 &params->spdy_initial_max_concurrent_streams);
953 globals_->max_spdy_concurrent_streams_limit.CopyToIfSet(
954 &params->spdy_max_concurrent_streams_limit);
955 globals_->force_spdy_single_domain.CopyToIfSet(
956 &params->force_spdy_single_domain);
957 globals_->enable_spdy_ip_pooling.CopyToIfSet(
958 &params->enable_spdy_ip_pooling);
[email protected]f9cf5572012-12-04 15:52:09959 globals_->enable_spdy_compression.CopyToIfSet(
960 &params->enable_spdy_compression);
961 globals_->enable_spdy_ping_based_connection_checking.CopyToIfSet(
962 &params->enable_spdy_ping_based_connection_checking);
963 globals_->spdy_default_protocol.CopyToIfSet(
964 &params->spdy_default_protocol);
[email protected]26615ae2013-06-13 17:50:59965 globals_->trusted_spdy_proxy.CopyToIfSet(
966 &params->trusted_spdy_proxy);
[email protected]b559b132013-01-29 22:13:32967 globals_->enable_quic.CopyToIfSet(&params->enable_quic);
[email protected]eb8f88e2013-07-15 09:52:17968 globals_->enable_quic_https.CopyToIfSet(&params->enable_quic_https);
[email protected]256fe9b2013-11-27 01:58:02969 globals_->quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length);
[email protected]49e85332013-06-04 04:18:03970 globals_->origin_to_force_quic_on.CopyToIfSet(
971 &params->origin_to_force_quic_on);
[email protected]c54c6962013-02-01 04:53:19972 params->enable_user_alternate_protocol_ports =
973 globals_->enable_user_alternate_protocol_ports;
[email protected]f9cf5572012-12-04 15:52:09974}
975
[email protected]4d45a6de2011-05-13 05:20:18976net::SSLConfigService* IOThread::GetSSLConfigService() {
977 return ssl_config_service_manager_->Get();
978}
979
[email protected]b09f76d62011-12-07 01:51:06980void IOThread::ChangedToOnTheRecordOnIOThread() {
981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
982
983 // Clear the host cache to avoid showing entries from the OTR session
984 // in about:net-internals.
985 ClearHostCache();
[email protected]b09f76d62011-12-07 01:51:06986}
987
[email protected]db0e86dd2011-03-16 14:47:21988void IOThread::InitSystemRequestContext() {
[email protected]5173de8b2013-06-02 21:16:02989 if (system_url_request_context_getter_.get())
[email protected]addb3242011-06-13 21:39:16990 return;
[email protected]63e26822011-07-16 19:07:35991 // If we're in unit_tests, IOThread may not be run.
[email protected]dd483702011-12-02 14:47:42992 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
[email protected]63e26822011-07-16 19:07:35993 return;
[email protected]53c5b0f2013-07-22 10:54:11994 system_proxy_config_service_.reset(
995 ProxyServiceFactory::CreateProxyConfigService(
996 pref_proxy_config_tracker_.get()));
[email protected]addb3242011-06-13 21:39:16997 system_url_request_context_getter_ =
998 new SystemURLRequestContextGetter(this);
[email protected]2e5b60a22011-11-28 15:56:41999 // Safe to post an unretained this pointer, since IOThread is
1000 // guaranteed to outlive the IO BrowserThread.
[email protected]dd483702011-12-02 14:47:421001 BrowserThread::PostTask(
1002 BrowserThread::IO,
1003 FROM_HERE,
1004 base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
1005 base::Unretained(this)));
[email protected]addb3242011-06-13 21:39:161006}
1007
1008void IOThread::InitSystemRequestContextOnIOThread() {
[email protected]db0e86dd2011-03-16 14:47:211009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]6104ea5d2011-04-27 21:37:121010 DCHECK(!globals_->system_proxy_service.get());
[email protected]db0e86dd2011-03-16 14:47:211011 DCHECK(system_proxy_config_service_.get());
1012
1013 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]6104ea5d2011-04-27 21:37:121014 globals_->system_proxy_service.reset(
[email protected]db0e86dd2011-03-16 14:47:211015 ProxyServiceFactory::CreateProxyService(
1016 net_log_,
[email protected]ef2bf422012-05-11 03:27:091017 globals_->proxy_script_fetcher_context.get(),
[email protected]8def32a02013-03-11 19:13:231018 globals_->system_network_delegate.get(),
[email protected]db0e86dd2011-03-16 14:47:211019 system_proxy_config_service_.release(),
[email protected]6104ea5d2011-04-27 21:37:121020 command_line));
[email protected]c2dad292012-09-07 21:27:351021
[email protected]db0e86dd2011-03-16 14:47:211022 net::HttpNetworkSession::Params system_params;
[email protected]f9cf5572012-12-04 15:52:091023 InitializeNetworkSessionParams(&system_params);
[email protected]db0e86dd2011-03-16 14:47:211024 system_params.net_log = net_log_;
[email protected]27c253802012-11-30 08:18:121025 system_params.proxy_service = globals_->system_proxy_service.get();
[email protected]c2dad292012-09-07 21:27:351026
[email protected]db0e86dd2011-03-16 14:47:211027 globals_->system_http_transaction_factory.reset(
1028 new net::HttpNetworkLayer(
1029 new net::HttpNetworkSession(system_params)));
[email protected]ef2bf422012-05-11 03:27:091030 globals_->system_request_context.reset(
1031 ConstructSystemRequestContext(globals_, net_log_));
[email protected]d24fc3a02012-02-11 02:08:341032
1033 sdch_manager_->set_sdch_fetcher(
1034 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
[email protected]db0e86dd2011-03-16 14:47:211035}
[email protected]fa4b6c32012-11-26 23:02:391036
1037void IOThread::UpdateDnsClientEnabled() {
1038 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
1039}
[email protected]903e63382013-06-01 00:40:581040
[email protected]256fe9b2013-11-27 01:58:021041void IOThread::ConfigureQuic(const CommandLine& command_line) {
[email protected]903e63382013-06-01 00:40:581042 // Always fetch the field trial group to ensure it is reported correctly.
1043 // The command line flags will be associated with a group that is reported
1044 // so long as trial is actually queried.
1045 std::string quic_trial_group =
1046 base::FieldTrialList::FindFullName(kQuicFieldTrialName);
1047
[email protected]256fe9b2013-11-27 01:58:021048 bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group);
1049 globals_->enable_quic.set(enable_quic);
1050 if (enable_quic) {
1051 globals_->enable_quic_https.set(
1052 ShouldEnableQuicHttps(command_line, quic_trial_group));
1053 }
1054
1055 size_t max_packet_length = GetQuicMaxPacketLength(command_line,
1056 quic_trial_group);
1057 if (max_packet_length != 0) {
1058 globals_->quic_max_packet_length.set(max_packet_length);
1059 }
1060
1061 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
1062 net::HostPortPair quic_origin =
1063 net::HostPortPair::FromString(
1064 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
1065 if (!quic_origin.IsEmpty()) {
1066 globals_->origin_to_force_quic_on.set(quic_origin);
1067 }
1068 }
1069}
1070
1071bool IOThread::ShouldEnableQuic(const CommandLine& command_line,
1072 base::StringPiece quic_trial_group) {
[email protected]903e63382013-06-01 00:40:581073 if (command_line.HasSwitch(switches::kDisableQuic))
1074 return false;
1075
[email protected]a64b213e2013-07-24 21:41:001076 if (command_line.HasSwitch(switches::kEnableQuic))
[email protected]903e63382013-06-01 00:40:581077 return true;
1078
[email protected]256fe9b2013-11-27 01:58:021079 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) ||
1080 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
[email protected]a64b213e2013-07-24 21:41:001081}
1082
[email protected]256fe9b2013-11-27 01:58:021083bool IOThread::ShouldEnableQuicHttps(const CommandLine& command_line,
1084 base::StringPiece quic_trial_group) {
[email protected]a64b213e2013-07-24 21:41:001085 if (command_line.HasSwitch(switches::kDisableQuicHttps))
1086 return false;
1087
1088 if (command_line.HasSwitch(switches::kEnableQuicHttps))
1089 return true;
1090
[email protected]256fe9b2013-11-27 01:58:021091 return quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
1092}
1093
1094size_t IOThread::GetQuicMaxPacketLength(const CommandLine& command_line,
1095 base::StringPiece quic_trial_group) {
1096 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
1097 unsigned value;
1098 if (!base::StringToUint(
1099 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
1100 &value)) {
1101 return 0;
1102 }
1103 return value;
1104 }
1105
1106 // Format of the packet length group names is:
1107 // (Https)?Enabled<length>BytePackets.
1108 base::StringPiece length_str(quic_trial_group);
1109 if (length_str.starts_with(kQuicFieldTrialEnabledGroupName)) {
1110 length_str.remove_prefix(strlen(kQuicFieldTrialEnabledGroupName));
1111 } else if (length_str.starts_with(kQuicFieldTrialHttpsEnabledGroupName)) {
1112 length_str.remove_prefix(strlen(kQuicFieldTrialHttpsEnabledGroupName));
1113 } else {
1114 return 0;
1115 }
1116 if (!length_str.ends_with(kQuicFieldTrialPacketLengthSuffix)) {
1117 return 0;
1118 }
1119 length_str.remove_suffix(strlen(kQuicFieldTrialPacketLengthSuffix));
1120 unsigned value;
1121 if (!base::StringToUint(length_str, &value)) {
1122 return 0;
1123 }
1124 return value;
[email protected]903e63382013-06-01 00:40:581125}