[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] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame^] | 28 | #include "base/time/time.h" |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 29 | #include "build/build_config.h" |
[email protected] | df2840d | 2011-02-20 16:32:32 | [diff] [blame] | 30 | #include "chrome/browser/browser_process.h" |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 31 | #include "chrome/browser/extensions/event_router_forwarder.h" |
[email protected] | 026876f3 | 2012-08-22 23:53:40 | [diff] [blame] | 32 | #include "chrome/browser/net/async_dns_field_trial.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] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 39 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 40 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 41 | #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 42 | #include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h" |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 43 | #include "chrome/common/chrome_content_client.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 44 | #include "chrome/common/chrome_switches.h" |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 45 | #include "chrome/common/chrome_version_info.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] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 48 | #include "components/policy/core/common/policy_service.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 49 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 50 | #include "content/public/browser/cookie_store_factory.h" |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 51 | #include "net/base/host_mapping_rules.h" |
[email protected] | 32eaa33 | 2010-02-08 22:15:54 | [diff] [blame] | 52 | #include "net/base/net_util.h" |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 53 | #include "net/base/network_time_notifier.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 54 | #include "net/base/sdch_manager.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 55 | #include "net/cert/cert_verifier.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 56 | #include "net/cert/cert_verify_proc.h" |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 57 | #include "net/cert/ct_known_logs.h" |
| 58 | #include "net/cert/ct_verifier.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 59 | #include "net/cert/multi_threaded_cert_verifier.h" |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 60 | #include "net/cookies/cookie_store.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 61 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 62 | #include "net/dns/host_resolver.h" |
| 63 | #include "net/dns/mapped_host_resolver.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 64 | #include "net/ftp/ftp_network_layer.h" |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 65 | #include "net/http/http_auth_filter.h" |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 66 | #include "net/http/http_auth_handler_factory.h" |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 67 | #include "net/http/http_network_layer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 68 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 69 | #include "net/proxy/proxy_config_service.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 70 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 71 | #include "net/proxy/proxy_service.h" |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 72 | #include "net/quic/quic_protocol.h" |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 73 | #include "net/socket/tcp_client_socket.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 74 | #include "net/spdy/spdy_session.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 75 | #include "net/ssl/default_server_bound_cert_store.h" |
| 76 | #include "net/ssl/server_bound_cert_service.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 77 | #include "net/url_request/data_protocol_handler.h" |
| 78 | #include "net/url_request/file_protocol_handler.h" |
| 79 | #include "net/url_request/ftp_protocol_handler.h" |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 80 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 81 | #include "net/url_request/url_fetcher.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 82 | #include "net/url_request/url_request_job_factory_impl.h" |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 83 | #include "net/url_request/url_request_throttler_manager.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 84 | #include "net/websockets/websocket_job.h" |
| 85 | |
[email protected] | 431ec41 | 2013-07-31 06:30:31 | [diff] [blame] | 86 | #if defined(OS_WIN) |
| 87 | #include "win8/util/win8_util.h" |
| 88 | #endif |
| 89 | |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 90 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 91 | #include "policy/policy_constants.h" |
| 92 | #endif |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 93 | |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 94 | #if !defined(USE_OPENSSL) |
| 95 | #include "net/cert/ct_log_verifier.h" |
| 96 | #include "net/cert/multi_log_ct_verifier.h" |
| 97 | #endif |
| 98 | |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 99 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 100 | #include "net/ocsp/nss_ocsp.h" |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 101 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 102 | |
[email protected] | f331875 | 2013-02-04 13:32:51 | [diff] [blame] | 103 | #if !defined(OS_IOS) && !defined(OS_ANDROID) |
[email protected] | a2c1b13 | 2013-02-01 12:28:47 | [diff] [blame] | 104 | #include "net/proxy/proxy_resolver_v8.h" |
| 105 | #endif |
| 106 | |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 107 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 108 | #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" |
| 109 | #endif |
| 110 | |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 111 | #if defined(OS_CHROMEOS) |
[email protected] | e456c74 | 2014-02-13 14:42:14 | [diff] [blame] | 112 | #include "chrome/browser/chromeos/login/user_manager.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 113 | #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h" |
| 114 | #endif |
| 115 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 116 | using content::BrowserThread; |
| 117 | |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 118 | class SafeBrowsingURLRequestContext; |
| 119 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 120 | // The IOThread object must outlive any tasks posted to the IO thread before the |
| 121 | // Quit task, so base::Bind() calls are not refcounted. |
| 122 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 123 | namespace { |
| 124 | |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 125 | const char kQuicFieldTrialName[] = "QUIC"; |
| 126 | const char kQuicFieldTrialEnabledGroupName[] = "Enabled"; |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 127 | const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled"; |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 128 | const char kQuicFieldTrialPacketLengthSuffix[] = "BytePackets"; |
[email protected] | c80f7c9 | 2014-02-27 13:12:02 | [diff] [blame] | 129 | const char kQuicFieldTrialPacingSuffix[] = "WithPacing"; |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 130 | |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 131 | const char kSpdyFieldTrialName[] = "SPDY"; |
| 132 | const char kSpdyFieldTrialDisabledGroupName[] = "SpdyDisabled"; |
| 133 | |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 134 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 135 | void ObserveKeychainEvents() { |
| 136 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 137 | net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); |
| 138 | } |
| 139 | #endif |
| 140 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 141 | // Used for the "system" URLRequestContext. |
| 142 | class SystemURLRequestContext : public net::URLRequestContext { |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 143 | public: |
| 144 | SystemURLRequestContext() { |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 145 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 146 | net::SetURLRequestContextForNSSHttpIO(this); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 147 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | private: |
| 151 | virtual ~SystemURLRequestContext() { |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 152 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 153 | net::SetURLRequestContextForNSSHttpIO(NULL); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 154 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 155 | } |
| 156 | }; |
| 157 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 158 | scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { |
[email protected] | d22f06e | 2013-06-11 16:01:17 | [diff] [blame] | 159 | TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 160 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 161 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 162 | net::HostResolver::Options options; |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 163 | |
| 164 | // Use the concurrency override from the command-line, if any. |
| 165 | if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
| 166 | std::string s = |
| 167 | command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
| 168 | |
| 169 | // Parse the switch (it should be a positive integer formatted as decimal). |
| 170 | int n; |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 171 | if (base::StringToInt(s, &n) && n > 0) { |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 172 | options.max_concurrent_resolves = static_cast<size_t>(n); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 173 | } else { |
| 174 | LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
| 175 | } |
| 176 | } |
| 177 | |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 178 | // Use the retry attempts override from the command-line, if any. |
| 179 | if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 180 | std::string s = |
| 181 | command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
| 182 | // Parse the switch (it should be a non-negative integer). |
| 183 | int n; |
| 184 | if (base::StringToInt(s, &n) && n >= 0) { |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 185 | options.max_retry_attempts = static_cast<size_t>(n); |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 186 | } else { |
| 187 | LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 188 | } |
| 189 | } |
| 190 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 191 | scoped_ptr<net::HostResolver> global_host_resolver( |
| 192 | net::HostResolver::CreateSystemResolver(options, net_log)); |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 193 | |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 194 | // Determine if we should disable IPv6 support. |
[email protected] | 23330db7 | 2013-07-18 03:32:11 | [diff] [blame] | 195 | if (command_line.HasSwitch(switches::kEnableIPv6)) { |
| 196 | // Disable IPv6 probing. |
| 197 | global_host_resolver->SetDefaultAddressFamily( |
| 198 | net::ADDRESS_FAMILY_UNSPECIFIED); |
| 199 | } else if (command_line.HasSwitch(switches::kDisableIPv6)) { |
| 200 | global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 201 | } |
| 202 | |
[email protected] | 3dc5d7ef | 2014-03-28 19:18:21 | [diff] [blame] | 203 | // If hostname remappings were specified on the command-line, layer these |
| 204 | // rules on top of the real host resolver. This allows forwarding all requests |
| 205 | // through a designated test server. |
| 206 | if (!command_line.HasSwitch(switches::kHostResolverRules)) |
| 207 | return global_host_resolver.PassAs<net::HostResolver>(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 208 | |
[email protected] | 3dc5d7ef | 2014-03-28 19:18:21 | [diff] [blame] | 209 | scoped_ptr<net::MappedHostResolver> remapped_resolver( |
| 210 | new net::MappedHostResolver(global_host_resolver.Pass())); |
| 211 | remapped_resolver->SetRulesFromString( |
| 212 | command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
| 213 | return remapped_resolver.PassAs<net::HostResolver>(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 214 | } |
| 215 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 216 | // TODO(willchan): Remove proxy script fetcher context since it's not necessary |
| 217 | // now that I got rid of refcounting URLRequestContexts. |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 218 | // See IOThread::Globals for details. |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 219 | net::URLRequestContext* |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 220 | ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| 221 | net::NetLog* net_log) { |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 222 | net::URLRequestContext* context = new net::URLRequestContext; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 223 | context->set_net_log(net_log); |
| 224 | context->set_host_resolver(globals->host_resolver.get()); |
| 225 | context->set_cert_verifier(globals->cert_verifier.get()); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 226 | context->set_transport_security_state( |
| 227 | globals->transport_security_state.get()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 228 | context->set_cert_transparency_verifier( |
| 229 | globals->cert_transparency_verifier.get()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 230 | context->set_http_auth_handler_factory( |
| 231 | globals->http_auth_handler_factory.get()); |
| 232 | context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 233 | context->set_http_transaction_factory( |
[email protected] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 234 | globals->proxy_script_fetcher_http_transaction_factory.get()); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 235 | context->set_job_factory( |
| 236 | globals->proxy_script_fetcher_url_request_job_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 237 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 238 | context->set_server_bound_cert_service( |
| 239 | globals->system_server_bound_cert_service.get()); |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 240 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 241 | context->set_http_user_agent_settings( |
| 242 | globals->http_user_agent_settings.get()); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 243 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 244 | // system URLRequestContext too. There's no reason this should be tied to a |
| 245 | // profile. |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 246 | return context; |
| 247 | } |
| 248 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 249 | net::URLRequestContext* |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 250 | ConstructSystemRequestContext(IOThread::Globals* globals, |
| 251 | net::NetLog* net_log) { |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 252 | net::URLRequestContext* context = new SystemURLRequestContext; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 253 | context->set_net_log(net_log); |
| 254 | context->set_host_resolver(globals->host_resolver.get()); |
| 255 | context->set_cert_verifier(globals->cert_verifier.get()); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 256 | context->set_transport_security_state( |
| 257 | globals->transport_security_state.get()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 258 | context->set_cert_transparency_verifier( |
| 259 | globals->cert_transparency_verifier.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 260 | context->set_http_auth_handler_factory( |
| 261 | globals->http_auth_handler_factory.get()); |
| 262 | context->set_proxy_service(globals->system_proxy_service.get()); |
| 263 | context->set_http_transaction_factory( |
| 264 | globals->system_http_transaction_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 265 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 266 | context->set_server_bound_cert_service( |
| 267 | globals->system_server_bound_cert_service.get()); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 268 | context->set_throttler_manager(globals->throttler_manager.get()); |
[email protected] | 815c69cf | 2012-06-30 00:52:08 | [diff] [blame] | 269 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 270 | context->set_http_user_agent_settings( |
| 271 | globals->http_user_agent_settings.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 272 | return context; |
| 273 | } |
| 274 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 275 | int GetSwitchValueAsInt(const CommandLine& command_line, |
| 276 | const std::string& switch_name) { |
| 277 | int value; |
| 278 | if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
| 279 | &value)) { |
| 280 | return 0; |
| 281 | } |
| 282 | return value; |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 285 | } // namespace |
| 286 | |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 287 | class IOThread::LoggingNetworkChangeObserver |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 288 | : public net::NetworkChangeNotifier::IPAddressObserver, |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 289 | public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 290 | public net::NetworkChangeNotifier::NetworkChangeObserver { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 291 | public: |
| 292 | // |net_log| must remain valid throughout our lifetime. |
| 293 | explicit LoggingNetworkChangeObserver(net::NetLog* net_log) |
| 294 | : net_log_(net_log) { |
| 295 | net::NetworkChangeNotifier::AddIPAddressObserver(this); |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 296 | net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 297 | net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | b94584a | 2013-02-07 03:02:08 | [diff] [blame] | 300 | virtual ~LoggingNetworkChangeObserver() { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 301 | net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 302 | net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 303 | net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 306 | // NetworkChangeNotifier::IPAddressObserver implementation. |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 307 | virtual void OnIPAddressChanged() OVERRIDE { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 308 | VLOG(1) << "Observed a change to the network IP addresses"; |
| 309 | |
[email protected] | 2fa0891 | 2012-06-14 20:56:26 | [diff] [blame] | 310 | net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 311 | } |
| 312 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 313 | // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 314 | virtual void OnConnectionTypeChanged( |
| 315 | net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { |
| 316 | std::string type_as_string = |
| 317 | net::NetworkChangeNotifier::ConnectionTypeToString(type); |
| 318 | |
| 319 | VLOG(1) << "Observed a change to network connectivity state " |
| 320 | << type_as_string; |
| 321 | |
| 322 | net_log_->AddGlobalEntry( |
| 323 | net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED, |
| 324 | net::NetLog::StringCallback("new_connection_type", &type_as_string)); |
| 325 | } |
| 326 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 327 | // NetworkChangeNotifier::NetworkChangeObserver implementation. |
| 328 | virtual void OnNetworkChanged( |
| 329 | net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { |
| 330 | std::string type_as_string = |
| 331 | net::NetworkChangeNotifier::ConnectionTypeToString(type); |
| 332 | |
| 333 | VLOG(1) << "Observed a network change to state " << type_as_string; |
| 334 | |
| 335 | net_log_->AddGlobalEntry( |
| 336 | net::NetLog::TYPE_NETWORK_CHANGED, |
| 337 | net::NetLog::StringCallback("new_connection_type", &type_as_string)); |
| 338 | } |
| 339 | |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 340 | private: |
| 341 | net::NetLog* net_log_; |
| 342 | DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
| 343 | }; |
| 344 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 345 | class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 346 | public: |
| 347 | explicit SystemURLRequestContextGetter(IOThread* io_thread); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 348 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 349 | // Implementation for net::UrlRequestContextGetter. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 350 | virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| 351 | virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 352 | GetNetworkTaskRunner() const OVERRIDE; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 353 | |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 354 | protected: |
| 355 | virtual ~SystemURLRequestContextGetter(); |
| 356 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 357 | private: |
| 358 | IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 359 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 360 | |
| 361 | base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 362 | }; |
| 363 | |
| 364 | SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 365 | IOThread* io_thread) |
| 366 | : io_thread_(io_thread), |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 367 | network_task_runner_( |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 368 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 372 | |
| 373 | net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| 374 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 375 | DCHECK(io_thread_->globals()->system_request_context.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 376 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 377 | return io_thread_->globals()->system_request_context.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 380 | scoped_refptr<base::SingleThreadTaskRunner> |
| 381 | SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 382 | return network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 385 | IOThread::Globals:: |
| 386 | SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( |
| 387 | Globals* globals) |
| 388 | : globals_(globals) { |
| 389 | DCHECK(globals_); |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 390 | } |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 391 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 392 | IOThread::Globals:: |
| 393 | SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { |
| 394 | if (globals_->system_request_context.get()) |
| 395 | globals_->system_request_context->AssertNoURLRequests(); |
| 396 | } |
| 397 | |
| 398 | IOThread::Globals::Globals() |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 399 | : system_request_context_leak_checker(this), |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 400 | ignore_certificate_errors(false), |
| 401 | http_pipelining_enabled(false), |
| 402 | testing_fixed_http_port(0), |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 403 | testing_fixed_https_port(0), |
| 404 | enable_user_alternate_protocol_ports(false) { |
| 405 | } |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 406 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 407 | IOThread::Globals::~Globals() {} |
| 408 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 409 | // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 410 | // dependencies and (2) make IOThread more flexible for testing. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 411 | IOThread::IOThread( |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 412 | PrefService* local_state, |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 413 | policy::PolicyService* policy_service, |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 414 | ChromeNetLog* net_log, |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 415 | extensions::EventRouterForwarder* extension_event_router_forwarder) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 416 | : net_log_(net_log), |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 417 | extension_event_router_forwarder_(extension_event_router_forwarder), |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 418 | globals_(NULL), |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 419 | sdch_manager_(NULL), |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 420 | is_spdy_disabled_by_policy_(false), |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame^] | 421 | weak_factory_(this), |
| 422 | creation_time_(base::TimeTicks::Now()) { |
[email protected] | f331875 | 2013-02-04 13:32:51 | [diff] [blame] | 423 | #if !defined(OS_IOS) && !defined(OS_ANDROID) |
[email protected] | 431ec41 | 2013-07-31 06:30:31 | [diff] [blame] | 424 | #if defined(OS_WIN) |
| 425 | if (!win8::IsSingleWindowMetroMode()) |
| 426 | net::ProxyResolverV8::RememberDefaultIsolate(); |
| 427 | else |
| 428 | net::ProxyResolverV8::CreateIsolate(); |
| 429 | #else |
[email protected] | a2c1b13 | 2013-02-01 12:28:47 | [diff] [blame] | 430 | net::ProxyResolverV8::RememberDefaultIsolate(); |
| 431 | #endif |
[email protected] | 431ec41 | 2013-07-31 06:30:31 | [diff] [blame] | 432 | #endif |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 433 | auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
| 434 | negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
| 435 | prefs::kDisableAuthNegotiateCnameLookup); |
| 436 | negotiate_enable_port_ = local_state->GetBoolean( |
| 437 | prefs::kEnableAuthNegotiatePort); |
| 438 | auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); |
| 439 | auth_delegate_whitelist_ = local_state->GetString( |
| 440 | prefs::kAuthNegotiateDelegateWhitelist); |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 441 | gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 442 | pref_proxy_config_tracker_.reset( |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 443 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 444 | local_state)); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 445 | ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 446 | &system_enable_referrers_, |
| 447 | NULL, |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 448 | NULL, |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 449 | local_state); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 450 | ssl_config_service_manager_.reset( |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 451 | SSLConfigServiceManager::CreateDefaultManager(local_state)); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 452 | |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 453 | base::Value* dns_client_enabled_default = new base::FundamentalValue( |
| 454 | chrome_browser_net::ConfigureAsyncDnsFieldTrial()); |
| 455 | local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled, |
| 456 | dns_client_enabled_default); |
| 457 | |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 458 | dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled, |
| 459 | local_state, |
| 460 | base::Bind(&IOThread::UpdateDnsClientEnabled, |
| 461 | base::Unretained(this))); |
| 462 | dns_client_enabled_.MoveToThread( |
| 463 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 464 | |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 465 | quick_check_enabled_.Init(prefs::kQuickCheckEnabled, |
| 466 | local_state); |
| 467 | quick_check_enabled_.MoveToThread( |
| 468 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 469 | |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 470 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 471 | is_spdy_disabled_by_policy_ = policy_service->GetPolicies( |
[email protected] | 2ccf8373 | 2013-02-04 20:19:02 | [diff] [blame] | 472 | policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get( |
| 473 | policy::key::kDisableSpdy) != NULL; |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 474 | #endif // ENABLE_CONFIGURATION_POLICY |
| 475 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 476 | BrowserThread::SetDelegate(BrowserThread::IO, this); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 477 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 478 | |
| 479 | IOThread::~IOThread() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 480 | // This isn't needed for production code, but in tests, IOThread may |
| 481 | // be multiply constructed. |
| 482 | BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
| 483 | |
[email protected] | d461ed2 | 2013-01-18 03:18:56 | [diff] [blame] | 484 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 485 | DCHECK(!globals_); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 486 | } |
| 487 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 488 | IOThread::Globals* IOThread::globals() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 489 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 490 | return globals_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 493 | void IOThread::SetGlobalsForTesting(Globals* globals) { |
| 494 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 495 | DCHECK(!globals || !globals_); |
| 496 | globals_ = globals; |
| 497 | } |
| 498 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 499 | ChromeNetLog* IOThread::net_log() { |
| 500 | return net_log_; |
| 501 | } |
| 502 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 503 | void IOThread::ChangedToOnTheRecord() { |
| 504 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 505 | BrowserThread::PostTask( |
| 506 | BrowserThread::IO, |
| 507 | FROM_HERE, |
| 508 | base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread, |
| 509 | base::Unretained(this))); |
| 510 | } |
| 511 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 512 | net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 513 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 514 | if (!system_url_request_context_getter_.get()) { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 515 | InitSystemRequestContext(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 516 | } |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 517 | return system_url_request_context_getter_.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 520 | void IOThread::Init() { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 521 | // Prefer to use InitAsync unless you need initialization to block |
| 522 | // the UI thread |
| 523 | } |
| 524 | |
| 525 | void IOThread::InitAsync() { |
| 526 | TRACE_EVENT0("startup", "IOThread::InitAsync"); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 527 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 528 | |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 529 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 530 | net::SetMessageLoopForNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 531 | #endif |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 532 | |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 533 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 534 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 535 | DCHECK(!globals_); |
| 536 | globals_ = new Globals; |
| 537 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 538 | // Add an observer that will emit network change events to the ChromeNetLog. |
| 539 | // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 540 | // logging the network change before other IO thread consumers respond to it. |
| 541 | network_change_observer_.reset( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 542 | new LoggingNetworkChangeObserver(net_log_)); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 543 | |
[email protected] | cde8b3c | 2012-08-13 19:20:52 | [diff] [blame] | 544 | // Setup the HistogramWatcher to run on the IO thread. |
| 545 | net::NetworkChangeNotifier::InitHistogramWatcher(); |
| 546 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 547 | globals_->extension_event_router_forwarder = |
| 548 | extension_event_router_forwarder_; |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 549 | ChromeNetworkDelegate* network_delegate = |
| 550 | new ChromeNetworkDelegate(extension_event_router_forwarder_, |
| 551 | &system_enable_referrers_); |
[email protected] | 3620bbc | 2013-10-05 05:07:23 | [diff] [blame] | 552 | if (command_line.HasSwitch(switches::kEnableClientHints)) |
| 553 | network_delegate->SetEnableClientHints(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 554 | if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 555 | network_delegate->NeverThrottleRequests(); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 556 | globals_->system_network_delegate.reset(network_delegate); |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 557 | globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 558 | UpdateDnsClientEnabled(); |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 559 | #if defined(OS_CHROMEOS) |
[email protected] | e456c74 | 2014-02-13 14:42:14 | [diff] [blame] | 560 | if (chromeos::UserManager::IsMultipleProfilesAllowed()) { |
| 561 | // Creates a CertVerifyProc that doesn't allow any profile-provided certs. |
| 562 | globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier( |
| 563 | new chromeos::CertVerifyProcChromeOS())); |
| 564 | } else // NOLINT Fallthrough to normal verifier if multiprofiles not allowed. |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 565 | #endif |
[email protected] | e456c74 | 2014-02-13 14:42:14 | [diff] [blame] | 566 | { |
| 567 | globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier( |
| 568 | net::CertVerifyProc::CreateDefault())); |
| 569 | } |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 570 | globals_->transport_security_state.reset(new net::TransportSecurityState()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 571 | #if !defined(USE_OPENSSL) |
| 572 | // For now, Certificate Transparency is only implemented for platforms |
| 573 | // that use NSS. |
| 574 | net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); |
| 575 | globals_->cert_transparency_verifier.reset(ct_verifier); |
| 576 | |
| 577 | // Add built-in logs |
| 578 | ct_verifier->AddLog(net::ct::CreateGooglePilotLogVerifier().Pass()); |
| 579 | ct_verifier->AddLog(net::ct::CreateGoogleAviatorLogVerifier().Pass()); |
| 580 | ct_verifier->AddLog(net::ct::CreateGoogleRocketeerLogVerifier().Pass()); |
| 581 | |
| 582 | // Add logs from command line |
| 583 | if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) { |
| 584 | std::string switch_value = command_line.GetSwitchValueASCII( |
| 585 | switches::kCertificateTransparencyLog); |
[email protected] | 344bc95 | 2014-01-29 14:04:59 | [diff] [blame] | 586 | std::vector<std::string> logs; |
| 587 | base::SplitString(switch_value, ',', &logs); |
| 588 | for (std::vector<std::string>::iterator it = logs.begin(); it != logs.end(); |
| 589 | ++it) { |
| 590 | const std::string& curr_log = *it; |
| 591 | size_t delim_pos = curr_log.find(":"); |
| 592 | CHECK(delim_pos != std::string::npos) |
| 593 | << "CT log description not provided (switch format" |
| 594 | " is 'description:base64_key')"; |
| 595 | std::string log_description(curr_log.substr(0, delim_pos)); |
| 596 | std::string ct_public_key_data; |
| 597 | CHECK(base::Base64Decode(curr_log.substr(delim_pos + 1), |
| 598 | &ct_public_key_data)) |
| 599 | << "Unable to decode CT public key."; |
| 600 | scoped_ptr<net::CTLogVerifier> external_log_verifier( |
| 601 | net::CTLogVerifier::Create(ct_public_key_data, log_description)); |
| 602 | CHECK(external_log_verifier) << "Unable to parse CT public key."; |
| 603 | VLOG(1) << "Adding log with description " << log_description; |
| 604 | ct_verifier->AddLog(external_log_verifier.Pass()); |
| 605 | } |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 606 | } |
| 607 | #else |
| 608 | if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) { |
| 609 | LOG(DFATAL) << "Certificate Transparency is not yet supported in Chrome " |
| 610 | "builds using OpenSSL."; |
| 611 | } |
| 612 | #endif |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 613 | globals_->ssl_config_service = GetSSLConfigService(); |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 614 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 615 | if (DataReductionProxySettings::IsDataReductionProxyAllowed()) { |
| 616 | spdyproxy_auth_origins_ = |
| 617 | DataReductionProxySettings::GetDataReductionProxies(); |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 618 | } |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 619 | #endif // defined(OS_ANDROID) || defined(OS_IOS) |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 620 | globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 621 | globals_->host_resolver.get())); |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 622 | globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 623 | // For the ProxyScriptFetcher, we use a direct ProxyService. |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 624 | globals_->proxy_script_fetcher_proxy_service.reset( |
| 625 | net::ProxyService::CreateDirectWithNetLog(net_log_)); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 626 | // In-memory cookie store. |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 627 | globals_->system_cookie_store = |
| 628 | content::CreateCookieStore(content::CookieStoreConfig()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 629 | // In-memory server bound cert store. |
| 630 | globals_->system_server_bound_cert_service.reset( |
| 631 | new net::ServerBoundCertService( |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 632 | new net::DefaultServerBoundCertStore(NULL), |
| 633 | base::WorkerPool::GetTaskRunner(true))); |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 634 | globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService()); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 635 | globals_->host_mapping_rules.reset(new net::HostMappingRules()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 636 | globals_->http_user_agent_settings.reset( |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 637 | new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent())); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 638 | if (command_line.HasSwitch(switches::kHostRules)) { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 639 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 640 | globals_->host_mapping_rules->SetRulesFromString( |
| 641 | command_line.GetSwitchValueASCII(switches::kHostRules)); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 642 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 643 | } |
| 644 | if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) |
| 645 | globals_->ignore_certificate_errors = true; |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 646 | if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 647 | globals_->testing_fixed_http_port = |
| 648 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 649 | } |
| 650 | if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 651 | globals_->testing_fixed_https_port = |
| 652 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 653 | } |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 654 | ConfigureQuic(command_line); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 655 | if (command_line.HasSwitch( |
| 656 | switches::kEnableUserAlternateProtocolPorts)) { |
| 657 | globals_->enable_user_alternate_protocol_ports = true; |
| 658 | } |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 659 | InitializeNetworkOptions(command_line); |
| 660 | |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 661 | net::HttpNetworkSession::Params session_params; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 662 | InitializeNetworkSessionParams(&session_params); |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 663 | session_params.net_log = net_log_; |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 664 | session_params.proxy_service = |
| 665 | globals_->proxy_script_fetcher_proxy_service.get(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 666 | |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 667 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:HttpNetworkSession"); |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 668 | scoped_refptr<net::HttpNetworkSession> network_session( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 669 | new net::HttpNetworkSession(session_params)); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 670 | globals_->proxy_script_fetcher_http_transaction_factory |
| 671 | .reset(new net::HttpNetworkLayer(network_session.get())); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 672 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:HttpNetworkSession"); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 673 | scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 674 | new net::URLRequestJobFactoryImpl()); |
[email protected] | 44495c48 | 2014-01-26 10:15:06 | [diff] [blame] | 675 | job_factory->SetProtocolHandler(content::kDataScheme, |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 676 | new net::DataProtocolHandler()); |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 677 | job_factory->SetProtocolHandler( |
[email protected] | 3e99baf | 2013-12-30 06:32:11 | [diff] [blame] | 678 | content::kFileScheme, |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 679 | new net::FileProtocolHandler( |
| 680 | content::BrowserThread::GetBlockingPool()-> |
| 681 | GetTaskRunnerWithShutdownBehavior( |
| 682 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 683 | #if !defined(DISABLE_FTP_SUPPORT) |
| 684 | globals_->proxy_script_fetcher_ftp_transaction_factory.reset( |
| 685 | new net::FtpNetworkLayer(globals_->host_resolver.get())); |
| 686 | job_factory->SetProtocolHandler( |
[email protected] | 72aa4c2 | 2013-12-01 15:09:35 | [diff] [blame] | 687 | content::kFtpScheme, |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 688 | new net::FtpProtocolHandler( |
| 689 | globals_->proxy_script_fetcher_ftp_transaction_factory.get())); |
| 690 | #endif |
| 691 | globals_->proxy_script_fetcher_url_request_job_factory = |
| 692 | job_factory.PassAs<net::URLRequestJobFactory>(); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 693 | |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 694 | globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 695 | globals_->throttler_manager->set_net_log(net_log_); |
[email protected] | 332a8c96 | 2013-07-17 22:31:23 | [diff] [blame] | 696 | // Always done in production, disabled only for unit tests. |
| 697 | globals_->throttler_manager->set_enable_thread_checks(true); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 698 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 699 | globals_->proxy_script_fetcher_context.reset( |
| 700 | ConstructProxyScriptFetcherContext(globals_, net_log_)); |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 701 | |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 702 | globals_->network_time_notifier.reset( |
| 703 | new net::NetworkTimeNotifier( |
| 704 | scoped_ptr<base::TickClock>(new base::DefaultTickClock()))); |
| 705 | |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 706 | sdch_manager_ = new net::SdchManager(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 707 | |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 708 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 709 | // Start observing Keychain events. This needs to be done on the UI thread, |
| 710 | // as Keychain services requires a CFRunLoop. |
| 711 | BrowserThread::PostTask(BrowserThread::UI, |
| 712 | FROM_HERE, |
| 713 | base::Bind(&ObserveKeychainEvents)); |
| 714 | #endif |
| 715 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 716 | // InitSystemRequestContext turns right around and posts a task back |
| 717 | // to the IO thread, so we can't let it run until we know the IO |
| 718 | // thread has started. |
| 719 | // |
| 720 | // Note that since we are at BrowserThread::Init time, the UI thread |
| 721 | // is blocked waiting for the thread to start. Therefore, posting |
| 722 | // this task to the main thread's message loop here is guaranteed to |
| 723 | // get it onto the message loop while the IOThread object still |
| 724 | // exists. However, the message might not be processed on the UI |
| 725 | // thread until after IOThread is gone, so use a weak pointer. |
| 726 | BrowserThread::PostTask(BrowserThread::UI, |
| 727 | FROM_HERE, |
| 728 | base::Bind(&IOThread::InitSystemRequestContext, |
| 729 | weak_factory_.GetWeakPtr())); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 730 | } |
| 731 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 732 | void IOThread::CleanUp() { |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 733 | base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); |
| 734 | |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 735 | delete sdch_manager_; |
| 736 | sdch_manager_ = NULL; |
| 737 | |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 738 | #if defined(USE_NSS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 739 | net::ShutdownNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 740 | #endif |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 741 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 742 | system_url_request_context_getter_ = NULL; |
| 743 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 744 | // Release objects that the net::URLRequestContext could have been pointing |
| 745 | // to. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 746 | |
| 747 | // This must be reset before the ChromeNetLog is destroyed. |
| 748 | network_change_observer_.reset(); |
| 749 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 750 | system_proxy_config_service_.reset(); |
| 751 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 752 | delete globals_; |
| 753 | globals_ = NULL; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 754 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 755 | base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 756 | } |
| 757 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 758 | void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 759 | // Only handle use-spdy command line flags if "spdy.disabled" preference is |
| 760 | // not disabled via policy. |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 761 | if (is_spdy_disabled_by_policy_) { |
| 762 | base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); |
| 763 | if (trial) |
| 764 | trial->Disable(); |
| 765 | } else { |
| 766 | std::string spdy_trial_group = |
| 767 | base::FieldTrialList::FindFullName(kSpdyFieldTrialName); |
| 768 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 769 | if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) { |
| 770 | // Enable WebSocket over SPDY. |
| 771 | net::WebSocketJob::set_websocket_over_spdy_enabled(true); |
| 772 | } |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 773 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 774 | if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
| 775 | globals_->trusted_spdy_proxy.set( |
| 776 | command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); |
| 777 | } |
| 778 | if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) |
| 779 | net::URLFetcher::SetIgnoreCertificateRequests(true); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 780 | |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 781 | if (command_line.HasSwitch(switches::kUseSpdy)) { |
| 782 | std::string spdy_mode = |
| 783 | command_line.GetSwitchValueASCII(switches::kUseSpdy); |
| 784 | EnableSpdy(spdy_mode); |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 785 | } else if (command_line.HasSwitch(switches::kEnableHttp2Draft04)) { |
| 786 | net::HttpStreamFactory::EnableNpnHttp2Draft04(); |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 787 | } else if (command_line.HasSwitch(switches::kEnableSpdy4a2)) { |
| 788 | net::HttpStreamFactory::EnableNpnSpdy4a2(); |
| 789 | } else if (command_line.HasSwitch(switches::kDisableSpdy31)) { |
| 790 | net::HttpStreamFactory::EnableNpnSpdy3(); |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 791 | } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { |
| 792 | net::HttpStreamFactory::EnableNpnHttpOnly(); |
| 793 | } else { |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 794 | if (spdy_trial_group == kSpdyFieldTrialDisabledGroupName && |
| 795 | !command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) { |
| 796 | net::HttpStreamFactory::set_spdy_enabled(false); |
| 797 | } else { |
| 798 | // Use SPDY/3.1 by default. |
[email protected] | 1101152 | 2013-11-19 02:18:15 | [diff] [blame] | 799 | net::HttpStreamFactory::EnableNpnSpdy31(); |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 800 | } |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 801 | } |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 802 | } |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 803 | |
| 804 | // TODO(rch): Make the client socket factory a per-network session |
| 805 | // instance, constructed from a NetworkSession::Params, to allow us |
| 806 | // to move this option to IOThread::Globals & |
| 807 | // HttpNetworkSession::Params. |
| 808 | if (command_line.HasSwitch(switches::kEnableTcpFastOpen)) |
| 809 | net::SetTCPFastOpenEnabled(true); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 810 | } |
| 811 | |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 812 | void IOThread::EnableSpdy(const std::string& mode) { |
| 813 | static const char kOff[] = "off"; |
| 814 | static const char kSSL[] = "ssl"; |
| 815 | static const char kDisableSSL[] = "no-ssl"; |
| 816 | static const char kDisablePing[] = "no-ping"; |
| 817 | static const char kExclude[] = "exclude"; // Hosts to exclude |
| 818 | static const char kDisableCompression[] = "no-compress"; |
| 819 | static const char kDisableAltProtocols[] = "no-alt-protocols"; |
| 820 | static const char kForceAltProtocols[] = "force-alt-protocols"; |
| 821 | static const char kSingleDomain[] = "single-domain"; |
| 822 | |
| 823 | static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; |
| 824 | |
| 825 | std::vector<std::string> spdy_options; |
| 826 | base::SplitString(mode, ',', &spdy_options); |
| 827 | |
| 828 | for (std::vector<std::string>::iterator it = spdy_options.begin(); |
| 829 | it != spdy_options.end(); ++it) { |
| 830 | const std::string& element = *it; |
| 831 | std::vector<std::string> name_value; |
| 832 | base::SplitString(element, '=', &name_value); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 833 | const std::string& option = |
| 834 | name_value.size() > 0 ? name_value[0] : std::string(); |
| 835 | const std::string value = |
| 836 | name_value.size() > 1 ? name_value[1] : std::string(); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 837 | |
| 838 | if (option == kOff) { |
| 839 | net::HttpStreamFactory::set_spdy_enabled(false); |
| 840 | } else if (option == kDisableSSL) { |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 841 | globals_->spdy_default_protocol.set(net::kProtoSPDY3); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 842 | net::HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 843 | net::HttpStreamFactory::set_force_spdy_always(true); |
| 844 | } else if (option == kSSL) { |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 845 | globals_->spdy_default_protocol.set(net::kProtoSPDY3); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 846 | net::HttpStreamFactory::set_force_spdy_over_ssl(true); |
| 847 | net::HttpStreamFactory::set_force_spdy_always(true); |
| 848 | } else if (option == kDisablePing) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 849 | globals_->enable_spdy_ping_based_connection_checking.set(false); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 850 | } else if (option == kExclude) { |
| 851 | net::HttpStreamFactory::add_forced_spdy_exclusion(value); |
| 852 | } else if (option == kDisableCompression) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 853 | globals_->enable_spdy_compression.set(false); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 854 | } else if (option == kDisableAltProtocols) { |
| 855 | net::HttpStreamFactory::set_use_alternate_protocols(false); |
| 856 | } else if (option == kForceAltProtocols) { |
| 857 | net::PortAlternateProtocolPair pair; |
| 858 | pair.port = 443; |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 859 | pair.protocol = net::NPN_SPDY_3; |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 860 | net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
| 861 | } else if (option == kSingleDomain) { |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 862 | DVLOG(1) << "FORCING SINGLE DOMAIN"; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 863 | globals_->force_spdy_single_domain.set(true); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 864 | } else if (option == kInitialMaxConcurrentStreams) { |
| 865 | int streams; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 866 | if (base::StringToInt(value, &streams)) |
| 867 | globals_->initial_max_spdy_concurrent_streams.set(streams); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 868 | } else if (option.empty() && it == spdy_options.begin()) { |
| 869 | continue; |
| 870 | } else { |
| 871 | LOG(DFATAL) << "Unrecognized spdy option: " << option; |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 876 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 877 | void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { |
| 878 | registry->RegisterStringPref(prefs::kAuthSchemes, |
| 879 | "basic,digest,ntlm,negotiate," |
| 880 | "spdyproxy"); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 881 | registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 882 | registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 883 | registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string()); |
| 884 | registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, |
| 885 | std::string()); |
| 886 | registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); |
| 887 | registry->RegisterStringPref(prefs::kSpdyProxyAuthOrigin, std::string()); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 888 | registry->RegisterBooleanPref(prefs::kEnableReferrers, true); |
| 889 | registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0); |
| 890 | registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0); |
[email protected] | eac11e1 | 2013-03-19 22:04:32 | [diff] [blame] | 891 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 892 | registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); |
| 893 | registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); |
[email protected] | 2db93e4 | 2013-08-07 17:40:41 | [diff] [blame] | 894 | registry->RegisterListPref( |
[email protected] | 0d36d1e | 2013-09-24 04:25:28 | [diff] [blame] | 895 | prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled); |
[email protected] | 2db93e4 | 2013-08-07 17:40:41 | [diff] [blame] | 896 | registry->RegisterListPref( |
[email protected] | 0d36d1e | 2013-09-24 04:25:28 | [diff] [blame] | 897 | prefs::kDailyContentLengthWithDataReductionProxyEnabled); |
| 898 | registry->RegisterListPref( |
[email protected] | 828eab2 | 2013-12-10 22:42:38 | [diff] [blame] | 899 | prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled); |
| 900 | registry->RegisterListPref( |
| 901 | prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled); |
| 902 | registry->RegisterListPref( |
| 903 | prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled); |
| 904 | registry->RegisterListPref( |
| 905 | prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled); |
| 906 | registry->RegisterListPref( |
[email protected] | 0d36d1e | 2013-09-24 04:25:28 | [diff] [blame] | 907 | prefs::kDailyOriginalContentLengthViaDataReductionProxy); |
| 908 | registry->RegisterListPref( |
| 909 | prefs::kDailyContentLengthViaDataReductionProxy); |
[email protected] | eac11e1 | 2013-03-19 22:04:32 | [diff] [blame] | 910 | registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 0L); |
| 911 | #endif |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 912 | registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true); |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 913 | registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 914 | } |
| 915 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 916 | net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( |
| 917 | net::HostResolver* resolver) { |
[email protected] | 9030a63 | 2010-11-19 20:12:09 | [diff] [blame] | 918 | net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL; |
| 919 | if (!auth_server_whitelist_.empty()) { |
| 920 | auth_filter_default_credentials = |
| 921 | new net::HttpAuthFilterWhitelist(auth_server_whitelist_); |
| 922 | } |
| 923 | net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL; |
| 924 | if (!auth_delegate_whitelist_.empty()) { |
| 925 | auth_filter_delegate = |
| 926 | new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_); |
| 927 | } |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 928 | globals_->url_security_manager.reset( |
[email protected] | d201b200e | 2010-08-27 17:35:02 | [diff] [blame] | 929 | net::URLSecurityManager::Create(auth_filter_default_credentials, |
| 930 | auth_filter_delegate)); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 931 | std::vector<std::string> supported_schemes; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 932 | base::SplitString(auth_schemes_, ',', &supported_schemes); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 933 | |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 934 | scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory( |
| 935 | net::HttpAuthHandlerRegistryFactory::Create( |
| 936 | supported_schemes, globals_->url_security_manager.get(), |
| 937 | resolver, gssapi_library_name_, negotiate_disable_cname_lookup_, |
| 938 | negotiate_enable_port_)); |
| 939 | |
[email protected] | d0389f6 | 2013-11-08 06:06:13 | [diff] [blame] | 940 | if (!spdyproxy_auth_origins_.empty()) { |
| 941 | registry_factory->RegisterSchemeFactory( |
| 942 | "spdyproxy", |
| 943 | new spdyproxy::HttpAuthHandlerSpdyProxy::Factory( |
| 944 | spdyproxy_auth_origins_)); |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | return registry_factory.release(); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 948 | } |
| 949 | |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 950 | void IOThread::ClearHostCache() { |
| 951 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 952 | |
[email protected] | 489d1a8 | 2011-10-12 03:09:11 | [diff] [blame] | 953 | net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 954 | if (host_cache) |
| 955 | host_cache->clear(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 956 | } |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 957 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 958 | void IOThread::InitializeNetworkSessionParams( |
| 959 | net::HttpNetworkSession::Params* params) { |
| 960 | params->host_resolver = globals_->host_resolver.get(); |
| 961 | params->cert_verifier = globals_->cert_verifier.get(); |
| 962 | params->server_bound_cert_service = |
| 963 | globals_->system_server_bound_cert_service.get(); |
| 964 | params->transport_security_state = globals_->transport_security_state.get(); |
| 965 | params->ssl_config_service = globals_->ssl_config_service.get(); |
| 966 | params->http_auth_handler_factory = globals_->http_auth_handler_factory.get(); |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 967 | params->http_server_properties = |
| 968 | globals_->http_server_properties->GetWeakPtr(); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 969 | params->network_delegate = globals_->system_network_delegate.get(); |
| 970 | params->host_mapping_rules = globals_->host_mapping_rules.get(); |
| 971 | params->ignore_certificate_errors = globals_->ignore_certificate_errors; |
| 972 | params->http_pipelining_enabled = globals_->http_pipelining_enabled; |
| 973 | params->testing_fixed_http_port = globals_->testing_fixed_http_port; |
| 974 | params->testing_fixed_https_port = globals_->testing_fixed_https_port; |
| 975 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 976 | globals_->initial_max_spdy_concurrent_streams.CopyToIfSet( |
| 977 | ¶ms->spdy_initial_max_concurrent_streams); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 978 | globals_->force_spdy_single_domain.CopyToIfSet( |
| 979 | ¶ms->force_spdy_single_domain); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 980 | globals_->enable_spdy_compression.CopyToIfSet( |
| 981 | ¶ms->enable_spdy_compression); |
| 982 | globals_->enable_spdy_ping_based_connection_checking.CopyToIfSet( |
| 983 | ¶ms->enable_spdy_ping_based_connection_checking); |
| 984 | globals_->spdy_default_protocol.CopyToIfSet( |
| 985 | ¶ms->spdy_default_protocol); |
[email protected] | 26615ae | 2013-06-13 17:50:59 | [diff] [blame] | 986 | globals_->trusted_spdy_proxy.CopyToIfSet( |
| 987 | ¶ms->trusted_spdy_proxy); |
[email protected] | b559b13 | 2013-01-29 22:13:32 | [diff] [blame] | 988 | globals_->enable_quic.CopyToIfSet(¶ms->enable_quic); |
[email protected] | eb8f88e | 2013-07-15 09:52:17 | [diff] [blame] | 989 | globals_->enable_quic_https.CopyToIfSet(¶ms->enable_quic_https); |
[email protected] | c80f7c9 | 2014-02-27 13:12:02 | [diff] [blame] | 990 | globals_->enable_quic_pacing.CopyToIfSet( |
| 991 | ¶ms->enable_quic_pacing); |
[email protected] | d412ef7 | 2014-03-03 21:13:14 | [diff] [blame] | 992 | globals_->enable_quic_persist_server_info.CopyToIfSet( |
| 993 | ¶ms->enable_quic_persist_server_info); |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 994 | globals_->enable_quic_port_selection.CopyToIfSet( |
| 995 | ¶ms->enable_quic_port_selection); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 996 | globals_->quic_max_packet_length.CopyToIfSet(¶ms->quic_max_packet_length); |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 997 | globals_->quic_supported_versions.CopyToIfSet( |
| 998 | ¶ms->quic_supported_versions); |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 999 | globals_->origin_to_force_quic_on.CopyToIfSet( |
| 1000 | ¶ms->origin_to_force_quic_on); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 1001 | params->enable_user_alternate_protocol_ports = |
| 1002 | globals_->enable_user_alternate_protocol_ports; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1003 | } |
| 1004 | |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame^] | 1005 | base::TimeTicks IOThread::creation_time() const { |
| 1006 | return creation_time_; |
| 1007 | } |
| 1008 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 1009 | net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 1010 | return ssl_config_service_manager_->Get(); |
| 1011 | } |
| 1012 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 1013 | void IOThread::ChangedToOnTheRecordOnIOThread() { |
| 1014 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1015 | |
| 1016 | // Clear the host cache to avoid showing entries from the OTR session |
| 1017 | // in about:net-internals. |
| 1018 | ClearHostCache(); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 1019 | } |
| 1020 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1021 | void IOThread::InitSystemRequestContext() { |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 1022 | if (system_url_request_context_getter_.get()) |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1023 | return; |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 1024 | // If we're in unit_tests, IOThread may not be run. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 1025 | if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 1026 | return; |
[email protected] | 53c5b0f | 2013-07-22 10:54:11 | [diff] [blame] | 1027 | system_proxy_config_service_.reset( |
| 1028 | ProxyServiceFactory::CreateProxyConfigService( |
| 1029 | pref_proxy_config_tracker_.get())); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1030 | system_url_request_context_getter_ = |
| 1031 | new SystemURLRequestContextGetter(this); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1032 | // Safe to post an unretained this pointer, since IOThread is |
| 1033 | // guaranteed to outlive the IO BrowserThread. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 1034 | BrowserThread::PostTask( |
| 1035 | BrowserThread::IO, |
| 1036 | FROM_HERE, |
| 1037 | base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
| 1038 | base::Unretained(this))); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | void IOThread::InitSystemRequestContextOnIOThread() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1042 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1043 | DCHECK(!globals_->system_proxy_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1044 | DCHECK(system_proxy_config_service_.get()); |
| 1045 | |
| 1046 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1047 | globals_->system_proxy_service.reset( |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1048 | ProxyServiceFactory::CreateProxyService( |
| 1049 | net_log_, |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1050 | globals_->proxy_script_fetcher_context.get(), |
[email protected] | 8def32a0 | 2013-03-11 19:13:23 | [diff] [blame] | 1051 | globals_->system_network_delegate.get(), |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1052 | system_proxy_config_service_.release(), |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 1053 | command_line, |
| 1054 | quick_check_enabled_.GetValue())); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 1055 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1056 | net::HttpNetworkSession::Params system_params; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1057 | InitializeNetworkSessionParams(&system_params); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1058 | system_params.net_log = net_log_; |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 1059 | system_params.proxy_service = globals_->system_proxy_service.get(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 1060 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1061 | globals_->system_http_transaction_factory.reset( |
| 1062 | new net::HttpNetworkLayer( |
| 1063 | new net::HttpNetworkSession(system_params))); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1064 | globals_->system_request_context.reset( |
| 1065 | ConstructSystemRequestContext(globals_, net_log_)); |
[email protected] | d24fc3a0 | 2012-02-11 02:08:34 | [diff] [blame] | 1066 | |
| 1067 | sdch_manager_->set_sdch_fetcher( |
| 1068 | new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1069 | } |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 1070 | |
| 1071 | void IOThread::UpdateDnsClientEnabled() { |
| 1072 | globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
| 1073 | } |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1074 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1075 | void IOThread::ConfigureQuic(const CommandLine& command_line) { |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1076 | // Always fetch the field trial group to ensure it is reported correctly. |
| 1077 | // The command line flags will be associated with a group that is reported |
| 1078 | // so long as trial is actually queried. |
| 1079 | std::string quic_trial_group = |
| 1080 | base::FieldTrialList::FindFullName(kQuicFieldTrialName); |
| 1081 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1082 | bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group); |
| 1083 | globals_->enable_quic.set(enable_quic); |
| 1084 | if (enable_quic) { |
| 1085 | globals_->enable_quic_https.set( |
| 1086 | ShouldEnableQuicHttps(command_line, quic_trial_group)); |
[email protected] | c80f7c9 | 2014-02-27 13:12:02 | [diff] [blame] | 1087 | globals_->enable_quic_pacing.set( |
| 1088 | ShouldEnableQuicPacing(command_line, quic_trial_group)); |
[email protected] | d412ef7 | 2014-03-03 21:13:14 | [diff] [blame] | 1089 | globals_->enable_quic_persist_server_info.set( |
| 1090 | ShouldEnableQuicPersistServerInfo(command_line)); |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1091 | globals_->enable_quic_port_selection.set( |
| 1092 | ShouldEnableQuicPortSelection(command_line)); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | size_t max_packet_length = GetQuicMaxPacketLength(command_line, |
| 1096 | quic_trial_group); |
| 1097 | if (max_packet_length != 0) { |
| 1098 | globals_->quic_max_packet_length.set(max_packet_length); |
| 1099 | } |
| 1100 | |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1101 | net::QuicVersion version = GetQuicVersion(command_line); |
| 1102 | if (version != net::QUIC_VERSION_UNSUPPORTED) { |
| 1103 | net::QuicVersionVector supported_versions; |
| 1104 | supported_versions.push_back(version); |
| 1105 | globals_->quic_supported_versions.set(supported_versions); |
| 1106 | } |
| 1107 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1108 | if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { |
| 1109 | net::HostPortPair quic_origin = |
| 1110 | net::HostPortPair::FromString( |
| 1111 | command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn)); |
| 1112 | if (!quic_origin.IsEmpty()) { |
| 1113 | globals_->origin_to_force_quic_on.set(quic_origin); |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | bool IOThread::ShouldEnableQuic(const CommandLine& command_line, |
| 1119 | base::StringPiece quic_trial_group) { |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1120 | if (command_line.HasSwitch(switches::kDisableQuic)) |
| 1121 | return false; |
| 1122 | |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1123 | if (command_line.HasSwitch(switches::kEnableQuic)) |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1124 | return true; |
| 1125 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1126 | return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || |
| 1127 | quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1128 | } |
| 1129 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1130 | bool IOThread::ShouldEnableQuicHttps(const CommandLine& command_line, |
| 1131 | base::StringPiece quic_trial_group) { |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1132 | if (command_line.HasSwitch(switches::kDisableQuicHttps)) |
| 1133 | return false; |
| 1134 | |
| 1135 | if (command_line.HasSwitch(switches::kEnableQuicHttps)) |
| 1136 | return true; |
| 1137 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1138 | return quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
| 1139 | } |
| 1140 | |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1141 | bool IOThread::ShouldEnableQuicPortSelection( |
| 1142 | const CommandLine& command_line) { |
| 1143 | if (command_line.HasSwitch(switches::kDisableQuicPortSelection)) |
| 1144 | return false; |
| 1145 | |
| 1146 | if (command_line.HasSwitch(switches::kEnableQuicPortSelection)) |
| 1147 | return true; |
| 1148 | |
| 1149 | #if defined(OS_WIN) |
| 1150 | chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 1151 | // Avoid picking ports (which might induce a security dialog) when we have a |
| 1152 | // beta or stable release. Allow in all other cases, including when we do a |
| 1153 | // developer build (CHANNEL_UNKNOWN). |
| 1154 | if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 1155 | channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 1156 | // TODO(grt) bug=329255: Detect presence of rule on Windows that allows us |
| 1157 | // to do port selection without inducing a dialog. |
| 1158 | // When we have an API to see if the administrative security manager will |
| 1159 | // allow port selection without a security dialog, we may return true if |
| 1160 | // we're sure there will be no security dialog. |
| 1161 | return false; |
| 1162 | } |
| 1163 | return true; |
| 1164 | #else |
| 1165 | return true; |
| 1166 | #endif |
| 1167 | } |
| 1168 | |
[email protected] | c80f7c9 | 2014-02-27 13:12:02 | [diff] [blame] | 1169 | bool IOThread::ShouldEnableQuicPacing(const CommandLine& command_line, |
| 1170 | base::StringPiece quic_trial_group) { |
| 1171 | if (command_line.HasSwitch(switches::kEnableQuicPacing)) |
| 1172 | return true; |
| 1173 | |
| 1174 | if (command_line.HasSwitch(switches::kDisableQuicPacing)) |
| 1175 | return false; |
| 1176 | |
| 1177 | return quic_trial_group.ends_with(kQuicFieldTrialPacingSuffix); |
| 1178 | } |
| 1179 | |
[email protected] | d412ef7 | 2014-03-03 21:13:14 | [diff] [blame] | 1180 | bool IOThread::ShouldEnableQuicPersistServerInfo( |
| 1181 | const CommandLine& command_line) { |
| 1182 | chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 1183 | // Avoid persisting of Quic server config information to disk cache when we |
| 1184 | // have a beta or stable release. Allow in all other cases, including when we |
| 1185 | // do a developer build (CHANNEL_UNKNOWN). |
| 1186 | if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 1187 | channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 1188 | return false; |
| 1189 | } |
| 1190 | return true; |
| 1191 | } |
| 1192 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1193 | size_t IOThread::GetQuicMaxPacketLength(const CommandLine& command_line, |
| 1194 | base::StringPiece quic_trial_group) { |
| 1195 | if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) { |
| 1196 | unsigned value; |
| 1197 | if (!base::StringToUint( |
| 1198 | command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength), |
| 1199 | &value)) { |
| 1200 | return 0; |
| 1201 | } |
| 1202 | return value; |
| 1203 | } |
| 1204 | |
| 1205 | // Format of the packet length group names is: |
| 1206 | // (Https)?Enabled<length>BytePackets. |
| 1207 | base::StringPiece length_str(quic_trial_group); |
| 1208 | if (length_str.starts_with(kQuicFieldTrialEnabledGroupName)) { |
| 1209 | length_str.remove_prefix(strlen(kQuicFieldTrialEnabledGroupName)); |
| 1210 | } else if (length_str.starts_with(kQuicFieldTrialHttpsEnabledGroupName)) { |
| 1211 | length_str.remove_prefix(strlen(kQuicFieldTrialHttpsEnabledGroupName)); |
| 1212 | } else { |
| 1213 | return 0; |
| 1214 | } |
| 1215 | if (!length_str.ends_with(kQuicFieldTrialPacketLengthSuffix)) { |
| 1216 | return 0; |
| 1217 | } |
| 1218 | length_str.remove_suffix(strlen(kQuicFieldTrialPacketLengthSuffix)); |
| 1219 | unsigned value; |
| 1220 | if (!base::StringToUint(length_str, &value)) { |
| 1221 | return 0; |
| 1222 | } |
| 1223 | return value; |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1224 | } |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1225 | |
| 1226 | net::QuicVersion IOThread::GetQuicVersion(const CommandLine& command_line) { |
| 1227 | if (!command_line.HasSwitch(switches::kQuicVersion)) { |
| 1228 | return net::QUIC_VERSION_UNSUPPORTED; |
| 1229 | } |
| 1230 | net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); |
| 1231 | std::string version_flag = |
| 1232 | command_line.GetSwitchValueASCII(switches::kQuicVersion); |
| 1233 | for (size_t i = 0; i < supported_versions.size(); ++i) { |
| 1234 | net::QuicVersion version = supported_versions[i]; |
| 1235 | if (net::QuicVersionToString(version) == version_flag) { |
| 1236 | return version; |
| 1237 | } |
| 1238 | } |
| 1239 | return net::QUIC_VERSION_UNSUPPORTED; |
| 1240 | } |