blob: 8a861cc3a76d09cfaa44c24592d72083e1a7e4f4 [file] [log] [blame]
[email protected]27a112c2011-01-06 04:19:301// Copyright (c) 2011 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]0ac83682010-01-22 17:46:278
[email protected]bcefe0f2010-11-10 16:19:109#include <string>
[email protected]c38831a12011-10-28 12:44:4910
[email protected]0ac83682010-01-22 17:46:2711#include "base/basictypes.h"
[email protected]2e5b60a22011-11-28 15:56:4112#include "base/compiler_specific.h"
13#include "base/memory/ref_counted.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]21ee224e2011-11-21 02:17:5315#include "base/memory/weak_ptr.h"
[email protected]4d45a6de2011-05-13 05:20:1816#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4017#include "chrome/browser/prefs/pref_member.h"
[email protected]2e5b60a22011-11-28 15:56:4118#include "content/public/browser/browser_thread.h"
19#include "content/public/browser/browser_thread_delegate.h"
[email protected]58bc7042010-07-07 18:04:1420#include "net/base/network_change_notifier.h"
[email protected]0ac83682010-01-22 17:46:2721
[email protected]9e743cd2010-03-16 07:03:5322class ChromeNetLog;
[email protected]3ce02412011-03-01 12:01:1523class ExtensionEventRouterForwarder;
[email protected]cc87500b2011-06-24 20:59:1924class MediaInternals;
[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]d13c3272010-02-04 00:24:5129namespace net {
[email protected]822581d2010-12-16 17:27:1530class CertVerifier;
[email protected]273e37d2011-08-11 01:49:1231class CookieStore;
[email protected]2db580532010-10-08 14:32:3732class DnsRRResolver;
[email protected]933bc5c62011-04-12 19:08:0233class FtpTransactionFactory;
[email protected]1889dc1b2010-10-14 22:03:1334class HostResolver;
[email protected]fa55e192010-02-15 14:25:5035class HttpAuthHandlerFactory;
[email protected]17291a022011-10-10 07:32:5336class HttpServerProperties;
[email protected]52617df2010-12-24 07:30:0137class HttpTransactionFactory;
[email protected]0651b812011-02-24 00:22:5038class NetworkDelegate;
[email protected]273e37d2011-08-11 01:49:1239class OriginBoundCertService;
[email protected]db0e86dd2011-03-16 14:47:2140class ProxyConfigService;
[email protected]2fb629202010-12-23 23:52:5741class ProxyService;
[email protected]3b543ab2011-09-17 21:47:0042class SdchManager;
[email protected]2fb629202010-12-23 23:52:5743class SSLConfigService;
[email protected]a2a41972011-12-07 17:47:2744class TransportSecurityState;
[email protected]27a112c2011-01-06 04:19:3045class URLRequestContext;
[email protected]abe2c032011-03-31 18:49:3446class URLRequestContextGetter;
[email protected]b4955e7d2010-04-16 20:22:3047class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5148} // namespace net
49
[email protected]2e5b60a22011-11-28 15:56:4150// Contains state associated with, initialized and cleaned up on, and
[email protected]dd483702011-12-02 14:47:4251// primarily used on, the IO thread.
[email protected]2e5b60a22011-11-28 15:56:4152class IOThread : public content::BrowserThreadDelegate {
[email protected]0ac83682010-01-22 17:46:2753 public:
[email protected]d13c3272010-02-04 00:24:5154 struct Globals {
[email protected]1889dc1b2010-10-14 22:03:1355 Globals();
56 ~Globals();
57
[email protected]cc87500b2011-06-24 20:59:1958 struct MediaGlobals {
59 MediaGlobals();
60 ~MediaGlobals();
61 // MediaInternals singleton used to aggregate media information.
62 scoped_ptr<MediaInternals> media_internals;
63 } media;
64
[email protected]0651b812011-02-24 00:22:5065 // The "system" NetworkDelegate, used for Profile-agnostic network events.
66 scoped_ptr<net::NetworkDelegate> system_network_delegate;
[email protected]73c45322010-10-01 23:57:5467 scoped_ptr<net::HostResolver> host_resolver;
[email protected]822581d2010-12-16 17:27:1568 scoped_ptr<net::CertVerifier> cert_verifier;
[email protected]a2a41972011-12-07 17:47:2769 // This TransportSecurityState doesn't load or save any state. It's only
70 // used to enforce pinning for system requests and will only use built-in
71 // pins.
72 scoped_ptr<net::TransportSecurityState> transport_security_state;
[email protected]2db580532010-10-08 14:32:3773 scoped_ptr<net::DnsRRResolver> dnsrr_resolver;
[email protected]2fb629202010-12-23 23:52:5774 scoped_refptr<net::SSLConfigService> ssl_config_service;
[email protected]fa55e192010-02-15 14:25:5075 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]17291a022011-10-10 07:32:5376 scoped_ptr<net::HttpServerProperties> http_server_properties;
[email protected]6104ea5d2011-04-27 21:37:1277 scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
[email protected]52617df2010-12-24 07:30:0178 scoped_ptr<net::HttpTransactionFactory>
79 proxy_script_fetcher_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:0280 scoped_ptr<net::FtpTransactionFactory>
81 proxy_script_fetcher_ftp_transaction_factory;
[email protected]b4955e7d2010-04-16 20:22:3082 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]77feb462011-05-16 23:37:2583 // We use a separate URLRequestContext for PAC fetches, in order to break
84 // the reference cycle:
85 // URLRequestContext=>PAC fetch=>URLRequest=>URLRequestContext.
86 // The first URLRequestContext is |system_url_request_context|. We introduce
87 // |proxy_script_fetcher_context| for the second context. It has a direct
88 // ProxyService, since we always directly connect to fetch the PAC script.
[email protected]27a112c2011-01-06 04:19:3089 scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context;
[email protected]6104ea5d2011-04-27 21:37:1290 scoped_ptr<net::ProxyService> system_proxy_service;
[email protected]db0e86dd2011-03-16 14:47:2191 scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:0292 scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory;
[email protected]db0e86dd2011-03-16 14:47:2193 scoped_refptr<net::URLRequestContext> system_request_context;
[email protected]273e37d2011-08-11 01:49:1294 // |cookie_store| and |origin_bound_cert_service| are shared between
95 // |proxy_script_fetcher_context| and |system_request_context|.
96 scoped_refptr<net::CookieStore> system_cookie_store;
97 scoped_ptr<net::OriginBoundCertService> system_origin_bound_cert_service;
[email protected]3ce02412011-03-01 12:01:1598 scoped_refptr<ExtensionEventRouterForwarder>
99 extension_event_router_forwarder;
[email protected]d13c3272010-02-04 00:24:51100 };
101
[email protected]b2fcd0e2010-12-01 15:19:40102 // |net_log| must either outlive the IOThread or be NULL.
[email protected]3ce02412011-03-01 12:01:15103 IOThread(PrefService* local_state,
104 ChromeNetLog* net_log,
105 ExtensionEventRouterForwarder* extension_event_router_forwarder);
[email protected]0ac83682010-01-22 17:46:27106
107 virtual ~IOThread();
108
[email protected]d13c3272010-02-04 00:24:51109 // Can only be called on the IO thread.
110 Globals* globals();
[email protected]0ac83682010-01-22 17:46:27111
[email protected]b2fcd0e2010-12-01 15:19:40112 ChromeNetLog* net_log();
113
[email protected]b09f76d62011-12-07 01:51:06114 // Handles changing to On The Record mode, discarding confidential data.
115 void ChangedToOnTheRecord();
116
[email protected]db0e86dd2011-03-16 14:47:21117 // Returns a getter for the URLRequestContext. Only called on the UI thread.
[email protected]abe2c032011-03-31 18:49:34118 net::URLRequestContextGetter* system_url_request_context_getter();
[email protected]db0e86dd2011-03-16 14:47:21119
[email protected]67372ecf2011-09-10 01:30:46120 // Clears the host cache. Intended to be used to prevent exposing recently
121 // visited sites on about:net-internals/#dns and about:dns pages. Must be
122 // called on the IO thread.
123 void ClearHostCache();
[email protected]d6f37fc2011-02-13 23:58:41124
[email protected]2e5b60a22011-11-28 15:56:41125 private:
126 // BrowserThreadDelegate implementation, runs on the IO thread.
127 // This handles initialization and destruction of state that must
128 // live on the IO thread.
[email protected]0d5c08e2011-11-21 16:51:06129 virtual void Init() OVERRIDE;
130 virtual void CleanUp() OVERRIDE;
[email protected]0ac83682010-01-22 17:46:27131
[email protected]db0e86dd2011-03-16 14:47:21132 // Provide SystemURLRequestContextGetter with access to
133 // InitSystemRequestContext().
134 friend class SystemURLRequestContextGetter;
135
[email protected]2e5b60a22011-11-28 15:56:41136 // Global state must be initialized on the IO thread, then this
137 // method must be invoked on the UI thread.
138 void InitSystemRequestContext();
139
140 // Lazy initialization of system request context for
141 // SystemURLRequestContextGetter. To be called on IO thread only
142 // after global state has been initialized on the IO thread, and
143 // SystemRequestContext state has been initialized on the UI thread.
144 void InitSystemRequestContextOnIOThread();
145
[email protected]bcefe0f2010-11-10 16:19:10146 static void RegisterPrefs(PrefService* local_state);
147
[email protected]65d34382010-07-01 18:12:26148 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(
149 net::HostResolver* resolver);
[email protected]eb3cac72010-02-26 21:07:45150
[email protected]4d45a6de2011-05-13 05:20:18151 // Returns an SSLConfigService instance.
152 net::SSLConfigService* GetSSLConfigService();
153
[email protected]b09f76d62011-12-07 01:51:06154 void ChangedToOnTheRecordOnIOThread();
155
[email protected]b2fcd0e2010-12-01 15:19:40156 // The NetLog is owned by the browser process, to allow logging from other
157 // threads during shutdown, but is used most frequently on the IOThread.
158 ChromeNetLog* net_log_;
159
[email protected]3ce02412011-03-01 12:01:15160 // The ExtensionEventRouterForwarder allows for sending events to extensions
161 // from the IOThread.
162 ExtensionEventRouterForwarder* extension_event_router_forwarder_;
163
[email protected]0ac83682010-01-22 17:46:27164 // These member variables are basically global, but their lifetimes are tied
165 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
166 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]b2fcd0e2010-12-01 15:19:40167 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27168
[email protected]d13c3272010-02-04 00:24:51169 // These member variables are initialized in Init() and do not change for the
170 // lifetime of the IO thread.
171
172 Globals* globals_;
173
[email protected]58bc7042010-07-07 18:04:14174 // Observer that logs network changes to the ChromeNetLog.
[email protected]232a5812011-03-04 22:42:08175 scoped_ptr<net::NetworkChangeNotifier::IPAddressObserver>
176 network_change_observer_;
[email protected]58bc7042010-07-07 18:04:14177
[email protected]0a8db0d2011-04-13 15:15:40178 BooleanPrefMember system_enable_referrers_;
179
[email protected]bcefe0f2010-11-10 16:19:10180 // Store HTTP Auth-related policies in this thread.
181 std::string auth_schemes_;
182 bool negotiate_disable_cname_lookup_;
183 bool negotiate_enable_port_;
184 std::string auth_server_whitelist_;
185 std::string auth_delegate_whitelist_;
[email protected]ac7f3fdb2010-11-12 12:47:05186 std::string gssapi_library_name_;
[email protected]bcefe0f2010-11-10 16:19:10187
[email protected]4d45a6de2011-05-13 05:20:18188 // This is an instance of the default SSLConfigServiceManager for the current
189 // platform and it gets SSL preferences from local_state object.
190 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
191
[email protected]d13c3272010-02-04 00:24:51192 // These member variables are initialized by a task posted to the IO thread,
193 // which gets posted by calling certain member functions of IOThread.
[email protected]db0e86dd2011-03-16 14:47:21194 scoped_ptr<net::ProxyConfigService> system_proxy_config_service_;
195
[email protected]6f96cbcb2011-11-04 02:26:07196 scoped_ptr<PrefProxyConfigTrackerImpl> pref_proxy_config_tracker_;
[email protected]db0e86dd2011-03-16 14:47:21197
[email protected]abe2c032011-03-31 18:49:34198 scoped_refptr<net::URLRequestContextGetter>
199 system_url_request_context_getter_;
[email protected]db0e86dd2011-03-16 14:47:21200
[email protected]3b543ab2011-09-17 21:47:00201 net::SdchManager* sdch_manager_;
202
[email protected]21ee224e2011-11-21 02:17:53203 base::WeakPtrFactory<IOThread> weak_factory_;
[email protected]addb3242011-06-13 21:39:16204
[email protected]0ac83682010-01-22 17:46:27205 DISALLOW_COPY_AND_ASSIGN(IOThread);
206};
207
[email protected]fa55e192010-02-15 14:25:50208#endif // CHROME_BROWSER_IO_THREAD_H_