blob: c5c7ce179e4447693d969cfb3aae67c7f6c456b1 [file] [log] [blame]
[email protected]d24fc3a02012-02-11 02:08:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0ac83682010-01-22 17:46:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/io_thread.h"
[email protected]e83326f2010-07-31 17:29:256
dchenge73d8520c2015-12-27 01:19:097#include <utility>
[email protected]bcefe0f2010-11-10 16:19:108#include <vector>
9
[email protected]284303b62013-11-28 15:11:5410#include "base/base64.h"
[email protected]21ee224e2011-11-21 02:17:5311#include "base/bind.h"
12#include "base/bind_helpers.h"
[email protected]aa84a7e2012-03-15 21:29:0613#include "base/command_line.h"
[email protected]c93123fa2012-04-19 02:49:4814#include "base/compiler_specific.h"
[email protected]58580352010-10-26 04:07:5015#include "base/debug/leak_tracker.h"
zhongyi81f85c6d92015-10-16 19:34:1416#include "base/environment.h"
davidben2a811e4e2015-12-01 10:49:3417#include "base/files/file_path.h"
[email protected]0ac83682010-01-22 17:46:2718#include "base/logging.h"
avi6846aef2015-12-26 01:09:3819#include "base/macros.h"
dcheng4af48582016-04-19 00:29:3520#include "base/memory/ptr_util.h"
[email protected]903e63382013-06-01 00:40:5821#include "base/metrics/field_trial.h"
davidben45eb19952016-05-05 16:30:4422#include "base/metrics/histogram_macros.h"
[email protected]7286e3fc2011-07-19 22:13:2423#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4124#include "base/strings/string_number_conversions.h"
bnce3553d92014-10-30 22:29:4525#include "base/strings/string_piece.h"
[email protected]1988e1c2013-02-28 20:27:4226#include "base/strings/string_split.h"
[email protected]9c7ddc92013-06-11 01:40:5727#include "base/strings/string_util.h"
davidben2a811e4e2015-12-01 10:49:3428#include "base/strings/utf_string_conversions.h"
[email protected]255620da2013-08-19 13:14:2929#include "base/threading/sequenced_worker_pool.h"
[email protected]3fc40c142011-12-01 13:09:0430#include "base/threading/thread.h"
[email protected]5bab49ec2012-05-04 21:13:1931#include "base/threading/worker_pool.h"
[email protected]d827e112014-03-31 17:45:0532#include "base/time/time.h"
primiano6221e572015-01-28 12:14:3433#include "base/trace_event/trace_event.h"
[email protected]addb3242011-06-13 21:39:1634#include "build/build_config.h"
[email protected]df2840d2011-02-20 16:32:3235#include "chrome/browser/browser_process.h"
sclittlea133de02015-11-10 23:54:2136#include "chrome/browser/data_usage/tab_id_annotator.h"
kundajif617523b2016-09-09 22:41:2437#include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h"
[email protected]026876f32012-08-22 23:53:4038#include "chrome/browser/net/async_dns_field_trial.h"
[email protected]c38831a12011-10-28 12:44:4939#include "chrome/browser/net/chrome_network_delegate.h"
[email protected]4588b3d2012-11-14 00:37:3840#include "chrome/browser/net/dns_probe_service.h"
[email protected]db0e86dd2011-03-16 14:47:2141#include "chrome/browser/net/proxy_service_factory.h"
eranm3c2d6432016-06-01 10:17:2742#include "chrome/browser/net/sth_distributor_provider.h"
sdefresne9fb67692015-08-03 18:48:2243#include "chrome/common/channel_info.h"
[email protected]aa051272014-03-10 05:56:5644#include "chrome/common/chrome_content_client.h"
[email protected]0ac83682010-01-22 17:46:2745#include "chrome/common/chrome_switches.h"
[email protected]bcefe0f2010-11-10 16:19:1046#include "chrome/common/pref_names.h"
eranm3c2d6432016-06-01 10:17:2747#include "components/certificate_transparency/tree_state_tracker.h"
megjablon3476e042014-10-14 19:21:5948#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
sclittle3f98c6c2015-11-19 22:59:2949#include "components/data_usage/core/data_use_aggregator.h"
sclittlec441f782015-11-12 01:12:0950#include "components/data_usage/core/data_use_amortizer.h"
sclittle3f98c6c2015-11-19 22:59:2951#include "components/data_usage/core/data_use_annotator.h"
kundajic6135962016-09-26 17:54:2852#include "components/data_use_measurement/core/data_use_ascriber.h"
gayane0b46091c2016-04-07 21:01:0553#include "components/metrics/metrics_service.h"
drogerc690e8802015-09-21 14:29:1654#include "components/net_log/chrome_net_log.h"
bnc210d6f32016-05-24 07:40:4755#include "components/network_session_configurator/network_session_configurator.h"
[email protected]76b4b152013-12-08 21:10:0456#include "components/policy/core/common/policy_service.h"
brettw39d6ba42016-08-24 16:56:3857#include "components/policy/policy_constants.h"
brettwb1fc1b82016-02-02 00:19:0858#include "components/prefs/pref_registry_simple.h"
59#include "components/prefs/pref_service.h"
abhishek.a2171c612852015-08-31 10:48:1960#include "components/proxy_config/pref_proxy_config_tracker.h"
[email protected]488a0e252014-06-25 04:37:4461#include "components/variations/variations_associated_data.h"
sdefresne9fb67692015-08-03 18:48:2262#include "components/version_info/version_info.h"
[email protected]c38831a12011-10-28 12:44:4963#include "content/public/browser/browser_thread.h"
[email protected]7c4b66b2014-01-04 12:28:1364#include "content/public/browser/cookie_store_factory.h"
eustasfbec9132015-12-30 14:56:5165#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:4066#include "content/public/common/content_switches.h"
rtenneti4d126a72015-06-23 17:32:0967#include "content/public/common/user_agent.h"
[email protected]c2dad292012-09-07 21:27:3568#include "net/base/host_mapping_rules.h"
pauljensen7b34e522016-05-12 18:20:5969#include "net/base/logging_network_change_observer.h"
rdsmith60e6e6fb2015-03-05 16:49:2070#include "net/base/sdch_manager.h"
rsleevi6df54182016-06-13 14:34:2371#include "net/cert/caching_cert_verifier.h"
[email protected]6e7845ae2013-03-29 21:48:1172#include "net/cert/cert_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3973#include "net/cert/cert_verify_proc.h"
[email protected]284303b62013-11-28 15:11:5474#include "net/cert/ct_known_logs.h"
davidbeneb5f8ef32014-09-04 14:14:3275#include "net/cert/ct_log_verifier.h"
estark6f9b3d82016-01-12 21:37:0576#include "net/cert/ct_policy_enforcer.h"
[email protected]284303b62013-11-28 15:11:5477#include "net/cert/ct_verifier.h"
davidbeneb5f8ef32014-09-04 14:14:3278#include "net/cert/multi_log_ct_verifier.h"
[email protected]f46f6d52014-02-08 04:00:3979#include "net/cert/multi_threaded_cert_verifier.h"
eranm3c2d6432016-06-01 10:17:2780#include "net/cert/sth_distributor.h"
81#include "net/cert/sth_observer.h"
[email protected]9a6c2aa2014-01-11 22:39:3982#include "net/cookies/cookie_store.h"
[email protected]bc71b8772013-04-10 20:55:1683#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5384#include "net/dns/host_resolver.h"
85#include "net/dns/mapped_host_resolver.h"
[email protected]b3ae2db2013-05-30 05:00:0586#include "net/ftp/ftp_network_layer.h"
[email protected]eb3cac72010-02-26 21:07:4587#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5088#include "net/http/http_auth_handler_factory.h"
aberentbba302d2015-12-03 10:20:1989#include "net/http/http_auth_preferences.h"
[email protected]2fb629202010-12-23 23:52:5790#include "net/http/http_network_layer.h"
[email protected]17291a022011-10-10 07:32:5391#include "net/http/http_server_properties_impl.h"
tbansalca83c002016-04-28 20:56:2892#include "net/nqe/external_estimate_provider.h"
93#include "net/nqe/network_quality_estimator.h"
[email protected]6104ea5d2011-04-27 21:37:1294#include "net/proxy/proxy_config_service.h"
[email protected]86933612010-10-16 23:10:3395#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1296#include "net/proxy/proxy_service.h"
zhongyi81f85c6d92015-10-16 19:34:1497#include "net/socket/ssl_client_socket.h"
[email protected]717e4e22013-04-10 20:52:2398#include "net/socket/tcp_client_socket.h"
[email protected]6b8a3c742014-07-25 00:25:3599#include "net/ssl/channel_id_service.h"
100#include "net/ssl/default_channel_id_store.h"
[email protected]b3ae2db2013-05-30 05:00:05101#include "net/url_request/data_protocol_handler.h"
102#include "net/url_request/file_protocol_handler.h"
103#include "net/url_request/ftp_protocol_handler.h"
[email protected]aa051272014-03-10 05:56:56104#include "net/url_request/static_http_user_agent_settings.h"
[email protected]3dc1bc42012-06-19 08:20:53105#include "net/url_request/url_fetcher.h"
[email protected]f9c8c7c2014-07-31 16:42:31106#include "net/url_request/url_request_context.h"
wjmacleanea309f72015-08-25 20:56:59107#include "net/url_request/url_request_context_builder.h"
[email protected]f9c8c7c2014-07-31 16:42:31108#include "net/url_request/url_request_context_getter.h"
[email protected]b3ae2db2013-05-30 05:00:05109#include "net/url_request/url_request_job_factory_impl.h"
brettw03e61962016-03-15 06:27:04110#include "url/url_constants.h"
[email protected]0ac83682010-01-22 17:46:27111
[email protected]84b7a552014-07-19 04:52:06112#if defined(ENABLE_EXTENSIONS)
113#include "chrome/browser/extensions/event_router_forwarder.h"
114#endif
115
jam1c5a91492016-02-24 20:47:53116#if defined(USE_NSS_CERTS)
eromaned744f32015-04-09 06:35:49117#include "net/cert_net/nss_ocsp.h"
[email protected]a592c0432012-12-01 18:10:29118#endif
[email protected]77feb462011-05-16 23:37:25119
sievers2f1e8112015-12-04 18:43:56120#if BUILDFLAG(ANDROID_JAVA_UI)
jeremyimb6c97ae2015-01-05 22:57:14121#include "base/android/build_info.h"
megjablon174bc342015-11-05 00:30:06122#include "chrome/browser/android/data_usage/external_data_use_observer.h"
tbansaldafbb3e2015-08-19 19:55:33123#include "chrome/browser/android/net/external_estimate_provider_android.h"
sclittlec441f782015-11-12 01:12:09124#include "components/data_usage/android/traffic_stats_amortizer.h"
jeremyimb6c97ae2015-01-05 22:57:14125#endif
126
[email protected]f46f6d52014-02-08 04:00:39127#if defined(OS_CHROMEOS)
128#include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
[email protected]106ccd2c2014-06-17 09:21:00129#include "chromeos/network/host_resolver_impl_chromeos.h"
[email protected]f46f6d52014-02-08 04:00:39130#endif
131
davidben45eb19952016-05-05 16:30:44132#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
133#include <openssl/cpu.h>
134#include "crypto/openssl_util.h"
135#endif
136
[email protected]631bb742011-11-02 11:29:39137using content::BrowserThread;
138
[email protected]075c0322012-02-14 00:56:44139class SafeBrowsingURLRequestContext;
140
[email protected]21ee224e2011-11-21 02:17:53141// The IOThread object must outlive any tasks posted to the IO thread before the
142// Quit task, so base::Bind() calls are not refcounted.
143
[email protected]0ac83682010-01-22 17:46:27144namespace {
145
tbansalb177b5392015-06-25 11:13:02146// Field trial for network quality estimator. Seeds RTT and downstream
147// throughput observations with values that correspond to the connection type
148// determined by the operating system.
149const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
150
jam1c5a91492016-02-24 20:47:53151#if defined(OS_MACOSX)
[email protected]11f5e3a2012-09-27 00:30:13152void ObserveKeychainEvents() {
thestig00844cea2015-09-08 21:44:52153 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]11f5e3a2012-09-27 00:30:13154 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
155}
156#endif
157
zhongyi81f85c6d92015-10-16 19:34:14158// Gets file path into ssl_keylog_file from command line argument or
159// environment variable. Command line argument has priority when
160// both specified.
davidben2a811e4e2015-12-01 10:49:34161base::FilePath GetSSLKeyLogFile(const base::CommandLine& command_line) {
zhongyi81f85c6d92015-10-16 19:34:14162 if (command_line.HasSwitch(switches::kSSLKeyLogFile)) {
davidben2a811e4e2015-12-01 10:49:34163 base::FilePath path =
164 command_line.GetSwitchValuePath(switches::kSSLKeyLogFile);
165 if (!path.empty())
166 return path;
zhongyi81f85c6d92015-10-16 19:34:14167 LOG(WARNING) << "ssl-key-log-file argument missing";
168 }
davidben2a811e4e2015-12-01 10:49:34169
dcheng4af48582016-04-19 00:29:35170 std::unique_ptr<base::Environment> env(base::Environment::Create());
davidben2a811e4e2015-12-01 10:49:34171 std::string path_str;
172 env->GetVar("SSLKEYLOGFILE", &path_str);
173#if defined(OS_WIN)
174 // base::Environment returns environment variables in UTF-8 on Windows.
175 return base::FilePath(base::UTF8ToUTF16(path_str));
176#else
177 return base::FilePath(path_str);
178#endif
zhongyi81f85c6d92015-10-16 19:34:14179}
180
[email protected]ee4c30d2012-11-07 15:08:43181// Used for the "system" URLRequestContext.
182class SystemURLRequestContext : public net::URLRequestContext {
[email protected]77feb462011-05-16 23:37:25183 public:
184 SystemURLRequestContext() {
jam1c5a91492016-02-24 20:47:53185#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09186 net::SetURLRequestContextForNSSHttpIO(this);
[email protected]a592c0432012-12-01 18:10:29187#endif
[email protected]77feb462011-05-16 23:37:25188 }
189
190 private:
Daniel Chenga542fca2014-10-21 09:51:29191 ~SystemURLRequestContext() override {
[email protected]424559492014-07-22 00:27:40192 AssertNoURLRequests();
jam1c5a91492016-02-24 20:47:53193#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09194 net::SetURLRequestContextForNSSHttpIO(NULL);
[email protected]a592c0432012-12-01 18:10:29195#endif
[email protected]77feb462011-05-16 23:37:25196 }
197};
198
dcheng4af48582016-04-19 00:29:35199std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
200 net::NetLog* net_log) {
[email protected]d22f06e2013-06-11 16:01:17201 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
avi556c05022014-12-22 23:31:43202 const base::CommandLine& command_line =
203 *base::CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:51204
[email protected]c54a8912012-10-22 22:09:43205 net::HostResolver::Options options;
[email protected]962b98212010-07-17 03:37:51206
[email protected]06ef6d92011-05-19 04:24:58207 // Use the retry attempts override from the command-line, if any.
208 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
209 std::string s =
210 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
211 // Parse the switch (it should be a non-negative integer).
212 int n;
213 if (base::StringToInt(s, &n) && n >= 0) {
[email protected]c54a8912012-10-22 22:09:43214 options.max_retry_attempts = static_cast<size_t>(n);
[email protected]06ef6d92011-05-19 04:24:58215 } else {
216 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
217 }
218 }
219
dcheng4af48582016-04-19 00:29:35220 std::unique_ptr<net::HostResolver> global_host_resolver;
[email protected]106ccd2c2014-06-17 09:21:00221#if defined OS_CHROMEOS
222 global_host_resolver =
223 chromeos::HostResolverImplChromeOS::CreateSystemResolver(options,
224 net_log);
225#else
226 global_host_resolver =
227 net::HostResolver::CreateSystemResolver(options, net_log);
228#endif
[email protected]9087aa32010-02-18 08:03:38229
[email protected]3dc5d7ef2014-03-28 19:18:21230 // If hostname remappings were specified on the command-line, layer these
231 // rules on top of the real host resolver. This allows forwarding all requests
232 // through a designated test server.
233 if (!command_line.HasSwitch(switches::kHostResolverRules))
dchenge73d8520c2015-12-27 01:19:09234 return global_host_resolver;
[email protected]0ac83682010-01-22 17:46:27235
dcheng4af48582016-04-19 00:29:35236 std::unique_ptr<net::MappedHostResolver> remapped_resolver(
dchenge73d8520c2015-12-27 01:19:09237 new net::MappedHostResolver(std::move(global_host_resolver)));
[email protected]3dc5d7ef2014-03-28 19:18:21238 remapped_resolver->SetRulesFromString(
239 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
dchenge73d8520c2015-12-27 01:19:09240 return std::move(remapped_resolver);
[email protected]0ac83682010-01-22 17:46:27241}
242
jam1671ed32016-07-27 16:31:24243int GetSwitchValueAsInt(const base::CommandLine& command_line,
244 const std::string& switch_name) {
245 int value;
246 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
247 &value)) {
248 return 0;
249 }
250 return value;
251}
252
[email protected]0ac83682010-01-22 17:46:27253} // namespace
254
[email protected]abe2c032011-03-31 18:49:34255class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
[email protected]db0e86dd2011-03-16 14:47:21256 public:
257 explicit SystemURLRequestContextGetter(IOThread* io_thread);
[email protected]db0e86dd2011-03-16 14:47:21258
[email protected]abe2c032011-03-31 18:49:34259 // Implementation for net::UrlRequestContextGetter.
Daniel Chenga542fca2014-10-21 09:51:29260 net::URLRequestContext* GetURLRequestContext() override;
261 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
262 const override;
[email protected]db0e86dd2011-03-16 14:47:21263
[email protected]13ed17f82012-04-06 02:27:18264 protected:
Daniel Chenga542fca2014-10-21 09:51:29265 ~SystemURLRequestContextGetter() override;
[email protected]13ed17f82012-04-06 02:27:18266
[email protected]db0e86dd2011-03-16 14:47:21267 private:
268 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
[email protected]4969b0122012-06-16 01:58:28269 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21270
271 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
272};
273
274SystemURLRequestContextGetter::SystemURLRequestContextGetter(
275 IOThread* io_thread)
276 : io_thread_(io_thread),
[email protected]4969b0122012-06-16 01:58:28277 network_task_runner_(
thestig529ad8a2016-07-08 20:30:12278 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)) {}
[email protected]db0e86dd2011-03-16 14:47:21279
280SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
281
282net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
thestig00844cea2015-09-08 21:44:52283 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]ef2bf422012-05-11 03:27:09284 DCHECK(io_thread_->globals()->system_request_context.get());
[email protected]db0e86dd2011-03-16 14:47:21285
[email protected]ef2bf422012-05-11 03:27:09286 return io_thread_->globals()->system_request_context.get();
[email protected]db0e86dd2011-03-16 14:47:21287}
288
[email protected]4969b0122012-06-16 01:58:28289scoped_refptr<base::SingleThreadTaskRunner>
290SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
291 return network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21292}
293
[email protected]c93123fa2012-04-19 02:49:48294IOThread::Globals::
295SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
296 Globals* globals)
297 : globals_(globals) {
298 DCHECK(globals_);
[email protected]7613faae2012-04-18 01:01:19299}
[email protected]1889dc1b2010-10-14 22:03:13300
[email protected]c93123fa2012-04-19 02:49:48301IOThread::Globals::
302SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {
303 if (globals_->system_request_context.get())
304 globals_->system_request_context->AssertNoURLRequests();
305}
306
maksim.sisov3d40c812016-05-02 13:27:16307IOThread::Globals::Globals() : system_request_context_leak_checker(this),
308 enable_brotli(false) {}
[email protected]c2dad292012-09-07 21:27:35309
[email protected]c93123fa2012-04-19 02:49:48310IOThread::Globals::~Globals() {}
311
[email protected]bcefe0f2010-11-10 16:19:10312// |local_state| is passed in explicitly in order to (1) reduce implicit
313// dependencies and (2) make IOThread more flexible for testing.
[email protected]3ce02412011-03-01 12:01:15314IOThread::IOThread(
[email protected]b1de2c72013-02-06 02:45:47315 PrefService* local_state,
[email protected]77305422012-11-29 16:51:39316 policy::PolicyService* policy_service,
drogerc690e8802015-09-21 14:29:16317 net_log::ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10318 extensions::EventRouterForwarder* extension_event_router_forwarder)
[email protected]2e5b60a22011-11-28 15:56:41319 : net_log_(net_log),
[email protected]84b7a552014-07-19 04:52:06320#if defined(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15321 extension_event_router_forwarder_(extension_event_router_forwarder),
[email protected]84b7a552014-07-19 04:52:06322#endif
mmenkea7da6da2016-09-01 21:56:52323 globals_(nullptr),
peletskyi5df83d42015-04-30 16:37:46324 is_quic_allowed_by_policy_(true),
mmenkea7da6da2016-09-01 21:56:52325 http_09_on_non_default_ports_enabled_(false),
mohan.reddy14cb4ad42014-09-17 18:15:14326 creation_time_(base::TimeTicks::Now()),
327 weak_factory_(this) {
aberentbba302d2015-12-03 10:20:19328 scoped_refptr<base::SingleThreadTaskRunner> io_thread_proxy =
thestig529ad8a2016-07-08 20:30:12329 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
[email protected]bcefe0f2010-11-10 16:19:10330 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
aberentbba302d2015-12-03 10:20:19331 negotiate_disable_cname_lookup_.Init(
332 prefs::kDisableAuthNegotiateCnameLookup, local_state,
333 base::Bind(&IOThread::UpdateNegotiateDisableCnameLookup,
334 base::Unretained(this)));
335 negotiate_disable_cname_lookup_.MoveToThread(io_thread_proxy);
336 negotiate_enable_port_.Init(
337 prefs::kEnableAuthNegotiatePort, local_state,
338 base::Bind(&IOThread::UpdateNegotiateEnablePort, base::Unretained(this)));
339 negotiate_enable_port_.MoveToThread(io_thread_proxy);
340 auth_server_whitelist_.Init(
341 prefs::kAuthServerWhitelist, local_state,
342 base::Bind(&IOThread::UpdateServerWhitelist, base::Unretained(this)));
343 auth_server_whitelist_.MoveToThread(io_thread_proxy);
344 auth_delegate_whitelist_.Init(
345 prefs::kAuthNegotiateDelegateWhitelist, local_state,
346 base::Bind(&IOThread::UpdateDelegateWhitelist, base::Unretained(this)));
347 auth_delegate_whitelist_.MoveToThread(io_thread_proxy);
348#if defined(OS_ANDROID)
349 auth_android_negotiate_account_type_.Init(
350 prefs::kAuthAndroidNegotiateAccountType, local_state,
351 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType,
352 base::Unretained(this)));
353 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy);
354#endif
355#if defined(OS_POSIX) && !defined(OS_ANDROID)
[email protected]ac7f3fdb2010-11-12 12:47:05356 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
aberentbba302d2015-12-03 10:20:19357#endif
[email protected]6f96cbcb2011-11-04 02:26:07358 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42359 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
360 local_state));
[email protected]9d8cfb682012-09-13 16:48:04361 ChromeNetworkDelegate::InitializePrefsOnUIThread(
362 &system_enable_referrers_,
igorcov193d8ad32016-05-27 11:03:21363 nullptr,
364 nullptr,
365 nullptr,
366 nullptr,
[email protected]9d8cfb682012-09-13 16:48:04367 local_state);
[email protected]4d45a6de2011-05-13 05:20:18368 ssl_config_service_manager_.reset(
abhishek.a212849cee2015-10-20 11:27:29369 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
370 local_state,
thestig529ad8a2016-07-08 20:30:12371 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
[email protected]2e5b60a22011-11-28 15:56:41372
[email protected]68a9b0d82013-03-08 07:05:07373 base::Value* dns_client_enabled_default = new base::FundamentalValue(
374 chrome_browser_net::ConfigureAsyncDnsFieldTrial());
375 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
376 dns_client_enabled_default);
ttuttle530184962015-01-13 00:24:07377 chrome_browser_net::LogAsyncDnsPrefSource(
378 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled));
[email protected]68a9b0d82013-03-08 07:05:07379
[email protected]fa4b6c32012-11-26 23:02:39380 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
381 local_state,
382 base::Bind(&IOThread::UpdateDnsClientEnabled,
383 base::Unretained(this)));
aberentbba302d2015-12-03 10:20:19384 dns_client_enabled_.MoveToThread(io_thread_proxy);
[email protected]fa4b6c32012-11-26 23:02:39385
[email protected]67378142013-12-17 21:57:17386 quick_check_enabled_.Init(prefs::kQuickCheckEnabled,
387 local_state);
aberentbba302d2015-12-03 10:20:19388 quick_check_enabled_.MoveToThread(io_thread_proxy);
[email protected]67378142013-12-17 21:57:17389
eroman9f7ea642016-06-03 21:28:29390 pac_https_url_stripping_enabled_.Init(prefs::kPacHttpsUrlStrippingEnabled,
391 local_state);
392 pac_https_url_stripping_enabled_.MoveToThread(io_thread_proxy);
393
peletskyi5df83d42015-04-30 16:37:46394 const base::Value* value = policy_service->GetPolicies(
395 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
396 std::string())).GetValue(policy::key::kQuicAllowed);
397 if (value)
398 value->GetAsBoolean(&is_quic_allowed_by_policy_);
[email protected]77305422012-11-29 16:51:39399
mmenkea7da6da2016-09-01 21:56:52400 value = policy_service
401 ->GetPolicies(policy::PolicyNamespace(
402 policy::POLICY_DOMAIN_CHROME, std::string()))
403 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled);
404 if (value)
405 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_);
406
gayane0b46091c2016-04-07 21:01:05407 // Some unit tests use IOThread but do not initialize MetricsService. In that
408 // case it is fine not to have |metrics_data_use_forwarder_|.
409 if (g_browser_process->metrics_service()) {
410 // Callback for updating data use prefs should be obtained on UI thread.
411 metrics_data_use_forwarder_ =
412 g_browser_process->metrics_service()->GetDataUseForwardingCallback();
413 }
414
eranm3c2d6432016-06-01 10:17:27415 chrome_browser_net::SetGlobalSTHDistributor(
416 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor()));
417
[email protected]2e5b60a22011-11-28 15:56:41418 BrowserThread::SetDelegate(BrowserThread::IO, this);
[email protected]bcefe0f2010-11-10 16:19:10419}
[email protected]0ac83682010-01-22 17:46:27420
421IOThread::~IOThread() {
[email protected]2e5b60a22011-11-28 15:56:41422 // This isn't needed for production code, but in tests, IOThread may
423 // be multiply constructed.
424 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
425
[email protected]d461ed22013-01-18 03:18:56426 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]d13c3272010-02-04 00:24:51427 DCHECK(!globals_);
eranm3c2d6432016-06-01 10:17:27428
429 // Destroy the old distributor to check that the observers list it holds is
430 // empty.
431 chrome_browser_net::SetGlobalSTHDistributor(nullptr);
[email protected]0ac83682010-01-22 17:46:27432}
433
[email protected]d13c3272010-02-04 00:24:51434IOThread::Globals* IOThread::globals() {
thestig00844cea2015-09-08 21:44:52435 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d13c3272010-02-04 00:24:51436 return globals_;
[email protected]0ac83682010-01-22 17:46:27437}
438
[email protected]37ac95b2013-07-23 23:39:35439void IOThread::SetGlobalsForTesting(Globals* globals) {
thestig00844cea2015-09-08 21:44:52440 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]37ac95b2013-07-23 23:39:35441 DCHECK(!globals || !globals_);
442 globals_ = globals;
443}
444
drogerc690e8802015-09-21 14:29:16445net_log::ChromeNetLog* IOThread::net_log() {
[email protected]b2fcd0e2010-12-01 15:19:40446 return net_log_;
447}
448
[email protected]b09f76d62011-12-07 01:51:06449void IOThread::ChangedToOnTheRecord() {
thestig00844cea2015-09-08 21:44:52450 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]b09f76d62011-12-07 01:51:06451 BrowserThread::PostTask(
452 BrowserThread::IO,
453 FROM_HERE,
454 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
455 base::Unretained(this)));
456}
457
[email protected]abe2c032011-03-31 18:49:34458net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
thestig00844cea2015-09-08 21:44:52459 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5173de8b2013-06-02 21:16:02460 if (!system_url_request_context_getter_.get()) {
[email protected]addb3242011-06-13 21:39:16461 InitSystemRequestContext();
[email protected]db0e86dd2011-03-16 14:47:21462 }
[email protected]5173de8b2013-06-02 21:16:02463 return system_url_request_context_getter_.get();
[email protected]db0e86dd2011-03-16 14:47:21464}
465
[email protected]0ac83682010-01-22 17:46:27466void IOThread::Init() {
[email protected]a5e73b82013-07-17 08:58:39467 TRACE_EVENT0("startup", "IOThread::InitAsync");
thestig00844cea2015-09-08 21:44:52468 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]70b92342010-10-12 05:54:06469
jam1c5a91492016-02-24 20:47:53470#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09471 net::SetMessageLoopForNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29472#endif
[email protected]70b92342010-10-12 05:54:06473
avi556c05022014-12-22 23:31:43474 const base::CommandLine& command_line =
475 *base::CommandLine::ForCurrentProcess();
[email protected]c2dad292012-09-07 21:27:35476
zhongyi81f85c6d92015-10-16 19:34:14477 // Export ssl keys if log file specified.
davidben2a811e4e2015-12-01 10:49:34478 base::FilePath ssl_keylog_file = GetSSLKeyLogFile(command_line);
zhongyi81f85c6d92015-10-16 19:34:14479 if (!ssl_keylog_file.empty()) {
davidben2a811e4e2015-12-01 10:49:34480 net::SSLClientSocket::SetSSLKeyLogFile(
481 ssl_keylog_file,
thestig529ad8a2016-07-08 20:30:12482 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE));
zhongyi81f85c6d92015-10-16 19:34:14483 }
484
[email protected]d13c3272010-02-04 00:24:51485 DCHECK(!globals_);
486 globals_ = new Globals;
487
[email protected]58bc7042010-07-07 18:04:14488 // Add an observer that will emit network change events to the ChromeNetLog.
489 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
490 // logging the network change before other IO thread consumers respond to it.
491 network_change_observer_.reset(
pauljensen7b34e522016-05-12 18:20:59492 new net::LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14493
[email protected]cde8b3c2012-08-13 19:20:52494 // Setup the HistogramWatcher to run on the IO thread.
495 net::NetworkChangeNotifier::InitHistogramWatcher();
496
[email protected]84b7a552014-07-19 04:52:06497#if defined(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15498 globals_->extension_event_router_forwarder =
499 extension_event_router_forwarder_;
[email protected]84b7a552014-07-19 04:52:06500#endif
501
dcheng4af48582016-04-19 00:29:35502 std::unique_ptr<data_usage::DataUseAmortizer> data_use_amortizer;
sievers2f1e8112015-12-04 18:43:56503#if BUILDFLAG(ANDROID_JAVA_UI)
sclittlec441f782015-11-12 01:12:09504 data_use_amortizer.reset(new data_usage::android::TrafficStatsAmortizer());
505#endif
506
kundajif617523b2016-09-09 22:41:24507 globals_->data_use_ascriber =
508 base::MakeUnique<data_use_measurement::ChromeDataUseAscriber>();
509
sclittle3f98c6c2015-11-19 22:59:29510 globals_->data_use_aggregator.reset(new data_usage::DataUseAggregator(
dcheng4af48582016-04-19 00:29:35511 std::unique_ptr<data_usage::DataUseAnnotator>(
sclittlec441f782015-11-12 01:12:09512 new chrome_browser_data_usage::TabIdAnnotator()),
dchenge73d8520c2015-12-27 01:19:09513 std::move(data_use_amortizer)));
sclittleae932be2015-10-08 20:53:50514
dcheng4af48582016-04-19 00:29:35515 std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate(
[email protected]84b7a552014-07-19 04:52:06516 new ChromeNetworkDelegate(extension_event_router_forwarder(),
gayane0b46091c2016-04-07 21:01:05517 &system_enable_referrers_,
518 metrics_data_use_forwarder_));
sclittleae932be2015-10-08 20:53:50519 // By default, data usage is considered off the record.
520 chrome_network_delegate->set_data_use_aggregator(
sclittle3f98c6c2015-11-19 22:59:29521 globals_->data_use_aggregator.get(),
522 true /* is_data_usage_off_the_record */);
tbansal796988c2015-10-14 02:41:22523
sievers2f1e8112015-12-04 18:43:56524#if BUILDFLAG(ANDROID_JAVA_UI)
sclittle3f98c6c2015-11-19 22:59:29525 globals_->external_data_use_observer.reset(
tbansal7c98c0a2015-11-03 21:39:51526 new chrome::android::ExternalDataUseObserver(
sclittle3f98c6c2015-11-19 22:59:29527 globals_->data_use_aggregator.get(),
thestig529ad8a2016-07-08 20:30:12528 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
529 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)));
tbansal796988c2015-10-14 02:41:22530#endif
[email protected]84b7a552014-07-19 04:52:06531
kundajic6135962016-09-26 17:54:28532 globals_->system_network_delegate =
533 globals_->data_use_ascriber->CreateNetworkDelegate(
534 std::move(chrome_network_delegate));
535
[email protected]c54a8912012-10-22 22:09:43536 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
tbansalea2fb8c2015-05-22 22:23:00537
tbansalb177b5392015-06-25 11:13:02538 std::map<std::string, std::string> network_quality_estimator_params;
539 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
540 &network_quality_estimator_params);
tbansal1c92d5b2015-08-14 20:14:43541
dcheng4af48582016-04-19 00:29:35542 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider;
sievers2f1e8112015-12-04 18:43:56543#if BUILDFLAG(ANDROID_JAVA_UI)
tbansal1c92d5b2015-08-14 20:14:43544 external_estimate_provider.reset(
tbansaldafbb3e2015-08-19 19:55:33545 new chrome::android::ExternalEstimateProviderAndroid());
tbansal1c92d5b2015-08-14 20:14:43546#endif
547 // Pass ownership.
548 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator(
dchenge73d8520c2015-12-27 01:19:09549 std::move(external_estimate_provider), network_quality_estimator_params));
tbansalea2fb8c2015-05-22 22:23:00550
[email protected]fa4b6c32012-11-26 23:02:39551 UpdateDnsClientEnabled();
[email protected]f46f6d52014-02-08 04:00:39552#if defined(OS_CHROMEOS)
[email protected]f9357a442014-05-15 18:44:07553 // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
rsleevi6df54182016-06-13 14:34:23554 globals_->cert_verifier = base::MakeUnique<net::CachingCertVerifier>(
555 base::MakeUnique<net::MultiThreadedCertVerifier>(
556 new chromeos::CertVerifyProcChromeOS()));
[email protected]f9357a442014-05-15 18:44:07557#else
rsleevi6df54182016-06-13 14:34:23558 globals_->cert_verifier = net::CertVerifier::CreateDefault();
[email protected]f9357a442014-05-15 18:44:07559#endif
560
davidbeneb5f8ef32014-09-04 14:14:32561 globals_->transport_security_state.reset(new net::TransportSecurityState());
562
eranm1a79db22015-11-24 10:56:49563 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs(
eranm03d454c2015-07-02 09:12:03564 net::ct::CreateLogVerifiersForKnownLogs());
[email protected]284303b62013-11-28 15:11:54565
eranm1a79db22015-11-24 10:56:49566 globals_->ct_logs.assign(ct_logs.begin(), ct_logs.end());
567
eranm03d454c2015-07-02 09:12:03568 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
569 globals_->cert_transparency_verifier.reset(ct_verifier);
570 // Add built-in logs
eranm1a79db22015-11-24 10:56:49571 ct_verifier->AddLogs(globals_->ct_logs);
eranm03d454c2015-07-02 09:12:03572
eranm3c2d6432016-06-01 10:17:27573 ct_tree_tracker_.reset(
574 new certificate_transparency::TreeStateTracker(globals_->ct_logs));
575 // Register the ct_tree_tracker_ as observer for new STHs.
576 RegisterSTHObserver(ct_tree_tracker_.get());
577 // Register the ct_tree_tracker_ as observer for verified SCTs.
578 globals_->cert_transparency_verifier->SetObserver(ct_tree_tracker_.get());
579
bnc18fb77f2016-04-04 20:54:04580 globals_->ct_policy_enforcer.reset(new net::CTPolicyEnforcer());
581 params_.ct_policy_enforcer = globals_->ct_policy_enforcer.get();
eranm6571b2b2014-12-03 15:53:23582
[email protected]4d45a6de2011-05-13 05:20:18583 globals_->ssl_config_service = GetSSLConfigService();
[email protected]f4bfa7672014-08-08 09:50:46584
aberentbba302d2015-12-03 10:20:19585 CreateDefaultAuthHandlerFactory();
[email protected]30d4c022013-07-18 22:58:16586 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
[email protected]2fb629202010-12-23 23:52:57587 // For the ProxyScriptFetcher, we use a direct ProxyService.
rdsmith82957ad2015-09-16 19:42:03588 globals_->proxy_script_fetcher_proxy_service =
589 net::ProxyService::CreateDirectWithNetLog(net_log_);
[email protected]273e37d2011-08-11 01:49:12590 // In-memory cookie store.
[email protected]9a6c2aa2014-01-11 22:39:39591 globals_->system_cookie_store =
mmenke606c59c2016-03-07 18:20:55592 content::CreateCookieStore(content::CookieStoreConfig());
[email protected]6b8a3c742014-07-25 00:25:35593 // In-memory channel ID store.
594 globals_->system_channel_id_service.reset(
595 new net::ChannelIDService(
596 new net::DefaultChannelIDStore(NULL),
[email protected]5bab49ec2012-05-04 21:13:19597 base::WorkerPool::GetTaskRunner(true)));
nharper3876dd562016-03-29 22:52:32598 globals_->system_cookie_store->SetChannelIDServiceID(
599 globals_->system_channel_id_service->GetUniqueID());
[email protected]4588b3d2012-11-14 00:37:38600 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
[email protected]c2dad292012-09-07 21:27:35601 globals_->host_mapping_rules.reset(new net::HostMappingRules());
bnc18fb77f2016-04-04 20:54:04602 params_.host_mapping_rules = globals_->host_mapping_rules.get();
[email protected]ee4c30d2012-11-07 15:08:43603 globals_->http_user_agent_settings.reset(
[email protected]aa051272014-03-10 05:56:56604 new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
[email protected]c2dad292012-09-07 21:27:35605 if (command_line.HasSwitch(switches::kHostRules)) {
[email protected]a5e73b82013-07-17 08:58:39606 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35607 globals_->host_mapping_rules->SetRulesFromString(
608 command_line.GetSwitchValueASCII(switches::kHostRules));
[email protected]a5e73b82013-07-17 08:58:39609 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35610 }
maksim.sisov3d40c812016-05-02 13:27:16611 globals_->enable_brotli =
bnc18fb77f2016-04-04 20:54:04612 base::FeatureList::IsEnabled(features::kBrotliEncoding);
613 params_.enable_token_binding =
nharperef2618642016-02-03 22:23:44614 base::FeatureList::IsEnabled(features::kTokenBinding);
bnce87c7c712016-08-01 23:59:48615
616 // Check for OS support of TCP FastOpen, and turn it on for all connections if
617 // indicated by user.
bnc18fb77f2016-04-04 20:54:04618 // TODO(rch): Make the client socket factory a per-network session instance,
619 // constructed from a NetworkSession::Params, to allow us to move this option
620 // to IOThread::Globals & HttpNetworkSession::Params.
bnc18fb77f2016-04-04 20:54:04621 bool always_enable_tfo_if_supported =
622 command_line.HasSwitch(switches::kEnableTcpFastOpen);
bnc18fb77f2016-04-04 20:54:04623 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_tfo_if_supported);
[email protected]f9cf5572012-12-04 15:52:09624
bnce87c7c712016-08-01 23:59:48625 ConfigureParamsFromFieldTrialsAndCommandLine(
mmenkea7da6da2016-09-01 21:56:52626 command_line, is_quic_allowed_by_policy_,
627 http_09_on_non_default_ports_enabled_, &params_);
bnce87c7c712016-08-01 23:59:48628
wjmacleanea309f72015-08-25 20:56:59629 TRACE_EVENT_BEGIN0("startup",
630 "IOThread::Init:ProxyScriptFetcherRequestContext");
[email protected]ef2bf422012-05-11 03:27:09631 globals_->proxy_script_fetcher_context.reset(
bnc18fb77f2016-04-04 20:54:04632 ConstructProxyScriptFetcherContext(globals_, params_, net_log_));
wjmacleanea309f72015-08-25 20:56:59633 TRACE_EVENT_END0("startup",
634 "IOThread::Init:ProxyScriptFetcherRequestContext");
[email protected]4a109492011-09-24 21:00:12635
jam1c5a91492016-02-24 20:47:53636#if defined(OS_MACOSX)
[email protected]11f5e3a2012-09-27 00:30:13637 // Start observing Keychain events. This needs to be done on the UI thread,
638 // as Keychain services requires a CFRunLoop.
639 BrowserThread::PostTask(BrowserThread::UI,
640 FROM_HERE,
641 base::Bind(&ObserveKeychainEvents));
642#endif
643
[email protected]2e5b60a22011-11-28 15:56:41644 // InitSystemRequestContext turns right around and posts a task back
645 // to the IO thread, so we can't let it run until we know the IO
646 // thread has started.
647 //
648 // Note that since we are at BrowserThread::Init time, the UI thread
649 // is blocked waiting for the thread to start. Therefore, posting
650 // this task to the main thread's message loop here is guaranteed to
651 // get it onto the message loop while the IOThread object still
652 // exists. However, the message might not be processed on the UI
653 // thread until after IOThread is gone, so use a weak pointer.
654 BrowserThread::PostTask(BrowserThread::UI,
655 FROM_HERE,
656 base::Bind(&IOThread::InitSystemRequestContext,
657 weak_factory_.GetWeakPtr()));
davidben45eb19952016-05-05 16:30:44658
659#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
660 // Record how common CPUs with broken NEON units are. See
661 // https://crbug.com/341598.
662 crypto::EnsureOpenSSLInit();
663 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON());
664#endif
[email protected]0ac83682010-01-22 17:46:27665}
666
[email protected]2a92cd92010-04-27 00:01:41667void IOThread::CleanUp() {
[email protected]075c0322012-02-14 00:56:44668 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
669
jam1c5a91492016-02-24 20:47:53670#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09671 net::ShutdownNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29672#endif
[email protected]59a3b362010-10-21 21:52:41673
[email protected]db0e86dd2011-03-16 14:47:21674 system_url_request_context_getter_ = NULL;
675
eranm3c2d6432016-06-01 10:17:27676 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier
677 // and unregister it from new STH notifications so it will take no actions
678 // on anything observed during CleanUp process.
679 globals()->cert_transparency_verifier->SetObserver(nullptr);
680 UnregisterSTHObserver(ct_tree_tracker_.get());
681
682 ct_tree_tracker_.reset();
683
[email protected]af669932012-01-17 19:26:58684 // Release objects that the net::URLRequestContext could have been pointing
685 // to.
[email protected]0ee7a3b2010-11-09 06:13:40686
[email protected]7592b41f2014-04-01 01:44:43687 // Shutdown the HistogramWatcher on the IO thread.
688 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
689
[email protected]0ee7a3b2010-11-09 06:13:40690 // This must be reset before the ChromeNetLog is destroyed.
691 network_change_observer_.reset();
692
[email protected]db0e86dd2011-03-16 14:47:21693 system_proxy_config_service_.reset();
[email protected]d13c3272010-02-04 00:24:51694 delete globals_;
695 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27696
[email protected]db0e86dd2011-03-16 14:47:21697 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27698}
699
bnc18fb77f2016-04-04 20:54:04700// static
[email protected]b1de2c72013-02-06 02:45:47701void IOThread::RegisterPrefs(PrefRegistrySimple* registry) {
702 registry->RegisterStringPref(prefs::kAuthSchemes,
bengr70266e22015-06-12 19:38:17703 "basic,digest,ntlm,negotiate");
[email protected]68a9b0d82013-03-08 07:05:07704 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
[email protected]b1de2c72013-02-06 02:45:47705 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
[email protected]007b3f82013-04-09 08:46:45706 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
707 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
708 std::string());
709 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
aberentec894a52015-07-09 14:45:53710 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType,
711 std::string());
[email protected]b1de2c72013-02-06 02:45:47712 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
[email protected]1575e3d2014-05-03 22:21:44713 data_reduction_proxy::RegisterPrefs(registry);
[email protected]68a9b0d82013-03-08 07:05:07714 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
[email protected]67378142013-12-17 21:57:17715 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
eroman9f7ea642016-06-03 21:28:29716 registry->RegisterBooleanPref(prefs::kPacHttpsUrlStrippingEnabled, true);
[email protected]bcefe0f2010-11-10 16:19:10717}
718
aberentbba302d2015-12-03 10:20:19719void IOThread::UpdateServerWhitelist() {
720 globals_->http_auth_preferences->set_server_whitelist(
721 auth_server_whitelist_.GetValue());
722}
[email protected]b7304162010-08-23 17:42:29723
aberentbba302d2015-12-03 10:20:19724void IOThread::UpdateDelegateWhitelist() {
725 globals_->http_auth_preferences->set_delegate_whitelist(
726 auth_delegate_whitelist_.GetValue());
727}
728
729#if defined(OS_ANDROID)
730void IOThread::UpdateAndroidAuthNegotiateAccountType() {
731 globals_->http_auth_preferences->set_auth_android_negotiate_account_type(
732 auth_android_negotiate_account_type_.GetValue());
733}
734#endif
735
736void IOThread::UpdateNegotiateDisableCnameLookup() {
737 globals_->http_auth_preferences->set_negotiate_disable_cname_lookup(
738 negotiate_disable_cname_lookup_.GetValue());
739}
740
741void IOThread::UpdateNegotiateEnablePort() {
742 globals_->http_auth_preferences->set_negotiate_enable_port(
743 negotiate_enable_port_.GetValue());
744}
745
746void IOThread::CreateDefaultAuthHandlerFactory() {
747 std::vector<std::string> supported_schemes = base::SplitString(
748 auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
749 globals_->http_auth_preferences.reset(new net::HttpAuthPreferences(
750 supported_schemes
751#if defined(OS_POSIX) && !defined(OS_ANDROID)
752 ,
753 gssapi_library_name_
754#endif
755 ));
756 UpdateServerWhitelist();
757 UpdateDelegateWhitelist();
758 UpdateNegotiateDisableCnameLookup();
759 UpdateNegotiateEnablePort();
760#if defined(OS_ANDROID)
761 UpdateAndroidAuthNegotiateAccountType();
762#endif
763 globals_->http_auth_handler_factory =
[email protected]ec44ee02012-09-28 21:31:51764 net::HttpAuthHandlerRegistryFactory::Create(
dchenge73d8520c2015-12-27 01:19:09765 globals_->http_auth_preferences.get(), globals_->host_resolver.get());
[email protected]eb3cac72010-02-26 21:07:45766}
767
msramek94f5656c2016-08-31 17:08:29768void IOThread::ClearHostCache(
769 const base::Callback<bool(const std::string&)>& host_filter) {
thestig00844cea2015-09-08 21:44:52770 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d6f37fc2011-02-13 23:58:41771
[email protected]489d1a82011-10-12 03:09:11772 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
773 if (host_cache)
msramek94f5656c2016-08-31 17:08:29774 host_cache->ClearForHosts(host_filter);
[email protected]0ac83682010-01-22 17:46:27775}
[email protected]db0e86dd2011-03-16 14:47:21776
bnc18fb77f2016-04-04 20:54:04777const net::HttpNetworkSession::Params& IOThread::NetworkSessionParams() const {
778 return params_;
[email protected]f9cf5572012-12-04 15:52:09779}
780
[email protected]d827e112014-03-31 17:45:05781base::TimeTicks IOThread::creation_time() const {
782 return creation_time_;
783}
784
[email protected]4d45a6de2011-05-13 05:20:18785net::SSLConfigService* IOThread::GetSSLConfigService() {
786 return ssl_config_service_manager_->Get();
787}
788
[email protected]b09f76d62011-12-07 01:51:06789void IOThread::ChangedToOnTheRecordOnIOThread() {
thestig00844cea2015-09-08 21:44:52790 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]b09f76d62011-12-07 01:51:06791
792 // Clear the host cache to avoid showing entries from the OTR session
793 // in about:net-internals.
msramek94f5656c2016-08-31 17:08:29794 ClearHostCache(base::Callback<bool(const std::string&)>());
[email protected]b09f76d62011-12-07 01:51:06795}
796
[email protected]db0e86dd2011-03-16 14:47:21797void IOThread::InitSystemRequestContext() {
[email protected]5173de8b2013-06-02 21:16:02798 if (system_url_request_context_getter_.get())
[email protected]addb3242011-06-13 21:39:16799 return;
[email protected]63e26822011-07-16 19:07:35800 // If we're in unit_tests, IOThread may not be run.
[email protected]dd483702011-12-02 14:47:42801 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
[email protected]63e26822011-07-16 19:07:35802 return;
csharrisonb7e3a082015-09-22 19:13:04803 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
804 pref_proxy_config_tracker_.get());
[email protected]addb3242011-06-13 21:39:16805 system_url_request_context_getter_ =
806 new SystemURLRequestContextGetter(this);
[email protected]2e5b60a22011-11-28 15:56:41807 // Safe to post an unretained this pointer, since IOThread is
808 // guaranteed to outlive the IO BrowserThread.
[email protected]dd483702011-12-02 14:47:42809 BrowserThread::PostTask(
810 BrowserThread::IO,
811 FROM_HERE,
812 base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
813 base::Unretained(this)));
[email protected]addb3242011-06-13 21:39:16814}
815
816void IOThread::InitSystemRequestContextOnIOThread() {
thestig00844cea2015-09-08 21:44:52817 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]6104ea5d2011-04-27 21:37:12818 DCHECK(!globals_->system_proxy_service.get());
[email protected]db0e86dd2011-03-16 14:47:21819 DCHECK(system_proxy_config_service_.get());
820
avi556c05022014-12-22 23:31:43821 const base::CommandLine& command_line =
822 *base::CommandLine::ForCurrentProcess();
rdsmith82957ad2015-09-16 19:42:03823 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
824 net_log_, globals_->proxy_script_fetcher_context.get(),
825 globals_->system_network_delegate.get(),
dchenge73d8520c2015-12-27 01:19:09826 std::move(system_proxy_config_service_), command_line,
eroman9f7ea642016-06-03 21:28:29827 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
[email protected]c2dad292012-09-07 21:27:35828
[email protected]ef2bf422012-05-11 03:27:09829 globals_->system_request_context.reset(
bnc18fb77f2016-04-04 20:54:04830 ConstructSystemRequestContext(globals_, params_, net_log_));
[email protected]db0e86dd2011-03-16 14:47:21831}
[email protected]fa4b6c32012-11-26 23:02:39832
833void IOThread::UpdateDnsClientEnabled() {
834 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
835}
[email protected]903e63382013-06-01 00:40:58836
eranm3c2d6432016-06-01 10:17:27837void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) {
838 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer);
839}
840
841void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) {
842 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer);
843}
844
eroman9f7ea642016-06-03 21:28:29845bool IOThread::WpadQuickCheckEnabled() const {
846 return quick_check_enabled_.GetValue();
847}
848
849bool IOThread::PacHttpsUrlStrippingEnabled() const {
850 return pac_https_url_stripping_enabled_.GetValue();
851}
852
bnc18fb77f2016-04-04 20:54:04853// static
wjmacleanea309f72015-08-25 20:56:59854net::URLRequestContext* IOThread::ConstructSystemRequestContext(
855 IOThread::Globals* globals,
bnc18fb77f2016-04-04 20:54:04856 const net::HttpNetworkSession::Params& params,
wjmacleanea309f72015-08-25 20:56:59857 net::NetLog* net_log) {
858 net::URLRequestContext* context = new SystemURLRequestContext;
859 context->set_net_log(net_log);
860 context->set_host_resolver(globals->host_resolver.get());
861 context->set_cert_verifier(globals->cert_verifier.get());
862 context->set_transport_security_state(
863 globals->transport_security_state.get());
864 context->set_cert_transparency_verifier(
865 globals->cert_transparency_verifier.get());
rsleevid6de8302016-06-21 01:33:20866 context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get());
wjmacleanea309f72015-08-25 20:56:59867 context->set_ssl_config_service(globals->ssl_config_service.get());
868 context->set_http_auth_handler_factory(
869 globals->http_auth_handler_factory.get());
870 context->set_proxy_service(globals->system_proxy_service.get());
871
872 globals->system_url_request_job_factory.reset(
873 new net::URLRequestJobFactoryImpl());
874 context->set_job_factory(globals->system_url_request_job_factory.get());
875
876 context->set_cookie_store(globals->system_cookie_store.get());
877 context->set_channel_id_service(
878 globals->system_channel_id_service.get());
879 context->set_network_delegate(globals->system_network_delegate.get());
880 context->set_http_user_agent_settings(
881 globals->http_user_agent_settings.get());
882 context->set_network_quality_estimator(
883 globals->network_quality_estimator.get());
wjmacleanea309f72015-08-25 20:56:59884
bnc525e175a2016-06-20 12:36:40885 context->set_http_server_properties(globals->http_server_properties.get());
wjmacleanea309f72015-08-25 20:56:59886
maksim.sisov3d40c812016-05-02 13:27:16887 context->set_enable_brotli(globals->enable_brotli);
888
bnc18fb77f2016-04-04 20:54:04889 net::HttpNetworkSession::Params system_params(params);
wjmacleanea309f72015-08-25 20:56:59890 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
891 context, &system_params);
892
mmenkee65e7af2015-10-13 17:16:42893 globals->system_http_network_session.reset(
894 new net::HttpNetworkSession(system_params));
wjmacleanea309f72015-08-25 20:56:59895 globals->system_http_transaction_factory.reset(
mmenkee65e7af2015-10-13 17:16:42896 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
wjmacleanea309f72015-08-25 20:56:59897 context->set_http_transaction_factory(
898 globals->system_http_transaction_factory.get());
899
900 return context;
901}
902
bnc0f6bff62016-04-05 16:51:09903// static
bnce87c7c712016-08-01 23:59:48904void IOThread::ConfigureParamsFromFieldTrialsAndCommandLine(
905 const base::CommandLine& command_line,
906 bool is_quic_allowed_by_policy,
mmenkea7da6da2016-09-01 21:56:52907 bool http_09_on_non_default_ports_enabled,
bnce87c7c712016-08-01 23:59:48908 net::HttpNetworkSession::Params* params) {
909 std::string quic_user_agent_id = chrome::GetChannelString();
910 if (!quic_user_agent_id.empty())
911 quic_user_agent_id.push_back(' ');
912 quic_user_agent_id.append(
913 version_info::GetProductNameAndVersionForUserAgent());
914 quic_user_agent_id.push_back(' ');
915 quic_user_agent_id.append(content::BuildOSCpuInfo());
916
917 bool is_quic_force_disabled = !is_quic_allowed_by_policy ||
918 command_line.HasSwitch(switches::kDisableQuic);
919 bool is_quic_force_enabled = command_line.HasSwitch(switches::kEnableQuic);
920
921 network_session_configurator::ParseFieldTrials(is_quic_force_disabled,
922 is_quic_force_enabled,
923 quic_user_agent_id, params);
924
925 // Command line flags override field trials.
926 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
927 net::URLFetcher::SetIgnoreCertificateRequests(true);
928
929 if (command_line.HasSwitch(switches::kDisableHttp2))
930 params->enable_http2 = false;
931
932 if (command_line.HasSwitch(switches::kDisableQuicPortSelection)) {
933 params->enable_quic_port_selection = false;
934 } else if (command_line.HasSwitch(switches::kEnableQuicPortSelection)) {
935 params->enable_quic_port_selection = true;
936 }
937
938 if (params->enable_quic) {
939 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) {
940 params->quic_connection_options =
941 net::QuicUtils::ParseQuicConnectionOptions(
942 command_line.GetSwitchValueASCII(
943 switches::kQuicConnectionOptions));
944 }
945
946 if (command_line.HasSwitch(switches::kQuicHostWhitelist)) {
947 std::string whitelist =
948 command_line.GetSwitchValueASCII(switches::kQuicHostWhitelist);
949 params->quic_host_whitelist.clear();
950 for (const std::string& host : base::SplitString(
951 whitelist, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
952 params->quic_host_whitelist.insert(host);
953 }
954 }
955
956 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
957 unsigned value;
958 if (base::StringToUint(
959 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
960 &value)) {
961 params->quic_max_packet_length = value;
962 }
963 }
964
965 if (command_line.HasSwitch(switches::kQuicVersion)) {
966 net::QuicVersion version = network_session_configurator::ParseQuicVersion(
967 command_line.GetSwitchValueASCII(switches::kQuicVersion));
968 if (version != net::QUIC_VERSION_UNSUPPORTED) {
969 net::QuicVersionVector supported_versions;
970 supported_versions.push_back(version);
971 params->quic_supported_versions = supported_versions;
972 }
973 }
974
975 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
976 std::string origins =
977 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn);
978 for (const std::string& host_port : base::SplitString(
979 origins, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
980 if (host_port == "*")
981 params->origins_to_force_quic_on.insert(net::HostPortPair());
982 net::HostPortPair quic_origin =
983 net::HostPortPair::FromString(host_port);
984 if (!quic_origin.IsEmpty())
985 params->origins_to_force_quic_on.insert(quic_origin);
986 }
987 }
988 }
989
990 // Parameters only controlled by command line.
991 if (command_line.HasSwitch(switches::kEnableUserAlternateProtocolPorts)) {
992 params->enable_user_alternate_protocol_ports = true;
993 }
994 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
995 params->ignore_certificate_errors = true;
996 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
997 params->testing_fixed_http_port =
998 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
999 }
1000 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
1001 params->testing_fixed_https_port =
1002 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
1003 }
mmenkea7da6da2016-09-01 21:56:521004
1005 params->http_09_on_non_default_ports_enabled =
1006 http_09_on_non_default_ports_enabled;
bnce87c7c712016-08-01 23:59:481007}
1008
1009// static
wjmacleanea309f72015-08-25 20:56:591010net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext(
1011 IOThread::Globals* globals,
bnc18fb77f2016-04-04 20:54:041012 const net::HttpNetworkSession::Params& params,
wjmacleanea309f72015-08-25 20:56:591013 net::NetLog* net_log) {
wjmacleanea309f72015-08-25 20:56:591014 net::URLRequestContext* context = new net::URLRequestContext;
1015 context->set_net_log(net_log);
1016 context->set_host_resolver(globals->host_resolver.get());
1017 context->set_cert_verifier(globals->cert_verifier.get());
1018 context->set_transport_security_state(
1019 globals->transport_security_state.get());
1020 context->set_cert_transparency_verifier(
1021 globals->cert_transparency_verifier.get());
rsleevid6de8302016-06-21 01:33:201022 context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get());
wjmacleanea309f72015-08-25 20:56:591023 context->set_ssl_config_service(globals->ssl_config_service.get());
1024 context->set_http_auth_handler_factory(
1025 globals->http_auth_handler_factory.get());
1026 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
1027
1028 context->set_job_factory(
1029 globals->proxy_script_fetcher_url_request_job_factory.get());
1030
1031 context->set_cookie_store(globals->system_cookie_store.get());
1032 context->set_channel_id_service(
1033 globals->system_channel_id_service.get());
1034 context->set_network_delegate(globals->system_network_delegate.get());
1035 context->set_http_user_agent_settings(
1036 globals->http_user_agent_settings.get());
bnc525e175a2016-06-20 12:36:401037 context->set_http_server_properties(globals->http_server_properties.get());
wjmacleanea309f72015-08-25 20:56:591038
maksim.sisov3d40c812016-05-02 13:27:161039 context->set_enable_brotli(globals->enable_brotli);
1040
bnc18fb77f2016-04-04 20:54:041041 net::HttpNetworkSession::Params session_params(params);
wjmacleanea309f72015-08-25 20:56:591042 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1043 context, &session_params);
1044
mmenkee65e7af2015-10-13 17:16:421045 globals->proxy_script_fetcher_http_network_session.reset(
wjmacleanea309f72015-08-25 20:56:591046 new net::HttpNetworkSession(session_params));
mmenkee65e7af2015-10-13 17:16:421047 globals->proxy_script_fetcher_http_transaction_factory.reset(
1048 new net::HttpNetworkLayer(
1049 globals->proxy_script_fetcher_http_network_session.get()));
wjmacleanea309f72015-08-25 20:56:591050 context->set_http_transaction_factory(
1051 globals->proxy_script_fetcher_http_transaction_factory.get());
1052
dcheng4af48582016-04-19 00:29:351053 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(
wjmacleanea309f72015-08-25 20:56:591054 new net::URLRequestJobFactoryImpl());
1055
ricea86fa1dd2016-09-13 05:59:451056 job_factory->SetProtocolHandler(url::kDataScheme,
1057 base::MakeUnique<net::DataProtocolHandler>());
wjmacleanea309f72015-08-25 20:56:591058 job_factory->SetProtocolHandler(
1059 url::kFileScheme,
ricea86fa1dd2016-09-13 05:59:451060 base::MakeUnique<net::FileProtocolHandler>(
wjmacleanea309f72015-08-25 20:56:591061 content::BrowserThread::GetBlockingPool()
1062 ->GetTaskRunnerWithShutdownBehavior(
ricea86fa1dd2016-09-13 05:59:451063 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
wjmacleanea309f72015-08-25 20:56:591064#if !defined(DISABLE_FTP_SUPPORT)
1065 globals->proxy_script_fetcher_ftp_transaction_factory.reset(
1066 new net::FtpNetworkLayer(globals->host_resolver.get()));
1067 job_factory->SetProtocolHandler(
1068 url::kFtpScheme,
ricea86fa1dd2016-09-13 05:59:451069 base::MakeUnique<net::FtpProtocolHandler>(
1070 globals->proxy_script_fetcher_ftp_transaction_factory.get()));
wjmacleanea309f72015-08-25 20:56:591071#endif
dchenge73d8520c2015-12-27 01:19:091072 globals->proxy_script_fetcher_url_request_job_factory =
1073 std::move(job_factory);
wjmacleanea309f72015-08-25 20:56:591074
1075 context->set_job_factory(
1076 globals->proxy_script_fetcher_url_request_job_factory.get());
1077
1078 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1079 // system URLRequestContext too. There's no reason this should be tied to a
1080 // profile.
1081 return context;
1082}
gayane0b46091c2016-04-07 21:01:051083
1084const metrics::UpdateUsagePrefCallbackType&
1085IOThread::GetMetricsDataUseForwarder() {
1086 return metrics_data_use_forwarder_;
1087}