[email protected] | d24fc3a0 | 2012-02-11 02:08:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 2 | // 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] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 6 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame^] | 9 | #include "base/base64.h" |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 10 | #include "base/bind.h" |
| 11 | #include "base/bind_helpers.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 14 | #include "base/debug/leak_tracker.h" |
[email protected] | d22f06e | 2013-06-11 16:01:17 | [diff] [blame] | 15 | #include "base/debug/trace_event.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 16 | #include "base/logging.h" |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 17 | #include "base/metrics/field_trial.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 18 | #include "base/prefs/pref_registry_simple.h" |
| 19 | #include "base/prefs/pref_service.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 20 | #include "base/stl_util.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 21 | #include "base/strings/string_number_conversions.h" |
[email protected] | 1988e1c | 2013-02-28 20:27:42 | [diff] [blame] | 22 | #include "base/strings/string_split.h" |
[email protected] | 9c7ddc9 | 2013-06-11 01:40:57 | [diff] [blame] | 23 | #include "base/strings/string_util.h" |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 24 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 3fc40c14 | 2011-12-01 13:09:04 | [diff] [blame] | 25 | #include "base/threading/thread.h" |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 26 | #include "base/threading/worker_pool.h" |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 27 | #include "base/time/default_tick_clock.h" |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 28 | #include "build/build_config.h" |
[email protected] | df2840d | 2011-02-20 16:32:32 | [diff] [blame] | 29 | #include "chrome/browser/browser_process.h" |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 30 | #include "chrome/browser/extensions/event_router_forwarder.h" |
[email protected] | 026876f3 | 2012-08-22 23:53:40 | [diff] [blame] | 31 | #include "chrome/browser/net/async_dns_field_trial.h" |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 32 | #include "chrome/browser/net/basic_http_user_agent_settings.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 33 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 34 | #include "chrome/browser/net/chrome_network_delegate.h" |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 35 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 36 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 37 | #include "chrome/browser/net/dns_probe_service.h" |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 38 | #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
[email protected] | a9e0d141 | 2012-08-20 22:13:01 | [diff] [blame] | 39 | #include "chrome/browser/net/load_time_stats.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 40 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 41 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 42 | #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 43 | #include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 44 | #include "chrome/browser/policy/policy_service.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 45 | #include "chrome/common/chrome_switches.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 46 | #include "chrome/common/pref_names.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 47 | #include "chrome/common/url_constants.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 48 | #include "content/public/browser/browser_thread.h" |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 49 | #include "net/base/host_mapping_rules.h" |
[email protected] | 32eaa33 | 2010-02-08 22:15:54 | [diff] [blame] | 50 | #include "net/base/net_util.h" |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 51 | #include "net/base/network_time_notifier.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 52 | #include "net/base/sdch_manager.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 53 | #include "net/cert/cert_verifier.h" |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame^] | 54 | #include "net/cert/ct_known_logs.h" |
| 55 | #include "net/cert/ct_verifier.h" |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 56 | #include "net/cookies/cookie_monster.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 57 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 58 | #include "net/dns/host_resolver.h" |
| 59 | #include "net/dns/mapped_host_resolver.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 60 | #include "net/ftp/ftp_network_layer.h" |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 61 | #include "net/http/http_auth_filter.h" |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 62 | #include "net/http/http_auth_handler_factory.h" |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 63 | #include "net/http/http_network_layer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 64 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 65 | #include "net/proxy/proxy_config_service.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 66 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 67 | #include "net/proxy/proxy_service.h" |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 68 | #include "net/socket/tcp_client_socket.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 69 | #include "net/spdy/spdy_session.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 70 | #include "net/ssl/default_server_bound_cert_store.h" |
| 71 | #include "net/ssl/server_bound_cert_service.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 72 | #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] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 75 | #include "net/url_request/url_fetcher.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 76 | #include "net/url_request/url_request_job_factory_impl.h" |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 77 | #include "net/url_request/url_request_throttler_manager.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 78 | #include "net/websockets/websocket_job.h" |
| 79 | |
[email protected] | 431ec41 | 2013-07-31 06:30:31 | [diff] [blame] | 80 | #if defined(OS_WIN) |
| 81 | #include "win8/util/win8_util.h" |
| 82 | #endif |
| 83 | |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 84 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 85 | #include "policy/policy_constants.h" |
| 86 | #endif |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 87 | |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame^] | 88 | #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] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 93 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 94 | #include "net/ocsp/nss_ocsp.h" |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 95 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 96 | |
[email protected] | f331875 | 2013-02-04 13:32:51 | [diff] [blame] | 97 | #if !defined(OS_IOS) && !defined(OS_ANDROID) |
[email protected] | a2c1b13 | 2013-02-01 12:28:47 | [diff] [blame] | 98 | #include "net/proxy/proxy_resolver_v8.h" |
| 99 | #endif |
| 100 | |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 101 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 102 | #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" |
| 103 | #endif |
| 104 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 105 | using content::BrowserThread; |
| 106 | |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 107 | class SafeBrowsingURLRequestContext; |
| 108 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 109 | // 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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 112 | namespace { |
| 113 | |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 114 | const char kQuicFieldTrialName[] = "QUIC"; |
| 115 | const char kQuicFieldTrialEnabledGroupName[] = "Enabled"; |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 116 | const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled"; |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 117 | const char kQuicFieldTrialPacketLengthSuffix[] = "BytePackets"; |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 118 | |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 119 | const char kSpdyFieldTrialName[] = "SPDY"; |
| 120 | const char kSpdyFieldTrialDisabledGroupName[] = "SpdyDisabled"; |
| 121 | |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 122 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 123 | void ObserveKeychainEvents() { |
| 124 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 125 | net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); |
| 126 | } |
| 127 | #endif |
| 128 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 129 | // Used for the "system" URLRequestContext. |
| 130 | class SystemURLRequestContext : public net::URLRequestContext { |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 131 | public: |
| 132 | SystemURLRequestContext() { |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 133 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 134 | net::SetURLRequestContextForNSSHttpIO(this); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 135 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | private: |
| 139 | virtual ~SystemURLRequestContext() { |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 140 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 141 | net::SetURLRequestContextForNSSHttpIO(NULL); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 142 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 143 | } |
| 144 | }; |
| 145 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 146 | scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { |
[email protected] | d22f06e | 2013-06-11 16:01:17 | [diff] [blame] | 147 | TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 148 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 149 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 150 | net::HostResolver::Options options; |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 151 | |
| 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] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 159 | if (base::StringToInt(s, &n) && n > 0) { |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 160 | options.max_concurrent_resolves = static_cast<size_t>(n); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 161 | } else { |
| 162 | LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
| 163 | } |
| 164 | } |
| 165 | |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 166 | // 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] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 173 | options.max_retry_attempts = static_cast<size_t>(n); |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 174 | } else { |
| 175 | LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 176 | } |
| 177 | } |
| 178 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 179 | scoped_ptr<net::HostResolver> global_host_resolver( |
| 180 | net::HostResolver::CreateSystemResolver(options, net_log)); |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 181 | |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 182 | // Determine if we should disable IPv6 support. |
[email protected] | 23330db7 | 2013-07-18 03:32:11 | [diff] [blame] | 183 | 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] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 189 | } |
| 190 | |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 191 | // 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] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 194 | if (!command_line.HasSwitch(switches::kHostResolverRules)) |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 195 | return global_host_resolver.PassAs<net::HostResolver>(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 196 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 197 | scoped_ptr<net::MappedHostResolver> remapped_resolver( |
| 198 | new net::MappedHostResolver(global_host_resolver.Pass())); |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 199 | remapped_resolver->SetRulesFromString( |
| 200 | command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 201 | return remapped_resolver.PassAs<net::HostResolver>(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 204 | // TODO(willchan): Remove proxy script fetcher context since it's not necessary |
| 205 | // now that I got rid of refcounting URLRequestContexts. |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 206 | // See IOThread::Globals for details. |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 207 | net::URLRequestContext* |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 208 | ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| 209 | net::NetLog* net_log) { |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 210 | net::URLRequestContext* context = new net::URLRequestContext; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 211 | 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] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 214 | context->set_transport_security_state( |
| 215 | globals->transport_security_state.get()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame^] | 216 | context->set_cert_transparency_verifier( |
| 217 | globals->cert_transparency_verifier.get()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 218 | 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] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 222 | globals->proxy_script_fetcher_http_transaction_factory.get()); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 223 | context->set_job_factory( |
| 224 | globals->proxy_script_fetcher_url_request_job_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 225 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 226 | context->set_server_bound_cert_service( |
| 227 | globals->system_server_bound_cert_service.get()); |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 228 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 229 | context->set_http_user_agent_settings( |
| 230 | globals->http_user_agent_settings.get()); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 231 | // 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] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 234 | return context; |
| 235 | } |
| 236 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 237 | net::URLRequestContext* |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 238 | ConstructSystemRequestContext(IOThread::Globals* globals, |
| 239 | net::NetLog* net_log) { |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 240 | net::URLRequestContext* context = new SystemURLRequestContext; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 241 | 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] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 244 | context->set_transport_security_state( |
| 245 | globals->transport_security_state.get()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame^] | 246 | context->set_cert_transparency_verifier( |
| 247 | globals->cert_transparency_verifier.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 248 | 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] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 253 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 254 | context->set_server_bound_cert_service( |
| 255 | globals->system_server_bound_cert_service.get()); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 256 | context->set_throttler_manager(globals->throttler_manager.get()); |
[email protected] | 815c69cf | 2012-06-30 00:52:08 | [diff] [blame] | 257 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 258 | context->set_http_user_agent_settings( |
| 259 | globals->http_user_agent_settings.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 260 | return context; |
| 261 | } |
| 262 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 263 | int 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] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 271 | } |
| 272 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 273 | } // namespace |
| 274 | |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 275 | class IOThread::LoggingNetworkChangeObserver |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 276 | : public net::NetworkChangeNotifier::IPAddressObserver, |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 277 | public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 278 | public net::NetworkChangeNotifier::NetworkChangeObserver { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 279 | 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] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 284 | net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 285 | net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 286 | } |
| 287 | |
[email protected] | b94584a | 2013-02-07 03:02:08 | [diff] [blame] | 288 | virtual ~LoggingNetworkChangeObserver() { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 289 | net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 290 | net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 291 | net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 294 | // NetworkChangeNotifier::IPAddressObserver implementation. |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 295 | virtual void OnIPAddressChanged() OVERRIDE { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 296 | VLOG(1) << "Observed a change to the network IP addresses"; |
| 297 | |
[email protected] | 2fa0891 | 2012-06-14 20:56:26 | [diff] [blame] | 298 | net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 299 | } |
| 300 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 301 | // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 302 | 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] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 315 | // 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] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 328 | private: |
| 329 | net::NetLog* net_log_; |
| 330 | DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
| 331 | }; |
| 332 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 333 | class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 334 | public: |
| 335 | explicit SystemURLRequestContextGetter(IOThread* io_thread); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 336 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 337 | // Implementation for net::UrlRequestContextGetter. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 338 | virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| 339 | virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 340 | GetNetworkTaskRunner() const OVERRIDE; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 341 | |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 342 | protected: |
| 343 | virtual ~SystemURLRequestContextGetter(); |
| 344 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 345 | private: |
| 346 | IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 347 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 348 | |
| 349 | base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 350 | }; |
| 351 | |
| 352 | SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 353 | IOThread* io_thread) |
| 354 | : io_thread_(io_thread), |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 355 | network_task_runner_( |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 356 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 360 | |
| 361 | net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| 362 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 363 | DCHECK(io_thread_->globals()->system_request_context.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 364 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 365 | return io_thread_->globals()->system_request_context.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 368 | scoped_refptr<base::SingleThreadTaskRunner> |
| 369 | SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 370 | return network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 373 | IOThread::Globals:: |
| 374 | SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( |
| 375 | Globals* globals) |
| 376 | : globals_(globals) { |
| 377 | DCHECK(globals_); |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 378 | } |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 379 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 380 | IOThread::Globals:: |
| 381 | SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { |
| 382 | if (globals_->system_request_context.get()) |
| 383 | globals_->system_request_context->AssertNoURLRequests(); |
| 384 | } |
| 385 | |
| 386 | IOThread::Globals::Globals() |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 387 | : system_request_context_leak_checker(this), |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 388 | ignore_certificate_errors(false), |
| 389 | http_pipelining_enabled(false), |
| 390 | testing_fixed_http_port(0), |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 391 | testing_fixed_https_port(0), |
| 392 | enable_user_alternate_protocol_ports(false) { |
| 393 | } |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 394 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 395 | IOThread::Globals::~Globals() {} |
| 396 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 397 | // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 398 | // dependencies and (2) make IOThread more flexible for testing. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 399 | IOThread::IOThread( |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 400 | PrefService* local_state, |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 401 | policy::PolicyService* policy_service, |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 402 | ChromeNetLog* net_log, |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 403 | extensions::EventRouterForwarder* extension_event_router_forwarder) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 404 | : net_log_(net_log), |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 405 | extension_event_router_forwarder_(extension_event_router_forwarder), |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 406 | globals_(NULL), |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 407 | sdch_manager_(NULL), |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 408 | is_spdy_disabled_by_policy_(false), |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 409 | weak_factory_(this) { |
[email protected] | f331875 | 2013-02-04 13:32:51 | [diff] [blame] | 410 | #if !defined(OS_IOS) && !defined(OS_ANDROID) |
[email protected] | 431ec41 | 2013-07-31 06:30:31 | [diff] [blame] | 411 | #if defined(OS_WIN) |
| 412 | if (!win8::IsSingleWindowMetroMode()) |
| 413 | net::ProxyResolverV8::RememberDefaultIsolate(); |
| 414 | else |
| 415 | net::ProxyResolverV8::CreateIsolate(); |
| 416 | #else |
[email protected] | a2c1b13 | 2013-02-01 12:28:47 | [diff] [blame] | 417 | net::ProxyResolverV8::RememberDefaultIsolate(); |
| 418 | #endif |
[email protected] | 431ec41 | 2013-07-31 06:30:31 | [diff] [blame] | 419 | #endif |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 420 | 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] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 428 | gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 429 | pref_proxy_config_tracker_.reset( |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 430 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 431 | local_state)); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 432 | ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 433 | &system_enable_referrers_, |
| 434 | NULL, |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 435 | NULL, |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 436 | local_state); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 437 | ssl_config_service_manager_.reset( |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 438 | SSLConfigServiceManager::CreateDefaultManager(local_state)); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 439 | |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 440 | 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] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 445 | 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] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 452 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 453 | is_spdy_disabled_by_policy_ = policy_service->GetPolicies( |
[email protected] | 2ccf8373 | 2013-02-04 20:19:02 | [diff] [blame] | 454 | policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get( |
| 455 | policy::key::kDisableSpdy) != NULL; |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 456 | #endif // ENABLE_CONFIGURATION_POLICY |
| 457 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 458 | BrowserThread::SetDelegate(BrowserThread::IO, this); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 459 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 460 | |
| 461 | IOThread::~IOThread() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 462 | // 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] | d461ed2 | 2013-01-18 03:18:56 | [diff] [blame] | 466 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 467 | DCHECK(!globals_); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 468 | } |
| 469 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 470 | IOThread::Globals* IOThread::globals() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 471 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 472 | return globals_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 473 | } |
| 474 | |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 475 | void IOThread::SetGlobalsForTesting(Globals* globals) { |
| 476 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 477 | DCHECK(!globals || !globals_); |
| 478 | globals_ = globals; |
| 479 | } |
| 480 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 481 | ChromeNetLog* IOThread::net_log() { |
| 482 | return net_log_; |
| 483 | } |
| 484 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 485 | void 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] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 494 | net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 495 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 496 | if (!system_url_request_context_getter_.get()) { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 497 | InitSystemRequestContext(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 498 | } |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 499 | return system_url_request_context_getter_.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 500 | } |
| 501 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 502 | void IOThread::Init() { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 503 | // Prefer to use InitAsync unless you need initialization to block |
| 504 | // the UI thread |
| 505 | } |
| 506 | |
| 507 | void IOThread::InitAsync() { |
| 508 | TRACE_EVENT0("startup", "IOThread::InitAsync"); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 509 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 510 | |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 511 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 512 | net::SetMessageLoopForNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 513 | #endif |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 514 | |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 515 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 516 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 517 | DCHECK(!globals_); |
| 518 | globals_ = new Globals; |
| 519 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 520 | // 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] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 524 | new LoggingNetworkChangeObserver(net_log_)); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 525 | |
[email protected] | cde8b3c | 2012-08-13 19:20:52 | [diff] [blame] | 526 | // Setup the HistogramWatcher to run on the IO thread. |
| 527 | net::NetworkChangeNotifier::InitHistogramWatcher(); |
| 528 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 529 | globals_->extension_event_router_forwarder = |
| 530 | extension_event_router_forwarder_; |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 531 | ChromeNetworkDelegate* network_delegate = |
| 532 | new ChromeNetworkDelegate(extension_event_router_forwarder_, |
| 533 | &system_enable_referrers_); |
[email protected] | 3620bbc | 2013-10-05 05:07:23 | [diff] [blame] | 534 | if (command_line.HasSwitch(switches::kEnableClientHints)) |
| 535 | network_delegate->SetEnableClientHints(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 536 | if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 537 | network_delegate->NeverThrottleRequests(); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 538 | globals_->system_network_delegate.reset(network_delegate); |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 539 | globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 540 | UpdateDnsClientEnabled(); |
[email protected] | 9f59fac | 2012-03-21 23:18:11 | [diff] [blame] | 541 | globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 542 | globals_->transport_security_state.reset(new net::TransportSecurityState()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame^] | 543 | #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] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 578 | globals_->ssl_config_service = GetSSLConfigService(); |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 579 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 580 | if (DataReductionProxySettings::IsDataReductionProxyAllowed()) { |
| 581 | spdyproxy_auth_origins_ = |
| 582 | DataReductionProxySettings::GetDataReductionProxies(); |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 583 | } |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 584 | #endif // defined(OS_ANDROID) || defined(OS_IOS) |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 585 | globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 586 | globals_->host_resolver.get())); |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 587 | globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 588 | // For the ProxyScriptFetcher, we use a direct ProxyService. |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 589 | globals_->proxy_script_fetcher_proxy_service.reset( |
| 590 | net::ProxyService::CreateDirectWithNetLog(net_log_)); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 591 | // In-memory cookie store. |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 592 | globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 593 | // In-memory server bound cert store. |
| 594 | globals_->system_server_bound_cert_service.reset( |
| 595 | new net::ServerBoundCertService( |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 596 | new net::DefaultServerBoundCertStore(NULL), |
| 597 | base::WorkerPool::GetTaskRunner(true))); |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 598 | globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService()); |
[email protected] | a9e0d141 | 2012-08-20 22:13:01 | [diff] [blame] | 599 | globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 600 | globals_->host_mapping_rules.reset(new net::HostMappingRules()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 601 | globals_->http_user_agent_settings.reset( |
[email protected] | 84f0543 | 2013-03-15 01:00:12 | [diff] [blame] | 602 | new BasicHttpUserAgentSettings(std::string())); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 603 | if (command_line.HasSwitch(switches::kHostRules)) { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 604 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 605 | globals_->host_mapping_rules->SetRulesFromString( |
| 606 | command_line.GetSwitchValueASCII(switches::kHostRules)); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 607 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 608 | } |
| 609 | if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) |
| 610 | globals_->ignore_certificate_errors = true; |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 611 | if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 612 | globals_->testing_fixed_http_port = |
| 613 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 614 | } |
| 615 | if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 616 | globals_->testing_fixed_https_port = |
| 617 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 618 | } |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 619 | ConfigureQuic(command_line); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 620 | if (command_line.HasSwitch( |
| 621 | switches::kEnableUserAlternateProtocolPorts)) { |
| 622 | globals_->enable_user_alternate_protocol_ports = true; |
| 623 | } |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 624 | InitializeNetworkOptions(command_line); |
| 625 | |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 626 | net::HttpNetworkSession::Params session_params; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 627 | InitializeNetworkSessionParams(&session_params); |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 628 | session_params.net_log = net_log_; |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 629 | session_params.proxy_service = |
| 630 | globals_->proxy_script_fetcher_proxy_service.get(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 631 | |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 632 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:HttpNetworkSession"); |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 633 | scoped_refptr<net::HttpNetworkSession> network_session( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 634 | new net::HttpNetworkSession(session_params)); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 635 | globals_->proxy_script_fetcher_http_transaction_factory |
| 636 | .reset(new net::HttpNetworkLayer(network_session.get())); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 637 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:HttpNetworkSession"); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 638 | scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 639 | new net::URLRequestJobFactoryImpl()); |
| 640 | job_factory->SetProtocolHandler(chrome::kDataScheme, |
| 641 | new net::DataProtocolHandler()); |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 642 | job_factory->SetProtocolHandler( |
| 643 | chrome::kFileScheme, |
| 644 | new net::FileProtocolHandler( |
| 645 | content::BrowserThread::GetBlockingPool()-> |
| 646 | GetTaskRunnerWithShutdownBehavior( |
| 647 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 648 | #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] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 658 | |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 659 | globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 660 | globals_->throttler_manager->set_net_log(net_log_); |
[email protected] | 332a8c96 | 2013-07-17 22:31:23 | [diff] [blame] | 661 | // Always done in production, disabled only for unit tests. |
| 662 | globals_->throttler_manager->set_enable_thread_checks(true); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 663 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 664 | globals_->proxy_script_fetcher_context.reset( |
| 665 | ConstructProxyScriptFetcherContext(globals_, net_log_)); |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 666 | |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 667 | globals_->network_time_notifier.reset( |
| 668 | new net::NetworkTimeNotifier( |
| 669 | scoped_ptr<base::TickClock>(new base::DefaultTickClock()))); |
| 670 | |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 671 | sdch_manager_ = new net::SdchManager(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 672 | |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 673 | #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] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 681 | // 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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 695 | } |
| 696 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 697 | void IOThread::CleanUp() { |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 698 | base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); |
| 699 | |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 700 | delete sdch_manager_; |
| 701 | sdch_manager_ = NULL; |
| 702 | |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 703 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 704 | net::ShutdownNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 705 | #endif |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 706 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 707 | system_url_request_context_getter_ = NULL; |
| 708 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 709 | // Release objects that the net::URLRequestContext could have been pointing |
| 710 | // to. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 711 | |
| 712 | // This must be reset before the ChromeNetLog is destroyed. |
| 713 | network_change_observer_.reset(); |
| 714 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 715 | system_proxy_config_service_.reset(); |
| 716 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 717 | delete globals_; |
| 718 | globals_ = NULL; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 719 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 720 | base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 721 | } |
| 722 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 723 | void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 724 | 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] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 730 | // Only handle use-spdy command line flags if "spdy.disabled" preference is |
| 731 | // not disabled via policy. |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 732 | 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] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 740 | if (command_line.HasSwitch(switches::kEnableIPPooling)) |
| 741 | globals_->enable_spdy_ip_pooling.set(true); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 742 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 743 | if (command_line.HasSwitch(switches::kDisableIPPooling)) |
| 744 | globals_->enable_spdy_ip_pooling.set(false); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 745 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 746 | if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) { |
| 747 | // Enable WebSocket over SPDY. |
| 748 | net::WebSocketJob::set_websocket_over_spdy_enabled(true); |
| 749 | } |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 750 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 751 | 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] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 762 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 763 | if (command_line.HasSwitch(switches::kUseSpdy)) { |
| 764 | std::string spdy_mode = |
| 765 | command_line.GetSwitchValueASCII(switches::kUseSpdy); |
| 766 | EnableSpdy(spdy_mode); |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 767 | } else if (command_line.HasSwitch(switches::kEnableHttp2Draft04)) { |
| 768 | net::HttpStreamFactory::EnableNpnHttp2Draft04(); |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 769 | } 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] | 1101152 | 2013-11-19 02:18:15 | [diff] [blame] | 773 | } else if (command_line.HasSwitch(switches::kEnableSpdy2)) { |
| 774 | net::HttpStreamFactory::EnableNpnSpdy31WithSpdy2(); |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 775 | } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { |
| 776 | net::HttpStreamFactory::EnableNpnHttpOnly(); |
| 777 | } else { |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 778 | 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] | 1101152 | 2013-11-19 02:18:15 | [diff] [blame] | 783 | net::HttpStreamFactory::EnableNpnSpdy31(); |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 784 | } |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 785 | } |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 786 | } |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 787 | |
| 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] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 794 | } |
| 795 | |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 796 | void 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] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 817 | 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] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 821 | |
| 822 | if (option == kOff) { |
| 823 | net::HttpStreamFactory::set_spdy_enabled(false); |
| 824 | } else if (option == kDisableSSL) { |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 825 | globals_->spdy_default_protocol.set(net::kProtoSPDY3); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 826 | net::HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 827 | net::HttpStreamFactory::set_force_spdy_always(true); |
| 828 | } else if (option == kSSL) { |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 829 | globals_->spdy_default_protocol.set(net::kProtoSPDY3); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 830 | net::HttpStreamFactory::set_force_spdy_over_ssl(true); |
| 831 | net::HttpStreamFactory::set_force_spdy_always(true); |
| 832 | } else if (option == kDisablePing) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 833 | globals_->enable_spdy_ping_based_connection_checking.set(false); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 834 | } else if (option == kExclude) { |
| 835 | net::HttpStreamFactory::add_forced_spdy_exclusion(value); |
| 836 | } else if (option == kDisableCompression) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 837 | globals_->enable_spdy_compression.set(false); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 838 | } 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] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 843 | pair.protocol = net::NPN_SPDY_3; |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 844 | net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
| 845 | } else if (option == kSingleDomain) { |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 846 | DVLOG(1) << "FORCING SINGLE DOMAIN"; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 847 | globals_->force_spdy_single_domain.set(true); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 848 | } else if (option == kInitialMaxConcurrentStreams) { |
| 849 | int streams; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 850 | if (base::StringToInt(value, &streams)) |
| 851 | globals_->initial_max_spdy_concurrent_streams.set(streams); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 852 | } 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] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 860 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 861 | void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { |
| 862 | registry->RegisterStringPref(prefs::kAuthSchemes, |
| 863 | "basic,digest,ntlm,negotiate," |
| 864 | "spdyproxy"); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 865 | registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 866 | registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 867 | 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] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 872 | registry->RegisterBooleanPref(prefs::kEnableReferrers, true); |
| 873 | registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0); |
| 874 | registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0); |
[email protected] | eac11e1 | 2013-03-19 22:04:32 | [diff] [blame] | 875 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 876 | registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); |
| 877 | registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); |
[email protected] | 2db93e4 | 2013-08-07 17:40:41 | [diff] [blame] | 878 | registry->RegisterListPref( |
[email protected] | 0d36d1e | 2013-09-24 04:25:28 | [diff] [blame] | 879 | prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled); |
[email protected] | 2db93e4 | 2013-08-07 17:40:41 | [diff] [blame] | 880 | registry->RegisterListPref( |
[email protected] | 0d36d1e | 2013-09-24 04:25:28 | [diff] [blame] | 881 | prefs::kDailyContentLengthWithDataReductionProxyEnabled); |
| 882 | registry->RegisterListPref( |
| 883 | prefs::kDailyOriginalContentLengthViaDataReductionProxy); |
| 884 | registry->RegisterListPref( |
| 885 | prefs::kDailyContentLengthViaDataReductionProxy); |
[email protected] | eac11e1 | 2013-03-19 22:04:32 | [diff] [blame] | 886 | registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 0L); |
| 887 | #endif |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 888 | registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 889 | } |
| 890 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 891 | net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( |
| 892 | net::HostResolver* resolver) { |
[email protected] | 9030a63 | 2010-11-19 20:12:09 | [diff] [blame] | 893 | 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] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 903 | globals_->url_security_manager.reset( |
[email protected] | d201b200e | 2010-08-27 17:35:02 | [diff] [blame] | 904 | net::URLSecurityManager::Create(auth_filter_default_credentials, |
| 905 | auth_filter_delegate)); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 906 | std::vector<std::string> supported_schemes; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 907 | base::SplitString(auth_schemes_, ',', &supported_schemes); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 908 | |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 909 | 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] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 915 | if (!spdyproxy_auth_origins_.empty()) { |
| 916 | registry_factory->RegisterSchemeFactory( |
| 917 | "spdyproxy", |
| 918 | new spdyproxy::HttpAuthHandlerSpdyProxy::Factory( |
| 919 | spdyproxy_auth_origins_)); |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | return registry_factory.release(); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 923 | } |
| 924 | |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 925 | void IOThread::ClearHostCache() { |
| 926 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 927 | |
[email protected] | 489d1a8 | 2011-10-12 03:09:11 | [diff] [blame] | 928 | net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 929 | if (host_cache) |
| 930 | host_cache->clear(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 931 | } |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 932 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 933 | void 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] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 942 | params->http_server_properties = |
| 943 | globals_->http_server_properties->GetWeakPtr(); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 944 | 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] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 951 | globals_->initial_max_spdy_concurrent_streams.CopyToIfSet( |
| 952 | ¶ms->spdy_initial_max_concurrent_streams); |
| 953 | globals_->max_spdy_concurrent_streams_limit.CopyToIfSet( |
| 954 | ¶ms->spdy_max_concurrent_streams_limit); |
| 955 | globals_->force_spdy_single_domain.CopyToIfSet( |
| 956 | ¶ms->force_spdy_single_domain); |
| 957 | globals_->enable_spdy_ip_pooling.CopyToIfSet( |
| 958 | ¶ms->enable_spdy_ip_pooling); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 959 | globals_->enable_spdy_compression.CopyToIfSet( |
| 960 | ¶ms->enable_spdy_compression); |
| 961 | globals_->enable_spdy_ping_based_connection_checking.CopyToIfSet( |
| 962 | ¶ms->enable_spdy_ping_based_connection_checking); |
| 963 | globals_->spdy_default_protocol.CopyToIfSet( |
| 964 | ¶ms->spdy_default_protocol); |
[email protected] | 26615ae | 2013-06-13 17:50:59 | [diff] [blame] | 965 | globals_->trusted_spdy_proxy.CopyToIfSet( |
| 966 | ¶ms->trusted_spdy_proxy); |
[email protected] | b559b13 | 2013-01-29 22:13:32 | [diff] [blame] | 967 | globals_->enable_quic.CopyToIfSet(¶ms->enable_quic); |
[email protected] | eb8f88e | 2013-07-15 09:52:17 | [diff] [blame] | 968 | globals_->enable_quic_https.CopyToIfSet(¶ms->enable_quic_https); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 969 | globals_->quic_max_packet_length.CopyToIfSet(¶ms->quic_max_packet_length); |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 970 | globals_->origin_to_force_quic_on.CopyToIfSet( |
| 971 | ¶ms->origin_to_force_quic_on); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 972 | params->enable_user_alternate_protocol_ports = |
| 973 | globals_->enable_user_alternate_protocol_ports; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 974 | } |
| 975 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 976 | net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 977 | return ssl_config_service_manager_->Get(); |
| 978 | } |
| 979 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 980 | void 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] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 986 | } |
| 987 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 988 | void IOThread::InitSystemRequestContext() { |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 989 | if (system_url_request_context_getter_.get()) |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 990 | return; |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 991 | // If we're in unit_tests, IOThread may not be run. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 992 | if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 993 | return; |
[email protected] | 53c5b0f | 2013-07-22 10:54:11 | [diff] [blame] | 994 | system_proxy_config_service_.reset( |
| 995 | ProxyServiceFactory::CreateProxyConfigService( |
| 996 | pref_proxy_config_tracker_.get())); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 997 | system_url_request_context_getter_ = |
| 998 | new SystemURLRequestContextGetter(this); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 999 | // Safe to post an unretained this pointer, since IOThread is |
| 1000 | // guaranteed to outlive the IO BrowserThread. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 1001 | BrowserThread::PostTask( |
| 1002 | BrowserThread::IO, |
| 1003 | FROM_HERE, |
| 1004 | base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
| 1005 | base::Unretained(this))); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | void IOThread::InitSystemRequestContextOnIOThread() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1009 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1010 | DCHECK(!globals_->system_proxy_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1011 | DCHECK(system_proxy_config_service_.get()); |
| 1012 | |
| 1013 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1014 | globals_->system_proxy_service.reset( |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1015 | ProxyServiceFactory::CreateProxyService( |
| 1016 | net_log_, |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1017 | globals_->proxy_script_fetcher_context.get(), |
[email protected] | 8def32a0 | 2013-03-11 19:13:23 | [diff] [blame] | 1018 | globals_->system_network_delegate.get(), |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1019 | system_proxy_config_service_.release(), |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1020 | command_line)); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 1021 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1022 | net::HttpNetworkSession::Params system_params; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1023 | InitializeNetworkSessionParams(&system_params); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1024 | system_params.net_log = net_log_; |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 1025 | system_params.proxy_service = globals_->system_proxy_service.get(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 1026 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1027 | globals_->system_http_transaction_factory.reset( |
| 1028 | new net::HttpNetworkLayer( |
| 1029 | new net::HttpNetworkSession(system_params))); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1030 | globals_->system_request_context.reset( |
| 1031 | ConstructSystemRequestContext(globals_, net_log_)); |
[email protected] | d24fc3a0 | 2012-02-11 02:08:34 | [diff] [blame] | 1032 | |
| 1033 | sdch_manager_->set_sdch_fetcher( |
| 1034 | new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1035 | } |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 1036 | |
| 1037 | void IOThread::UpdateDnsClientEnabled() { |
| 1038 | globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
| 1039 | } |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1040 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1041 | void IOThread::ConfigureQuic(const CommandLine& command_line) { |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1042 | // 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] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1048 | 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 | |
| 1071 | bool IOThread::ShouldEnableQuic(const CommandLine& command_line, |
| 1072 | base::StringPiece quic_trial_group) { |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1073 | if (command_line.HasSwitch(switches::kDisableQuic)) |
| 1074 | return false; |
| 1075 | |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1076 | if (command_line.HasSwitch(switches::kEnableQuic)) |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1077 | return true; |
| 1078 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1079 | return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || |
| 1080 | quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1081 | } |
| 1082 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1083 | bool IOThread::ShouldEnableQuicHttps(const CommandLine& command_line, |
| 1084 | base::StringPiece quic_trial_group) { |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1085 | if (command_line.HasSwitch(switches::kDisableQuicHttps)) |
| 1086 | return false; |
| 1087 | |
| 1088 | if (command_line.HasSwitch(switches::kEnableQuicHttps)) |
| 1089 | return true; |
| 1090 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1091 | return quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
| 1092 | } |
| 1093 | |
| 1094 | size_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] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1125 | } |