blob: de61126a3955a407e8353be7a420a82da74d5f5a [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]c5aa8262012-08-21 11:19:5415#include "chrome/browser/api/prefs/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]0ac83682010-01-22 17:46:2720
[email protected]9e743cd2010-03-16 07:03:5321class ChromeNetLog;
[email protected]77305422012-11-29 16:51:3922class CommandLine;
[email protected]6f96cbcb2011-11-04 02:26:0723class PrefProxyConfigTrackerImpl;
[email protected]bcefe0f2010-11-10 16:19:1024class PrefService;
[email protected]db0e86dd2011-03-16 14:47:2125class SystemURLRequestContextGetter;
[email protected]0ac83682010-01-22 17:46:2726
[email protected]7613faae2012-04-18 01:01:1927namespace chrome_browser_net {
[email protected]4588b3d2012-11-14 00:37:3828class DnsProbeService;
[email protected]7613faae2012-04-18 01:01:1929class HttpPipeliningCompatibilityClient;
[email protected]a9e0d1412012-08-20 22:13:0130class LoadTimeStats;
[email protected]7613faae2012-04-18 01:01:1931}
32
[email protected]5a38dfd2012-07-23 23:22:1033namespace extensions {
34class EventRouterForwarder;
35}
36
[email protected]d13c3272010-02-04 00:24:5137namespace net {
[email protected]822581d2010-12-16 17:27:1538class CertVerifier;
[email protected]273e37d2011-08-11 01:49:1239class CookieStore;
[email protected]933bc5c62011-04-12 19:08:0240class FtpTransactionFactory;
[email protected]c2dad292012-09-07 21:27:3541class HostMappingRules;
[email protected]1889dc1b2010-10-14 22:03:1342class HostResolver;
[email protected]fa55e192010-02-15 14:25:5043class HttpAuthHandlerFactory;
[email protected]17291a022011-10-10 07:32:5344class HttpServerProperties;
[email protected]52617df2010-12-24 07:30:0145class HttpTransactionFactory;
[email protected]ee4c30d2012-11-07 15:08:4346class HttpUserAgentSettings;
[email protected]0651b812011-02-24 00:22:5047class NetworkDelegate;
[email protected]9c4eff22012-03-20 22:42:2948class ServerBoundCertService;
[email protected]db0e86dd2011-03-16 14:47:2149class ProxyConfigService;
[email protected]2fb629202010-12-23 23:52:5750class ProxyService;
[email protected]3b543ab2011-09-17 21:47:0051class SdchManager;
[email protected]2fb629202010-12-23 23:52:5752class SSLConfigService;
[email protected]a2a41972011-12-07 17:47:2753class TransportSecurityState;
[email protected]27a112c2011-01-06 04:19:3054class URLRequestContext;
[email protected]abe2c032011-03-31 18:49:3455class URLRequestContextGetter;
[email protected]a73a2802012-05-02 19:20:1556class URLRequestThrottlerManager;
[email protected]b4955e7d2010-04-16 20:22:3057class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5158} // namespace net
59
[email protected]77305422012-11-29 16:51:3960namespace policy {
61class PolicyService;
62} // namespace policy
63
[email protected]2e5b60a22011-11-28 15:56:4164// Contains state associated with, initialized and cleaned up on, and
[email protected]dd483702011-12-02 14:47:4265// primarily used on, the IO thread.
[email protected]c92b8612011-12-13 22:18:5966//
67// If you are looking to interact with the IO thread (e.g. post tasks
68// to it or check if it is the current thread), see
69// content::BrowserThread.
[email protected]2e5b60a22011-11-28 15:56:4170class IOThread : public content::BrowserThreadDelegate {
[email protected]0ac83682010-01-22 17:46:2771 public:
[email protected]d13c3272010-02-04 00:24:5172 struct Globals {
[email protected]c93123fa2012-04-19 02:49:4873 class SystemRequestContextLeakChecker {
74 public:
75 explicit SystemRequestContextLeakChecker(Globals* globals);
76 ~SystemRequestContextLeakChecker();
77
78 private:
79 Globals* const globals_;
80 };
81
[email protected]1889dc1b2010-10-14 22:03:1382 Globals();
83 ~Globals();
84
[email protected]0651b812011-02-24 00:22:5085 // The "system" NetworkDelegate, used for Profile-agnostic network events.
86 scoped_ptr<net::NetworkDelegate> system_network_delegate;
[email protected]73c45322010-10-01 23:57:5487 scoped_ptr<net::HostResolver> host_resolver;
[email protected]822581d2010-12-16 17:27:1588 scoped_ptr<net::CertVerifier> cert_verifier;
[email protected]a2a41972011-12-07 17:47:2789 // This TransportSecurityState doesn't load or save any state. It's only
90 // used to enforce pinning for system requests and will only use built-in
91 // pins.
92 scoped_ptr<net::TransportSecurityState> transport_security_state;
[email protected]2fb629202010-12-23 23:52:5793 scoped_refptr<net::SSLConfigService> ssl_config_service;
[email protected]fa55e192010-02-15 14:25:5094 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]17291a022011-10-10 07:32:5395 scoped_ptr<net::HttpServerProperties> http_server_properties;
[email protected]6104ea5d2011-04-27 21:37:1296 scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
[email protected]52617df2010-12-24 07:30:0197 scoped_ptr<net::HttpTransactionFactory>
98 proxy_script_fetcher_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:0299 scoped_ptr<net::FtpTransactionFactory>
100 proxy_script_fetcher_ftp_transaction_factory;
[email protected]a73a2802012-05-02 19:20:15101 scoped_ptr<net::URLRequestThrottlerManager> throttler_manager;
[email protected]b4955e7d2010-04-16 20:22:30102 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]ef2bf422012-05-11 03:27:09103 // TODO(willchan): Remove proxy script fetcher context since it's not
104 // necessary now that I got rid of refcounting URLRequestContexts.
105 //
[email protected]77feb462011-05-16 23:37:25106 // The first URLRequestContext is |system_url_request_context|. We introduce
107 // |proxy_script_fetcher_context| for the second context. It has a direct
108 // ProxyService, since we always directly connect to fetch the PAC script.
[email protected]ef2bf422012-05-11 03:27:09109 scoped_ptr<net::URLRequestContext> proxy_script_fetcher_context;
[email protected]6104ea5d2011-04-27 21:37:12110 scoped_ptr<net::ProxyService> system_proxy_service;
[email protected]db0e86dd2011-03-16 14:47:21111 scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:02112 scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory;
[email protected]ef2bf422012-05-11 03:27:09113 scoped_ptr<net::URLRequestContext> system_request_context;
[email protected]c93123fa2012-04-19 02:49:48114 SystemRequestContextLeakChecker system_request_context_leak_checker;
[email protected]9c4eff22012-03-20 22:42:29115 // |system_cookie_store| and |system_server_bound_cert_service| are shared
[email protected]4617d2da2012-01-13 20:46:49116 // between |proxy_script_fetcher_context| and |system_request_context|.
[email protected]273e37d2011-08-11 01:49:12117 scoped_refptr<net::CookieStore> system_cookie_store;
[email protected]9c4eff22012-03-20 22:42:29118 scoped_ptr<net::ServerBoundCertService> system_server_bound_cert_service;
[email protected]5a38dfd2012-07-23 23:22:10119 scoped_refptr<extensions::EventRouterForwarder>
[email protected]3ce02412011-03-01 12:01:15120 extension_event_router_forwarder;
[email protected]7613faae2012-04-18 01:01:19121 scoped_ptr<chrome_browser_net::HttpPipeliningCompatibilityClient>
122 http_pipelining_compatibility_client;
[email protected]a9e0d1412012-08-20 22:13:01123 scoped_ptr<chrome_browser_net::LoadTimeStats> load_time_stats;
[email protected]c2dad292012-09-07 21:27:35124 scoped_ptr<net::HostMappingRules> host_mapping_rules;
[email protected]ee4c30d2012-11-07 15:08:43125 scoped_ptr<net::HttpUserAgentSettings> http_user_agent_settings;
[email protected]c2dad292012-09-07 21:27:35126 bool ignore_certificate_errors;
127 bool http_pipelining_enabled;
128 uint16 testing_fixed_http_port;
129 uint16 testing_fixed_https_port;
[email protected]4588b3d2012-11-14 00:37:38130 // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a
131 // main frame load fails with a DNS error in order to provide more useful
132 // information to the renderer so it can show a more specific error page.
133 scoped_ptr<chrome_browser_net::DnsProbeService> dns_probe_service;
[email protected]d13c3272010-02-04 00:24:51134 };
135
[email protected]b2fcd0e2010-12-01 15:19:40136 // |net_log| must either outlive the IOThread or be NULL.
[email protected]3ce02412011-03-01 12:01:15137 IOThread(PrefService* local_state,
[email protected]77305422012-11-29 16:51:39138 policy::PolicyService* policy_service,
[email protected]3ce02412011-03-01 12:01:15139 ChromeNetLog* net_log,
[email protected]5a38dfd2012-07-23 23:22:10140 extensions::EventRouterForwarder* extension_event_router_forwarder);
[email protected]0ac83682010-01-22 17:46:27141
142 virtual ~IOThread();
143
[email protected]d13c3272010-02-04 00:24:51144 // Can only be called on the IO thread.
145 Globals* globals();
[email protected]0ac83682010-01-22 17:46:27146
[email protected]b2fcd0e2010-12-01 15:19:40147 ChromeNetLog* net_log();
148
[email protected]b09f76d62011-12-07 01:51:06149 // Handles changing to On The Record mode, discarding confidential data.
150 void ChangedToOnTheRecord();
151
[email protected]db0e86dd2011-03-16 14:47:21152 // Returns a getter for the URLRequestContext. Only called on the UI thread.
[email protected]abe2c032011-03-31 18:49:34153 net::URLRequestContextGetter* system_url_request_context_getter();
[email protected]db0e86dd2011-03-16 14:47:21154
[email protected]67372ecf2011-09-10 01:30:46155 // Clears the host cache. Intended to be used to prevent exposing recently
156 // visited sites on about:net-internals/#dns and about:dns pages. Must be
157 // called on the IO thread.
158 void ClearHostCache();
[email protected]d6f37fc2011-02-13 23:58:41159
[email protected]2e5b60a22011-11-28 15:56:41160 private:
[email protected]77305422012-11-29 16:51:39161 // Provide SystemURLRequestContextGetter with access to
162 // InitSystemRequestContext().
163 friend class SystemURLRequestContextGetter;
164
[email protected]2e5b60a22011-11-28 15:56:41165 // BrowserThreadDelegate implementation, runs on the IO thread.
166 // This handles initialization and destruction of state that must
167 // live on the IO thread.
[email protected]0d5c08e2011-11-21 16:51:06168 virtual void Init() OVERRIDE;
169 virtual void CleanUp() OVERRIDE;
[email protected]0ac83682010-01-22 17:46:27170
[email protected]77305422012-11-29 16:51:39171 void InitializeNetworkOptions(const CommandLine& parsed_command_line);
[email protected]db0e86dd2011-03-16 14:47:21172
[email protected]443a30ed2012-11-30 02:56:46173 // Enable the SPDY protocol. If this function is not called, SPDY/3
174 // will be enabled.
175 // "off" : Disables SPDY support entirely.
176 // "ssl" : Forces SPDY for all HTTPS requests.
177 // "no-ssl" : Forces SPDY for all HTTP requests.
178 // "no-ping" : Disables SPDY ping connection testing.
179 // "exclude=<host>" : Disables SPDY support for the host <host>.
180 // "no-compress" : Disables SPDY header compression.
181 // "no-alt-protocols : Disables alternate protocol support.
182 // "force-alt-protocols : Forces an alternate protocol of SPDY/2
183 // on port 443.
184 // "single-domain" : Forces all spdy traffic to a single domain.
185 // "init-max-streams=<limit>" : Specifies the maximum number of concurrent
186 // streams for a SPDY session, unless the
187 // specifies a different value via SETTINGS.
188 void EnableSpdy(const std::string& mode);
189
[email protected]2e5b60a22011-11-28 15:56:41190 // Global state must be initialized on the IO thread, then this
191 // method must be invoked on the UI thread.
192 void InitSystemRequestContext();
193
194 // Lazy initialization of system request context for
195 // SystemURLRequestContextGetter. To be called on IO thread only
196 // after global state has been initialized on the IO thread, and
197 // SystemRequestContext state has been initialized on the UI thread.
198 void InitSystemRequestContextOnIOThread();
199
[email protected]bcefe0f2010-11-10 16:19:10200 static void RegisterPrefs(PrefService* local_state);
201
[email protected]65d34382010-07-01 18:12:26202 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(
203 net::HostResolver* resolver);
[email protected]eb3cac72010-02-26 21:07:45204
[email protected]4d45a6de2011-05-13 05:20:18205 // Returns an SSLConfigService instance.
206 net::SSLConfigService* GetSSLConfigService();
207
[email protected]b09f76d62011-12-07 01:51:06208 void ChangedToOnTheRecordOnIOThread();
209
[email protected]fa4b6c32012-11-26 23:02:39210 void UpdateDnsClientEnabled();
211
[email protected]b2fcd0e2010-12-01 15:19:40212 // The NetLog is owned by the browser process, to allow logging from other
213 // threads during shutdown, but is used most frequently on the IOThread.
214 ChromeNetLog* net_log_;
215
[email protected]5a38dfd2012-07-23 23:22:10216 // The extensions::EventRouterForwarder allows for sending events to
217 // extensions from the IOThread.
218 extensions::EventRouterForwarder* extension_event_router_forwarder_;
[email protected]3ce02412011-03-01 12:01:15219
[email protected]0ac83682010-01-22 17:46:27220 // These member variables are basically global, but their lifetimes are tied
221 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
222 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]b2fcd0e2010-12-01 15:19:40223 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27224
[email protected]d13c3272010-02-04 00:24:51225 // These member variables are initialized in Init() and do not change for the
226 // lifetime of the IO thread.
227
228 Globals* globals_;
229
[email protected]58bc7042010-07-07 18:04:14230 // Observer that logs network changes to the ChromeNetLog.
[email protected]e0845d5f2012-05-29 00:11:41231 class LoggingNetworkChangeObserver;
232 scoped_ptr<LoggingNetworkChangeObserver> network_change_observer_;
[email protected]58bc7042010-07-07 18:04:14233
[email protected]0a8db0d2011-04-13 15:15:40234 BooleanPrefMember system_enable_referrers_;
235
[email protected]fa4b6c32012-11-26 23:02:39236 BooleanPrefMember dns_client_enabled_;
237
[email protected]bcefe0f2010-11-10 16:19:10238 // Store HTTP Auth-related policies in this thread.
239 std::string auth_schemes_;
240 bool negotiate_disable_cname_lookup_;
241 bool negotiate_enable_port_;
242 std::string auth_server_whitelist_;
243 std::string auth_delegate_whitelist_;
[email protected]ac7f3fdb2010-11-12 12:47:05244 std::string gssapi_library_name_;
[email protected]ec44ee02012-09-28 21:31:51245 std::string spdyproxy_origin_;
[email protected]bcefe0f2010-11-10 16:19:10246
[email protected]4d45a6de2011-05-13 05:20:18247 // This is an instance of the default SSLConfigServiceManager for the current
248 // platform and it gets SSL preferences from local_state object.
249 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
250
[email protected]d13c3272010-02-04 00:24:51251 // These member variables are initialized by a task posted to the IO thread,
252 // which gets posted by calling certain member functions of IOThread.
[email protected]db0e86dd2011-03-16 14:47:21253 scoped_ptr<net::ProxyConfigService> system_proxy_config_service_;
254
[email protected]6f96cbcb2011-11-04 02:26:07255 scoped_ptr<PrefProxyConfigTrackerImpl> pref_proxy_config_tracker_;
[email protected]db0e86dd2011-03-16 14:47:21256
[email protected]abe2c032011-03-31 18:49:34257 scoped_refptr<net::URLRequestContextGetter>
258 system_url_request_context_getter_;
[email protected]db0e86dd2011-03-16 14:47:21259
[email protected]3b543ab2011-09-17 21:47:00260 net::SdchManager* sdch_manager_;
261
[email protected]77305422012-11-29 16:51:39262 // True if SPDY is disabled by policy.
263 bool is_spdy_disabled_by_policy_;
264
[email protected]21ee224e2011-11-21 02:17:53265 base::WeakPtrFactory<IOThread> weak_factory_;
[email protected]addb3242011-06-13 21:39:16266
[email protected]0ac83682010-01-22 17:46:27267 DISALLOW_COPY_AND_ASSIGN(IOThread);
268};
269
[email protected]fa55e192010-02-15 14:25:50270#endif // CHROME_BROWSER_IO_THREAD_H_