[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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 15 | #include "base/logging.h" |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 17 | #include "base/prefs/pref_registry_simple.h" |
| 18 | #include "base/prefs/pref_service.h" |
michaeln | 3e5bced | 2015-02-09 22:58:23 | [diff] [blame] | 19 | #include "base/profiler/scoped_tracker.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" |
bnc | e3553d9 | 2014-10-30 22:29:45 | [diff] [blame] | 22 | #include "base/strings/string_piece.h" |
[email protected] | 1988e1c | 2013-02-28 20:27:42 | [diff] [blame] | 23 | #include "base/strings/string_split.h" |
[email protected] | 9c7ddc9 | 2013-06-11 01:40:57 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 25 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 3fc40c14 | 2011-12-01 13:09:04 | [diff] [blame] | 26 | #include "base/threading/thread.h" |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 27 | #include "base/threading/worker_pool.h" |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 28 | #include "base/time/time.h" |
primiano | 6221e57 | 2015-01-28 12:14:34 | [diff] [blame] | 29 | #include "base/trace_event/trace_event.h" |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 30 | #include "build/build_config.h" |
[email protected] | df2840d | 2011-02-20 16:32:32 | [diff] [blame] | 31 | #include "chrome/browser/browser_process.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] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 35 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 36 | #include "chrome/browser/net/dns_probe_service.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 37 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 38 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 39 | #include "chrome/common/chrome_content_client.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 40 | #include "chrome/common/chrome_switches.h" |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 41 | #include "chrome/common/chrome_version_info.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 42 | #include "chrome/common/pref_names.h" |
megjablon | 3476e04 | 2014-10-14 19:21:59 | [diff] [blame] | 43 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 44 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
[email protected] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 45 | #include "components/policy/core/common/policy_service.h" |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 46 | #include "components/variations/variations_associated_data.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 47 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 48 | #include "content/public/browser/cookie_store_factory.h" |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 49 | #include "net/base/host_mapping_rules.h" |
[email protected] | 32eaa33 | 2010-02-08 22:15:54 | [diff] [blame] | 50 | #include "net/base/net_util.h" |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 51 | #include "net/base/network_quality_estimator.h" |
rdsmith | 60e6e6fb | 2015-03-05 16:49:20 | [diff] [blame] | 52 | #include "net/base/sdch_manager.h" |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 53 | #include "net/cert/cert_policy_enforcer.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 54 | #include "net/cert/cert_verifier.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 55 | #include "net/cert/cert_verify_proc.h" |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 56 | #include "net/cert/ct_known_logs.h" |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 57 | #include "net/cert/ct_known_logs_static.h" |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 58 | #include "net/cert/ct_log_verifier.h" |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 59 | #include "net/cert/ct_verifier.h" |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 60 | #include "net/cert/multi_log_ct_verifier.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 61 | #include "net/cert/multi_threaded_cert_verifier.h" |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 62 | #include "net/cookies/cookie_store.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 63 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 64 | #include "net/dns/host_resolver.h" |
| 65 | #include "net/dns/mapped_host_resolver.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 66 | #include "net/ftp/ftp_network_layer.h" |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 67 | #include "net/http/http_auth_filter.h" |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 68 | #include "net/http/http_auth_handler_factory.h" |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 69 | #include "net/http/http_network_layer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 70 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 71 | #include "net/proxy/proxy_config_service.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 72 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 73 | #include "net/proxy/proxy_service.h" |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 74 | #include "net/quic/crypto/crypto_protocol.h" |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 75 | #include "net/quic/quic_protocol.h" |
mef | cb6537c | 2014-11-12 19:38:50 | [diff] [blame] | 76 | #include "net/quic/quic_utils.h" |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 77 | #include "net/socket/tcp_client_socket.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 78 | #include "net/spdy/spdy_session.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 79 | #include "net/ssl/channel_id_service.h" |
| 80 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 81 | #include "net/url_request/data_protocol_handler.h" |
| 82 | #include "net/url_request/file_protocol_handler.h" |
| 83 | #include "net/url_request/ftp_protocol_handler.h" |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 84 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 85 | #include "net/url_request/url_fetcher.h" |
[email protected] | f9c8c7c | 2014-07-31 16:42:31 | [diff] [blame] | 86 | #include "net/url_request/url_request_context.h" |
| 87 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 88 | #include "net/url_request/url_request_job_factory_impl.h" |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 89 | #include "net/url_request/url_request_throttler_manager.h" |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 90 | #include "url/url_constants.h" |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 91 | |
| 92 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 93 | #include "policy/policy_constants.h" |
| 94 | #endif |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 95 | |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 96 | #if defined(ENABLE_EXTENSIONS) |
| 97 | #include "chrome/browser/extensions/event_router_forwarder.h" |
| 98 | #endif |
| 99 | |
davidben | 71f35ff | 2015-04-17 20:54:48 | [diff] [blame] | 100 | #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
eroman | ed744f3 | 2015-04-09 06:35:49 | [diff] [blame] | 101 | #include "net/cert_net/nss_ocsp.h" |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 102 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 103 | |
jeremyim | b6c97ae | 2015-01-05 22:57:14 | [diff] [blame] | 104 | #if defined(OS_ANDROID) |
| 105 | #include "base/android/build_info.h" |
| 106 | #endif |
| 107 | |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 108 | #if defined(OS_CHROMEOS) |
| 109 | #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h" |
[email protected] | 106ccd2c | 2014-06-17 09:21:00 | [diff] [blame] | 110 | #include "chromeos/network/host_resolver_impl_chromeos.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 111 | #endif |
| 112 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 113 | using content::BrowserThread; |
| 114 | |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 115 | class SafeBrowsingURLRequestContext; |
| 116 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 117 | // The IOThread object must outlive any tasks posted to the IO thread before the |
| 118 | // Quit task, so base::Bind() calls are not refcounted. |
| 119 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 120 | namespace { |
| 121 | |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 122 | const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen"; |
| 123 | const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled"; |
| 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] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 128 | |
[email protected] | 44a10142 | 2014-07-02 22:12:57 | [diff] [blame] | 129 | // The SPDY trial composes two different trial plus control groups: |
| 130 | // * A "holdback" group with SPDY disabled, and corresponding control |
| 131 | // (SPDY/3.1). The primary purpose of the holdback group is to encourage site |
| 132 | // operators to do feature detection rather than UA-sniffing. As such, this |
| 133 | // trial runs continuously. |
| 134 | // * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and |
| 135 | // eventual SPDY/4 deployment. |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 136 | const char kSpdyFieldTrialName[] = "SPDY"; |
bnc | e3553d9 | 2014-10-30 22:29:45 | [diff] [blame] | 137 | const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled"; |
bnc | e3553d9 | 2014-10-30 22:29:45 | [diff] [blame] | 138 | const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled"; |
| 139 | const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled"; |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 140 | const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized"; |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 141 | |
ricea | 64c07d79 | 2014-10-08 03:37:00 | [diff] [blame] | 142 | // Field trial for Cache-Control: stale-while-revalidate directive. |
| 143 | const char kStaleWhileRevalidateFieldTrialName[] = "StaleWhileRevalidate"; |
| 144 | |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 145 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 146 | void ObserveKeychainEvents() { |
| 147 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 148 | net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); |
| 149 | } |
| 150 | #endif |
| 151 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 152 | // Used for the "system" URLRequestContext. |
| 153 | class SystemURLRequestContext : public net::URLRequestContext { |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 154 | public: |
| 155 | SystemURLRequestContext() { |
davidben | 71f35ff | 2015-04-17 20:54:48 | [diff] [blame] | 156 | #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 157 | net::SetURLRequestContextForNSSHttpIO(this); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 158 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | private: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 162 | ~SystemURLRequestContext() override { |
[email protected] | 42455949 | 2014-07-22 00:27:40 | [diff] [blame] | 163 | AssertNoURLRequests(); |
davidben | 71f35ff | 2015-04-17 20:54:48 | [diff] [blame] | 164 | #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 165 | net::SetURLRequestContextForNSSHttpIO(NULL); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 166 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 167 | } |
| 168 | }; |
| 169 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 170 | scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { |
[email protected] | d22f06e | 2013-06-11 16:01:17 | [diff] [blame] | 171 | TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 172 | const base::CommandLine& command_line = |
| 173 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 174 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 175 | net::HostResolver::Options options; |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 176 | |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 177 | // Use the retry attempts override from the command-line, if any. |
| 178 | if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 179 | std::string s = |
| 180 | command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
| 181 | // Parse the switch (it should be a non-negative integer). |
| 182 | int n; |
| 183 | if (base::StringToInt(s, &n) && n >= 0) { |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 184 | options.max_retry_attempts = static_cast<size_t>(n); |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 185 | } else { |
| 186 | LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 187 | } |
| 188 | } |
| 189 | |
[email protected] | 106ccd2c | 2014-06-17 09:21:00 | [diff] [blame] | 190 | scoped_ptr<net::HostResolver> global_host_resolver; |
| 191 | #if defined OS_CHROMEOS |
| 192 | global_host_resolver = |
| 193 | chromeos::HostResolverImplChromeOS::CreateSystemResolver(options, |
| 194 | net_log); |
| 195 | #else |
| 196 | global_host_resolver = |
| 197 | net::HostResolver::CreateSystemResolver(options, net_log); |
| 198 | #endif |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 199 | |
[email protected] | 3dc5d7ef | 2014-03-28 19:18:21 | [diff] [blame] | 200 | // If hostname remappings were specified on the command-line, layer these |
| 201 | // rules on top of the real host resolver. This allows forwarding all requests |
| 202 | // through a designated test server. |
| 203 | if (!command_line.HasSwitch(switches::kHostResolverRules)) |
dcheng | 383ba8a | 2014-10-16 23:55:19 | [diff] [blame] | 204 | return global_host_resolver.Pass(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 205 | |
[email protected] | 3dc5d7ef | 2014-03-28 19:18:21 | [diff] [blame] | 206 | scoped_ptr<net::MappedHostResolver> remapped_resolver( |
| 207 | new net::MappedHostResolver(global_host_resolver.Pass())); |
| 208 | remapped_resolver->SetRulesFromString( |
| 209 | command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
dcheng | 383ba8a | 2014-10-16 23:55:19 | [diff] [blame] | 210 | return remapped_resolver.Pass(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 213 | // TODO(willchan): Remove proxy script fetcher context since it's not necessary |
| 214 | // now that I got rid of refcounting URLRequestContexts. |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 215 | // See IOThread::Globals for details. |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 216 | net::URLRequestContext* |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 217 | ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| 218 | net::NetLog* net_log) { |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 219 | net::URLRequestContext* context = new net::URLRequestContext; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 220 | context->set_net_log(net_log); |
| 221 | context->set_host_resolver(globals->host_resolver.get()); |
| 222 | context->set_cert_verifier(globals->cert_verifier.get()); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 223 | context->set_transport_security_state( |
| 224 | globals->transport_security_state.get()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 225 | context->set_cert_transparency_verifier( |
| 226 | globals->cert_transparency_verifier.get()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 227 | context->set_http_auth_handler_factory( |
| 228 | globals->http_auth_handler_factory.get()); |
| 229 | context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 230 | context->set_http_transaction_factory( |
[email protected] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 231 | globals->proxy_script_fetcher_http_transaction_factory.get()); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 232 | context->set_job_factory( |
| 233 | globals->proxy_script_fetcher_url_request_job_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 234 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 235 | context->set_channel_id_service( |
| 236 | globals->system_channel_id_service.get()); |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 237 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 238 | context->set_http_user_agent_settings( |
| 239 | globals->http_user_agent_settings.get()); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 240 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 241 | // system URLRequestContext too. There's no reason this should be tied to a |
| 242 | // profile. |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 243 | return context; |
| 244 | } |
| 245 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 246 | net::URLRequestContext* |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 247 | ConstructSystemRequestContext(IOThread::Globals* globals, |
| 248 | net::NetLog* net_log) { |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 249 | net::URLRequestContext* context = new SystemURLRequestContext; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 250 | context->set_net_log(net_log); |
| 251 | context->set_host_resolver(globals->host_resolver.get()); |
| 252 | context->set_cert_verifier(globals->cert_verifier.get()); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 253 | context->set_transport_security_state( |
| 254 | globals->transport_security_state.get()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 255 | context->set_cert_transparency_verifier( |
| 256 | globals->cert_transparency_verifier.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 257 | context->set_http_auth_handler_factory( |
| 258 | globals->http_auth_handler_factory.get()); |
| 259 | context->set_proxy_service(globals->system_proxy_service.get()); |
| 260 | context->set_http_transaction_factory( |
| 261 | globals->system_http_transaction_factory.get()); |
[email protected] | 2944afa | 2014-06-13 00:41:29 | [diff] [blame] | 262 | context->set_job_factory(globals->system_url_request_job_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 263 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 264 | context->set_channel_id_service( |
| 265 | globals->system_channel_id_service.get()); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 266 | context->set_throttler_manager(globals->throttler_manager.get()); |
[email protected] | 815c69cf | 2012-06-30 00:52:08 | [diff] [blame] | 267 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 268 | context->set_http_user_agent_settings( |
| 269 | globals->http_user_agent_settings.get()); |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 270 | context->set_network_quality_estimator( |
| 271 | globals->network_quality_estimator.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 272 | return context; |
| 273 | } |
| 274 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 275 | int GetSwitchValueAsInt(const base::CommandLine& command_line, |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 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] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 285 | // Returns the value associated with |key| in |params| or "" if the |
| 286 | // key is not present in the map. |
| 287 | const std::string& GetVariationParam( |
| 288 | const std::map<std::string, std::string>& params, |
| 289 | const std::string& key) { |
| 290 | std::map<std::string, std::string>::const_iterator it = params.find(key); |
| 291 | if (it == params.end()) |
| 292 | return base::EmptyString(); |
| 293 | |
| 294 | return it->second; |
| 295 | } |
| 296 | |
ricea | 4373698 | 2014-10-30 09:15:48 | [diff] [blame] | 297 | // Return true if stale-while-revalidate support should be enabled. |
| 298 | bool IsStaleWhileRevalidateEnabled(const base::CommandLine& command_line) { |
| 299 | if (command_line.HasSwitch(switches::kEnableStaleWhileRevalidate)) |
| 300 | return true; |
| 301 | const std::string group_name = |
| 302 | base::FieldTrialList::FindFullName(kStaleWhileRevalidateFieldTrialName); |
| 303 | return group_name == "Enabled"; |
| 304 | } |
| 305 | |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 306 | // Parse kUseSpdy command line flag options, which may contain the following: |
| 307 | // |
| 308 | // "off" : Disables SPDY support entirely. |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 309 | // "no-ping" : Disables SPDY ping connection testing. |
| 310 | // "exclude=<host>" : Disables SPDY support for the host <host>. |
| 311 | // "no-compress" : Disables SPDY header compression. |
| 312 | // "no-alt-protocols : Disables alternate protocol support. |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 313 | // "init-max-streams=<limit>" : Specifies the maximum number of concurrent |
| 314 | // streams for a SPDY session, unless the |
| 315 | // specifies a different value via SETTINGS. |
| 316 | void ConfigureSpdyGlobalsFromUseSpdyArgument(const std::string& mode, |
| 317 | IOThread::Globals* globals) { |
| 318 | static const char kOff[] = "off"; |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 319 | static const char kDisablePing[] = "no-ping"; |
| 320 | static const char kExclude[] = "exclude"; // Hosts to exclude |
| 321 | static const char kDisableCompression[] = "no-compress"; |
| 322 | static const char kDisableAltProtocols[] = "no-alt-protocols"; |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 323 | static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; |
| 324 | |
| 325 | std::vector<std::string> spdy_options; |
| 326 | base::SplitString(mode, ',', &spdy_options); |
| 327 | |
| 328 | for (const std::string& element : spdy_options) { |
| 329 | std::vector<std::string> name_value; |
| 330 | base::SplitString(element, '=', &name_value); |
| 331 | const std::string& option = |
| 332 | name_value.size() > 0 ? name_value[0] : std::string(); |
| 333 | const std::string value = |
| 334 | name_value.size() > 1 ? name_value[1] : std::string(); |
| 335 | |
| 336 | if (option == kOff) { |
| 337 | net::HttpStreamFactory::set_spdy_enabled(false); |
| 338 | continue; |
| 339 | } |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 340 | if (option == kDisablePing) { |
| 341 | globals->enable_spdy_ping_based_connection_checking.set(false); |
| 342 | continue; |
| 343 | } |
| 344 | if (option == kExclude) { |
| 345 | globals->forced_spdy_exclusions.insert( |
| 346 | net::HostPortPair::FromURL(GURL(value))); |
| 347 | continue; |
| 348 | } |
| 349 | if (option == kDisableCompression) { |
| 350 | globals->enable_spdy_compression.set(false); |
| 351 | continue; |
| 352 | } |
| 353 | if (option == kDisableAltProtocols) { |
| 354 | globals->use_alternate_protocols.set(false); |
| 355 | continue; |
| 356 | } |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 357 | if (option == kInitialMaxConcurrentStreams) { |
| 358 | int streams; |
| 359 | if (base::StringToInt(value, &streams)) { |
| 360 | globals->initial_max_spdy_concurrent_streams.set(streams); |
| 361 | continue; |
| 362 | } |
| 363 | } |
| 364 | LOG(DFATAL) << "Unrecognized spdy option: " << option; |
| 365 | } |
| 366 | } |
| 367 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 368 | } // namespace |
| 369 | |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 370 | class IOThread::LoggingNetworkChangeObserver |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 371 | : public net::NetworkChangeNotifier::IPAddressObserver, |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 372 | public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 373 | public net::NetworkChangeNotifier::NetworkChangeObserver { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 374 | public: |
| 375 | // |net_log| must remain valid throughout our lifetime. |
| 376 | explicit LoggingNetworkChangeObserver(net::NetLog* net_log) |
| 377 | : net_log_(net_log) { |
| 378 | net::NetworkChangeNotifier::AddIPAddressObserver(this); |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 379 | net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 380 | net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 381 | } |
| 382 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 383 | ~LoggingNetworkChangeObserver() override { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 384 | net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 385 | net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 386 | net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 389 | // NetworkChangeNotifier::IPAddressObserver implementation. |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 390 | void OnIPAddressChanged() override { |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 391 | VLOG(1) << "Observed a change to the network IP addresses"; |
| 392 | |
[email protected] | 2fa0891 | 2012-06-14 20:56:26 | [diff] [blame] | 393 | net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 396 | // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 397 | void OnConnectionTypeChanged( |
mostynb | 01d8b10e | 2014-10-13 09:44:44 | [diff] [blame] | 398 | net::NetworkChangeNotifier::ConnectionType type) override { |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 399 | std::string type_as_string = |
| 400 | net::NetworkChangeNotifier::ConnectionTypeToString(type); |
| 401 | |
| 402 | VLOG(1) << "Observed a change to network connectivity state " |
| 403 | << type_as_string; |
| 404 | |
| 405 | net_log_->AddGlobalEntry( |
| 406 | net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED, |
| 407 | net::NetLog::StringCallback("new_connection_type", &type_as_string)); |
| 408 | } |
| 409 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 410 | // NetworkChangeNotifier::NetworkChangeObserver implementation. |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 411 | void OnNetworkChanged( |
mostynb | 01d8b10e | 2014-10-13 09:44:44 | [diff] [blame] | 412 | net::NetworkChangeNotifier::ConnectionType type) override { |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 413 | std::string type_as_string = |
| 414 | net::NetworkChangeNotifier::ConnectionTypeToString(type); |
| 415 | |
| 416 | VLOG(1) << "Observed a network change to state " << type_as_string; |
| 417 | |
| 418 | net_log_->AddGlobalEntry( |
| 419 | net::NetLog::TYPE_NETWORK_CHANGED, |
| 420 | net::NetLog::StringCallback("new_connection_type", &type_as_string)); |
| 421 | } |
| 422 | |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 423 | private: |
| 424 | net::NetLog* net_log_; |
| 425 | DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
| 426 | }; |
| 427 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 428 | class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 429 | public: |
| 430 | explicit SystemURLRequestContextGetter(IOThread* io_thread); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 431 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 432 | // Implementation for net::UrlRequestContextGetter. |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 433 | net::URLRequestContext* GetURLRequestContext() override; |
| 434 | scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| 435 | const override; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 436 | |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 437 | protected: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 438 | ~SystemURLRequestContextGetter() override; |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 439 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 440 | private: |
| 441 | IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 442 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 443 | |
| 444 | base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 445 | }; |
| 446 | |
| 447 | SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 448 | IOThread* io_thread) |
| 449 | : io_thread_(io_thread), |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 450 | network_task_runner_( |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 451 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 455 | |
| 456 | net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| 457 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 458 | DCHECK(io_thread_->globals()->system_request_context.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 459 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 460 | return io_thread_->globals()->system_request_context.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 463 | scoped_refptr<base::SingleThreadTaskRunner> |
| 464 | SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 465 | return network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 466 | } |
| 467 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 468 | IOThread::Globals:: |
| 469 | SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( |
| 470 | Globals* globals) |
| 471 | : globals_(globals) { |
| 472 | DCHECK(globals_); |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 473 | } |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 474 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 475 | IOThread::Globals:: |
| 476 | SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { |
| 477 | if (globals_->system_request_context.get()) |
| 478 | globals_->system_request_context->AssertNoURLRequests(); |
| 479 | } |
| 480 | |
| 481 | IOThread::Globals::Globals() |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 482 | : system_request_context_leak_checker(this), |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 483 | ignore_certificate_errors(false), |
ricea | 64c07d79 | 2014-10-08 03:37:00 | [diff] [blame] | 484 | use_stale_while_revalidate(false), |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 485 | testing_fixed_http_port(0), |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 486 | testing_fixed_https_port(0), |
| 487 | enable_user_alternate_protocol_ports(false) { |
| 488 | } |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 489 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 490 | IOThread::Globals::~Globals() {} |
| 491 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 492 | // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 493 | // dependencies and (2) make IOThread more flexible for testing. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 494 | IOThread::IOThread( |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 495 | PrefService* local_state, |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 496 | policy::PolicyService* policy_service, |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 497 | ChromeNetLog* net_log, |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 498 | extensions::EventRouterForwarder* extension_event_router_forwarder) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 499 | : net_log_(net_log), |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 500 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 501 | extension_event_router_forwarder_(extension_event_router_forwarder), |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 502 | #endif |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 503 | globals_(NULL), |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 504 | is_spdy_disabled_by_policy_(false), |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 505 | is_quic_allowed_by_policy_(true), |
mohan.reddy | 14cb4ad4 | 2014-09-17 18:15:14 | [diff] [blame] | 506 | creation_time_(base::TimeTicks::Now()), |
| 507 | weak_factory_(this) { |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 508 | auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
| 509 | negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
| 510 | prefs::kDisableAuthNegotiateCnameLookup); |
| 511 | negotiate_enable_port_ = local_state->GetBoolean( |
| 512 | prefs::kEnableAuthNegotiatePort); |
| 513 | auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); |
| 514 | auth_delegate_whitelist_ = local_state->GetString( |
| 515 | prefs::kAuthNegotiateDelegateWhitelist); |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 516 | gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 517 | pref_proxy_config_tracker_.reset( |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 518 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 519 | local_state)); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 520 | ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 521 | &system_enable_referrers_, |
| 522 | NULL, |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 523 | NULL, |
treib | 4e26f665 | 2014-12-01 14:34:18 | [diff] [blame] | 524 | NULL, |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 525 | local_state); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 526 | ssl_config_service_manager_.reset( |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 527 | SSLConfigServiceManager::CreateDefaultManager(local_state)); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 528 | |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 529 | base::Value* dns_client_enabled_default = new base::FundamentalValue( |
| 530 | chrome_browser_net::ConfigureAsyncDnsFieldTrial()); |
| 531 | local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled, |
| 532 | dns_client_enabled_default); |
ttuttle | 53018496 | 2015-01-13 00:24:07 | [diff] [blame] | 533 | chrome_browser_net::LogAsyncDnsPrefSource( |
| 534 | local_state->FindPreference(prefs::kBuiltInDnsClientEnabled)); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 535 | |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 536 | dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled, |
| 537 | local_state, |
| 538 | base::Bind(&IOThread::UpdateDnsClientEnabled, |
| 539 | base::Unretained(this))); |
| 540 | dns_client_enabled_.MoveToThread( |
| 541 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 542 | |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 543 | quick_check_enabled_.Init(prefs::kQuickCheckEnabled, |
| 544 | local_state); |
| 545 | quick_check_enabled_.MoveToThread( |
| 546 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 547 | |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 548 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 549 | is_spdy_disabled_by_policy_ = policy_service->GetPolicies( |
[email protected] | 2ccf8373 | 2013-02-04 20:19:02 | [diff] [blame] | 550 | policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get( |
| 551 | policy::key::kDisableSpdy) != NULL; |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 552 | |
| 553 | const base::Value* value = policy_service->GetPolicies( |
| 554 | policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
| 555 | std::string())).GetValue(policy::key::kQuicAllowed); |
| 556 | if (value) |
| 557 | value->GetAsBoolean(&is_quic_allowed_by_policy_); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 558 | #endif // ENABLE_CONFIGURATION_POLICY |
| 559 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 560 | BrowserThread::SetDelegate(BrowserThread::IO, this); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 561 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 562 | |
| 563 | IOThread::~IOThread() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 564 | // This isn't needed for production code, but in tests, IOThread may |
| 565 | // be multiply constructed. |
| 566 | BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
| 567 | |
[email protected] | d461ed2 | 2013-01-18 03:18:56 | [diff] [blame] | 568 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 569 | DCHECK(!globals_); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 572 | IOThread::Globals* IOThread::globals() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 573 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 574 | return globals_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 575 | } |
| 576 | |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 577 | void IOThread::SetGlobalsForTesting(Globals* globals) { |
| 578 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 579 | DCHECK(!globals || !globals_); |
| 580 | globals_ = globals; |
| 581 | } |
| 582 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 583 | ChromeNetLog* IOThread::net_log() { |
| 584 | return net_log_; |
| 585 | } |
| 586 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 587 | void IOThread::ChangedToOnTheRecord() { |
| 588 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 589 | BrowserThread::PostTask( |
| 590 | BrowserThread::IO, |
| 591 | FROM_HERE, |
| 592 | base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread, |
| 593 | base::Unretained(this))); |
| 594 | } |
| 595 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 596 | net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 597 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 598 | if (!system_url_request_context_getter_.get()) { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 599 | InitSystemRequestContext(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 600 | } |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 601 | return system_url_request_context_getter_.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 602 | } |
| 603 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 604 | void IOThread::Init() { |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 605 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 606 | // is fixed. |
| 607 | tracked_objects::ScopedTracker tracking_profile1( |
| 608 | FROM_HERE_WITH_EXPLICIT_FUNCTION("466432 IOThread::InitAsync::Start")); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 609 | TRACE_EVENT0("startup", "IOThread::InitAsync"); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 610 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 611 | |
davidben | 71f35ff | 2015-04-17 20:54:48 | [diff] [blame] | 612 | #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 613 | net::SetMessageLoopForNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 614 | #endif |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 615 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 616 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 617 | // is fixed. |
| 618 | tracked_objects::ScopedTracker tracking_profile2( |
| 619 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 620 | "466432 IOThread::InitAsync::CommandLineForCurrentProcess")); |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 621 | const base::CommandLine& command_line = |
| 622 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 623 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 624 | DCHECK(!globals_); |
| 625 | globals_ = new Globals; |
| 626 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 627 | // Add an observer that will emit network change events to the ChromeNetLog. |
| 628 | // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 629 | // logging the network change before other IO thread consumers respond to it. |
| 630 | network_change_observer_.reset( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 631 | new LoggingNetworkChangeObserver(net_log_)); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 632 | |
[email protected] | cde8b3c | 2012-08-13 19:20:52 | [diff] [blame] | 633 | // Setup the HistogramWatcher to run on the IO thread. |
| 634 | net::NetworkChangeNotifier::InitHistogramWatcher(); |
| 635 | |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 636 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 637 | globals_->extension_event_router_forwarder = |
| 638 | extension_event_router_forwarder_; |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 639 | #endif |
| 640 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 641 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 642 | // is fixed. |
| 643 | tracked_objects::ScopedTracker tracking_profile3( |
| 644 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 645 | "466432 IOThread::InitAsync::ChromeNetworkDelegate")); |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 646 | scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate( |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 647 | new ChromeNetworkDelegate(extension_event_router_forwarder(), |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 648 | &system_enable_referrers_)); |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 649 | |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 650 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 651 | if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 652 | chrome_network_delegate->NeverThrottleRequests(); |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 653 | #endif |
| 654 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 655 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 656 | // is fixed. |
| 657 | tracked_objects::ScopedTracker tracking_profile4( |
| 658 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 659 | "466432 IOThread::InitAsync::CreateGlobalHostResolver")); |
bengr | 9463b577 | 2015-01-24 00:24:54 | [diff] [blame] | 660 | globals_->system_network_delegate = chrome_network_delegate.Pass(); |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 661 | globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 662 | |
| 663 | globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator()); |
| 664 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 665 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 666 | // is fixed. |
| 667 | tracked_objects::ScopedTracker tracking_profile5( |
| 668 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 669 | "466432 IOThread::InitAsync::UpdateDnsClientEnabled::Start")); |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 670 | UpdateDnsClientEnabled(); |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 671 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 672 | // is fixed. |
| 673 | tracked_objects::ScopedTracker tracking_profile6( |
| 674 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 675 | "466432 IOThread::InitAsync::UpdateDnsClientEnabled::End")); |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 676 | #if defined(OS_CHROMEOS) |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 677 | // Creates a CertVerifyProc that doesn't allow any profile-provided certs. |
| 678 | globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier( |
| 679 | new chromeos::CertVerifyProcChromeOS())); |
| 680 | #else |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 681 | globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier( |
| 682 | net::CertVerifyProc::CreateDefault())); |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 683 | #endif |
| 684 | |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 685 | globals_->transport_security_state.reset(new net::TransportSecurityState()); |
| 686 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 687 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 688 | // is fixed. |
| 689 | tracked_objects::ScopedTracker tracking_profile7( |
| 690 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 691 | "466432 IOThread::InitAsync::CreateMultiLogVerifier")); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 692 | net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); |
| 693 | globals_->cert_transparency_verifier.reset(ct_verifier); |
| 694 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 695 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 696 | // is fixed. |
| 697 | tracked_objects::ScopedTracker tracking_profile8( |
| 698 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 699 | "466432 IOThread::InitAsync::CreateLogVerifiers::Start")); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 700 | // Add built-in logs |
[email protected] | c78b21a | 2014-06-24 17:47:51 | [diff] [blame] | 701 | ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 702 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 703 | // is fixed. |
| 704 | tracked_objects::ScopedTracker tracking_profile9( |
| 705 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 706 | "466432 IOThread::InitAsync::CreateLogVerifiers::End")); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 707 | |
| 708 | // Add logs from command line |
| 709 | if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) { |
| 710 | std::string switch_value = command_line.GetSwitchValueASCII( |
| 711 | switches::kCertificateTransparencyLog); |
[email protected] | 344bc95 | 2014-01-29 14:04:59 | [diff] [blame] | 712 | std::vector<std::string> logs; |
| 713 | base::SplitString(switch_value, ',', &logs); |
| 714 | for (std::vector<std::string>::iterator it = logs.begin(); it != logs.end(); |
| 715 | ++it) { |
| 716 | const std::string& curr_log = *it; |
eranm | d2f0b87 | 2015-05-05 16:57:03 | [diff] [blame] | 717 | std::vector<std::string> log_metadata; |
| 718 | base::SplitString(curr_log, ':', &log_metadata); |
| 719 | CHECK_GE(log_metadata.size(), 3u) |
| 720 | << "CT log metadata missing: Switch format is " |
| 721 | << "'description:base64_key:url_without_schema'."; |
| 722 | std::string log_description(log_metadata[0]); |
| 723 | std::string log_url(std::string("https://") + log_metadata[2]); |
[email protected] | 344bc95 | 2014-01-29 14:04:59 | [diff] [blame] | 724 | std::string ct_public_key_data; |
eranm | d2f0b87 | 2015-05-05 16:57:03 | [diff] [blame] | 725 | CHECK(base::Base64Decode(log_metadata[1], &ct_public_key_data)) |
[email protected] | 344bc95 | 2014-01-29 14:04:59 | [diff] [blame] | 726 | << "Unable to decode CT public key."; |
| 727 | scoped_ptr<net::CTLogVerifier> external_log_verifier( |
eranm | d2f0b87 | 2015-05-05 16:57:03 | [diff] [blame] | 728 | net::CTLogVerifier::Create(ct_public_key_data, log_description, |
| 729 | log_url)); |
[email protected] | 344bc95 | 2014-01-29 14:04:59 | [diff] [blame] | 730 | CHECK(external_log_verifier) << "Unable to parse CT public key."; |
| 731 | VLOG(1) << "Adding log with description " << log_description; |
| 732 | ct_verifier->AddLog(external_log_verifier.Pass()); |
| 733 | } |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 734 | } |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 735 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 736 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 737 | // is fixed. |
| 738 | tracked_objects::ScopedTracker tracking_profile10( |
| 739 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 740 | "466432 IOThread::InitAsync::CertPolicyEnforcer")); |
eranm | 9ca6c9a | 2015-05-06 19:10:00 | [diff] [blame] | 741 | net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer; |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 742 | globals_->cert_policy_enforcer.reset(policy_enforcer); |
| 743 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 744 | globals_->ssl_config_service = GetSSLConfigService(); |
[email protected] | f4bfa767 | 2014-08-08 09:50:46 | [diff] [blame] | 745 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 746 | globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 747 | globals_->host_resolver.get())); |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 748 | globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 749 | // For the ProxyScriptFetcher, we use a direct ProxyService. |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 750 | globals_->proxy_script_fetcher_proxy_service.reset( |
| 751 | net::ProxyService::CreateDirectWithNetLog(net_log_)); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 752 | // In-memory cookie store. |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 753 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 754 | // is fixed. |
| 755 | tracked_objects::ScopedTracker tracking_profile11( |
| 756 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 757 | "466432 IOThread::InitAsync::CreateCookieStore::Start")); |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 758 | globals_->system_cookie_store = |
| 759 | content::CreateCookieStore(content::CookieStoreConfig()); |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 760 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 761 | // is fixed. |
| 762 | tracked_objects::ScopedTracker tracking_profile12( |
| 763 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 764 | "466432 IOThread::InitAsync::CreateCookieStore::End")); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 765 | // In-memory channel ID store. |
| 766 | globals_->system_channel_id_service.reset( |
| 767 | new net::ChannelIDService( |
| 768 | new net::DefaultChannelIDStore(NULL), |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 769 | base::WorkerPool::GetTaskRunner(true))); |
erikchen | b035763 | 2015-04-22 00:36:50 | [diff] [blame] | 770 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 771 | // is fixed. |
| 772 | tracked_objects::ScopedTracker tracking_profile12_1( |
| 773 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 774 | "466432 IOThread::InitAsync::CreateDnsProbeService")); |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 775 | globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService()); |
erikchen | b035763 | 2015-04-22 00:36:50 | [diff] [blame] | 776 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 777 | // is fixed. |
| 778 | tracked_objects::ScopedTracker tracking_profile12_2( |
| 779 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 780 | "466432 IOThread::InitAsync::CreateHostMappingRules")); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 781 | globals_->host_mapping_rules.reset(new net::HostMappingRules()); |
erikchen | b035763 | 2015-04-22 00:36:50 | [diff] [blame] | 782 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 783 | // is fixed. |
| 784 | tracked_objects::ScopedTracker tracking_profile12_3( |
| 785 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 786 | "466432 IOThread::InitAsync::CreateHTTPUserAgentSettings")); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 787 | globals_->http_user_agent_settings.reset( |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 788 | new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent())); |
erikchen | b035763 | 2015-04-22 00:36:50 | [diff] [blame] | 789 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 790 | // is fixed. |
| 791 | tracked_objects::ScopedTracker tracking_profile12_4( |
| 792 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 793 | "466432 IOThread::InitAsync::CommandLineConfiguration")); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 794 | if (command_line.HasSwitch(switches::kHostRules)) { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 795 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 796 | globals_->host_mapping_rules->SetRulesFromString( |
| 797 | command_line.GetSwitchValueASCII(switches::kHostRules)); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 798 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 799 | } |
| 800 | if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) |
| 801 | globals_->ignore_certificate_errors = true; |
ricea | 4373698 | 2014-10-30 09:15:48 | [diff] [blame] | 802 | globals_->use_stale_while_revalidate = |
| 803 | IsStaleWhileRevalidateEnabled(command_line); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 804 | if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 805 | globals_->testing_fixed_http_port = |
| 806 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 807 | } |
| 808 | if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 809 | globals_->testing_fixed_https_port = |
| 810 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 811 | } |
erikchen | b035763 | 2015-04-22 00:36:50 | [diff] [blame] | 812 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 813 | // is fixed. |
| 814 | tracked_objects::ScopedTracker tracking_profile12_5( |
| 815 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 816 | "466432 IOThread::InitAsync::QuicConfiguration")); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 817 | ConfigureQuic(command_line); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 818 | if (command_line.HasSwitch( |
| 819 | switches::kEnableUserAlternateProtocolPorts)) { |
| 820 | globals_->enable_user_alternate_protocol_ports = true; |
| 821 | } |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 822 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 823 | // is fixed. |
| 824 | tracked_objects::ScopedTracker tracking_profile13( |
| 825 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 826 | "466432 IOThread::InitAsync::InitializeNetworkOptions")); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 827 | InitializeNetworkOptions(command_line); |
| 828 | |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 829 | net::HttpNetworkSession::Params session_params; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 830 | InitializeNetworkSessionParams(&session_params); |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 831 | session_params.net_log = net_log_; |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 832 | session_params.proxy_service = |
| 833 | globals_->proxy_script_fetcher_proxy_service.get(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 834 | |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 835 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 836 | // is fixed. |
| 837 | tracked_objects::ScopedTracker tracking_profile14( |
| 838 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 839 | "466432 IOThread::InitAsync::HttpNetorkSession::Start")); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 840 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:HttpNetworkSession"); |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 841 | scoped_refptr<net::HttpNetworkSession> network_session( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 842 | new net::HttpNetworkSession(session_params)); |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 843 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 844 | // is fixed. |
| 845 | tracked_objects::ScopedTracker tracking_profile15( |
| 846 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 847 | "466432 IOThread::InitAsync::HttpNetorkSession::End")); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 848 | globals_->proxy_script_fetcher_http_transaction_factory |
| 849 | .reset(new net::HttpNetworkLayer(network_session.get())); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 850 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:HttpNetworkSession"); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 851 | scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 852 | new net::URLRequestJobFactoryImpl()); |
erikchen | dc7ecc41 | 2015-03-12 02:46:36 | [diff] [blame] | 853 | |
| 854 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
| 855 | // is fixed. |
| 856 | tracked_objects::ScopedTracker tracking_profile16( |
| 857 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 858 | "466432 IOThread::InitAsync::SetProtocolHandler")); |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 859 | job_factory->SetProtocolHandler(url::kDataScheme, |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 860 | new net::DataProtocolHandler()); |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 861 | job_factory->SetProtocolHandler( |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 862 | url::kFileScheme, |
[email protected] | 255620da | 2013-08-19 13:14:29 | [diff] [blame] | 863 | new net::FileProtocolHandler( |
| 864 | content::BrowserThread::GetBlockingPool()-> |
| 865 | GetTaskRunnerWithShutdownBehavior( |
| 866 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 867 | #if !defined(DISABLE_FTP_SUPPORT) |
| 868 | globals_->proxy_script_fetcher_ftp_transaction_factory.reset( |
| 869 | new net::FtpNetworkLayer(globals_->host_resolver.get())); |
| 870 | job_factory->SetProtocolHandler( |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 871 | url::kFtpScheme, |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 872 | new net::FtpProtocolHandler( |
| 873 | globals_->proxy_script_fetcher_ftp_transaction_factory.get())); |
| 874 | #endif |
dcheng | 383ba8a | 2014-10-16 23:55:19 | [diff] [blame] | 875 | globals_->proxy_script_fetcher_url_request_job_factory = job_factory.Pass(); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 876 | |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 877 | globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 878 | globals_->throttler_manager->set_net_log(net_log_); |
[email protected] | 332a8c96 | 2013-07-17 22:31:23 | [diff] [blame] | 879 | // Always done in production, disabled only for unit tests. |
| 880 | globals_->throttler_manager->set_enable_thread_checks(true); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 881 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 882 | globals_->proxy_script_fetcher_context.reset( |
| 883 | ConstructProxyScriptFetcherContext(globals_, net_log_)); |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 884 | |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 885 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 886 | // Start observing Keychain events. This needs to be done on the UI thread, |
| 887 | // as Keychain services requires a CFRunLoop. |
| 888 | BrowserThread::PostTask(BrowserThread::UI, |
| 889 | FROM_HERE, |
| 890 | base::Bind(&ObserveKeychainEvents)); |
| 891 | #endif |
| 892 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 893 | // InitSystemRequestContext turns right around and posts a task back |
| 894 | // to the IO thread, so we can't let it run until we know the IO |
| 895 | // thread has started. |
| 896 | // |
| 897 | // Note that since we are at BrowserThread::Init time, the UI thread |
| 898 | // is blocked waiting for the thread to start. Therefore, posting |
| 899 | // this task to the main thread's message loop here is guaranteed to |
| 900 | // get it onto the message loop while the IOThread object still |
| 901 | // exists. However, the message might not be processed on the UI |
| 902 | // thread until after IOThread is gone, so use a weak pointer. |
| 903 | BrowserThread::PostTask(BrowserThread::UI, |
| 904 | FROM_HERE, |
| 905 | base::Bind(&IOThread::InitSystemRequestContext, |
| 906 | weak_factory_.GetWeakPtr())); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 907 | } |
| 908 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 909 | void IOThread::CleanUp() { |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 910 | base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); |
| 911 | |
davidben | 71f35ff | 2015-04-17 20:54:48 | [diff] [blame] | 912 | #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 913 | net::ShutdownNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 914 | #endif |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 915 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 916 | system_url_request_context_getter_ = NULL; |
| 917 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 918 | // Release objects that the net::URLRequestContext could have been pointing |
| 919 | // to. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 920 | |
[email protected] | 7592b41f | 2014-04-01 01:44:43 | [diff] [blame] | 921 | // Shutdown the HistogramWatcher on the IO thread. |
| 922 | net::NetworkChangeNotifier::ShutdownHistogramWatcher(); |
| 923 | |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 924 | // This must be reset before the ChromeNetLog is destroyed. |
| 925 | network_change_observer_.reset(); |
| 926 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 927 | system_proxy_config_service_.reset(); |
| 928 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 929 | delete globals_; |
| 930 | globals_ = NULL; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 931 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 932 | base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 933 | } |
| 934 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 935 | void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 936 | // Only handle use-spdy command line flags if "spdy.disabled" preference is |
| 937 | // not disabled via policy. |
[email protected] | aedfccd9b | 2013-10-02 03:24:46 | [diff] [blame] | 938 | if (is_spdy_disabled_by_policy_) { |
| 939 | base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); |
| 940 | if (trial) |
| 941 | trial->Disable(); |
| 942 | } else { |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 943 | std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName); |
| 944 | VariationParameters params; |
| 945 | if (!variations::GetVariationParams(kSpdyFieldTrialName, ¶ms)) { |
| 946 | params.clear(); |
[email protected] | aedf781f | 2013-07-15 21:38:15 | [diff] [blame] | 947 | } |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 948 | ConfigureSpdyGlobals(command_line, group, params, globals_); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 949 | } |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 950 | |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 951 | ConfigureTCPFastOpen(command_line); |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 952 | |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 953 | // TODO(rch): Make the client socket factory a per-network session |
| 954 | // instance, constructed from a NetworkSession::Params, to allow us |
| 955 | // to move this option to IOThread::Globals & |
| 956 | // HttpNetworkSession::Params. |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 957 | } |
jri | dcb4ae92 | 2014-09-12 23:52:39 | [diff] [blame] | 958 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 959 | void IOThread::ConfigureTCPFastOpen(const base::CommandLine& command_line) { |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 960 | const std::string trial_group = |
| 961 | base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); |
| 962 | if (trial_group == kTCPFastOpenHttpsEnabledGroupName) |
| 963 | globals_->enable_tcp_fast_open_for_ssl.set(true); |
jri | dcb4ae92 | 2014-09-12 23:52:39 | [diff] [blame] | 964 | bool always_enable_if_supported = |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 965 | command_line.HasSwitch(switches::kEnableTcpFastOpen); |
jri | dcb4ae92 | 2014-09-12 23:52:39 | [diff] [blame] | 966 | // Check for OS support of TCP FastOpen, and turn it on for all connections |
| 967 | // if indicated by user. |
| 968 | net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_if_supported); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 969 | } |
| 970 | |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 971 | // static |
| 972 | void IOThread::ConfigureSpdyGlobals( |
| 973 | const base::CommandLine& command_line, |
| 974 | base::StringPiece spdy_trial_group, |
| 975 | const VariationParameters& spdy_trial_params, |
| 976 | IOThread::Globals* globals) { |
| 977 | if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
| 978 | globals->trusted_spdy_proxy.set( |
| 979 | command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); |
| 980 | } |
| 981 | if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) |
| 982 | net::URLFetcher::SetIgnoreCertificateRequests(true); |
| 983 | |
| 984 | if (command_line.HasSwitch(switches::kUseSpdy)) { |
| 985 | std::string spdy_mode = |
| 986 | command_line.GetSwitchValueASCII(switches::kUseSpdy); |
| 987 | ConfigureSpdyGlobalsFromUseSpdyArgument(spdy_mode, globals); |
| 988 | return; |
| 989 | } |
| 990 | |
| 991 | globals->next_protos.clear(); |
| 992 | globals->next_protos.push_back(net::kProtoHTTP11); |
| 993 | bool enable_quic = false; |
| 994 | globals->enable_quic.CopyToIfSet(&enable_quic); |
| 995 | if (enable_quic) { |
| 996 | globals->next_protos.push_back(net::kProtoQUIC1SPDY3); |
| 997 | } |
| 998 | |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 999 | // No SPDY command-line flags have been specified. Examine trial groups. |
bnc | e3553d9 | 2014-10-30 22:29:45 | [diff] [blame] | 1000 | if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) { |
[email protected] | 44a10142 | 2014-07-02 22:12:57 | [diff] [blame] | 1001 | net::HttpStreamFactory::set_spdy_enabled(false); |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 1002 | return; |
[email protected] | 44a10142 | 2014-07-02 22:12:57 | [diff] [blame] | 1003 | } |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 1004 | if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy31GroupNamePrefix)) { |
| 1005 | globals->next_protos.push_back(net::kProtoSPDY31); |
| 1006 | globals->use_alternate_protocols.set(true); |
| 1007 | return; |
| 1008 | } |
| 1009 | if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy4GroupNamePrefix)) { |
| 1010 | globals->next_protos.push_back(net::kProtoSPDY31); |
| 1011 | globals->next_protos.push_back(net::kProtoSPDY4_14); |
| 1012 | globals->next_protos.push_back(net::kProtoSPDY4); |
| 1013 | globals->use_alternate_protocols.set(true); |
| 1014 | return; |
| 1015 | } |
| 1016 | if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) { |
| 1017 | bool spdy_enabled = false; |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1018 | if (base::LowerCaseEqualsASCII( |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 1019 | GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) { |
| 1020 | globals->next_protos.push_back(net::kProtoSPDY31); |
| 1021 | spdy_enabled = true; |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 1022 | } |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1023 | if (base::LowerCaseEqualsASCII( |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 1024 | GetVariationParam(spdy_trial_params, "enable_http2_14"), "true")) { |
| 1025 | globals->next_protos.push_back(net::kProtoSPDY4_14); |
| 1026 | spdy_enabled = true; |
| 1027 | } |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1028 | if (base::LowerCaseEqualsASCII( |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 1029 | GetVariationParam(spdy_trial_params, "enable_http2"), "true")) { |
| 1030 | globals->next_protos.push_back(net::kProtoSPDY4); |
| 1031 | spdy_enabled = true; |
| 1032 | } |
| 1033 | // TODO(bnc): HttpStreamFactory::spdy_enabled_ is redundant with |
| 1034 | // globals->next_protos, can it be eliminated? |
| 1035 | net::HttpStreamFactory::set_spdy_enabled(spdy_enabled); |
| 1036 | globals->use_alternate_protocols.set(true); |
| 1037 | return; |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 1038 | } |
bnc | bc0b05b | 2015-03-25 19:50:58 | [diff] [blame] | 1039 | |
| 1040 | // By default, enable HTTP/2. |
| 1041 | globals->next_protos.push_back(net::kProtoSPDY31); |
| 1042 | globals->next_protos.push_back(net::kProtoSPDY4_14); |
| 1043 | globals->next_protos.push_back(net::kProtoSPDY4); |
| 1044 | globals->use_alternate_protocols.set(true); |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 1045 | } |
| 1046 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 1047 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 1048 | void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { |
| 1049 | registry->RegisterStringPref(prefs::kAuthSchemes, |
bengr | 70266e2 | 2015-06-12 19:38:17 | [diff] [blame^] | 1050 | "basic,digest,ntlm,negotiate"); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 1051 | registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 1052 | registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1053 | registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string()); |
| 1054 | registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, |
| 1055 | std::string()); |
| 1056 | registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); |
[email protected] | a0a0693 | 2014-04-14 21:23:42 | [diff] [blame] | 1057 | registry->RegisterStringPref( |
| 1058 | data_reduction_proxy::prefs::kDataReductionProxy, std::string()); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 1059 | registry->RegisterBooleanPref(prefs::kEnableReferrers, true); |
[email protected] | 1575e3d | 2014-05-03 22:21:44 | [diff] [blame] | 1060 | data_reduction_proxy::RegisterPrefs(registry); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 1061 | registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true); |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 1062 | registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 1063 | } |
| 1064 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 1065 | net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( |
| 1066 | net::HostResolver* resolver) { |
[email protected] | 9030a63 | 2010-11-19 20:12:09 | [diff] [blame] | 1067 | net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL; |
| 1068 | if (!auth_server_whitelist_.empty()) { |
| 1069 | auth_filter_default_credentials = |
| 1070 | new net::HttpAuthFilterWhitelist(auth_server_whitelist_); |
| 1071 | } |
| 1072 | net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL; |
| 1073 | if (!auth_delegate_whitelist_.empty()) { |
| 1074 | auth_filter_delegate = |
| 1075 | new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_); |
| 1076 | } |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 1077 | globals_->url_security_manager.reset( |
[email protected] | d201b200e | 2010-08-27 17:35:02 | [diff] [blame] | 1078 | net::URLSecurityManager::Create(auth_filter_default_credentials, |
| 1079 | auth_filter_delegate)); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 1080 | std::vector<std::string> supported_schemes; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 1081 | base::SplitString(auth_schemes_, ',', &supported_schemes); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 1082 | |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 1083 | scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory( |
| 1084 | net::HttpAuthHandlerRegistryFactory::Create( |
| 1085 | supported_schemes, globals_->url_security_manager.get(), |
| 1086 | resolver, gssapi_library_name_, negotiate_disable_cname_lookup_, |
| 1087 | negotiate_enable_port_)); |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 1088 | return registry_factory.release(); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 1089 | } |
| 1090 | |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 1091 | void IOThread::ClearHostCache() { |
| 1092 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1093 | |
[email protected] | 489d1a8 | 2011-10-12 03:09:11 | [diff] [blame] | 1094 | net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 1095 | if (host_cache) |
| 1096 | host_cache->clear(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 1097 | } |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1098 | |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1099 | void IOThread::InitializeNetworkSessionParams( |
| 1100 | net::HttpNetworkSession::Params* params) { |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1101 | InitializeNetworkSessionParamsFromGlobals(*globals_, params); |
| 1102 | } |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1103 | |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1104 | // static |
| 1105 | void IOThread::InitializeNetworkSessionParamsFromGlobals( |
| 1106 | const IOThread::Globals& globals, |
| 1107 | net::HttpNetworkSession::Params* params) { |
| 1108 | params->host_resolver = globals.host_resolver.get(); |
| 1109 | params->cert_verifier = globals.cert_verifier.get(); |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 1110 | params->cert_policy_enforcer = globals.cert_policy_enforcer.get(); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 1111 | params->channel_id_service = globals.system_channel_id_service.get(); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1112 | params->transport_security_state = globals.transport_security_state.get(); |
| 1113 | params->ssl_config_service = globals.ssl_config_service.get(); |
| 1114 | params->http_auth_handler_factory = globals.http_auth_handler_factory.get(); |
| 1115 | params->http_server_properties = |
| 1116 | globals.http_server_properties->GetWeakPtr(); |
| 1117 | params->network_delegate = globals.system_network_delegate.get(); |
| 1118 | params->host_mapping_rules = globals.host_mapping_rules.get(); |
| 1119 | params->ignore_certificate_errors = globals.ignore_certificate_errors; |
ricea | 64c07d79 | 2014-10-08 03:37:00 | [diff] [blame] | 1120 | params->use_stale_while_revalidate = globals.use_stale_while_revalidate; |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1121 | params->testing_fixed_http_port = globals.testing_fixed_http_port; |
| 1122 | params->testing_fixed_https_port = globals.testing_fixed_https_port; |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 1123 | globals.enable_tcp_fast_open_for_ssl.CopyToIfSet( |
| 1124 | ¶ms->enable_tcp_fast_open_for_ssl); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1125 | |
| 1126 | globals.initial_max_spdy_concurrent_streams.CopyToIfSet( |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1127 | ¶ms->spdy_initial_max_concurrent_streams); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1128 | globals.enable_spdy_compression.CopyToIfSet( |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1129 | ¶ms->enable_spdy_compression); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1130 | globals.enable_spdy_ping_based_connection_checking.CopyToIfSet( |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1131 | ¶ms->enable_spdy_ping_based_connection_checking); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1132 | globals.spdy_default_protocol.CopyToIfSet( |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1133 | ¶ms->spdy_default_protocol); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1134 | params->next_protos = globals.next_protos; |
| 1135 | globals.trusted_spdy_proxy.CopyToIfSet(¶ms->trusted_spdy_proxy); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1136 | params->forced_spdy_exclusions = globals.forced_spdy_exclusions; |
| 1137 | globals.use_alternate_protocols.CopyToIfSet( |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1138 | ¶ms->use_alternate_protocols); |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1139 | globals.alternative_service_probability_threshold.CopyToIfSet( |
| 1140 | ¶ms->alternative_service_probability_threshold); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1141 | |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1142 | globals.enable_quic.CopyToIfSet(¶ms->enable_quic); |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1143 | globals.disable_insecure_quic.CopyToIfSet(¶ms->disable_insecure_quic); |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 1144 | globals.enable_quic_for_proxies.CopyToIfSet(¶ms->enable_quic_for_proxies); |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 1145 | globals.quic_always_require_handshake_confirmation.CopyToIfSet( |
| 1146 | ¶ms->quic_always_require_handshake_confirmation); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 1147 | globals.quic_disable_connection_pooling.CopyToIfSet( |
| 1148 | ¶ms->quic_disable_connection_pooling); |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 1149 | globals.quic_load_server_info_timeout_srtt_multiplier.CopyToIfSet( |
| 1150 | ¶ms->quic_load_server_info_timeout_srtt_multiplier); |
rtenneti | 4f80997 | 2015-02-11 19:38:34 | [diff] [blame] | 1151 | globals.quic_enable_connection_racing.CopyToIfSet( |
| 1152 | ¶ms->quic_enable_connection_racing); |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 1153 | globals.quic_enable_non_blocking_io.CopyToIfSet( |
| 1154 | ¶ms->quic_enable_non_blocking_io); |
rch | 9976b0c | 2015-06-10 21:27:23 | [diff] [blame] | 1155 | globals.quic_prefer_aes.CopyToIfSet(¶ms->quic_prefer_aes); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 1156 | globals.quic_disable_disk_cache.CopyToIfSet( |
| 1157 | ¶ms->quic_disable_disk_cache); |
rtenneti | 374e5688 | 2015-03-28 13:49:54 | [diff] [blame] | 1158 | globals.quic_max_number_of_lossy_connections.CopyToIfSet( |
| 1159 | ¶ms->quic_max_number_of_lossy_connections); |
| 1160 | globals.quic_packet_loss_threshold.CopyToIfSet( |
| 1161 | ¶ms->quic_packet_loss_threshold); |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 1162 | globals.quic_socket_receive_buffer_size.CopyToIfSet( |
| 1163 | ¶ms->quic_socket_receive_buffer_size); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1164 | globals.enable_quic_port_selection.CopyToIfSet( |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1165 | ¶ms->enable_quic_port_selection); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1166 | globals.quic_max_packet_length.CopyToIfSet(¶ms->quic_max_packet_length); |
| 1167 | globals.quic_user_agent_id.CopyToIfSet(¶ms->quic_user_agent_id); |
| 1168 | globals.quic_supported_versions.CopyToIfSet( |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1169 | ¶ms->quic_supported_versions); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1170 | params->quic_connection_options = globals.quic_connection_options; |
| 1171 | |
| 1172 | globals.origin_to_force_quic_on.CopyToIfSet( |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 1173 | ¶ms->origin_to_force_quic_on); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 1174 | params->enable_user_alternate_protocol_ports = |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1175 | globals.enable_user_alternate_protocol_ports; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1176 | } |
| 1177 | |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 1178 | base::TimeTicks IOThread::creation_time() const { |
| 1179 | return creation_time_; |
| 1180 | } |
| 1181 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 1182 | net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 1183 | return ssl_config_service_manager_->Get(); |
| 1184 | } |
| 1185 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 1186 | void IOThread::ChangedToOnTheRecordOnIOThread() { |
| 1187 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1188 | |
| 1189 | // Clear the host cache to avoid showing entries from the OTR session |
| 1190 | // in about:net-internals. |
| 1191 | ClearHostCache(); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 1192 | } |
| 1193 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1194 | void IOThread::InitSystemRequestContext() { |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 1195 | if (system_url_request_context_getter_.get()) |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1196 | return; |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 1197 | // If we're in unit_tests, IOThread may not be run. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 1198 | if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 1199 | return; |
[email protected] | 53c5b0f | 2013-07-22 10:54:11 | [diff] [blame] | 1200 | system_proxy_config_service_.reset( |
| 1201 | ProxyServiceFactory::CreateProxyConfigService( |
| 1202 | pref_proxy_config_tracker_.get())); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1203 | system_url_request_context_getter_ = |
| 1204 | new SystemURLRequestContextGetter(this); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1205 | // Safe to post an unretained this pointer, since IOThread is |
| 1206 | // guaranteed to outlive the IO BrowserThread. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 1207 | BrowserThread::PostTask( |
| 1208 | BrowserThread::IO, |
| 1209 | FROM_HERE, |
| 1210 | base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
| 1211 | base::Unretained(this))); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | void IOThread::InitSystemRequestContextOnIOThread() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1215 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1216 | DCHECK(!globals_->system_proxy_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1217 | DCHECK(system_proxy_config_service_.get()); |
| 1218 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1219 | const base::CommandLine& command_line = |
| 1220 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 1221 | globals_->system_proxy_service.reset( |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1222 | ProxyServiceFactory::CreateProxyService( |
| 1223 | net_log_, |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1224 | globals_->proxy_script_fetcher_context.get(), |
[email protected] | 8def32a0 | 2013-03-11 19:13:23 | [diff] [blame] | 1225 | globals_->system_network_delegate.get(), |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1226 | system_proxy_config_service_.release(), |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 1227 | command_line, |
| 1228 | quick_check_enabled_.GetValue())); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 1229 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1230 | net::HttpNetworkSession::Params system_params; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 1231 | InitializeNetworkSessionParams(&system_params); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1232 | system_params.net_log = net_log_; |
[email protected] | 27c25380 | 2012-11-30 08:18:12 | [diff] [blame] | 1233 | system_params.proxy_service = globals_->system_proxy_service.get(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 1234 | |
michaeln | e2fd577c | 2015-02-27 02:10:13 | [diff] [blame] | 1235 | globals_->system_http_transaction_factory.reset( |
| 1236 | new net::HttpNetworkLayer( |
| 1237 | new net::HttpNetworkSession(system_params))); |
[email protected] | 2944afa | 2014-06-13 00:41:29 | [diff] [blame] | 1238 | globals_->system_url_request_job_factory.reset( |
| 1239 | new net::URLRequestJobFactoryImpl()); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1240 | globals_->system_request_context.reset( |
| 1241 | ConstructSystemRequestContext(globals_, net_log_)); |
[email protected] | db8bf05 | 2014-06-25 11:53:10 | [diff] [blame] | 1242 | globals_->system_request_context->set_ssl_config_service( |
dcheng | 319a2195 | 2014-08-26 22:52:40 | [diff] [blame] | 1243 | globals_->ssl_config_service.get()); |
[email protected] | db8bf05 | 2014-06-25 11:53:10 | [diff] [blame] | 1244 | globals_->system_request_context->set_http_server_properties( |
| 1245 | globals_->http_server_properties->GetWeakPtr()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 1246 | } |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 1247 | |
| 1248 | void IOThread::UpdateDnsClientEnabled() { |
| 1249 | globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
| 1250 | } |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1251 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1252 | void IOThread::ConfigureQuic(const base::CommandLine& command_line) { |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1253 | // Always fetch the field trial group to ensure it is reported correctly. |
| 1254 | // The command line flags will be associated with a group that is reported |
| 1255 | // so long as trial is actually queried. |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1256 | std::string group = |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1257 | base::FieldTrialList::FindFullName(kQuicFieldTrialName); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1258 | VariationParameters params; |
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 1259 | if (!variations::GetVariationParams(kQuicFieldTrialName, ¶ms)) { |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1260 | params.clear(); |
| 1261 | } |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1262 | |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 1263 | ConfigureQuicGlobals(command_line, group, params, is_quic_allowed_by_policy_, |
| 1264 | globals_); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | // static |
| 1268 | void IOThread::ConfigureQuicGlobals( |
| 1269 | const base::CommandLine& command_line, |
| 1270 | base::StringPiece quic_trial_group, |
| 1271 | const VariationParameters& quic_trial_params, |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 1272 | bool quic_allowed_by_policy, |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1273 | IOThread::Globals* globals) { |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 1274 | bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group, |
| 1275 | quic_allowed_by_policy); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1276 | globals->enable_quic.set(enable_quic); |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 1277 | bool enable_quic_for_proxies = ShouldEnableQuicForProxies( |
| 1278 | command_line, quic_trial_group, quic_allowed_by_policy); |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 1279 | globals->enable_quic_for_proxies.set(enable_quic_for_proxies); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1280 | if (enable_quic) { |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1281 | globals->disable_insecure_quic.set( |
| 1282 | ShouldDisableInsecureQuic(quic_trial_params)); |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 1283 | globals->quic_always_require_handshake_confirmation.set( |
| 1284 | ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params)); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 1285 | globals->quic_disable_connection_pooling.set( |
| 1286 | ShouldQuicDisableConnectionPooling(quic_trial_params)); |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 1287 | int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params); |
| 1288 | if (receive_buffer_size != 0) { |
| 1289 | globals->quic_socket_receive_buffer_size.set(receive_buffer_size); |
| 1290 | } |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 1291 | float load_server_info_timeout_srtt_multiplier = |
| 1292 | GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params); |
| 1293 | if (load_server_info_timeout_srtt_multiplier != 0) { |
| 1294 | globals->quic_load_server_info_timeout_srtt_multiplier.set( |
| 1295 | load_server_info_timeout_srtt_multiplier); |
| 1296 | } |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 1297 | globals->quic_enable_connection_racing.set( |
| 1298 | ShouldQuicEnableConnectionRacing(quic_trial_params)); |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 1299 | globals->quic_enable_non_blocking_io.set( |
| 1300 | ShouldQuicEnableNonBlockingIO(quic_trial_params)); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 1301 | globals->quic_disable_disk_cache.set( |
| 1302 | ShouldQuicDisableDiskCache(quic_trial_params)); |
rch | 9976b0c | 2015-06-10 21:27:23 | [diff] [blame] | 1303 | globals->quic_prefer_aes.set( |
| 1304 | ShouldQuicPreferAes(quic_trial_params)); |
rtenneti | 374e5688 | 2015-03-28 13:49:54 | [diff] [blame] | 1305 | int max_number_of_lossy_connections = GetQuicMaxNumberOfLossyConnections( |
| 1306 | quic_trial_params); |
| 1307 | if (max_number_of_lossy_connections != 0) { |
| 1308 | globals->quic_max_number_of_lossy_connections.set( |
| 1309 | max_number_of_lossy_connections); |
| 1310 | } |
| 1311 | float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params); |
| 1312 | if (packet_loss_threshold != 0) |
| 1313 | globals->quic_packet_loss_threshold.set(packet_loss_threshold); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1314 | globals->enable_quic_port_selection.set( |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1315 | ShouldEnableQuicPortSelection(command_line)); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1316 | globals->quic_connection_options = |
| 1317 | GetQuicConnectionOptions(command_line, quic_trial_params); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | size_t max_packet_length = GetQuicMaxPacketLength(command_line, |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1321 | quic_trial_params); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1322 | if (max_packet_length != 0) { |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1323 | globals->quic_max_packet_length.set(max_packet_length); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1324 | } |
| 1325 | |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 1326 | std::string quic_user_agent_id = |
| 1327 | chrome::VersionInfo::GetVersionStringModifier(); |
[email protected] | adb9ded | 2014-07-25 08:31:44 | [diff] [blame] | 1328 | if (!quic_user_agent_id.empty()) |
| 1329 | quic_user_agent_id.push_back(' '); |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 1330 | chrome::VersionInfo version_info; |
| 1331 | quic_user_agent_id.append(version_info.ProductNameAndVersionForUserAgent()); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1332 | globals->quic_user_agent_id.set(quic_user_agent_id); |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 1333 | |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1334 | net::QuicVersion version = GetQuicVersion(command_line, quic_trial_params); |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1335 | if (version != net::QUIC_VERSION_UNSUPPORTED) { |
| 1336 | net::QuicVersionVector supported_versions; |
| 1337 | supported_versions.push_back(version); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1338 | globals->quic_supported_versions.set(supported_versions); |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1339 | } |
| 1340 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1341 | double threshold = GetAlternativeProtocolProbabilityThreshold( |
| 1342 | command_line, quic_trial_params); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1343 | if (threshold >=0 && threshold <= 1) { |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1344 | globals->alternative_service_probability_threshold.set(threshold); |
| 1345 | globals->http_server_properties->SetAlternativeServiceProbabilityThreshold( |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1346 | threshold); |
| 1347 | } |
| 1348 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1349 | if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { |
| 1350 | net::HostPortPair quic_origin = |
| 1351 | net::HostPortPair::FromString( |
| 1352 | command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn)); |
| 1353 | if (!quic_origin.IsEmpty()) { |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1354 | globals->origin_to_force_quic_on.set(quic_origin); |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | } |
| 1358 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1359 | bool IOThread::ShouldEnableQuic(const base::CommandLine& command_line, |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 1360 | base::StringPiece quic_trial_group, |
| 1361 | bool quic_allowed_by_policy) { |
| 1362 | if (command_line.HasSwitch(switches::kDisableQuic) || !quic_allowed_by_policy) |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1363 | return false; |
| 1364 | |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1365 | if (command_line.HasSwitch(switches::kEnableQuic)) |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1366 | return true; |
| 1367 | |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1368 | return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || |
| 1369 | quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
[email protected] | a64b213e | 2013-07-24 21:41:00 | [diff] [blame] | 1370 | } |
| 1371 | |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 1372 | // static |
| 1373 | bool IOThread::ShouldEnableQuicForProxies(const base::CommandLine& command_line, |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 1374 | base::StringPiece quic_trial_group, |
| 1375 | bool quic_allowed_by_policy) { |
| 1376 | return ShouldEnableQuic( |
| 1377 | command_line, quic_trial_group, quic_allowed_by_policy) || |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 1378 | ShouldEnableQuicForDataReductionProxy(); |
| 1379 | } |
| 1380 | |
| 1381 | // static |
| 1382 | bool IOThread::ShouldEnableQuicForDataReductionProxy() { |
| 1383 | const base::CommandLine& command_line = |
| 1384 | *base::CommandLine::ForCurrentProcess(); |
| 1385 | |
| 1386 | if (command_line.HasSwitch(switches::kDisableQuic)) |
| 1387 | return false; |
| 1388 | |
| 1389 | return data_reduction_proxy::DataReductionProxyParams:: |
| 1390 | IsIncludedInQuicFieldTrial(); |
| 1391 | } |
| 1392 | |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1393 | // static |
| 1394 | bool IOThread::ShouldDisableInsecureQuic( |
| 1395 | const VariationParameters& quic_trial_params) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1396 | return base::LowerCaseEqualsASCII( |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1397 | GetVariationParam(quic_trial_params, "disable_insecure_quic"), |
| 1398 | "true"); |
| 1399 | } |
| 1400 | |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1401 | bool IOThread::ShouldEnableQuicPortSelection( |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1402 | const base::CommandLine& command_line) { |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1403 | if (command_line.HasSwitch(switches::kDisableQuicPortSelection)) |
| 1404 | return false; |
| 1405 | |
| 1406 | if (command_line.HasSwitch(switches::kEnableQuicPortSelection)) |
| 1407 | return true; |
| 1408 | |
[email protected] | 3273b3c | 2014-05-23 16:52:28 | [diff] [blame] | 1409 | return false; // Default to disabling port selection on all channels. |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 1410 | } |
| 1411 | |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1412 | net::QuicTagVector IOThread::GetQuicConnectionOptions( |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1413 | const base::CommandLine& command_line, |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1414 | const VariationParameters& quic_trial_params) { |
| 1415 | if (command_line.HasSwitch(switches::kQuicConnectionOptions)) { |
mef | cb6537c | 2014-11-12 19:38:50 | [diff] [blame] | 1416 | return net::QuicUtils::ParseQuicConnectionOptions( |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1417 | command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions)); |
| 1418 | } |
| 1419 | |
| 1420 | VariationParameters::const_iterator it = |
[email protected] | 8cc87811 | 2014-08-15 04:06:44 | [diff] [blame] | 1421 | quic_trial_params.find("connection_options"); |
| 1422 | if (it == quic_trial_params.end()) { |
rch | e9efff4 | 2015-01-12 17:58:19 | [diff] [blame] | 1423 | return net::QuicTagVector(); |
[email protected] | 8cc87811 | 2014-08-15 04:06:44 | [diff] [blame] | 1424 | } |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1425 | |
mef | cb6537c | 2014-11-12 19:38:50 | [diff] [blame] | 1426 | return net::QuicUtils::ParseQuicConnectionOptions(it->second); |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1427 | } |
| 1428 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1429 | // static |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1430 | double IOThread::GetAlternativeProtocolProbabilityThreshold( |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1431 | const base::CommandLine& command_line, |
| 1432 | const VariationParameters& quic_trial_params) { |
| 1433 | double value; |
| 1434 | if (command_line.HasSwitch( |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1435 | switches::kAlternativeServiceProbabilityThreshold)) { |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1436 | if (base::StringToDouble( |
| 1437 | command_line.GetSwitchValueASCII( |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1438 | switches::kAlternativeServiceProbabilityThreshold), |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1439 | &value)) { |
| 1440 | return value; |
| 1441 | } |
| 1442 | } |
rch | 1664275 | 2014-09-18 00:29:16 | [diff] [blame] | 1443 | if (command_line.HasSwitch(switches::kEnableQuic)) { |
| 1444 | return 0; |
| 1445 | } |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1446 | // TODO(bnc): Remove when new parameter name rolls out and server |
| 1447 | // configuration is changed. |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1448 | if (base::StringToDouble( |
| 1449 | GetVariationParam(quic_trial_params, |
| 1450 | "alternate_protocol_probability_threshold"), |
| 1451 | &value)) { |
| 1452 | return value; |
| 1453 | } |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1454 | if (base::StringToDouble( |
| 1455 | GetVariationParam(quic_trial_params, |
| 1456 | "alternative_service_probability_threshold"), |
| 1457 | &value)) { |
| 1458 | return value; |
| 1459 | } |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1460 | return -1; |
| 1461 | } |
| 1462 | |
| 1463 | // static |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 1464 | bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation( |
| 1465 | const VariationParameters& quic_trial_params) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1466 | return base::LowerCaseEqualsASCII( |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 1467 | GetVariationParam(quic_trial_params, |
| 1468 | "always_require_handshake_confirmation"), |
| 1469 | "true"); |
| 1470 | } |
| 1471 | |
| 1472 | // static |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 1473 | bool IOThread::ShouldQuicDisableConnectionPooling( |
| 1474 | const VariationParameters& quic_trial_params) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1475 | return base::LowerCaseEqualsASCII( |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 1476 | GetVariationParam(quic_trial_params, "disable_connection_pooling"), |
| 1477 | "true"); |
| 1478 | } |
| 1479 | |
| 1480 | // static |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 1481 | float IOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier( |
| 1482 | const VariationParameters& quic_trial_params) { |
| 1483 | double value; |
| 1484 | if (base::StringToDouble(GetVariationParam(quic_trial_params, |
| 1485 | "load_server_info_time_to_srtt"), |
| 1486 | &value)) { |
| 1487 | return (float)value; |
| 1488 | } |
| 1489 | return 0.0f; |
| 1490 | } |
| 1491 | |
| 1492 | // static |
rtenneti | 4f80997 | 2015-02-11 19:38:34 | [diff] [blame] | 1493 | bool IOThread::ShouldQuicEnableConnectionRacing( |
| 1494 | const VariationParameters& quic_trial_params) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1495 | return base::LowerCaseEqualsASCII( |
rtenneti | 4f80997 | 2015-02-11 19:38:34 | [diff] [blame] | 1496 | GetVariationParam(quic_trial_params, "enable_connection_racing"), |
| 1497 | "true"); |
| 1498 | } |
| 1499 | |
| 1500 | // static |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 1501 | bool IOThread::ShouldQuicEnableNonBlockingIO( |
| 1502 | const VariationParameters& quic_trial_params) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1503 | return base::LowerCaseEqualsASCII( |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 1504 | GetVariationParam(quic_trial_params, "enable_non_blocking_io"), |
| 1505 | "true"); |
| 1506 | } |
| 1507 | |
| 1508 | // static |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 1509 | bool IOThread::ShouldQuicDisableDiskCache( |
| 1510 | const VariationParameters& quic_trial_params) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 1511 | return base::LowerCaseEqualsASCII( |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 1512 | GetVariationParam(quic_trial_params, "disable_disk_cache"), "true"); |
| 1513 | } |
| 1514 | |
| 1515 | // static |
rch | 9976b0c | 2015-06-10 21:27:23 | [diff] [blame] | 1516 | bool IOThread::ShouldQuicPreferAes( |
| 1517 | const VariationParameters& quic_trial_params) { |
| 1518 | return base::LowerCaseEqualsASCII( |
| 1519 | GetVariationParam(quic_trial_params, "prefer_aes"), "true"); |
| 1520 | } |
| 1521 | |
| 1522 | // static |
rtenneti | 374e5688 | 2015-03-28 13:49:54 | [diff] [blame] | 1523 | int IOThread::GetQuicMaxNumberOfLossyConnections( |
| 1524 | const VariationParameters& quic_trial_params) { |
| 1525 | int value; |
| 1526 | if (base::StringToInt(GetVariationParam(quic_trial_params, |
| 1527 | "max_number_of_lossy_connections"), |
| 1528 | &value)) { |
| 1529 | return value; |
| 1530 | } |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | // static |
| 1535 | float IOThread::GetQuicPacketLossThreshold( |
| 1536 | const VariationParameters& quic_trial_params) { |
| 1537 | double value; |
| 1538 | if (base::StringToDouble(GetVariationParam(quic_trial_params, |
| 1539 | "packet_loss_threshold"), |
| 1540 | &value)) { |
| 1541 | return (float)value; |
| 1542 | } |
| 1543 | return 0.0f; |
| 1544 | } |
| 1545 | |
| 1546 | // static |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 1547 | int IOThread::GetQuicSocketReceiveBufferSize( |
| 1548 | const VariationParameters& quic_trial_params) { |
| 1549 | int value; |
| 1550 | if (base::StringToInt(GetVariationParam(quic_trial_params, |
| 1551 | "receive_buffer_size"), |
| 1552 | &value)) { |
| 1553 | return value; |
| 1554 | } |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | // static |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1559 | size_t IOThread::GetQuicMaxPacketLength( |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1560 | const base::CommandLine& command_line, |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1561 | const VariationParameters& quic_trial_params) { |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 1562 | if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) { |
| 1563 | unsigned value; |
| 1564 | if (!base::StringToUint( |
| 1565 | command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength), |
| 1566 | &value)) { |
| 1567 | return 0; |
| 1568 | } |
| 1569 | return value; |
| 1570 | } |
| 1571 | |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1572 | unsigned value; |
| 1573 | if (base::StringToUint(GetVariationParam(quic_trial_params, |
| 1574 | "max_packet_length"), |
| 1575 | &value)) { |
| 1576 | return value; |
| 1577 | } |
rch | cc4b8cf | 2014-12-05 20:24:38 | [diff] [blame] | 1578 | return 0; |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 1579 | } |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1580 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1581 | // static |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1582 | net::QuicVersion IOThread::GetQuicVersion( |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1583 | const base::CommandLine& command_line, |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1584 | const VariationParameters& quic_trial_params) { |
| 1585 | if (command_line.HasSwitch(switches::kQuicVersion)) { |
| 1586 | return ParseQuicVersion( |
| 1587 | command_line.GetSwitchValueASCII(switches::kQuicVersion)); |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1588 | } |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1589 | |
| 1590 | return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version")); |
| 1591 | } |
| 1592 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1593 | // static |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1594 | net::QuicVersion IOThread::ParseQuicVersion(const std::string& quic_version) { |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1595 | net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1596 | for (size_t i = 0; i < supported_versions.size(); ++i) { |
| 1597 | net::QuicVersion version = supported_versions[i]; |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1598 | if (net::QuicVersionToString(version) == quic_version) { |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1599 | return version; |
| 1600 | } |
| 1601 | } |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 1602 | |
[email protected] | 6a31ca5 | 2013-12-23 00:44:34 | [diff] [blame] | 1603 | return net::QUIC_VERSION_UNSUPPORTED; |
| 1604 | } |