blob: 0f1eab35f76bd6d4ab95ef2c9c94253c906a6bcc [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
[email protected]bcefe0f2010-11-10 16:19:108#include <string>
[email protected]c38831a12011-10-28 12:44:499
[email protected]0ac83682010-01-22 17:46:2710#include "base/basictypes.h"
[email protected]2e5b60a22011-11-28 15:56:4111#include "base/compiler_specific.h"
12#include "base/memory/ref_counted.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]21ee224e2011-11-21 02:17:5314#include "base/memory/weak_ptr.h"
[email protected]0abb67122012-12-12 11:36:0515#include "base/prefs/public/pref_member.h"
[email protected]4d45a6de2011-05-13 05:20:1816#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]2e5b60a22011-11-28 15:56:4117#include "content/public/browser/browser_thread.h"
18#include "content/public/browser/browser_thread_delegate.h"
[email protected]58bc7042010-07-07 18:04:1419#include "net/base/network_change_notifier.h"
[email protected]f9cf5572012-12-04 15:52:0920#include "net/http/http_network_session.h"
21#include "net/socket/next_proto.h"
[email protected]0ac83682010-01-22 17:46:2722
[email protected]9e743cd2010-03-16 07:03:5323class ChromeNetLog;
[email protected]77305422012-11-29 16:51:3924class CommandLine;
[email protected]6f96cbcb2011-11-04 02:26:0725class PrefProxyConfigTrackerImpl;
[email protected]bcefe0f2010-11-10 16:19:1026class PrefService;
[email protected]db0e86dd2011-03-16 14:47:2127class SystemURLRequestContextGetter;
[email protected]0ac83682010-01-22 17:46:2728
[email protected]7613faae2012-04-18 01:01:1929namespace chrome_browser_net {
[email protected]4588b3d2012-11-14 00:37:3830class DnsProbeService;
[email protected]7613faae2012-04-18 01:01:1931class HttpPipeliningCompatibilityClient;
[email protected]a9e0d1412012-08-20 22:13:0132class LoadTimeStats;
[email protected]7613faae2012-04-18 01:01:1933}
34
[email protected]5a38dfd2012-07-23 23:22:1035namespace extensions {
36class EventRouterForwarder;
37}
38
[email protected]d13c3272010-02-04 00:24:5139namespace net {
[email protected]822581d2010-12-16 17:27:1540class CertVerifier;
[email protected]273e37d2011-08-11 01:49:1241class CookieStore;
[email protected]933bc5c62011-04-12 19:08:0242class FtpTransactionFactory;
[email protected]c2dad292012-09-07 21:27:3543class HostMappingRules;
[email protected]1889dc1b2010-10-14 22:03:1344class HostResolver;
[email protected]fa55e192010-02-15 14:25:5045class HttpAuthHandlerFactory;
[email protected]17291a022011-10-10 07:32:5346class HttpServerProperties;
[email protected]52617df2010-12-24 07:30:0147class HttpTransactionFactory;
[email protected]ee4c30d2012-11-07 15:08:4348class HttpUserAgentSettings;
[email protected]0651b812011-02-24 00:22:5049class NetworkDelegate;
[email protected]9c4eff22012-03-20 22:42:2950class ServerBoundCertService;
[email protected]db0e86dd2011-03-16 14:47:2151class ProxyConfigService;
[email protected]2fb629202010-12-23 23:52:5752class ProxyService;
[email protected]3b543ab2011-09-17 21:47:0053class SdchManager;
[email protected]2fb629202010-12-23 23:52:5754class SSLConfigService;
[email protected]a2a41972011-12-07 17:47:2755class TransportSecurityState;
[email protected]27a112c2011-01-06 04:19:3056class URLRequestContext;
[email protected]abe2c032011-03-31 18:49:3457class URLRequestContextGetter;
[email protected]a73a2802012-05-02 19:20:1558class URLRequestThrottlerManager;
[email protected]b4955e7d2010-04-16 20:22:3059class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5160} // namespace net
61
[email protected]77305422012-11-29 16:51:3962namespace policy {
63class PolicyService;
64} // namespace policy
65
[email protected]2e5b60a22011-11-28 15:56:4166// Contains state associated with, initialized and cleaned up on, and
[email protected]dd483702011-12-02 14:47:4267// primarily used on, the IO thread.
[email protected]c92b8612011-12-13 22:18:5968//
69// If you are looking to interact with the IO thread (e.g. post tasks
70// to it or check if it is the current thread), see
71// content::BrowserThread.
[email protected]2e5b60a22011-11-28 15:56:4172class IOThread : public content::BrowserThreadDelegate {
[email protected]0ac83682010-01-22 17:46:2773 public:
[email protected]d13c3272010-02-04 00:24:5174 struct Globals {
[email protected]f9cf5572012-12-04 15:52:0975 template <typename T>
76 class Optional {
77 public:
78 Optional() : set_(false) {}
79
80 void set(T value) {
81 set_ = true;
82 value_ = value;
83 }
84 void CopyToIfSet(T* value) {
85 if (set_) {
86 *value = value_;
87 }
88 }
89
90 private:
91 bool set_;
92 T value_;
93 };
94
[email protected]c93123fa2012-04-19 02:49:4895 class SystemRequestContextLeakChecker {
96 public:
97 explicit SystemRequestContextLeakChecker(Globals* globals);
98 ~SystemRequestContextLeakChecker();
99
100 private:
101 Globals* const globals_;
102 };
103
[email protected]1889dc1b2010-10-14 22:03:13104 Globals();
105 ~Globals();
106
[email protected]0651b812011-02-24 00:22:50107 // The "system" NetworkDelegate, used for Profile-agnostic network events.
108 scoped_ptr<net::NetworkDelegate> system_network_delegate;
[email protected]73c45322010-10-01 23:57:54109 scoped_ptr<net::HostResolver> host_resolver;
[email protected]822581d2010-12-16 17:27:15110 scoped_ptr<net::CertVerifier> cert_verifier;
[email protected]a2a41972011-12-07 17:47:27111 // This TransportSecurityState doesn't load or save any state. It's only
112 // used to enforce pinning for system requests and will only use built-in
113 // pins.
114 scoped_ptr<net::TransportSecurityState> transport_security_state;
[email protected]2fb629202010-12-23 23:52:57115 scoped_refptr<net::SSLConfigService> ssl_config_service;
[email protected]fa55e192010-02-15 14:25:50116 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]17291a022011-10-10 07:32:53117 scoped_ptr<net::HttpServerProperties> http_server_properties;
[email protected]6104ea5d2011-04-27 21:37:12118 scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
[email protected]52617df2010-12-24 07:30:01119 scoped_ptr<net::HttpTransactionFactory>
120 proxy_script_fetcher_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:02121 scoped_ptr<net::FtpTransactionFactory>
122 proxy_script_fetcher_ftp_transaction_factory;
[email protected]a73a2802012-05-02 19:20:15123 scoped_ptr<net::URLRequestThrottlerManager> throttler_manager;
[email protected]b4955e7d2010-04-16 20:22:30124 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]ef2bf422012-05-11 03:27:09125 // TODO(willchan): Remove proxy script fetcher context since it's not
126 // necessary now that I got rid of refcounting URLRequestContexts.
127 //
[email protected]77feb462011-05-16 23:37:25128 // The first URLRequestContext is |system_url_request_context|. We introduce
129 // |proxy_script_fetcher_context| for the second context. It has a direct
130 // ProxyService, since we always directly connect to fetch the PAC script.
[email protected]ef2bf422012-05-11 03:27:09131 scoped_ptr<net::URLRequestContext> proxy_script_fetcher_context;
[email protected]6104ea5d2011-04-27 21:37:12132 scoped_ptr<net::ProxyService> system_proxy_service;
[email protected]db0e86dd2011-03-16 14:47:21133 scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:02134 scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory;
[email protected]ef2bf422012-05-11 03:27:09135 scoped_ptr<net::URLRequestContext> system_request_context;
[email protected]c93123fa2012-04-19 02:49:48136 SystemRequestContextLeakChecker system_request_context_leak_checker;
[email protected]9c4eff22012-03-20 22:42:29137 // |system_cookie_store| and |system_server_bound_cert_service| are shared
[email protected]4617d2da2012-01-13 20:46:49138 // between |proxy_script_fetcher_context| and |system_request_context|.
[email protected]273e37d2011-08-11 01:49:12139 scoped_refptr<net::CookieStore> system_cookie_store;
[email protected]9c4eff22012-03-20 22:42:29140 scoped_ptr<net::ServerBoundCertService> system_server_bound_cert_service;
[email protected]5a38dfd2012-07-23 23:22:10141 scoped_refptr<extensions::EventRouterForwarder>
[email protected]3ce02412011-03-01 12:01:15142 extension_event_router_forwarder;
[email protected]7613faae2012-04-18 01:01:19143 scoped_ptr<chrome_browser_net::HttpPipeliningCompatibilityClient>
144 http_pipelining_compatibility_client;
[email protected]a9e0d1412012-08-20 22:13:01145 scoped_ptr<chrome_browser_net::LoadTimeStats> load_time_stats;
[email protected]c2dad292012-09-07 21:27:35146 scoped_ptr<net::HostMappingRules> host_mapping_rules;
[email protected]ee4c30d2012-11-07 15:08:43147 scoped_ptr<net::HttpUserAgentSettings> http_user_agent_settings;
[email protected]c2dad292012-09-07 21:27:35148 bool ignore_certificate_errors;
149 bool http_pipelining_enabled;
150 uint16 testing_fixed_http_port;
151 uint16 testing_fixed_https_port;
[email protected]f9cf5572012-12-04 15:52:09152 Optional<size_t> max_spdy_sessions_per_domain;
153 Optional<size_t> initial_max_spdy_concurrent_streams;
154 Optional<size_t> max_spdy_concurrent_streams_limit;
155 Optional<bool> force_spdy_single_domain;
156 Optional<bool> enable_spdy_ip_pooling;
157 Optional<bool> enable_spdy_credential_frames;
158 Optional<bool> enable_spdy_compression;
159 Optional<bool> enable_spdy_ping_based_connection_checking;
160 Optional<net::NextProto> spdy_default_protocol;
[email protected]f1e97e92012-12-16 04:53:25161 Optional<uint16> origin_port_to_force_quic_on;
[email protected]4588b3d2012-11-14 00:37:38162 // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a
163 // main frame load fails with a DNS error in order to provide more useful
164 // information to the renderer so it can show a more specific error page.
165 scoped_ptr<chrome_browser_net::DnsProbeService> dns_probe_service;
[email protected]d13c3272010-02-04 00:24:51166 };
167
[email protected]b2fcd0e2010-12-01 15:19:40168 // |net_log| must either outlive the IOThread or be NULL.
[email protected]3ce02412011-03-01 12:01:15169 IOThread(PrefService* local_state,
[email protected]77305422012-11-29 16:51:39170 policy::PolicyService* policy_service,
[email protected]3ce02412011-03-01 12:01:15171 ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10172 extensions::EventRouterForwarder* extension_event_router_forwarder);
[email protected]0ac83682010-01-22 17:46:27173
174 virtual ~IOThread();
175
[email protected]d13c3272010-02-04 00:24:51176 // Can only be called on the IO thread.
177 Globals* globals();
[email protected]0ac83682010-01-22 17:46:27178
[email protected]b2fcd0e2010-12-01 15:19:40179 ChromeNetLog* net_log();
180
[email protected]b09f76d62011-12-07 01:51:06181 // Handles changing to On The Record mode, discarding confidential data.
182 void ChangedToOnTheRecord();
183
[email protected]db0e86dd2011-03-16 14:47:21184 // Returns a getter for the URLRequestContext. Only called on the UI thread.
[email protected]abe2c032011-03-31 18:49:34185 net::URLRequestContextGetter* system_url_request_context_getter();
[email protected]db0e86dd2011-03-16 14:47:21186
[email protected]67372ecf2011-09-10 01:30:46187 // Clears the host cache. Intended to be used to prevent exposing recently
188 // visited sites on about:net-internals/#dns and about:dns pages. Must be
189 // called on the IO thread.
190 void ClearHostCache();
[email protected]d6f37fc2011-02-13 23:58:41191
[email protected]f9cf5572012-12-04 15:52:09192 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params);
193
[email protected]2e5b60a22011-11-28 15:56:41194 private:
[email protected]77305422012-11-29 16:51:39195 // Provide SystemURLRequestContextGetter with access to
196 // InitSystemRequestContext().
197 friend class SystemURLRequestContextGetter;
198
[email protected]2e5b60a22011-11-28 15:56:41199 // BrowserThreadDelegate implementation, runs on the IO thread.
200 // This handles initialization and destruction of state that must
201 // live on the IO thread.
[email protected]0d5c08e2011-11-21 16:51:06202 virtual void Init() OVERRIDE;
203 virtual void CleanUp() OVERRIDE;
[email protected]0ac83682010-01-22 17:46:27204
[email protected]77305422012-11-29 16:51:39205 void InitializeNetworkOptions(const CommandLine& parsed_command_line);
[email protected]db0e86dd2011-03-16 14:47:21206
[email protected]443a30ed2012-11-30 02:56:46207 // Enable the SPDY protocol. If this function is not called, SPDY/3
208 // will be enabled.
209 // "off" : Disables SPDY support entirely.
210 // "ssl" : Forces SPDY for all HTTPS requests.
211 // "no-ssl" : Forces SPDY for all HTTP requests.
212 // "no-ping" : Disables SPDY ping connection testing.
213 // "exclude=<host>" : Disables SPDY support for the host <host>.
214 // "no-compress" : Disables SPDY header compression.
215 // "no-alt-protocols : Disables alternate protocol support.
216 // "force-alt-protocols : Forces an alternate protocol of SPDY/2
217 // on port 443.
218 // "single-domain" : Forces all spdy traffic to a single domain.
219 // "init-max-streams=<limit>" : Specifies the maximum number of concurrent
220 // streams for a SPDY session, unless the
221 // specifies a different value via SETTINGS.
222 void EnableSpdy(const std::string& mode);
223
[email protected]2e5b60a22011-11-28 15:56:41224 // Global state must be initialized on the IO thread, then this
225 // method must be invoked on the UI thread.
226 void InitSystemRequestContext();
227
228 // Lazy initialization of system request context for
229 // SystemURLRequestContextGetter. To be called on IO thread only
230 // after global state has been initialized on the IO thread, and
231 // SystemRequestContext state has been initialized on the UI thread.
232 void InitSystemRequestContextOnIOThread();
233
[email protected]bcefe0f2010-11-10 16:19:10234 static void RegisterPrefs(PrefService* local_state);
235
[email protected]65d34382010-07-01 18:12:26236 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(
237 net::HostResolver* resolver);
[email protected]eb3cac72010-02-26 21:07:45238
[email protected]4d45a6de2011-05-13 05:20:18239 // Returns an SSLConfigService instance.
240 net::SSLConfigService* GetSSLConfigService();
241
[email protected]b09f76d62011-12-07 01:51:06242 void ChangedToOnTheRecordOnIOThread();
243
[email protected]fa4b6c32012-11-26 23:02:39244 void UpdateDnsClientEnabled();
245
[email protected]b2fcd0e2010-12-01 15:19:40246 // The NetLog is owned by the browser process, to allow logging from other
247 // threads during shutdown, but is used most frequently on the IOThread.
248 ChromeNetLog* net_log_;
249
[email protected]5a38dfd2012-07-23 23:22:10250 // The extensions::EventRouterForwarder allows for sending events to
251 // extensions from the IOThread.
252 extensions::EventRouterForwarder* extension_event_router_forwarder_;
[email protected]3ce02412011-03-01 12:01:15253
[email protected]0ac83682010-01-22 17:46:27254 // These member variables are basically global, but their lifetimes are tied
255 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
256 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]b2fcd0e2010-12-01 15:19:40257 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27258
[email protected]d13c3272010-02-04 00:24:51259 // These member variables are initialized in Init() and do not change for the
260 // lifetime of the IO thread.
261
262 Globals* globals_;
263
[email protected]58bc7042010-07-07 18:04:14264 // Observer that logs network changes to the ChromeNetLog.
[email protected]e0845d5f2012-05-29 00:11:41265 class LoggingNetworkChangeObserver;
266 scoped_ptr<LoggingNetworkChangeObserver> network_change_observer_;
[email protected]58bc7042010-07-07 18:04:14267
[email protected]0a8db0d2011-04-13 15:15:40268 BooleanPrefMember system_enable_referrers_;
269
[email protected]fa4b6c32012-11-26 23:02:39270 BooleanPrefMember dns_client_enabled_;
271
[email protected]bcefe0f2010-11-10 16:19:10272 // Store HTTP Auth-related policies in this thread.
273 std::string auth_schemes_;
274 bool negotiate_disable_cname_lookup_;
275 bool negotiate_enable_port_;
276 std::string auth_server_whitelist_;
277 std::string auth_delegate_whitelist_;
[email protected]ac7f3fdb2010-11-12 12:47:05278 std::string gssapi_library_name_;
[email protected]ec44ee02012-09-28 21:31:51279 std::string spdyproxy_origin_;
[email protected]bcefe0f2010-11-10 16:19:10280
[email protected]4d45a6de2011-05-13 05:20:18281 // This is an instance of the default SSLConfigServiceManager for the current
282 // platform and it gets SSL preferences from local_state object.
283 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
284
[email protected]d13c3272010-02-04 00:24:51285 // These member variables are initialized by a task posted to the IO thread,
286 // which gets posted by calling certain member functions of IOThread.
[email protected]db0e86dd2011-03-16 14:47:21287 scoped_ptr<net::ProxyConfigService> system_proxy_config_service_;
288
[email protected]6f96cbcb2011-11-04 02:26:07289 scoped_ptr<PrefProxyConfigTrackerImpl> pref_proxy_config_tracker_;
[email protected]db0e86dd2011-03-16 14:47:21290
[email protected]abe2c032011-03-31 18:49:34291 scoped_refptr<net::URLRequestContextGetter>
292 system_url_request_context_getter_;
[email protected]db0e86dd2011-03-16 14:47:21293
[email protected]3b543ab2011-09-17 21:47:00294 net::SdchManager* sdch_manager_;
295
[email protected]77305422012-11-29 16:51:39296 // True if SPDY is disabled by policy.
297 bool is_spdy_disabled_by_policy_;
298
[email protected]21ee224e2011-11-21 02:17:53299 base::WeakPtrFactory<IOThread> weak_factory_;
[email protected]addb3242011-06-13 21:39:16300
[email protected]0ac83682010-01-22 17:46:27301 DISALLOW_COPY_AND_ASSIGN(IOThread);
302};
303
[email protected]fa55e192010-02-15 14:25:50304#endif // CHROME_BROWSER_IO_THREAD_H_