blob: 7876d7afc63152a564b54e487309d330fb2530cf [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"
fdoraydd7eb402017-04-26 21:44:2529#include "base/task_scheduler/post_task.h"
[email protected]3fc40c142011-12-01 13:09:0430#include "base/threading/thread.h"
[email protected]d827e112014-03-31 17:45:0531#include "base/time/time.h"
primiano6221e572015-01-28 12:14:3432#include "base/trace_event/trace_event.h"
[email protected]addb3242011-06-13 21:39:1633#include "build/build_config.h"
[email protected]df2840d2011-02-20 16:32:3234#include "chrome/browser/browser_process.h"
sclittlea133de02015-11-10 23:54:2135#include "chrome/browser/data_usage/tab_id_annotator.h"
kundajif617523b2016-09-09 22:41:2436#include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h"
[email protected]026876f32012-08-22 23:53:4037#include "chrome/browser/net/async_dns_field_trial.h"
[email protected]c38831a12011-10-28 12:44:4938#include "chrome/browser/net/chrome_network_delegate.h"
[email protected]4588b3d2012-11-14 00:37:3839#include "chrome/browser/net/dns_probe_service.h"
[email protected]db0e86dd2011-03-16 14:47:2140#include "chrome/browser/net/proxy_service_factory.h"
eranm3c2d6432016-06-01 10:17:2741#include "chrome/browser/net/sth_distributor_provider.h"
sdefresne9fb67692015-08-03 18:48:2242#include "chrome/common/channel_info.h"
[email protected]aa051272014-03-10 05:56:5643#include "chrome/common/chrome_content_client.h"
[email protected]0ac83682010-01-22 17:46:2744#include "chrome/common/chrome_switches.h"
[email protected]bcefe0f2010-11-10 16:19:1045#include "chrome/common/pref_names.h"
eranm3c2d6432016-06-01 10:17:2746#include "components/certificate_transparency/tree_state_tracker.h"
megjablon3476e042014-10-14 19:21:5947#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
sclittle3f98c6c2015-11-19 22:59:2948#include "components/data_usage/core/data_use_aggregator.h"
sclittlec441f782015-11-12 01:12:0949#include "components/data_usage/core/data_use_amortizer.h"
sclittle3f98c6c2015-11-19 22:59:2950#include "components/data_usage/core/data_use_annotator.h"
kundajic6135962016-09-26 17:54:2851#include "components/data_use_measurement/core/data_use_ascriber.h"
gayane0b46091c2016-04-07 21:01:0552#include "components/metrics/metrics_service.h"
drogerc690e8802015-09-21 14:29:1653#include "components/net_log/chrome_net_log.h"
bnc210d6f32016-05-24 07:40:4754#include "components/network_session_configurator/network_session_configurator.h"
[email protected]76b4b152013-12-08 21:10:0455#include "components/policy/core/common/policy_service.h"
brettw39d6ba42016-08-24 16:56:3856#include "components/policy/policy_constants.h"
brettwb1fc1b82016-02-02 00:19:0857#include "components/prefs/pref_registry_simple.h"
58#include "components/prefs/pref_service.h"
abhishek.a2171c612852015-08-31 10:48:1959#include "components/proxy_config/pref_proxy_config_tracker.h"
[email protected]488a0e252014-06-25 04:37:4460#include "components/variations/variations_associated_data.h"
sdefresne9fb67692015-08-03 18:48:2261#include "components/version_info/version_info.h"
[email protected]c38831a12011-10-28 12:44:4962#include "content/public/browser/browser_thread.h"
[email protected]7c4b66b2014-01-04 12:28:1363#include "content/public/browser/cookie_store_factory.h"
eustasfbec9132015-12-30 14:56:5164#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:4065#include "content/public/common/content_switches.h"
rtenneti4d126a72015-06-23 17:32:0966#include "content/public/common/user_agent.h"
brettw00899e62016-11-12 02:10:1767#include "extensions/features/features.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]eb3cac72010-02-26 21:07:4586#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5087#include "net/http/http_auth_handler_factory.h"
aberentbba302d2015-12-03 10:20:1988#include "net/http/http_auth_preferences.h"
[email protected]2fb629202010-12-23 23:52:5789#include "net/http/http_network_layer.h"
[email protected]17291a022011-10-10 07:32:5390#include "net/http/http_server_properties_impl.h"
brettwa1228ebb2016-10-28 03:51:3491#include "net/net_features.h"
tbansalca83c002016-04-28 20:56:2892#include "net/nqe/external_estimate_provider.h"
93#include "net/nqe/network_quality_estimator.h"
tbansald3e08ca62017-05-04 19:51:0994#include "net/nqe/network_quality_estimator_params.h"
[email protected]6104ea5d2011-04-27 21:37:1295#include "net/proxy/proxy_config_service.h"
[email protected]86933612010-10-16 23:10:3396#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]6104ea5d2011-04-27 21:37:1297#include "net/proxy/proxy_service.h"
rch4c967ea2016-12-22 01:41:0798#include "net/quic/chromium/quic_utils_chromium.h"
zhongyi81f85c6d92015-10-16 19:34:1499#include "net/socket/ssl_client_socket.h"
[email protected]717e4e22013-04-10 20:52:23100#include "net/socket/tcp_client_socket.h"
[email protected]6b8a3c742014-07-25 00:25:35101#include "net/ssl/channel_id_service.h"
102#include "net/ssl/default_channel_id_store.h"
[email protected]b3ae2db2013-05-30 05:00:05103#include "net/url_request/data_protocol_handler.h"
104#include "net/url_request/file_protocol_handler.h"
105#include "net/url_request/ftp_protocol_handler.h"
[email protected]aa051272014-03-10 05:56:56106#include "net/url_request/static_http_user_agent_settings.h"
[email protected]3dc1bc42012-06-19 08:20:53107#include "net/url_request/url_fetcher.h"
[email protected]f9c8c7c2014-07-31 16:42:31108#include "net/url_request/url_request_context.h"
wjmacleanea309f72015-08-25 20:56:59109#include "net/url_request/url_request_context_builder.h"
[email protected]f9c8c7c2014-07-31 16:42:31110#include "net/url_request/url_request_context_getter.h"
[email protected]b3ae2db2013-05-30 05:00:05111#include "net/url_request/url_request_job_factory_impl.h"
brettw03e61962016-03-15 06:27:04112#include "url/url_constants.h"
[email protected]0ac83682010-01-22 17:46:27113
brettw00899e62016-11-12 02:10:17114#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]84b7a552014-07-19 04:52:06115#include "chrome/browser/extensions/event_router_forwarder.h"
116#endif
117
jam1c5a91492016-02-24 20:47:53118#if defined(USE_NSS_CERTS)
eromaned744f32015-04-09 06:35:49119#include "net/cert_net/nss_ocsp.h"
[email protected]a592c0432012-12-01 18:10:29120#endif
[email protected]77feb462011-05-16 23:37:25121
zpengdb4a58e2017-01-10 17:40:32122#if defined(OS_ANDROID)
jeremyimb6c97ae2015-01-05 22:57:14123#include "base/android/build_info.h"
megjablon174bc342015-11-05 00:30:06124#include "chrome/browser/android/data_usage/external_data_use_observer.h"
tbansaldafbb3e2015-08-19 19:55:33125#include "chrome/browser/android/net/external_estimate_provider_android.h"
sclittlec441f782015-11-12 01:12:09126#include "components/data_usage/android/traffic_stats_amortizer.h"
estark9a263782017-01-20 02:13:04127#include "net/cert/cert_net_fetcher.h"
128#include "net/cert/cert_verify_proc_android.h"
129#include "net/cert_net/cert_net_fetcher_impl.h"
zpengdb4a58e2017-01-10 17:40:32130#endif // defined(OS_ANDROID)
jeremyimb6c97ae2015-01-05 22:57:14131
[email protected]f46f6d52014-02-08 04:00:39132#if defined(OS_CHROMEOS)
133#include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
zentaroe0326352017-05-09 13:11:51134#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
[email protected]106ccd2c2014-06-17 09:21:00135#include "chromeos/network/host_resolver_impl_chromeos.h"
[email protected]f46f6d52014-02-08 04:00:39136#endif
137
davidben45eb19952016-05-05 16:30:44138#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
davidben45eb19952016-05-05 16:30:44139#include "crypto/openssl_util.h"
tfarina29a3a1742016-10-28 18:47:33140#include "third_party/boringssl/src/include/openssl/cpu.h"
davidben45eb19952016-05-05 16:30:44141#endif
142
[email protected]631bb742011-11-02 11:29:39143using content::BrowserThread;
144
[email protected]075c0322012-02-14 00:56:44145class SafeBrowsingURLRequestContext;
146
[email protected]21ee224e2011-11-21 02:17:53147// The IOThread object must outlive any tasks posted to the IO thread before the
148// Quit task, so base::Bind() calls are not refcounted.
149
[email protected]0ac83682010-01-22 17:46:27150namespace {
151
tbansalb177b5392015-06-25 11:13:02152// Field trial for network quality estimator. Seeds RTT and downstream
153// throughput observations with values that correspond to the connection type
154// determined by the operating system.
155const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
156
jam1c5a91492016-02-24 20:47:53157#if defined(OS_MACOSX)
[email protected]11f5e3a2012-09-27 00:30:13158void ObserveKeychainEvents() {
thestig00844cea2015-09-08 21:44:52159 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]11f5e3a2012-09-27 00:30:13160 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
161}
162#endif
163
zhongyi81f85c6d92015-10-16 19:34:14164// Gets file path into ssl_keylog_file from command line argument or
165// environment variable. Command line argument has priority when
166// both specified.
davidben2a811e4e2015-12-01 10:49:34167base::FilePath GetSSLKeyLogFile(const base::CommandLine& command_line) {
zhongyi81f85c6d92015-10-16 19:34:14168 if (command_line.HasSwitch(switches::kSSLKeyLogFile)) {
davidben2a811e4e2015-12-01 10:49:34169 base::FilePath path =
170 command_line.GetSwitchValuePath(switches::kSSLKeyLogFile);
171 if (!path.empty())
172 return path;
zhongyi81f85c6d92015-10-16 19:34:14173 LOG(WARNING) << "ssl-key-log-file argument missing";
174 }
davidben2a811e4e2015-12-01 10:49:34175
dcheng4af48582016-04-19 00:29:35176 std::unique_ptr<base::Environment> env(base::Environment::Create());
davidben2a811e4e2015-12-01 10:49:34177 std::string path_str;
178 env->GetVar("SSLKEYLOGFILE", &path_str);
179#if defined(OS_WIN)
180 // base::Environment returns environment variables in UTF-8 on Windows.
181 return base::FilePath(base::UTF8ToUTF16(path_str));
182#else
183 return base::FilePath(path_str);
184#endif
zhongyi81f85c6d92015-10-16 19:34:14185}
186
[email protected]ee4c30d2012-11-07 15:08:43187// Used for the "system" URLRequestContext.
188class SystemURLRequestContext : public net::URLRequestContext {
[email protected]77feb462011-05-16 23:37:25189 public:
190 SystemURLRequestContext() {
jam1c5a91492016-02-24 20:47:53191#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09192 net::SetURLRequestContextForNSSHttpIO(this);
[email protected]a592c0432012-12-01 18:10:29193#endif
estark9a263782017-01-20 02:13:04194#if defined(OS_ANDROID)
195 net::CertVerifyProcAndroid::SetCertNetFetcher(
196 net::CreateCertNetFetcher(this));
197#endif
[email protected]77feb462011-05-16 23:37:25198 }
199
200 private:
Daniel Chenga542fca2014-10-21 09:51:29201 ~SystemURLRequestContext() override {
[email protected]424559492014-07-22 00:27:40202 AssertNoURLRequests();
jam1c5a91492016-02-24 20:47:53203#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09204 net::SetURLRequestContextForNSSHttpIO(NULL);
[email protected]a592c0432012-12-01 18:10:29205#endif
[email protected]77feb462011-05-16 23:37:25206 }
207};
208
dcheng4af48582016-04-19 00:29:35209std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
210 net::NetLog* net_log) {
[email protected]d22f06e2013-06-11 16:01:17211 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver");
avi556c05022014-12-22 23:31:43212 const base::CommandLine& command_line =
213 *base::CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:51214
[email protected]c54a8912012-10-22 22:09:43215 net::HostResolver::Options options;
[email protected]962b98212010-07-17 03:37:51216
[email protected]06ef6d92011-05-19 04:24:58217 // Use the retry attempts override from the command-line, if any.
218 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
219 std::string s =
220 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
221 // Parse the switch (it should be a non-negative integer).
222 int n;
223 if (base::StringToInt(s, &n) && n >= 0) {
[email protected]c54a8912012-10-22 22:09:43224 options.max_retry_attempts = static_cast<size_t>(n);
[email protected]06ef6d92011-05-19 04:24:58225 } else {
226 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
227 }
228 }
229
dcheng4af48582016-04-19 00:29:35230 std::unique_ptr<net::HostResolver> global_host_resolver;
[email protected]106ccd2c2014-06-17 09:21:00231#if defined OS_CHROMEOS
232 global_host_resolver =
233 chromeos::HostResolverImplChromeOS::CreateSystemResolver(options,
234 net_log);
235#else
236 global_host_resolver =
237 net::HostResolver::CreateSystemResolver(options, net_log);
238#endif
[email protected]9087aa32010-02-18 08:03:38239
[email protected]3dc5d7ef2014-03-28 19:18:21240 // If hostname remappings were specified on the command-line, layer these
241 // rules on top of the real host resolver. This allows forwarding all requests
242 // through a designated test server.
243 if (!command_line.HasSwitch(switches::kHostResolverRules))
dchenge73d8520c2015-12-27 01:19:09244 return global_host_resolver;
[email protected]0ac83682010-01-22 17:46:27245
dcheng4af48582016-04-19 00:29:35246 std::unique_ptr<net::MappedHostResolver> remapped_resolver(
dchenge73d8520c2015-12-27 01:19:09247 new net::MappedHostResolver(std::move(global_host_resolver)));
[email protected]3dc5d7ef2014-03-28 19:18:21248 remapped_resolver->SetRulesFromString(
249 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
dchenge73d8520c2015-12-27 01:19:09250 return std::move(remapped_resolver);
[email protected]0ac83682010-01-22 17:46:27251}
252
jam1671ed32016-07-27 16:31:24253int GetSwitchValueAsInt(const base::CommandLine& command_line,
254 const std::string& switch_name) {
255 int value;
256 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
257 &value)) {
258 return 0;
259 }
260 return value;
261}
262
robliao7253fd22016-12-01 18:41:38263// This function is for forwarding metrics usage pref changes to the metrics
264// service on the appropriate thread.
265// TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread.
266void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name,
267 int message_size,
268 bool is_cellular) {
tzik3f7781d2017-04-20 17:09:33269 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
270 base::BindOnce(
271 [](const std::string& service_name,
272 int message_size, bool is_cellular) {
273 // Some unit tests use IOThread but do not
274 // initialize MetricsService. In that case it's
275 // fine to skip the update.
276 auto* metrics_service =
277 g_browser_process->metrics_service();
278 if (metrics_service) {
279 metrics_service->UpdateMetricsUsagePrefs(
280 service_name, message_size, is_cellular);
281 }
282 },
283 service_name, message_size, is_cellular));
robliao7253fd22016-12-01 18:41:38284}
285
[email protected]0ac83682010-01-22 17:46:27286} // namespace
287
[email protected]abe2c032011-03-31 18:49:34288class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
[email protected]db0e86dd2011-03-16 14:47:21289 public:
290 explicit SystemURLRequestContextGetter(IOThread* io_thread);
[email protected]db0e86dd2011-03-16 14:47:21291
[email protected]abe2c032011-03-31 18:49:34292 // Implementation for net::UrlRequestContextGetter.
Daniel Chenga542fca2014-10-21 09:51:29293 net::URLRequestContext* GetURLRequestContext() override;
294 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
295 const override;
[email protected]db0e86dd2011-03-16 14:47:21296
[email protected]13ed17f82012-04-06 02:27:18297 protected:
Daniel Chenga542fca2014-10-21 09:51:29298 ~SystemURLRequestContextGetter() override;
[email protected]13ed17f82012-04-06 02:27:18299
[email protected]db0e86dd2011-03-16 14:47:21300 private:
301 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
[email protected]4969b0122012-06-16 01:58:28302 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21303
304 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
305};
306
307SystemURLRequestContextGetter::SystemURLRequestContextGetter(
308 IOThread* io_thread)
309 : io_thread_(io_thread),
[email protected]4969b0122012-06-16 01:58:28310 network_task_runner_(
thestig529ad8a2016-07-08 20:30:12311 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)) {}
[email protected]db0e86dd2011-03-16 14:47:21312
313SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
314
315net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
thestig00844cea2015-09-08 21:44:52316 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]ef2bf422012-05-11 03:27:09317 DCHECK(io_thread_->globals()->system_request_context.get());
[email protected]db0e86dd2011-03-16 14:47:21318
[email protected]ef2bf422012-05-11 03:27:09319 return io_thread_->globals()->system_request_context.get();
[email protected]db0e86dd2011-03-16 14:47:21320}
321
[email protected]4969b0122012-06-16 01:58:28322scoped_refptr<base::SingleThreadTaskRunner>
323SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
324 return network_task_runner_;
[email protected]db0e86dd2011-03-16 14:47:21325}
326
[email protected]c93123fa2012-04-19 02:49:48327IOThread::Globals::
328SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
329 Globals* globals)
330 : globals_(globals) {
331 DCHECK(globals_);
[email protected]7613faae2012-04-18 01:01:19332}
[email protected]1889dc1b2010-10-14 22:03:13333
[email protected]c93123fa2012-04-19 02:49:48334IOThread::Globals::
335SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {
336 if (globals_->system_request_context.get())
337 globals_->system_request_context->AssertNoURLRequests();
338}
339
maksim.sisov3d40c812016-05-02 13:27:16340IOThread::Globals::Globals() : system_request_context_leak_checker(this),
341 enable_brotli(false) {}
[email protected]c2dad292012-09-07 21:27:35342
[email protected]c93123fa2012-04-19 02:49:48343IOThread::Globals::~Globals() {}
344
[email protected]bcefe0f2010-11-10 16:19:10345// |local_state| is passed in explicitly in order to (1) reduce implicit
346// dependencies and (2) make IOThread more flexible for testing.
[email protected]3ce02412011-03-01 12:01:15347IOThread::IOThread(
[email protected]b1de2c72013-02-06 02:45:47348 PrefService* local_state,
[email protected]77305422012-11-29 16:51:39349 policy::PolicyService* policy_service,
drogerc690e8802015-09-21 14:29:16350 net_log::ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10351 extensions::EventRouterForwarder* extension_event_router_forwarder)
[email protected]2e5b60a22011-11-28 15:56:41352 : net_log_(net_log),
brettw00899e62016-11-12 02:10:17353#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15354 extension_event_router_forwarder_(extension_event_router_forwarder),
[email protected]84b7a552014-07-19 04:52:06355#endif
mmenkea7da6da2016-09-01 21:56:52356 globals_(nullptr),
peletskyi5df83d42015-04-30 16:37:46357 is_quic_allowed_by_policy_(true),
mmenke82d19a582017-01-27 23:26:32358 http_09_on_non_default_ports_enabled_(false),
mohan.reddy14cb4ad42014-09-17 18:15:14359 creation_time_(base::TimeTicks::Now()),
360 weak_factory_(this) {
aberentbba302d2015-12-03 10:20:19361 scoped_refptr<base::SingleThreadTaskRunner> io_thread_proxy =
thestig529ad8a2016-07-08 20:30:12362 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
[email protected]bcefe0f2010-11-10 16:19:10363 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
aberentbba302d2015-12-03 10:20:19364 negotiate_disable_cname_lookup_.Init(
365 prefs::kDisableAuthNegotiateCnameLookup, local_state,
366 base::Bind(&IOThread::UpdateNegotiateDisableCnameLookup,
367 base::Unretained(this)));
368 negotiate_disable_cname_lookup_.MoveToThread(io_thread_proxy);
369 negotiate_enable_port_.Init(
370 prefs::kEnableAuthNegotiatePort, local_state,
371 base::Bind(&IOThread::UpdateNegotiateEnablePort, base::Unretained(this)));
372 negotiate_enable_port_.MoveToThread(io_thread_proxy);
373 auth_server_whitelist_.Init(
374 prefs::kAuthServerWhitelist, local_state,
375 base::Bind(&IOThread::UpdateServerWhitelist, base::Unretained(this)));
376 auth_server_whitelist_.MoveToThread(io_thread_proxy);
377 auth_delegate_whitelist_.Init(
378 prefs::kAuthNegotiateDelegateWhitelist, local_state,
379 base::Bind(&IOThread::UpdateDelegateWhitelist, base::Unretained(this)));
380 auth_delegate_whitelist_.MoveToThread(io_thread_proxy);
381#if defined(OS_ANDROID)
382 auth_android_negotiate_account_type_.Init(
383 prefs::kAuthAndroidNegotiateAccountType, local_state,
384 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType,
385 base::Unretained(this)));
386 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy);
387#endif
388#if defined(OS_POSIX) && !defined(OS_ANDROID)
[email protected]ac7f3fdb2010-11-12 12:47:05389 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
aberentbba302d2015-12-03 10:20:19390#endif
zentaroe0326352017-05-09 13:11:51391#if defined(OS_CHROMEOS)
392 policy::BrowserPolicyConnectorChromeOS* connector =
393 g_browser_process->platform_part()->browser_policy_connector_chromeos();
394 allow_gssapi_library_load_ = connector->IsActiveDirectoryManaged();
395#endif
[email protected]6f96cbcb2011-11-04 02:26:07396 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42397 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
398 local_state));
[email protected]9d8cfb682012-09-13 16:48:04399 ChromeNetworkDelegate::InitializePrefsOnUIThread(
400 &system_enable_referrers_,
igorcov193d8ad32016-05-27 11:03:21401 nullptr,
402 nullptr,
403 nullptr,
404 nullptr,
[email protected]9d8cfb682012-09-13 16:48:04405 local_state);
[email protected]4d45a6de2011-05-13 05:20:18406 ssl_config_service_manager_.reset(
abhishek.a212849cee2015-10-20 11:27:29407 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
408 local_state,
thestig529ad8a2016-07-08 20:30:12409 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
[email protected]2e5b60a22011-11-28 15:56:41410
jdoerrie239723572017-03-02 12:09:19411 base::Value* dns_client_enabled_default =
412 new base::Value(chrome_browser_net::ConfigureAsyncDnsFieldTrial());
[email protected]68a9b0d82013-03-08 07:05:07413 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
414 dns_client_enabled_default);
ttuttle530184962015-01-13 00:24:07415 chrome_browser_net::LogAsyncDnsPrefSource(
416 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled));
[email protected]68a9b0d82013-03-08 07:05:07417
[email protected]fa4b6c32012-11-26 23:02:39418 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
419 local_state,
420 base::Bind(&IOThread::UpdateDnsClientEnabled,
421 base::Unretained(this)));
aberentbba302d2015-12-03 10:20:19422 dns_client_enabled_.MoveToThread(io_thread_proxy);
[email protected]fa4b6c32012-11-26 23:02:39423
[email protected]67378142013-12-17 21:57:17424 quick_check_enabled_.Init(prefs::kQuickCheckEnabled,
425 local_state);
aberentbba302d2015-12-03 10:20:19426 quick_check_enabled_.MoveToThread(io_thread_proxy);
[email protected]67378142013-12-17 21:57:17427
eroman9f7ea642016-06-03 21:28:29428 pac_https_url_stripping_enabled_.Init(prefs::kPacHttpsUrlStrippingEnabled,
429 local_state);
430 pac_https_url_stripping_enabled_.MoveToThread(io_thread_proxy);
431
peletskyi5df83d42015-04-30 16:37:46432 const base::Value* value = policy_service->GetPolicies(
433 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
434 std::string())).GetValue(policy::key::kQuicAllowed);
435 if (value)
436 value->GetAsBoolean(&is_quic_allowed_by_policy_);
[email protected]77305422012-11-29 16:51:39437
mmenkea7da6da2016-09-01 21:56:52438 value = policy_service
439 ->GetPolicies(policy::PolicyNamespace(
440 policy::POLICY_DOMAIN_CHROME, std::string()))
441 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled);
442 if (value)
443 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_);
444
eranm3c2d6432016-06-01 10:17:27445 chrome_browser_net::SetGlobalSTHDistributor(
446 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor()));
447
gab90becc92016-12-08 17:19:34448 BrowserThread::SetIOThreadDelegate(this);
[email protected]bcefe0f2010-11-10 16:19:10449}
[email protected]0ac83682010-01-22 17:46:27450
451IOThread::~IOThread() {
[email protected]2e5b60a22011-11-28 15:56:41452 // This isn't needed for production code, but in tests, IOThread may
453 // be multiply constructed.
gab90becc92016-12-08 17:19:34454 BrowserThread::SetIOThreadDelegate(nullptr);
[email protected]2e5b60a22011-11-28 15:56:41455
[email protected]d461ed22013-01-18 03:18:56456 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]d13c3272010-02-04 00:24:51457 DCHECK(!globals_);
eranm3c2d6432016-06-01 10:17:27458
459 // Destroy the old distributor to check that the observers list it holds is
460 // empty.
461 chrome_browser_net::SetGlobalSTHDistributor(nullptr);
[email protected]0ac83682010-01-22 17:46:27462}
463
[email protected]d13c3272010-02-04 00:24:51464IOThread::Globals* IOThread::globals() {
thestig00844cea2015-09-08 21:44:52465 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d13c3272010-02-04 00:24:51466 return globals_;
[email protected]0ac83682010-01-22 17:46:27467}
468
[email protected]37ac95b2013-07-23 23:39:35469void IOThread::SetGlobalsForTesting(Globals* globals) {
thestig00844cea2015-09-08 21:44:52470 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]37ac95b2013-07-23 23:39:35471 DCHECK(!globals || !globals_);
472 globals_ = globals;
473}
474
drogerc690e8802015-09-21 14:29:16475net_log::ChromeNetLog* IOThread::net_log() {
[email protected]b2fcd0e2010-12-01 15:19:40476 return net_log_;
477}
478
[email protected]b09f76d62011-12-07 01:51:06479void IOThread::ChangedToOnTheRecord() {
thestig00844cea2015-09-08 21:44:52480 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]b09f76d62011-12-07 01:51:06481 BrowserThread::PostTask(
tzik3f7781d2017-04-20 17:09:33482 BrowserThread::IO, FROM_HERE,
483 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread,
484 base::Unretained(this)));
[email protected]b09f76d62011-12-07 01:51:06485}
486
[email protected]abe2c032011-03-31 18:49:34487net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
thestig00844cea2015-09-08 21:44:52488 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5173de8b2013-06-02 21:16:02489 if (!system_url_request_context_getter_.get()) {
[email protected]addb3242011-06-13 21:39:16490 InitSystemRequestContext();
[email protected]db0e86dd2011-03-16 14:47:21491 }
[email protected]5173de8b2013-06-02 21:16:02492 return system_url_request_context_getter_.get();
[email protected]db0e86dd2011-03-16 14:47:21493}
494
[email protected]0ac83682010-01-22 17:46:27495void IOThread::Init() {
[email protected]a5e73b82013-07-17 08:58:39496 TRACE_EVENT0("startup", "IOThread::InitAsync");
thestig00844cea2015-09-08 21:44:52497 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]70b92342010-10-12 05:54:06498
jam1c5a91492016-02-24 20:47:53499#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09500 net::SetMessageLoopForNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29501#endif
[email protected]70b92342010-10-12 05:54:06502
avi556c05022014-12-22 23:31:43503 const base::CommandLine& command_line =
504 *base::CommandLine::ForCurrentProcess();
[email protected]c2dad292012-09-07 21:27:35505
zhongyi81f85c6d92015-10-16 19:34:14506 // Export ssl keys if log file specified.
davidben2a811e4e2015-12-01 10:49:34507 base::FilePath ssl_keylog_file = GetSSLKeyLogFile(command_line);
zhongyi81f85c6d92015-10-16 19:34:14508 if (!ssl_keylog_file.empty()) {
davidben2a811e4e2015-12-01 10:49:34509 net::SSLClientSocket::SetSSLKeyLogFile(
510 ssl_keylog_file,
thestig529ad8a2016-07-08 20:30:12511 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE));
zhongyi81f85c6d92015-10-16 19:34:14512 }
513
[email protected]d13c3272010-02-04 00:24:51514 DCHECK(!globals_);
515 globals_ = new Globals;
516
[email protected]58bc7042010-07-07 18:04:14517 // Add an observer that will emit network change events to the ChromeNetLog.
518 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
519 // logging the network change before other IO thread consumers respond to it.
520 network_change_observer_.reset(
pauljensen7b34e522016-05-12 18:20:59521 new net::LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14522
[email protected]cde8b3c2012-08-13 19:20:52523 // Setup the HistogramWatcher to run on the IO thread.
524 net::NetworkChangeNotifier::InitHistogramWatcher();
525
brettw00899e62016-11-12 02:10:17526#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15527 globals_->extension_event_router_forwarder =
528 extension_event_router_forwarder_;
[email protected]84b7a552014-07-19 04:52:06529#endif
530
dcheng4af48582016-04-19 00:29:35531 std::unique_ptr<data_usage::DataUseAmortizer> data_use_amortizer;
zpengdb4a58e2017-01-10 17:40:32532#if defined(OS_ANDROID)
sclittlec441f782015-11-12 01:12:09533 data_use_amortizer.reset(new data_usage::android::TrafficStatsAmortizer());
zpengdb4a58e2017-01-10 17:40:32534#endif // defined(OS_ANDROID)
sclittlec441f782015-11-12 01:12:09535
kundajif617523b2016-09-09 22:41:24536 globals_->data_use_ascriber =
537 base::MakeUnique<data_use_measurement::ChromeDataUseAscriber>();
538
sclittle3f98c6c2015-11-19 22:59:29539 globals_->data_use_aggregator.reset(new data_usage::DataUseAggregator(
dcheng4af48582016-04-19 00:29:35540 std::unique_ptr<data_usage::DataUseAnnotator>(
sclittlec441f782015-11-12 01:12:09541 new chrome_browser_data_usage::TabIdAnnotator()),
dchenge73d8520c2015-12-27 01:19:09542 std::move(data_use_amortizer)));
sclittleae932be2015-10-08 20:53:50543
dcheng4af48582016-04-19 00:29:35544 std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate(
[email protected]84b7a552014-07-19 04:52:06545 new ChromeNetworkDelegate(extension_event_router_forwarder(),
rajendrant14a5a852016-11-17 17:58:48546 &system_enable_referrers_));
sclittleae932be2015-10-08 20:53:50547 // By default, data usage is considered off the record.
548 chrome_network_delegate->set_data_use_aggregator(
sclittle3f98c6c2015-11-19 22:59:29549 globals_->data_use_aggregator.get(),
550 true /* is_data_usage_off_the_record */);
tbansal796988c2015-10-14 02:41:22551
zpengdb4a58e2017-01-10 17:40:32552#if defined(OS_ANDROID)
sclittle3f98c6c2015-11-19 22:59:29553 globals_->external_data_use_observer.reset(
tbansal7c98c0a2015-11-03 21:39:51554 new chrome::android::ExternalDataUseObserver(
sclittle3f98c6c2015-11-19 22:59:29555 globals_->data_use_aggregator.get(),
thestig529ad8a2016-07-08 20:30:12556 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
557 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)));
zpengdb4a58e2017-01-10 17:40:32558#endif // defined(OS_ANDROID)
[email protected]84b7a552014-07-19 04:52:06559
kundajic6135962016-09-26 17:54:28560 globals_->system_network_delegate =
561 globals_->data_use_ascriber->CreateNetworkDelegate(
robliao7253fd22016-12-01 18:41:38562 std::move(chrome_network_delegate), GetMetricsDataUseForwarder());
kundajic6135962016-09-26 17:54:28563
[email protected]c54a8912012-10-22 22:09:43564 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
tbansalea2fb8c2015-05-22 22:23:00565
tbansalb177b5392015-06-25 11:13:02566 std::map<std::string, std::string> network_quality_estimator_params;
567 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
568 &network_quality_estimator_params);
tbansal1c92d5b2015-08-14 20:14:43569
tbansald3e08ca62017-05-04 19:51:09570 if (command_line.HasSwitch(switches::kForceEffectiveConnectionType)) {
571 const std::string force_ect_value =
572 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
573 switches::kForceEffectiveConnectionType);
574
575 if (!force_ect_value.empty()) {
576 // If the effective connection type is forced using command line switch,
577 // it overrides the one set by field trial.
578 network_quality_estimator_params[net::kForceEffectiveConnectionType] =
579 force_ect_value;
580 }
581 }
582
dcheng4af48582016-04-19 00:29:35583 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider;
zpengdb4a58e2017-01-10 17:40:32584#if defined(OS_ANDROID)
tbansal1c92d5b2015-08-14 20:14:43585 external_estimate_provider.reset(
tbansaldafbb3e2015-08-19 19:55:33586 new chrome::android::ExternalEstimateProviderAndroid());
zpengdb4a58e2017-01-10 17:40:32587#endif // defined(OS_ANDROID)
tbansal1c92d5b2015-08-14 20:14:43588 // Pass ownership.
589 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator(
tbansal97e38a22017-01-20 20:43:02590 std::move(external_estimate_provider), network_quality_estimator_params,
591 net_log_));
tbansalea2fb8c2015-05-22 22:23:00592
[email protected]fa4b6c32012-11-26 23:02:39593 UpdateDnsClientEnabled();
[email protected]f46f6d52014-02-08 04:00:39594#if defined(OS_CHROMEOS)
[email protected]f9357a442014-05-15 18:44:07595 // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
rsleevi6df54182016-06-13 14:34:23596 globals_->cert_verifier = base::MakeUnique<net::CachingCertVerifier>(
597 base::MakeUnique<net::MultiThreadedCertVerifier>(
598 new chromeos::CertVerifyProcChromeOS()));
[email protected]f9357a442014-05-15 18:44:07599#else
rsleevi6df54182016-06-13 14:34:23600 globals_->cert_verifier = net::CertVerifier::CreateDefault();
[email protected]f9357a442014-05-15 18:44:07601#endif
602
davidbeneb5f8ef32014-09-04 14:14:32603 globals_->transport_security_state.reset(new net::TransportSecurityState());
604
eranm1a79db22015-11-24 10:56:49605 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs(
eranm03d454c2015-07-02 09:12:03606 net::ct::CreateLogVerifiersForKnownLogs());
[email protected]284303b62013-11-28 15:11:54607
eranm1a79db22015-11-24 10:56:49608 globals_->ct_logs.assign(ct_logs.begin(), ct_logs.end());
609
eranm03d454c2015-07-02 09:12:03610 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
611 globals_->cert_transparency_verifier.reset(ct_verifier);
612 // Add built-in logs
eranm1a79db22015-11-24 10:56:49613 ct_verifier->AddLogs(globals_->ct_logs);
eranm03d454c2015-07-02 09:12:03614
eranmbbf5af702017-02-02 16:06:18615 ct_tree_tracker_.reset(new certificate_transparency::TreeStateTracker(
616 globals_->ct_logs, net_log_));
eranm3c2d6432016-06-01 10:17:27617 // Register the ct_tree_tracker_ as observer for new STHs.
618 RegisterSTHObserver(ct_tree_tracker_.get());
619 // Register the ct_tree_tracker_ as observer for verified SCTs.
620 globals_->cert_transparency_verifier->SetObserver(ct_tree_tracker_.get());
621
bnc18fb77f2016-04-04 20:54:04622 globals_->ct_policy_enforcer.reset(new net::CTPolicyEnforcer());
623 params_.ct_policy_enforcer = globals_->ct_policy_enforcer.get();
eranm6571b2b2014-12-03 15:53:23624
[email protected]4d45a6de2011-05-13 05:20:18625 globals_->ssl_config_service = GetSSLConfigService();
[email protected]f4bfa7672014-08-08 09:50:46626
aberentbba302d2015-12-03 10:20:19627 CreateDefaultAuthHandlerFactory();
[email protected]30d4c022013-07-18 22:58:16628 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
[email protected]2fb629202010-12-23 23:52:57629 // For the ProxyScriptFetcher, we use a direct ProxyService.
rdsmith82957ad2015-09-16 19:42:03630 globals_->proxy_script_fetcher_proxy_service =
631 net::ProxyService::CreateDirectWithNetLog(net_log_);
[email protected]273e37d2011-08-11 01:49:12632 // In-memory cookie store.
[email protected]9a6c2aa2014-01-11 22:39:39633 globals_->system_cookie_store =
mmenke606c59c2016-03-07 18:20:55634 content::CreateCookieStore(content::CookieStoreConfig());
[email protected]6b8a3c742014-07-25 00:25:35635 // In-memory channel ID store.
636 globals_->system_channel_id_service.reset(
fdoraya89e673c2017-01-31 21:44:21637 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL)));
nharper3876dd562016-03-29 22:52:32638 globals_->system_cookie_store->SetChannelIDServiceID(
639 globals_->system_channel_id_service->GetUniqueID());
[email protected]4588b3d2012-11-14 00:37:38640 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
[email protected]c2dad292012-09-07 21:27:35641 globals_->host_mapping_rules.reset(new net::HostMappingRules());
bnc18fb77f2016-04-04 20:54:04642 params_.host_mapping_rules = globals_->host_mapping_rules.get();
[email protected]ee4c30d2012-11-07 15:08:43643 globals_->http_user_agent_settings.reset(
[email protected]aa051272014-03-10 05:56:56644 new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
[email protected]c2dad292012-09-07 21:27:35645 if (command_line.HasSwitch(switches::kHostRules)) {
[email protected]a5e73b82013-07-17 08:58:39646 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35647 globals_->host_mapping_rules->SetRulesFromString(
648 command_line.GetSwitchValueASCII(switches::kHostRules));
[email protected]a5e73b82013-07-17 08:58:39649 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
[email protected]c2dad292012-09-07 21:27:35650 }
maksim.sisov3d40c812016-05-02 13:27:16651 globals_->enable_brotli =
bnc18fb77f2016-04-04 20:54:04652 base::FeatureList::IsEnabled(features::kBrotliEncoding);
653 params_.enable_token_binding =
nharperef2618642016-02-03 22:23:44654 base::FeatureList::IsEnabled(features::kTokenBinding);
bnce87c7c712016-08-01 23:59:48655
656 // Check for OS support of TCP FastOpen, and turn it on for all connections if
657 // indicated by user.
bnc18fb77f2016-04-04 20:54:04658 // TODO(rch): Make the client socket factory a per-network session instance,
659 // constructed from a NetworkSession::Params, to allow us to move this option
660 // to IOThread::Globals & HttpNetworkSession::Params.
bnc18fb77f2016-04-04 20:54:04661 bool always_enable_tfo_if_supported =
662 command_line.HasSwitch(switches::kEnableTcpFastOpen);
bnc18fb77f2016-04-04 20:54:04663 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_tfo_if_supported);
[email protected]f9cf5572012-12-04 15:52:09664
bnce87c7c712016-08-01 23:59:48665 ConfigureParamsFromFieldTrialsAndCommandLine(
mmenkea7da6da2016-09-01 21:56:52666 command_line, is_quic_allowed_by_policy_,
667 http_09_on_non_default_ports_enabled_, &params_);
bnce87c7c712016-08-01 23:59:48668
wjmacleanea309f72015-08-25 20:56:59669 TRACE_EVENT_BEGIN0("startup",
670 "IOThread::Init:ProxyScriptFetcherRequestContext");
[email protected]ef2bf422012-05-11 03:27:09671 globals_->proxy_script_fetcher_context.reset(
bnc18fb77f2016-04-04 20:54:04672 ConstructProxyScriptFetcherContext(globals_, params_, net_log_));
wjmacleanea309f72015-08-25 20:56:59673 TRACE_EVENT_END0("startup",
674 "IOThread::Init:ProxyScriptFetcherRequestContext");
[email protected]4a109492011-09-24 21:00:12675
jam1c5a91492016-02-24 20:47:53676#if defined(OS_MACOSX)
[email protected]11f5e3a2012-09-27 00:30:13677 // Start observing Keychain events. This needs to be done on the UI thread,
678 // as Keychain services requires a CFRunLoop.
679 BrowserThread::PostTask(BrowserThread::UI,
680 FROM_HERE,
681 base::Bind(&ObserveKeychainEvents));
682#endif
683
[email protected]2e5b60a22011-11-28 15:56:41684 // InitSystemRequestContext turns right around and posts a task back
685 // to the IO thread, so we can't let it run until we know the IO
686 // thread has started.
687 //
688 // Note that since we are at BrowserThread::Init time, the UI thread
689 // is blocked waiting for the thread to start. Therefore, posting
690 // this task to the main thread's message loop here is guaranteed to
691 // get it onto the message loop while the IOThread object still
692 // exists. However, the message might not be processed on the UI
693 // thread until after IOThread is gone, so use a weak pointer.
tzik3f7781d2017-04-20 17:09:33694 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
695 base::BindOnce(&IOThread::InitSystemRequestContext,
696 weak_factory_.GetWeakPtr()));
davidben45eb19952016-05-05 16:30:44697
698#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
699 // Record how common CPUs with broken NEON units are. See
700 // https://crbug.com/341598.
701 crypto::EnsureOpenSSLInit();
702 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON());
703#endif
[email protected]0ac83682010-01-22 17:46:27704}
705
[email protected]2a92cd92010-04-27 00:01:41706void IOThread::CleanUp() {
[email protected]075c0322012-02-14 00:56:44707 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
708
jam1c5a91492016-02-24 20:47:53709#if defined(USE_NSS_CERTS)
[email protected]8c434cbc2012-03-14 14:25:09710 net::ShutdownNSSHttpIO();
[email protected]a592c0432012-12-01 18:10:29711#endif
[email protected]59a3b362010-10-21 21:52:41712
estark9a263782017-01-20 02:13:04713#if defined(OS_ANDROID)
714 net::CertVerifyProcAndroid::ShutdownCertNetFetcher();
715#endif
716
[email protected]db0e86dd2011-03-16 14:47:21717 system_url_request_context_getter_ = NULL;
718
eranm3c2d6432016-06-01 10:17:27719 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier
720 // and unregister it from new STH notifications so it will take no actions
721 // on anything observed during CleanUp process.
722 globals()->cert_transparency_verifier->SetObserver(nullptr);
723 UnregisterSTHObserver(ct_tree_tracker_.get());
724
725 ct_tree_tracker_.reset();
726
[email protected]af669932012-01-17 19:26:58727 // Release objects that the net::URLRequestContext could have been pointing
728 // to.
[email protected]0ee7a3b2010-11-09 06:13:40729
[email protected]7592b41f2014-04-01 01:44:43730 // Shutdown the HistogramWatcher on the IO thread.
731 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
732
[email protected]0ee7a3b2010-11-09 06:13:40733 // This must be reset before the ChromeNetLog is destroyed.
734 network_change_observer_.reset();
735
[email protected]db0e86dd2011-03-16 14:47:21736 system_proxy_config_service_.reset();
[email protected]d13c3272010-02-04 00:24:51737 delete globals_;
738 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27739
[email protected]db0e86dd2011-03-16 14:47:21740 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27741}
742
bnc18fb77f2016-04-04 20:54:04743// static
[email protected]b1de2c72013-02-06 02:45:47744void IOThread::RegisterPrefs(PrefRegistrySimple* registry) {
745 registry->RegisterStringPref(prefs::kAuthSchemes,
bengr70266e22015-06-12 19:38:17746 "basic,digest,ntlm,negotiate");
[email protected]68a9b0d82013-03-08 07:05:07747 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
[email protected]b1de2c72013-02-06 02:45:47748 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
[email protected]007b3f82013-04-09 08:46:45749 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
750 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
751 std::string());
752 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
aberentec894a52015-07-09 14:45:53753 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType,
754 std::string());
[email protected]b1de2c72013-02-06 02:45:47755 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
[email protected]1575e3d2014-05-03 22:21:44756 data_reduction_proxy::RegisterPrefs(registry);
[email protected]68a9b0d82013-03-08 07:05:07757 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
[email protected]67378142013-12-17 21:57:17758 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
eroman9f7ea642016-06-03 21:28:29759 registry->RegisterBooleanPref(prefs::kPacHttpsUrlStrippingEnabled, true);
[email protected]bcefe0f2010-11-10 16:19:10760}
761
aberentbba302d2015-12-03 10:20:19762void IOThread::UpdateServerWhitelist() {
763 globals_->http_auth_preferences->set_server_whitelist(
764 auth_server_whitelist_.GetValue());
765}
[email protected]b7304162010-08-23 17:42:29766
aberentbba302d2015-12-03 10:20:19767void IOThread::UpdateDelegateWhitelist() {
768 globals_->http_auth_preferences->set_delegate_whitelist(
769 auth_delegate_whitelist_.GetValue());
770}
771
772#if defined(OS_ANDROID)
773void IOThread::UpdateAndroidAuthNegotiateAccountType() {
774 globals_->http_auth_preferences->set_auth_android_negotiate_account_type(
775 auth_android_negotiate_account_type_.GetValue());
776}
777#endif
778
779void IOThread::UpdateNegotiateDisableCnameLookup() {
780 globals_->http_auth_preferences->set_negotiate_disable_cname_lookup(
781 negotiate_disable_cname_lookup_.GetValue());
782}
783
784void IOThread::UpdateNegotiateEnablePort() {
785 globals_->http_auth_preferences->set_negotiate_enable_port(
786 negotiate_enable_port_.GetValue());
787}
788
789void IOThread::CreateDefaultAuthHandlerFactory() {
790 std::vector<std::string> supported_schemes = base::SplitString(
791 auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
792 globals_->http_auth_preferences.reset(new net::HttpAuthPreferences(
793 supported_schemes
794#if defined(OS_POSIX) && !defined(OS_ANDROID)
795 ,
796 gssapi_library_name_
797#endif
zentaroe0326352017-05-09 13:11:51798#if defined(OS_CHROMEOS)
799 ,
800 allow_gssapi_library_load_
801#endif
aberentbba302d2015-12-03 10:20:19802 ));
803 UpdateServerWhitelist();
804 UpdateDelegateWhitelist();
805 UpdateNegotiateDisableCnameLookup();
806 UpdateNegotiateEnablePort();
807#if defined(OS_ANDROID)
808 UpdateAndroidAuthNegotiateAccountType();
809#endif
810 globals_->http_auth_handler_factory =
[email protected]ec44ee02012-09-28 21:31:51811 net::HttpAuthHandlerRegistryFactory::Create(
dchenge73d8520c2015-12-27 01:19:09812 globals_->http_auth_preferences.get(), globals_->host_resolver.get());
[email protected]eb3cac72010-02-26 21:07:45813}
814
msramek94f5656c2016-08-31 17:08:29815void IOThread::ClearHostCache(
816 const base::Callback<bool(const std::string&)>& host_filter) {
thestig00844cea2015-09-08 21:44:52817 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d6f37fc2011-02-13 23:58:41818
[email protected]489d1a82011-10-12 03:09:11819 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
820 if (host_cache)
msramek94f5656c2016-08-31 17:08:29821 host_cache->ClearForHosts(host_filter);
[email protected]0ac83682010-01-22 17:46:27822}
[email protected]db0e86dd2011-03-16 14:47:21823
bnc18fb77f2016-04-04 20:54:04824const net::HttpNetworkSession::Params& IOThread::NetworkSessionParams() const {
825 return params_;
[email protected]f9cf5572012-12-04 15:52:09826}
827
pmarko6ab8be242017-01-11 11:02:55828void IOThread::DisableQuic() {
829 params_.enable_quic = false;
830
831 if (globals_->system_http_network_session)
832 globals_->system_http_network_session->DisableQuic();
833
834 if (globals_->proxy_script_fetcher_http_network_session)
835 globals_->proxy_script_fetcher_http_network_session->DisableQuic();
836}
837
[email protected]d827e112014-03-31 17:45:05838base::TimeTicks IOThread::creation_time() const {
839 return creation_time_;
840}
841
[email protected]4d45a6de2011-05-13 05:20:18842net::SSLConfigService* IOThread::GetSSLConfigService() {
843 return ssl_config_service_manager_->Get();
844}
845
[email protected]b09f76d62011-12-07 01:51:06846void IOThread::ChangedToOnTheRecordOnIOThread() {
thestig00844cea2015-09-08 21:44:52847 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]b09f76d62011-12-07 01:51:06848
849 // Clear the host cache to avoid showing entries from the OTR session
850 // in about:net-internals.
msramek94f5656c2016-08-31 17:08:29851 ClearHostCache(base::Callback<bool(const std::string&)>());
[email protected]b09f76d62011-12-07 01:51:06852}
853
[email protected]db0e86dd2011-03-16 14:47:21854void IOThread::InitSystemRequestContext() {
[email protected]5173de8b2013-06-02 21:16:02855 if (system_url_request_context_getter_.get())
[email protected]addb3242011-06-13 21:39:16856 return;
[email protected]63e26822011-07-16 19:07:35857 // If we're in unit_tests, IOThread may not be run.
[email protected]dd483702011-12-02 14:47:42858 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO))
[email protected]63e26822011-07-16 19:07:35859 return;
csharrisonb7e3a082015-09-22 19:13:04860 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
861 pref_proxy_config_tracker_.get());
[email protected]addb3242011-06-13 21:39:16862 system_url_request_context_getter_ =
863 new SystemURLRequestContextGetter(this);
[email protected]2e5b60a22011-11-28 15:56:41864 // Safe to post an unretained this pointer, since IOThread is
865 // guaranteed to outlive the IO BrowserThread.
[email protected]dd483702011-12-02 14:47:42866 BrowserThread::PostTask(
tzik3f7781d2017-04-20 17:09:33867 BrowserThread::IO, FROM_HERE,
868 base::BindOnce(&IOThread::InitSystemRequestContextOnIOThread,
869 base::Unretained(this)));
[email protected]addb3242011-06-13 21:39:16870}
871
872void IOThread::InitSystemRequestContextOnIOThread() {
thestig00844cea2015-09-08 21:44:52873 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]6104ea5d2011-04-27 21:37:12874 DCHECK(!globals_->system_proxy_service.get());
[email protected]db0e86dd2011-03-16 14:47:21875 DCHECK(system_proxy_config_service_.get());
876
avi556c05022014-12-22 23:31:43877 const base::CommandLine& command_line =
878 *base::CommandLine::ForCurrentProcess();
rdsmith82957ad2015-09-16 19:42:03879 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
880 net_log_, globals_->proxy_script_fetcher_context.get(),
881 globals_->system_network_delegate.get(),
dchenge73d8520c2015-12-27 01:19:09882 std::move(system_proxy_config_service_), command_line,
eroman9f7ea642016-06-03 21:28:29883 WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled());
[email protected]c2dad292012-09-07 21:27:35884
[email protected]ef2bf422012-05-11 03:27:09885 globals_->system_request_context.reset(
bnc18fb77f2016-04-04 20:54:04886 ConstructSystemRequestContext(globals_, params_, net_log_));
[email protected]db0e86dd2011-03-16 14:47:21887}
[email protected]fa4b6c32012-11-26 23:02:39888
889void IOThread::UpdateDnsClientEnabled() {
890 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
891}
[email protected]903e63382013-06-01 00:40:58892
eranm3c2d6432016-06-01 10:17:27893void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) {
894 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer);
895}
896
897void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) {
898 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer);
899}
900
eroman9f7ea642016-06-03 21:28:29901bool IOThread::WpadQuickCheckEnabled() const {
902 return quick_check_enabled_.GetValue();
903}
904
905bool IOThread::PacHttpsUrlStrippingEnabled() const {
906 return pac_https_url_stripping_enabled_.GetValue();
907}
908
bnc18fb77f2016-04-04 20:54:04909// static
wjmacleanea309f72015-08-25 20:56:59910net::URLRequestContext* IOThread::ConstructSystemRequestContext(
911 IOThread::Globals* globals,
bnc18fb77f2016-04-04 20:54:04912 const net::HttpNetworkSession::Params& params,
wjmacleanea309f72015-08-25 20:56:59913 net::NetLog* net_log) {
914 net::URLRequestContext* context = new SystemURLRequestContext;
mmenke518c27b2017-05-04 23:15:21915
916 context->set_network_quality_estimator(
917 globals->network_quality_estimator.get());
918 context->set_enable_brotli(globals->enable_brotli);
919 context->set_name("system");
920
921 context->set_http_user_agent_settings(
922 globals->http_user_agent_settings.get());
923 context->set_network_delegate(globals->system_network_delegate.get());
wjmacleanea309f72015-08-25 20:56:59924 context->set_net_log(net_log);
925 context->set_host_resolver(globals->host_resolver.get());
mmenke518c27b2017-05-04 23:15:21926 context->set_proxy_service(globals->system_proxy_service.get());
wjmacleanea309f72015-08-25 20:56:59927 context->set_ssl_config_service(globals->ssl_config_service.get());
928 context->set_http_auth_handler_factory(
929 globals->http_auth_handler_factory.get());
wjmacleanea309f72015-08-25 20:56:59930
931 context->set_cookie_store(globals->system_cookie_store.get());
932 context->set_channel_id_service(
933 globals->system_channel_id_service.get());
mmenke518c27b2017-05-04 23:15:21934 context->set_transport_security_state(
935 globals->transport_security_state.get());
wjmacleanea309f72015-08-25 20:56:59936
bnc525e175a2016-06-20 12:36:40937 context->set_http_server_properties(globals->http_server_properties.get());
wjmacleanea309f72015-08-25 20:56:59938
mmenke518c27b2017-05-04 23:15:21939 context->set_cert_verifier(globals->cert_verifier.get());
940 context->set_cert_transparency_verifier(
941 globals->cert_transparency_verifier.get());
942 context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get());
maksim.sisov3d40c812016-05-02 13:27:16943
bnc18fb77f2016-04-04 20:54:04944 net::HttpNetworkSession::Params system_params(params);
wjmacleanea309f72015-08-25 20:56:59945 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
946 context, &system_params);
947
mmenkee65e7af2015-10-13 17:16:42948 globals->system_http_network_session.reset(
949 new net::HttpNetworkSession(system_params));
wjmacleanea309f72015-08-25 20:56:59950 globals->system_http_transaction_factory.reset(
mmenkee65e7af2015-10-13 17:16:42951 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
mmenke518c27b2017-05-04 23:15:21952
wjmacleanea309f72015-08-25 20:56:59953 context->set_http_transaction_factory(
954 globals->system_http_transaction_factory.get());
955
mmenke518c27b2017-05-04 23:15:21956 globals->system_url_request_job_factory.reset(
957 new net::URLRequestJobFactoryImpl());
958 context->set_job_factory(globals->system_url_request_job_factory.get());
959
wjmacleanea309f72015-08-25 20:56:59960 return context;
961}
962
bnc0f6bff62016-04-05 16:51:09963// static
bnce87c7c712016-08-01 23:59:48964void IOThread::ConfigureParamsFromFieldTrialsAndCommandLine(
965 const base::CommandLine& command_line,
966 bool is_quic_allowed_by_policy,
mmenkea7da6da2016-09-01 21:56:52967 bool http_09_on_non_default_ports_enabled,
bnce87c7c712016-08-01 23:59:48968 net::HttpNetworkSession::Params* params) {
969 std::string quic_user_agent_id = chrome::GetChannelString();
970 if (!quic_user_agent_id.empty())
971 quic_user_agent_id.push_back(' ');
972 quic_user_agent_id.append(
973 version_info::GetProductNameAndVersionForUserAgent());
974 quic_user_agent_id.push_back(' ');
975 quic_user_agent_id.append(content::BuildOSCpuInfo());
976
977 bool is_quic_force_disabled = !is_quic_allowed_by_policy ||
978 command_line.HasSwitch(switches::kDisableQuic);
979 bool is_quic_force_enabled = command_line.HasSwitch(switches::kEnableQuic);
980
981 network_session_configurator::ParseFieldTrials(is_quic_force_disabled,
982 is_quic_force_enabled,
983 quic_user_agent_id, params);
984
985 // Command line flags override field trials.
986 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
987 net::URLFetcher::SetIgnoreCertificateRequests(true);
988
989 if (command_line.HasSwitch(switches::kDisableHttp2))
990 params->enable_http2 = false;
991
bnce87c7c712016-08-01 23:59:48992 if (params->enable_quic) {
993 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) {
994 params->quic_connection_options =
rch4c967ea2016-12-22 01:41:07995 net::ParseQuicConnectionOptions(
bnce87c7c712016-08-01 23:59:48996 command_line.GetSwitchValueASCII(
997 switches::kQuicConnectionOptions));
998 }
999
bnce87c7c712016-08-01 23:59:481000 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
1001 unsigned value;
1002 if (base::StringToUint(
1003 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
1004 &value)) {
1005 params->quic_max_packet_length = value;
1006 }
1007 }
1008
1009 if (command_line.HasSwitch(switches::kQuicVersion)) {
1010 net::QuicVersion version = network_session_configurator::ParseQuicVersion(
1011 command_line.GetSwitchValueASCII(switches::kQuicVersion));
1012 if (version != net::QUIC_VERSION_UNSUPPORTED) {
1013 net::QuicVersionVector supported_versions;
1014 supported_versions.push_back(version);
1015 params->quic_supported_versions = supported_versions;
1016 }
1017 }
1018
1019 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
1020 std::string origins =
1021 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn);
1022 for (const std::string& host_port : base::SplitString(
1023 origins, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
1024 if (host_port == "*")
1025 params->origins_to_force_quic_on.insert(net::HostPortPair());
1026 net::HostPortPair quic_origin =
1027 net::HostPortPair::FromString(host_port);
1028 if (!quic_origin.IsEmpty())
1029 params->origins_to_force_quic_on.insert(quic_origin);
1030 }
1031 }
1032 }
1033
1034 // Parameters only controlled by command line.
1035 if (command_line.HasSwitch(switches::kEnableUserAlternateProtocolPorts)) {
1036 params->enable_user_alternate_protocol_ports = true;
1037 }
martinkrfc8514d2017-01-20 01:37:111038 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) {
bnce87c7c712016-08-01 23:59:481039 params->ignore_certificate_errors = true;
martinkrfc8514d2017-01-20 01:37:111040 }
1041 UMA_HISTOGRAM_BOOLEAN(
1042 "Net.Certificate.IgnoreErrors",
1043 command_line.HasSwitch(switches::kIgnoreCertificateErrors));
bnce87c7c712016-08-01 23:59:481044 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
1045 params->testing_fixed_http_port =
1046 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
1047 }
1048 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
1049 params->testing_fixed_https_port =
1050 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
1051 }
mmenkea7da6da2016-09-01 21:56:521052
1053 params->http_09_on_non_default_ports_enabled =
1054 http_09_on_non_default_ports_enabled;
bnce87c7c712016-08-01 23:59:481055}
1056
1057// static
wjmacleanea309f72015-08-25 20:56:591058net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext(
1059 IOThread::Globals* globals,
bnc18fb77f2016-04-04 20:54:041060 const net::HttpNetworkSession::Params& params,
wjmacleanea309f72015-08-25 20:56:591061 net::NetLog* net_log) {
wjmacleanea309f72015-08-25 20:56:591062 net::URLRequestContext* context = new net::URLRequestContext;
1063 context->set_net_log(net_log);
1064 context->set_host_resolver(globals->host_resolver.get());
1065 context->set_cert_verifier(globals->cert_verifier.get());
1066 context->set_transport_security_state(
1067 globals->transport_security_state.get());
1068 context->set_cert_transparency_verifier(
1069 globals->cert_transparency_verifier.get());
rsleevid6de8302016-06-21 01:33:201070 context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get());
wjmacleanea309f72015-08-25 20:56:591071 context->set_ssl_config_service(globals->ssl_config_service.get());
1072 context->set_http_auth_handler_factory(
1073 globals->http_auth_handler_factory.get());
1074 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
1075
1076 context->set_job_factory(
1077 globals->proxy_script_fetcher_url_request_job_factory.get());
1078
1079 context->set_cookie_store(globals->system_cookie_store.get());
1080 context->set_channel_id_service(
1081 globals->system_channel_id_service.get());
1082 context->set_network_delegate(globals->system_network_delegate.get());
1083 context->set_http_user_agent_settings(
1084 globals->http_user_agent_settings.get());
bnc525e175a2016-06-20 12:36:401085 context->set_http_server_properties(globals->http_server_properties.get());
wjmacleanea309f72015-08-25 20:56:591086
maksim.sisov3d40c812016-05-02 13:27:161087 context->set_enable_brotli(globals->enable_brotli);
1088
bnc18fb77f2016-04-04 20:54:041089 net::HttpNetworkSession::Params session_params(params);
wjmacleanea309f72015-08-25 20:56:591090 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1091 context, &session_params);
1092
mmenkee65e7af2015-10-13 17:16:421093 globals->proxy_script_fetcher_http_network_session.reset(
wjmacleanea309f72015-08-25 20:56:591094 new net::HttpNetworkSession(session_params));
mmenkee65e7af2015-10-13 17:16:421095 globals->proxy_script_fetcher_http_transaction_factory.reset(
1096 new net::HttpNetworkLayer(
1097 globals->proxy_script_fetcher_http_network_session.get()));
xunjieli96ab36a72016-12-05 21:36:051098 context->set_name("proxy");
wjmacleanea309f72015-08-25 20:56:591099 context->set_http_transaction_factory(
1100 globals->proxy_script_fetcher_http_transaction_factory.get());
1101
dcheng4af48582016-04-19 00:29:351102 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(
wjmacleanea309f72015-08-25 20:56:591103 new net::URLRequestJobFactoryImpl());
1104
ricea86fa1dd2016-09-13 05:59:451105 job_factory->SetProtocolHandler(url::kDataScheme,
1106 base::MakeUnique<net::DataProtocolHandler>());
wjmacleanea309f72015-08-25 20:56:591107 job_factory->SetProtocolHandler(
1108 url::kFileScheme,
ricea86fa1dd2016-09-13 05:59:451109 base::MakeUnique<net::FileProtocolHandler>(
fdoraydd7eb402017-04-26 21:44:251110 base::CreateTaskRunnerWithTraits(
fdoray4ad14932017-05-03 21:21:111111 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
1112 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})));
brettwa1228ebb2016-10-28 03:51:341113#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
wjmacleanea309f72015-08-25 20:56:591114 job_factory->SetProtocolHandler(
1115 url::kFtpScheme,
mmenkecd4c7532016-10-19 18:36:051116 net::FtpProtocolHandler::Create(globals->host_resolver.get()));
wjmacleanea309f72015-08-25 20:56:591117#endif
dchenge73d8520c2015-12-27 01:19:091118 globals->proxy_script_fetcher_url_request_job_factory =
1119 std::move(job_factory);
wjmacleanea309f72015-08-25 20:56:591120
1121 context->set_job_factory(
1122 globals->proxy_script_fetcher_url_request_job_factory.get());
1123
1124 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1125 // system URLRequestContext too. There's no reason this should be tied to a
1126 // profile.
1127 return context;
1128}
gayane0b46091c2016-04-07 21:01:051129
robliao7253fd22016-12-01 18:41:381130metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() {
1131 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread);
gayane0b46091c2016-04-07 21:01:051132}