blob: a45c96a875ef017e4ef38a3f1a45263636408ece [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"
sievers2f1e8112015-12-04 18:43:5626#include "chrome/common/features.h"
rajendrant14a5a852016-11-17 17:58:4827#include "components/metrics/data_use_tracker.h"
brettwb1fc1b82016-02-02 00:19:0828#include "components/prefs/pref_member.h"
abhishek.a212849cee2015-10-20 11:27:2929#include "components/ssl_config/ssl_config_service_manager.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"
mmenkef73a5122017-07-13 23:27:3932#include "content/public/common/network_service.mojom.h"
33#include "content/public/network/network_service.h"
brettw00899e62016-11-12 02:10:1734#include "extensions/features/features.h"
[email protected]58bc7042010-07-07 18:04:1435#include "net/base/network_change_notifier.h"
tbansal15973c32017-05-10 18:40:4436#include "net/nqe/network_quality_estimator.h"
[email protected]0ac83682010-01-22 17:46:2737
[email protected]53c5b0f2013-07-22 10:54:1138class PrefProxyConfigTracker;
[email protected]bcefe0f2010-11-10 16:19:1039class PrefService;
[email protected]b1de2c72013-02-06 02:45:4740class PrefRegistrySimple;
Matt Menke21b9cc62017-08-23 15:45:4541class SystemNetworkContextManager;
[email protected]0ac83682010-01-22 17:46:2742
zpengdb4a58e2017-01-10 17:40:3243#if defined(OS_ANDROID)
tbansal41fc4b72015-11-09 22:19:2844namespace chrome {
45namespace android {
46class ExternalDataUseObserver;
47}
48}
zpengdb4a58e2017-01-10 17:40:3249#endif // defined(OS_ANDROID)
tbansal41fc4b72015-11-09 22:19:2850
eranm3c2d6432016-06-01 10:17:2751namespace certificate_transparency {
52class TreeStateTracker;
53}
54
[email protected]7613faae2012-04-18 01:01:1955namespace chrome_browser_net {
[email protected]4588b3d2012-11-14 00:37:3856class DnsProbeService;
[email protected]7613faae2012-04-18 01:01:1957}
58
sclittle3f98c6c2015-11-19 22:59:2959namespace data_usage {
60class DataUseAggregator;
61}
62
kundajif617523b2016-09-09 22:41:2463namespace data_use_measurement {
64class ChromeDataUseAscriber;
65}
66
[email protected]5a38dfd2012-07-23 23:22:1067namespace extensions {
68class EventRouterForwarder;
69}
70
[email protected]d13c3272010-02-04 00:24:5171namespace net {
eranm1a79db22015-11-24 10:56:4972class CTLogVerifier;
[email protected]1889dc1b2010-10-14 22:03:1373class HostResolver;
mmenkec2af5952017-06-07 23:26:4774class HttpAuthHandlerFactory;
aberentbba302d2015-12-03 10:20:1975class HttpAuthPreferences;
pauljensen7b34e522016-05-12 18:20:5976class LoggingNetworkChangeObserver;
tbansalea2fb8c2015-05-22 22:23:0077class NetworkQualityEstimator;
[email protected]db0e86dd2011-03-16 14:47:2178class ProxyConfigService;
tbansal1bd4a952017-06-06 23:01:4679class RTTAndThroughputEstimatesObserver;
[email protected]2fb629202010-12-23 23:52:5780class SSLConfigService;
[email protected]27a112c2011-01-06 04:19:3081class URLRequestContext;
mmenke1c261ff2017-07-23 17:06:3582class URLRequestContextBuilderMojo;
[email protected]abe2c032011-03-31 18:49:3483class URLRequestContextGetter;
eranm3c2d6432016-06-01 10:17:2784
85namespace ct {
86class STHObserver;
87}
88
[email protected]d13c3272010-02-04 00:24:5189} // namespace net
90
drogerc690e8802015-09-21 14:29:1691namespace net_log {
92class ChromeNetLog;
93}
94
[email protected]77305422012-11-29 16:51:3995namespace policy {
96class PolicyService;
97} // namespace policy
98
[email protected]488a0e252014-06-25 04:37:4499namespace test {
100class IOThreadPeer;
101} // namespace test
102
[email protected]2e5b60a22011-11-28 15:56:41103// Contains state associated with, initialized and cleaned up on, and
[email protected]dd483702011-12-02 14:47:42104// primarily used on, the IO thread.
[email protected]c92b8612011-12-13 22:18:59105//
106// If you are looking to interact with the IO thread (e.g. post tasks
107// to it or check if it is the current thread), see
108// content::BrowserThread.
[email protected]2e5b60a22011-11-28 15:56:41109class IOThread : public content::BrowserThreadDelegate {
[email protected]0ac83682010-01-22 17:46:27110 public:
[email protected]d13c3272010-02-04 00:24:51111 struct Globals {
[email protected]c93123fa2012-04-19 02:49:48112 class SystemRequestContextLeakChecker {
113 public:
114 explicit SystemRequestContextLeakChecker(Globals* globals);
115 ~SystemRequestContextLeakChecker();
116
117 private:
118 Globals* const globals_;
119 };
120
[email protected]1889dc1b2010-10-14 22:03:13121 Globals();
122 ~Globals();
123
mmenkef73a5122017-07-13 23:27:39124 // In-process NetworkService for use in URLRequestContext configuration when
125 // the network service created through the ServiceManager is disabled. See
126 // SystemNetworkContextManager's header comment for more details
127 std::unique_ptr<content::NetworkService> network_service;
128
kundajif617523b2016-09-09 22:41:24129 // Ascribes all data use in Chrome to a source, such as page loads.
130 std::unique_ptr<data_use_measurement::ChromeDataUseAscriber>
131 data_use_ascriber;
sclittle3f98c6c2015-11-19 22:59:29132 // Global aggregator of data use. It must outlive the
133 // |system_network_delegate|.
dcheng4af48582016-04-19 00:29:35134 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator;
zpengdb4a58e2017-01-10 17:40:32135#if defined(OS_ANDROID)
sclittle3f98c6c2015-11-19 22:59:29136 // An external observer of data use.
dcheng4af48582016-04-19 00:29:35137 std::unique_ptr<chrome::android::ExternalDataUseObserver>
sclittle3f98c6c2015-11-19 22:59:29138 external_data_use_observer;
zpengdb4a58e2017-01-10 17:40:32139#endif // defined(OS_ANDROID)
eranm1a79db22015-11-24 10:56:49140 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs;
dcheng4af48582016-04-19 00:29:35141 std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences;
mmenkef73a5122017-07-13 23:27:39142 std::unique_ptr<content::mojom::NetworkContext> system_network_context;
143 net::URLRequestContext* system_request_context;
[email protected]c93123fa2012-04-19 02:49:48144 SystemRequestContextLeakChecker system_request_context_leak_checker;
brettw00899e62016-11-12 02:10:17145#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]5a38dfd2012-07-23 23:22:10146 scoped_refptr<extensions::EventRouterForwarder>
[email protected]3ce02412011-03-01 12:01:15147 extension_event_router_forwarder;
[email protected]84b7a552014-07-19 04:52:06148#endif
dcheng4af48582016-04-19 00:29:35149 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator;
tbansal1bd4a952017-06-06 23:01:46150 std::unique_ptr<net::RTTAndThroughputEstimatesObserver>
tbansal15973c32017-05-10 18:40:44151 network_quality_observer;
[email protected]cf4cae32014-05-27 00:39:10152
[email protected]4588b3d2012-11-14 00:37:38153 // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a
154 // main frame load fails with a DNS error in order to provide more useful
155 // information to the renderer so it can show a more specific error page.
dcheng4af48582016-04-19 00:29:35156 std::unique_ptr<chrome_browser_net::DnsProbeService> dns_probe_service;
maksim.sisov3d40c812016-05-02 13:27:16157
158 // Enables Brotli Content-Encoding support
159 bool enable_brotli;
bnc18fb77f2016-04-04 20:54:04160 };
161
[email protected]b2fcd0e2010-12-01 15:19:40162 // |net_log| must either outlive the IOThread or be NULL.
[email protected]b1de2c72013-02-06 02:45:47163 IOThread(PrefService* local_state,
[email protected]77305422012-11-29 16:51:39164 policy::PolicyService* policy_service,
drogerc690e8802015-09-21 14:29:16165 net_log::ChromeNetLog* net_log,
Matt Menke21b9cc62017-08-23 15:45:45166 extensions::EventRouterForwarder* extension_event_router_forwarder,
167 SystemNetworkContextManager* system_network_context_manager);
[email protected]0ac83682010-01-22 17:46:27168
Daniel Chenga542fca2014-10-21 09:51:29169 ~IOThread() override;
[email protected]0ac83682010-01-22 17:46:27170
[email protected]3c319eb2013-02-21 14:44:45171 static void RegisterPrefs(PrefRegistrySimple* registry);
172
[email protected]d13c3272010-02-04 00:24:51173 // Can only be called on the IO thread.
174 Globals* globals();
[email protected]0ac83682010-01-22 17:46:27175
[email protected]37ac95b2013-07-23 23:39:35176 // Allows overriding Globals in tests where IOThread::Init() and
177 // IOThread::CleanUp() are not called. This allows for injecting mocks into
178 // IOThread global objects.
179 void SetGlobalsForTesting(Globals* globals);
180
drogerc690e8802015-09-21 14:29:16181 net_log::ChromeNetLog* net_log();
[email protected]b2fcd0e2010-12-01 15:19:40182
[email protected]b09f76d62011-12-07 01:51:06183 // Handles changing to On The Record mode, discarding confidential data.
184 void ChangedToOnTheRecord();
185
[email protected]db0e86dd2011-03-16 14:47:21186 // Returns a getter for the URLRequestContext. Only called on the UI thread.
[email protected]abe2c032011-03-31 18:49:34187 net::URLRequestContextGetter* system_url_request_context_getter();
[email protected]db0e86dd2011-03-16 14:47:21188
msramek94f5656c2016-08-31 17:08:29189 // Clears the host cache. Intended to be used to prevent exposing recently
[email protected]67372ecf2011-09-10 01:30:46190 // visited sites on about:net-internals/#dns and about:dns pages. Must be
msramek94f5656c2016-08-31 17:08:29191 // called on the IO thread. If |host_filter| is not null, only hosts matched
192 // by it are deleted from the cache.
193 void ClearHostCache(
194 const base::Callback<bool(const std::string&)>& host_filter);
[email protected]d6f37fc2011-02-13 23:58:41195
Matt Menkecfef87d2017-08-03 13:03:06196 // Dynamically disables QUIC for all NetworkContexts using the IOThread's
197 // NetworkService. Re-enabling Quic dynamically is not supported for
198 // simplicity and requires a browser restart. May only be called on the IO
199 // thread.
pmarko6ab8be242017-01-11 11:02:55200 void DisableQuic();
201
gayane0b46091c2016-04-07 21:01:05202 // Returns the callback for updating data use prefs.
robliao7253fd22016-12-01 18:41:38203 metrics::UpdateUsagePrefCallbackType GetMetricsDataUseForwarder();
gayane0b46091c2016-04-07 21:01:05204
eranm3c2d6432016-06-01 10:17:27205 // Registers the |observer| for new STH notifications.
206 void RegisterSTHObserver(net::ct::STHObserver* observer);
207
208 // Un-registers the |observer|.
209 void UnregisterSTHObserver(net::ct::STHObserver* observer);
210
eroman9f7ea642016-06-03 21:28:29211 // Returns true if the indicated proxy resolution features are
212 // enabled. These features are controlled through
213 // preferences/policy/commandline.
214 //
215 // For a description of what these features are, and how they are
216 // configured, see the comments in pref_names.cc for
217 // |kQuickCheckEnabled| and |kPacHttpsUrlStrippingEnabled
218 // respectively.
219 bool WpadQuickCheckEnabled() const;
220 bool PacHttpsUrlStrippingEnabled() const;
221
mmenke1c261ff2017-07-23 17:06:35222 // Configures |builder|'s ProxyService to use the specified
223 // |proxy_config_service| and sets a number of proxy-related options based on
224 // prefs, policies, and the command line.
225 void SetUpProxyConfigService(
226 net::URLRequestContextBuilderMojo* builder,
227 std::unique_ptr<net::ProxyConfigService> proxy_config_service) const;
228
[email protected]2e5b60a22011-11-28 15:56:41229 private:
[email protected]488a0e252014-06-25 04:37:44230 friend class test::IOThreadPeer;
[email protected]488a0e252014-06-25 04:37:44231
[email protected]2e5b60a22011-11-28 15:56:41232 // BrowserThreadDelegate implementation, runs on the IO thread.
233 // This handles initialization and destruction of state that must
234 // live on the IO thread.
Daniel Chenga542fca2014-10-21 09:51:29235 void Init() override;
Daniel Chenga542fca2014-10-21 09:51:29236 void CleanUp() override;
[email protected]0ac83682010-01-22 17:46:27237
mmenkec2af5952017-06-07 23:26:47238 std::unique_ptr<net::HttpAuthHandlerFactory> CreateDefaultAuthHandlerFactory(
239 net::HostResolver* host_resolver);
[email protected]eb3cac72010-02-26 21:07:45240
[email protected]4d45a6de2011-05-13 05:20:18241 // Returns an SSLConfigService instance.
242 net::SSLConfigService* GetSSLConfigService();
243
[email protected]b09f76d62011-12-07 01:51:06244 void ChangedToOnTheRecordOnIOThread();
245
[email protected]fa4b6c32012-11-26 23:02:39246 void UpdateDnsClientEnabled();
aberentbba302d2015-12-03 10:20:19247 void UpdateServerWhitelist();
248 void UpdateDelegateWhitelist();
249 void UpdateAndroidAuthNegotiateAccountType();
250 void UpdateNegotiateDisableCnameLookup();
251 void UpdateNegotiateEnablePort();
[email protected]fa4b6c32012-11-26 23:02:39252
[email protected]84b7a552014-07-19 04:52:06253 extensions::EventRouterForwarder* extension_event_router_forwarder() {
brettw00899e62016-11-12 02:10:17254#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]84b7a552014-07-19 04:52:06255 return extension_event_router_forwarder_;
256#else
257 return NULL;
258#endif
259 }
mmenkef2e53b22017-05-15 18:40:18260 void ConstructSystemRequestContext();
wjmacleanea309f72015-08-25 20:56:59261
[email protected]b2fcd0e2010-12-01 15:19:40262 // The NetLog is owned by the browser process, to allow logging from other
263 // threads during shutdown, but is used most frequently on the IOThread.
drogerc690e8802015-09-21 14:29:16264 net_log::ChromeNetLog* net_log_;
[email protected]b2fcd0e2010-12-01 15:19:40265
brettw00899e62016-11-12 02:10:17266#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]5a38dfd2012-07-23 23:22:10267 // The extensions::EventRouterForwarder allows for sending events to
268 // extensions from the IOThread.
269 extensions::EventRouterForwarder* extension_event_router_forwarder_;
[email protected]84b7a552014-07-19 04:52:06270#endif
[email protected]3ce02412011-03-01 12:01:15271
[email protected]0ac83682010-01-22 17:46:27272 // These member variables are basically global, but their lifetimes are tied
273 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
274 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]b2fcd0e2010-12-01 15:19:40275 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27276
[email protected]d13c3272010-02-04 00:24:51277 // These member variables are initialized in Init() and do not change for the
278 // lifetime of the IO thread.
279
280 Globals* globals_;
281
[email protected]58bc7042010-07-07 18:04:14282 // Observer that logs network changes to the ChromeNetLog.
pauljensen7b34e522016-05-12 18:20:59283 std::unique_ptr<net::LoggingNetworkChangeObserver> network_change_observer_;
[email protected]58bc7042010-07-07 18:04:14284
eranm3c2d6432016-06-01 10:17:27285 std::unique_ptr<certificate_transparency::TreeStateTracker> ct_tree_tracker_;
286
[email protected]0a8db0d2011-04-13 15:15:40287 BooleanPrefMember system_enable_referrers_;
288
[email protected]fa4b6c32012-11-26 23:02:39289 BooleanPrefMember dns_client_enabled_;
290
[email protected]67378142013-12-17 21:57:17291 BooleanPrefMember quick_check_enabled_;
292
eroman9f7ea642016-06-03 21:28:29293 BooleanPrefMember pac_https_url_stripping_enabled_;
294
[email protected]bcefe0f2010-11-10 16:19:10295 // Store HTTP Auth-related policies in this thread.
aberentbba302d2015-12-03 10:20:19296 // TODO(aberent) Make the list of auth schemes a PrefMember, so that the
297 // policy can change after startup (https://crbug/549273).
[email protected]bcefe0f2010-11-10 16:19:10298 std::string auth_schemes_;
aberentbba302d2015-12-03 10:20:19299 BooleanPrefMember negotiate_disable_cname_lookup_;
300 BooleanPrefMember negotiate_enable_port_;
301 StringPrefMember auth_server_whitelist_;
302 StringPrefMember auth_delegate_whitelist_;
303
304#if defined(OS_ANDROID)
305 StringPrefMember auth_android_negotiate_account_type_;
306#endif
307#if defined(OS_POSIX) && !defined(OS_ANDROID)
308 // No PrefMember for the GSSAPI library name, since changing it after startup
309 // requires unloading the existing GSSAPI library, which could cause all sorts
310 // of problems for, for example, active Negotiate transactions.
[email protected]ac7f3fdb2010-11-12 12:47:05311 std::string gssapi_library_name_;
aberentbba302d2015-12-03 10:20:19312#endif
[email protected]bcefe0f2010-11-10 16:19:10313
zentaroe0326352017-05-09 13:11:51314#if defined(OS_CHROMEOS)
315 bool allow_gssapi_library_load_;
316#endif
317
mmenkef73a5122017-07-13 23:27:39318 // These are set on the UI thread, and then consumed during initialization on
319 // the IO thread.
320 content::mojom::NetworkContextRequest network_context_request_;
321 content::mojom::NetworkContextParamsPtr network_context_params_;
322
[email protected]4d45a6de2011-05-13 05:20:18323 // This is an instance of the default SSLConfigServiceManager for the current
324 // platform and it gets SSL preferences from local_state object.
dcheng4af48582016-04-19 00:29:35325 std::unique_ptr<ssl_config::SSLConfigServiceManager>
326 ssl_config_service_manager_;
[email protected]4d45a6de2011-05-13 05:20:18327
[email protected]d13c3272010-02-04 00:24:51328 // These member variables are initialized by a task posted to the IO thread,
329 // which gets posted by calling certain member functions of IOThread.
dcheng4af48582016-04-19 00:29:35330 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_;
[email protected]db0e86dd2011-03-16 14:47:21331
dcheng4af48582016-04-19 00:29:35332 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
[email protected]db0e86dd2011-03-16 14:47:21333
[email protected]abe2c032011-03-31 18:49:34334 scoped_refptr<net::URLRequestContextGetter>
335 system_url_request_context_getter_;
[email protected]db0e86dd2011-03-16 14:47:21336
Matt Menkecfef87d2017-08-03 13:03:06337 // True if QUIC is initially enabled.
338 bool is_quic_allowed_on_init_;
peletskyi5df83d42015-04-30 16:37:46339
mohan.reddy14cb4ad42014-09-17 18:15:14340 base::WeakPtrFactory<IOThread> weak_factory_;
341
[email protected]0ac83682010-01-22 17:46:27342 DISALLOW_COPY_AND_ASSIGN(IOThread);
343};
344
[email protected]fa55e192010-02-15 14:25:50345#endif // CHROME_BROWSER_IO_THREAD_H_