[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 2 | // 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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 8 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 9 | #include <string> |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 10 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
| 13 | #include "base/memory/ref_counted.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 16 | #include "chrome/browser/net/ssl_config_service_manager.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 17 | #include "chrome/browser/prefs/pref_member.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 18 | #include "content/public/browser/browser_thread.h" |
| 19 | #include "content/public/browser/browser_thread_delegate.h" |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 20 | #include "net/base/network_change_notifier.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 21 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 22 | class ChromeNetLog; |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 23 | class ExtensionEventRouterForwarder; |
[email protected] | cc87500b | 2011-06-24 20:59:19 | [diff] [blame] | 24 | class MediaInternals; |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 25 | class PrefProxyConfigTrackerImpl; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 26 | class PrefService; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 27 | class SystemURLRequestContextGetter; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 28 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 29 | namespace net { |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 30 | class CertVerifier; |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 31 | class CookieStore; |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame] | 32 | class DnsRRResolver; |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 33 | class FtpTransactionFactory; |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 34 | class HostResolver; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 35 | class HttpAuthHandlerFactory; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 36 | class HttpServerProperties; |
[email protected] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 37 | class HttpTransactionFactory; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 38 | class NetworkDelegate; |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 39 | class OriginBoundCertService; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 40 | class ProxyConfigService; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 41 | class ProxyService; |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 42 | class SdchManager; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 43 | class SSLConfigService; |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 44 | class URLRequestContext; |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 45 | class URLRequestContextGetter; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 46 | class URLSecurityManager; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 47 | } // namespace net |
| 48 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 49 | // Contains state associated with, initialized and cleaned up on, and |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 50 | // primarily used on, the IO thread. |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 51 | class IOThread : public content::BrowserThreadDelegate { |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 52 | public: |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 53 | struct Globals { |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 54 | Globals(); |
| 55 | ~Globals(); |
| 56 | |
[email protected] | cc87500b | 2011-06-24 20:59:19 | [diff] [blame] | 57 | struct MediaGlobals { |
| 58 | MediaGlobals(); |
| 59 | ~MediaGlobals(); |
| 60 | // MediaInternals singleton used to aggregate media information. |
| 61 | scoped_ptr<MediaInternals> media_internals; |
| 62 | } media; |
| 63 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 64 | // The "system" NetworkDelegate, used for Profile-agnostic network events. |
| 65 | scoped_ptr<net::NetworkDelegate> system_network_delegate; |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 66 | scoped_ptr<net::HostResolver> host_resolver; |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 67 | scoped_ptr<net::CertVerifier> cert_verifier; |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame] | 68 | scoped_ptr<net::DnsRRResolver> dnsrr_resolver; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 69 | scoped_refptr<net::SSLConfigService> ssl_config_service; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 70 | scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 71 | scoped_ptr<net::HttpServerProperties> http_server_properties; |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 72 | scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service; |
[email protected] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 73 | scoped_ptr<net::HttpTransactionFactory> |
| 74 | proxy_script_fetcher_http_transaction_factory; |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 75 | scoped_ptr<net::FtpTransactionFactory> |
| 76 | proxy_script_fetcher_ftp_transaction_factory; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 77 | scoped_ptr<net::URLSecurityManager> url_security_manager; |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 78 | // We use a separate URLRequestContext for PAC fetches, in order to break |
| 79 | // the reference cycle: |
| 80 | // URLRequestContext=>PAC fetch=>URLRequest=>URLRequestContext. |
| 81 | // The first URLRequestContext is |system_url_request_context|. We introduce |
| 82 | // |proxy_script_fetcher_context| for the second context. It has a direct |
| 83 | // ProxyService, since we always directly connect to fetch the PAC script. |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 84 | scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context; |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 85 | scoped_ptr<net::ProxyService> system_proxy_service; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 86 | scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory; |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 87 | scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 88 | scoped_refptr<net::URLRequestContext> system_request_context; |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 89 | // |cookie_store| and |origin_bound_cert_service| are shared between |
| 90 | // |proxy_script_fetcher_context| and |system_request_context|. |
| 91 | scoped_refptr<net::CookieStore> system_cookie_store; |
| 92 | scoped_ptr<net::OriginBoundCertService> system_origin_bound_cert_service; |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 93 | scoped_refptr<ExtensionEventRouterForwarder> |
| 94 | extension_event_router_forwarder; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 95 | }; |
| 96 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 97 | // |net_log| must either outlive the IOThread or be NULL. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 98 | IOThread(PrefService* local_state, |
| 99 | ChromeNetLog* net_log, |
| 100 | ExtensionEventRouterForwarder* extension_event_router_forwarder); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 101 | |
| 102 | virtual ~IOThread(); |
| 103 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 104 | // Can only be called on the IO thread. |
| 105 | Globals* globals(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 106 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 107 | ChromeNetLog* net_log(); |
| 108 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame^] | 109 | // Handles changing to On The Record mode, discarding confidential data. |
| 110 | void ChangedToOnTheRecord(); |
| 111 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 112 | // Returns a getter for the URLRequestContext. Only called on the UI thread. |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 113 | net::URLRequestContextGetter* system_url_request_context_getter(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 114 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 115 | // Clears the host cache. Intended to be used to prevent exposing recently |
| 116 | // visited sites on about:net-internals/#dns and about:dns pages. Must be |
| 117 | // called on the IO thread. |
| 118 | void ClearHostCache(); |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 119 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 120 | private: |
| 121 | // BrowserThreadDelegate implementation, runs on the IO thread. |
| 122 | // This handles initialization and destruction of state that must |
| 123 | // live on the IO thread. |
[email protected] | 0d5c08e | 2011-11-21 16:51:06 | [diff] [blame] | 124 | virtual void Init() OVERRIDE; |
| 125 | virtual void CleanUp() OVERRIDE; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 126 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 127 | // Provide SystemURLRequestContextGetter with access to |
| 128 | // InitSystemRequestContext(). |
| 129 | friend class SystemURLRequestContextGetter; |
| 130 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 131 | // Global state must be initialized on the IO thread, then this |
| 132 | // method must be invoked on the UI thread. |
| 133 | void InitSystemRequestContext(); |
| 134 | |
| 135 | // Lazy initialization of system request context for |
| 136 | // SystemURLRequestContextGetter. To be called on IO thread only |
| 137 | // after global state has been initialized on the IO thread, and |
| 138 | // SystemRequestContext state has been initialized on the UI thread. |
| 139 | void InitSystemRequestContextOnIOThread(); |
| 140 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 141 | static void RegisterPrefs(PrefService* local_state); |
| 142 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 143 | net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory( |
| 144 | net::HostResolver* resolver); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 145 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 146 | // Returns an SSLConfigService instance. |
| 147 | net::SSLConfigService* GetSSLConfigService(); |
| 148 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame^] | 149 | void ChangedToOnTheRecordOnIOThread(); |
| 150 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 151 | // The NetLog is owned by the browser process, to allow logging from other |
| 152 | // threads during shutdown, but is used most frequently on the IOThread. |
| 153 | ChromeNetLog* net_log_; |
| 154 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 155 | // The ExtensionEventRouterForwarder allows for sending events to extensions |
| 156 | // from the IOThread. |
| 157 | ExtensionEventRouterForwarder* extension_event_router_forwarder_; |
| 158 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 159 | // These member variables are basically global, but their lifetimes are tied |
| 160 | // to the IOThread. IOThread owns them all, despite not using scoped_ptr. |
| 161 | // This is because the destructor of IOThread runs on the wrong thread. All |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 162 | // member variables should be deleted in CleanUp(). |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 163 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 164 | // These member variables are initialized in Init() and do not change for the |
| 165 | // lifetime of the IO thread. |
| 166 | |
| 167 | Globals* globals_; |
| 168 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 169 | // Observer that logs network changes to the ChromeNetLog. |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 170 | scoped_ptr<net::NetworkChangeNotifier::IPAddressObserver> |
| 171 | network_change_observer_; |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 172 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 173 | BooleanPrefMember system_enable_referrers_; |
| 174 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 175 | // Store HTTP Auth-related policies in this thread. |
| 176 | std::string auth_schemes_; |
| 177 | bool negotiate_disable_cname_lookup_; |
| 178 | bool negotiate_enable_port_; |
| 179 | std::string auth_server_whitelist_; |
| 180 | std::string auth_delegate_whitelist_; |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 181 | std::string gssapi_library_name_; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 182 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 183 | // This is an instance of the default SSLConfigServiceManager for the current |
| 184 | // platform and it gets SSL preferences from local_state object. |
| 185 | scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; |
| 186 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 187 | // These member variables are initialized by a task posted to the IO thread, |
| 188 | // which gets posted by calling certain member functions of IOThread. |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 189 | scoped_ptr<net::ProxyConfigService> system_proxy_config_service_; |
| 190 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 191 | scoped_ptr<PrefProxyConfigTrackerImpl> pref_proxy_config_tracker_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 192 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 193 | scoped_refptr<net::URLRequestContextGetter> |
| 194 | system_url_request_context_getter_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 195 | |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 196 | net::SdchManager* sdch_manager_; |
| 197 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 198 | base::WeakPtrFactory<IOThread> weak_factory_; |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 199 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 200 | DISALLOW_COPY_AND_ASSIGN(IOThread); |
| 201 | }; |
| 202 | |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 203 | #endif // CHROME_BROWSER_IO_THREAD_H_ |