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