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