blob: b4c7a4997a09ba4d85f7d5122c60258d4b7ed0fd [file] [log] [blame]
[email protected]4617d2da2012-01-13 20:46:491// 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#ifndef CHROME_BROWSER_IO_THREAD_H_
6#define CHROME_BROWSER_IO_THREAD_H_
7
avi6846aef2015-12-26 01:09:388#include <stddef.h>
9#include <stdint.h>
10
tbansalb177b5392015-06-25 11:13:0211#include <map>
dcheng4af48582016-04-19 00:29:3512#include <memory>
bnca580cbcf42015-08-17 17:21:1913#include <set>
[email protected]bcefe0f2010-11-10 16:19:1014#include <string>
rch74da0e1a2016-01-14 02:49:3215#include <unordered_set>
[email protected]d0389f62013-11-08 06:06:1316#include <vector>
[email protected]c38831a12011-10-28 12:44:4917
[email protected]2e5b60a22011-11-28 15:56:4118#include "base/compiler_specific.h"
avi6846aef2015-12-26 01:09:3819#include "base/macros.h"
[email protected]2e5b60a22011-11-28 15:56:4120#include "base/memory/ref_counted.h"
[email protected]21ee224e2011-11-21 02:17:5321#include "base/memory/weak_ptr.h"
bnce3553d92014-10-30 22:29:4522#include "base/strings/string_piece.h"
avi6846aef2015-12-26 01:09:3823#include "build/build_config.h"
[email protected]a702da72014-07-09 05:23:5424#include "chrome/browser/net/chrome_network_delegate.h"
mmenkef73a5122017-07-13 23:27:3925#include "chrome/browser/net/system_network_context_manager.h"
Ryan Sleevi4689ad32018-04-16 19:09:0526#include "chrome/browser/ssl/ssl_config_service_manager.h"
Scott Violet6200d332018-02-23 21:29:2327#include "chrome/common/buildflags.h"
rajendrant14a5a852016-11-17 17:58:4828#include "components/metrics/data_use_tracker.h"
brettwb1fc1b82016-02-02 00:19:0829#include "components/prefs/pref_member.h"
[email protected]2e5b60a22011-11-28 15:56:4130#include "content/public/browser/browser_thread.h"
31#include "content/public/browser/browser_thread_delegate.h"
Scott Violetc8240b02018-03-08 22:03:5932#include "extensions/buildflags/buildflags.h"
[email protected]58bc7042010-07-07 18:04:1433#include "net/base/network_change_notifier.h"
Ken Rockot54311e62018-02-10 19:01:5234#include "services/network/public/mojom/network_service.mojom.h"
John Abd-El-Malek4556c6b02018-02-01 22:11:2335#include "services/network/url_request_context_owner.h"
[email protected]0ac83682010-01-22 17:46:2736
[email protected]b1de2c72013-02-06 02:45:4737class PrefRegistrySimple;
Matt Menked2a43b32017-12-04 23:30:1638class PrefService;
Matt Menke21b9cc62017-08-23 15:45:4539class SystemNetworkContextManager;
[email protected]0ac83682010-01-22 17:46:2740
zpengdb4a58e2017-01-10 17:40:3241#if defined(OS_ANDROID)
tbansal41fc4b72015-11-09 22:19:2842namespace android {
43class ExternalDataUseObserver;
44}
zpengdb4a58e2017-01-10 17:40:3245#endif // defined(OS_ANDROID)
tbansal41fc4b72015-11-09 22:19:2846
eranm3c2d6432016-06-01 10:17:2747namespace certificate_transparency {
48class TreeStateTracker;
Ryan Sleevi6d00e4f32018-04-06 23:45:5149class STHObserver;
eranm3c2d6432016-06-01 10:17:2750}
51
[email protected]7613faae2012-04-18 01:01:1952namespace chrome_browser_net {
[email protected]4588b3d2012-11-14 00:37:3853class DnsProbeService;
[email protected]7613faae2012-04-18 01:01:1954}
55
sclittle3f98c6c2015-11-19 22:59:2956namespace data_usage {
57class DataUseAggregator;
58}
59
kundajif617523b2016-09-09 22:41:2460namespace data_use_measurement {
61class ChromeDataUseAscriber;
62}
63
[email protected]5a38dfd2012-07-23 23:22:1064namespace extensions {
65class EventRouterForwarder;
66}
67
[email protected]d13c3272010-02-04 00:24:5168namespace net {
Rob Percival5c442f82018-03-28 22:10:5769class CertVerifier;
eranm1a79db22015-11-24 10:56:4970class CTLogVerifier;
[email protected]1889dc1b2010-10-14 22:03:1371class HostResolver;
mmenkec2af5952017-06-07 23:26:4772class HttpAuthHandlerFactory;
aberentbba302d2015-12-03 10:20:1973class HttpAuthPreferences;
tbansalea2fb8c2015-05-22 22:23:0074class NetworkQualityEstimator;
tbansal1bd4a952017-06-06 23:01:4675class RTTAndThroughputEstimatesObserver;
[email protected]2fb629202010-12-23 23:52:5776class SSLConfigService;
[email protected]27a112c2011-01-06 04:19:3077class URLRequestContext;
[email protected]abe2c032011-03-31 18:49:3478class URLRequestContextGetter;
[email protected]d13c3272010-02-04 00:24:5179} // namespace net
80
drogerc690e8802015-09-21 14:29:1681namespace net_log {
82class ChromeNetLog;
83}
84
John Abd-El-Malek3bbbdf92018-01-30 03:27:3585namespace network {
86class URLRequestContextBuilderMojo;
87}
88
[email protected]77305422012-11-29 16:51:3989namespace policy {
90class PolicyService;
91} // namespace policy
92
[email protected]2e5b60a22011-11-28 15:56:4193// Contains state associated with, initialized and cleaned up on, and
[email protected]dd483702011-12-02 14:47:4294// primarily used on, the IO thread.
[email protected]c92b8612011-12-13 22:18:5995//
96// If you are looking to interact with the IO thread (e.g. post tasks
97// to it or check if it is the current thread), see
98// content::BrowserThread.
[email protected]2e5b60a22011-11-28 15:56:4199class IOThread : public content::BrowserThreadDelegate {
[email protected]0ac83682010-01-22 17:46:27100 public:
[email protected]d13c3272010-02-04 00:24:51101 struct Globals {
[email protected]c93123fa2012-04-19 02:49:48102 class SystemRequestContextLeakChecker {
103 public:
104 explicit SystemRequestContextLeakChecker(Globals* globals);
105 ~SystemRequestContextLeakChecker();
106
107 private:
108 Globals* const globals_;
109 };
110
[email protected]1889dc1b2010-10-14 22:03:13111 Globals();
112 ~Globals();
113
John Abd-El-Malekdeec0082017-12-20 20:47:47114 bool quic_disabled = false;
mmenkef73a5122017-07-13 23:27:39115
kundajif617523b2016-09-09 22:41:24116 // Ascribes all data use in Chrome to a source, such as page loads.
117 std::unique_ptr<data_use_measurement::ChromeDataUseAscriber>
118 data_use_ascriber;
sclittle3f98c6c2015-11-19 22:59:29119 // Global aggregator of data use. It must outlive the
120 // |system_network_delegate|.
dcheng4af48582016-04-19 00:29:35121 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator;
zpengdb4a58e2017-01-10 17:40:32122#if defined(OS_ANDROID)
sclittle3f98c6c2015-11-19 22:59:29123 // An external observer of data use.
cm.sanchic0fc6342017-11-28 03:59:29124 std::unique_ptr<android::ExternalDataUseObserver>
sclittle3f98c6c2015-11-19 22:59:29125 external_data_use_observer;
zpengdb4a58e2017-01-10 17:40:32126#endif // defined(OS_ANDROID)
eranm1a79db22015-11-24 10:56:49127 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs;
dcheng4af48582016-04-19 00:29:35128 std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences;
Matt Menked9ec7077b2018-02-28 01:13:36129
Matt Menkeabb7a382018-03-23 18:25:23130 // NetworkQualityEstimator only for use in dummy in-process
131 // URLRequestContext when network service is enabled.
132 // TODO(mmenke): Remove this, once all consumers only access the
133 // NetworkQualityEstimator through network service APIs. Then will no longer
134 // need to create an in-process one.
135 std::unique_ptr<net::NetworkQualityEstimator>
136 deprecated_network_quality_estimator;
137
Matt Menked9ec7077b2018-02-28 01:13:36138 std::unique_ptr<net::RTTAndThroughputEstimatesObserver>
139 network_quality_observer;
140
John Abd-El-Malekdeec0082017-12-20 20:47:47141 // When the network service is enabled, this holds on to a
142 // content::NetworkContext class that owns |system_request_context|.
John Abd-El-Malek53670dd2018-01-18 22:07:21143 std::unique_ptr<network::mojom::NetworkContext> system_network_context;
John Abd-El-Malekdeec0082017-12-20 20:47:47144 // When the network service is disabled, this owns |system_request_context|.
John Abd-El-Malek3bbbdf92018-01-30 03:27:35145 network::URLRequestContextOwner system_request_context_owner;
mmenkef73a5122017-07-13 23:27:39146 net::URLRequestContext* system_request_context;
brettw00899e62016-11-12 02:10:17147#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]5a38dfd2012-07-23 23:22:10148 scoped_refptr<extensions::EventRouterForwarder>
[email protected]3ce02412011-03-01 12:01:15149 extension_event_router_forwarder;
[email protected]84b7a552014-07-19 04:52:06150#endif
[email protected]4588b3d2012-11-14 00:37:38151 // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a
152 // main frame load fails with a DNS error in order to provide more useful
153 // information to the renderer so it can show a more specific error page.
dcheng4af48582016-04-19 00:29:35154 std::unique_ptr<chrome_browser_net::DnsProbeService> dns_probe_service;
bnc18fb77f2016-04-04 20:54:04155 };
156
[email protected]b2fcd0e2010-12-01 15:19:40157 // |net_log| must either outlive the IOThread or be NULL.
[email protected]b1de2c72013-02-06 02:45:47158 IOThread(PrefService* local_state,
[email protected]77305422012-11-29 16:51:39159 policy::PolicyService* policy_service,
drogerc690e8802015-09-21 14:29:16160 net_log::ChromeNetLog* net_log,
Matt Menke21b9cc62017-08-23 15:45:45161 extensions::EventRouterForwarder* extension_event_router_forwarder,
162 SystemNetworkContextManager* system_network_context_manager);
[email protected]0ac83682010-01-22 17:46:27163
Daniel Chenga542fca2014-10-21 09:51:29164 ~IOThread() override;
[email protected]0ac83682010-01-22 17:46:27165
[email protected]3c319eb2013-02-21 14:44:45166 static void RegisterPrefs(PrefRegistrySimple* registry);
Rob Percival5c442f82018-03-28 22:10:57167 static void SetCertVerifierForTesting(net::CertVerifier* cert_verifier);
[email protected]3c319eb2013-02-21 14:44:45168
[email protected]d13c3272010-02-04 00:24:51169 // Can only be called on the IO thread.
170 Globals* globals();
[email protected]0ac83682010-01-22 17:46:27171
drogerc690e8802015-09-21 14:29:16172 net_log::ChromeNetLog* net_log();
[email protected]b2fcd0e2010-12-01 15:19:40173
[email protected]b09f76d62011-12-07 01:51:06174 // Handles changing to On The Record mode, discarding confidential data.
175 void ChangedToOnTheRecord();
176
[email protected]db0e86dd2011-03-16 14:47:21177 // Returns a getter for the URLRequestContext. Only called on the UI thread.
[email protected]abe2c032011-03-31 18:49:34178 net::URLRequestContextGetter* system_url_request_context_getter();
[email protected]db0e86dd2011-03-16 14:47:21179
msramek94f5656c2016-08-31 17:08:29180 // Clears the host cache. Intended to be used to prevent exposing recently
[email protected]67372ecf2011-09-10 01:30:46181 // visited sites on about:net-internals/#dns and about:dns pages. Must be
msramek94f5656c2016-08-31 17:08:29182 // called on the IO thread. If |host_filter| is not null, only hosts matched
183 // by it are deleted from the cache.
184 void ClearHostCache(
185 const base::Callback<bool(const std::string&)>& host_filter);
[email protected]d6f37fc2011-02-13 23:58:41186
Matt Menkecfef87d2017-08-03 13:03:06187 // Dynamically disables QUIC for all NetworkContexts using the IOThread's
188 // NetworkService. Re-enabling Quic dynamically is not supported for
189 // simplicity and requires a browser restart. May only be called on the IO
190 // thread.
pmarko6ab8be242017-01-11 11:02:55191 void DisableQuic();
192
gayane0b46091c2016-04-07 21:01:05193 // Returns the callback for updating data use prefs.
robliao7253fd22016-12-01 18:41:38194 metrics::UpdateUsagePrefCallbackType GetMetricsDataUseForwarder();
gayane0b46091c2016-04-07 21:01:05195
eranm3c2d6432016-06-01 10:17:27196 // Registers the |observer| for new STH notifications.
Ryan Sleevi6d00e4f32018-04-06 23:45:51197 void RegisterSTHObserver(certificate_transparency::STHObserver* observer);
eranm3c2d6432016-06-01 10:17:27198
199 // Un-registers the |observer|.
Ryan Sleevi6d00e4f32018-04-06 23:45:51200 void UnregisterSTHObserver(certificate_transparency::STHObserver* observer);
eranm3c2d6432016-06-01 10:17:27201
Lily Houghton8c2f97d2018-01-22 05:06:59202 // Configures |builder|'s ProxyResolutionService based on prefs and policies.
John Abd-El-Malek3bbbdf92018-01-30 03:27:35203 void SetUpProxyService(network::URLRequestContextBuilderMojo* builder) const;
mmenke1c261ff2017-07-23 17:06:35204
Rob Percivalbc658a22017-12-13 08:24:42205 certificate_transparency::TreeStateTracker* ct_tree_tracker() const;
206
[email protected]2e5b60a22011-11-28 15:56:41207 private:
208 // BrowserThreadDelegate implementation, runs on the IO thread.
209 // This handles initialization and destruction of state that must
210 // live on the IO thread.
Daniel Chenga542fca2014-10-21 09:51:29211 void Init() override;
Daniel Chenga542fca2014-10-21 09:51:29212 void CleanUp() override;
[email protected]0ac83682010-01-22 17:46:27213
mmenkec2af5952017-06-07 23:26:47214 std::unique_ptr<net::HttpAuthHandlerFactory> CreateDefaultAuthHandlerFactory(
215 net::HostResolver* host_resolver);
[email protected]eb3cac72010-02-26 21:07:45216
[email protected]4d45a6de2011-05-13 05:20:18217 // Returns an SSLConfigService instance.
218 net::SSLConfigService* GetSSLConfigService();
219
[email protected]b09f76d62011-12-07 01:51:06220 void ChangedToOnTheRecordOnIOThread();
221
[email protected]fa4b6c32012-11-26 23:02:39222 void UpdateDnsClientEnabled();
aberentbba302d2015-12-03 10:20:19223 void UpdateServerWhitelist();
224 void UpdateDelegateWhitelist();
225 void UpdateAndroidAuthNegotiateAccountType();
226 void UpdateNegotiateDisableCnameLookup();
227 void UpdateNegotiateEnablePort();
Zentaro Kavanaghbad511c2017-10-18 22:29:00228#if defined(OS_POSIX)
229 void UpdateNtlmV2Enabled();
230#endif
[email protected]fa4b6c32012-11-26 23:02:39231
[email protected]84b7a552014-07-19 04:52:06232 extensions::EventRouterForwarder* extension_event_router_forwarder() {
brettw00899e62016-11-12 02:10:17233#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]84b7a552014-07-19 04:52:06234 return extension_event_router_forwarder_;
235#else
236 return NULL;
237#endif
238 }
mmenkef2e53b22017-05-15 18:40:18239 void ConstructSystemRequestContext();
wjmacleanea309f72015-08-25 20:56:59240
[email protected]b2fcd0e2010-12-01 15:19:40241 // The NetLog is owned by the browser process, to allow logging from other
242 // threads during shutdown, but is used most frequently on the IOThread.
drogerc690e8802015-09-21 14:29:16243 net_log::ChromeNetLog* net_log_;
[email protected]b2fcd0e2010-12-01 15:19:40244
brettw00899e62016-11-12 02:10:17245#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]5a38dfd2012-07-23 23:22:10246 // The extensions::EventRouterForwarder allows for sending events to
247 // extensions from the IOThread.
248 extensions::EventRouterForwarder* extension_event_router_forwarder_;
[email protected]84b7a552014-07-19 04:52:06249#endif
[email protected]3ce02412011-03-01 12:01:15250
[email protected]0ac83682010-01-22 17:46:27251 // These member variables are basically global, but their lifetimes are tied
252 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
253 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]b2fcd0e2010-12-01 15:19:40254 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27255
[email protected]d13c3272010-02-04 00:24:51256 // These member variables are initialized in Init() and do not change for the
257 // lifetime of the IO thread.
258
259 Globals* globals_;
260
eranm3c2d6432016-06-01 10:17:27261 std::unique_ptr<certificate_transparency::TreeStateTracker> ct_tree_tracker_;
262
[email protected]0a8db0d2011-04-13 15:15:40263 BooleanPrefMember system_enable_referrers_;
264
[email protected]fa4b6c32012-11-26 23:02:39265 BooleanPrefMember dns_client_enabled_;
266
Brad Lassey786929ad2018-02-21 20:54:27267 StringListPrefMember dns_over_https_servers_;
268
269 StringListPrefMember dns_over_https_server_methods_;
270
[email protected]bcefe0f2010-11-10 16:19:10271 // Store HTTP Auth-related policies in this thread.
aberentbba302d2015-12-03 10:20:19272 // TODO(aberent) Make the list of auth schemes a PrefMember, so that the
273 // policy can change after startup (https://crbug/549273).
[email protected]bcefe0f2010-11-10 16:19:10274 std::string auth_schemes_;
aberentbba302d2015-12-03 10:20:19275 BooleanPrefMember negotiate_disable_cname_lookup_;
276 BooleanPrefMember negotiate_enable_port_;
Zentaro Kavanaghbad511c2017-10-18 22:29:00277#if defined(OS_POSIX)
278 BooleanPrefMember ntlm_v2_enabled_;
279#endif
aberentbba302d2015-12-03 10:20:19280 StringPrefMember auth_server_whitelist_;
281 StringPrefMember auth_delegate_whitelist_;
282
283#if defined(OS_ANDROID)
284 StringPrefMember auth_android_negotiate_account_type_;
285#endif
Lutz Justen9edd41e52017-09-29 04:53:08286#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
aberentbba302d2015-12-03 10:20:19287 // No PrefMember for the GSSAPI library name, since changing it after startup
288 // requires unloading the existing GSSAPI library, which could cause all sorts
289 // of problems for, for example, active Negotiate transactions.
[email protected]ac7f3fdb2010-11-12 12:47:05290 std::string gssapi_library_name_;
aberentbba302d2015-12-03 10:20:19291#endif
[email protected]bcefe0f2010-11-10 16:19:10292
zentaroe0326352017-05-09 13:11:51293#if defined(OS_CHROMEOS)
294 bool allow_gssapi_library_load_;
295#endif
296
mmenkef73a5122017-07-13 23:27:39297 // These are set on the UI thread, and then consumed during initialization on
298 // the IO thread.
John Abd-El-Malek53670dd2018-01-18 22:07:21299 network::mojom::NetworkContextRequest network_context_request_;
300 network::mojom::NetworkContextParamsPtr network_context_params_;
mmenkef73a5122017-07-13 23:27:39301
[email protected]4d45a6de2011-05-13 05:20:18302 // This is an instance of the default SSLConfigServiceManager for the current
303 // platform and it gets SSL preferences from local_state object.
Ryan Sleevi4689ad32018-04-16 19:09:05304 std::unique_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
[email protected]4d45a6de2011-05-13 05:20:18305
[email protected]abe2c032011-03-31 18:49:34306 scoped_refptr<net::URLRequestContextGetter>
307 system_url_request_context_getter_;
[email protected]db0e86dd2011-03-16 14:47:21308
Matt Menkecfef87d2017-08-03 13:03:06309 // True if QUIC is initially enabled.
310 bool is_quic_allowed_on_init_;
peletskyi5df83d42015-04-30 16:37:46311
mohan.reddy14cb4ad42014-09-17 18:15:14312 base::WeakPtrFactory<IOThread> weak_factory_;
313
[email protected]0ac83682010-01-22 17:46:27314 DISALLOW_COPY_AND_ASSIGN(IOThread);
315};
316
[email protected]fa55e192010-02-15 14:25:50317#endif // CHROME_BROWSER_IO_THREAD_H_