blob: 974dab4c485c0af1856c0ad6450dd81d175083e9 [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]27a112c2011-01-06 04:19:3044class URLRequestContext;
[email protected]abe2c032011-03-31 18:49:3445class URLRequestContextGetter;
[email protected]b4955e7d2010-04-16 20:22:3046class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5147} // namespace net
48
[email protected]2e5b60a22011-11-28 15:56:4149// Contains state associated with, initialized and cleaned up on, and
[email protected]dd483702011-12-02 14:47:4250// primarily used on, the IO thread.
[email protected]2e5b60a22011-11-28 15:56:4151class IOThread : public content::BrowserThreadDelegate {
[email protected]0ac83682010-01-22 17:46:2752 public:
[email protected]d13c3272010-02-04 00:24:5153 struct Globals {
[email protected]1889dc1b2010-10-14 22:03:1354 Globals();
55 ~Globals();
56
[email protected]cc87500b2011-06-24 20:59:1957 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]0651b812011-02-24 00:22:5064 // The "system" NetworkDelegate, used for Profile-agnostic network events.
65 scoped_ptr<net::NetworkDelegate> system_network_delegate;
[email protected]73c45322010-10-01 23:57:5466 scoped_ptr<net::HostResolver> host_resolver;
[email protected]822581d2010-12-16 17:27:1567 scoped_ptr<net::CertVerifier> cert_verifier;
[email protected]2db580532010-10-08 14:32:3768 scoped_ptr<net::DnsRRResolver> dnsrr_resolver;
[email protected]2fb629202010-12-23 23:52:5769 scoped_refptr<net::SSLConfigService> ssl_config_service;
[email protected]fa55e192010-02-15 14:25:5070 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]17291a022011-10-10 07:32:5371 scoped_ptr<net::HttpServerProperties> http_server_properties;
[email protected]6104ea5d2011-04-27 21:37:1272 scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
[email protected]52617df2010-12-24 07:30:0173 scoped_ptr<net::HttpTransactionFactory>
74 proxy_script_fetcher_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:0275 scoped_ptr<net::FtpTransactionFactory>
76 proxy_script_fetcher_ftp_transaction_factory;
[email protected]b4955e7d2010-04-16 20:22:3077 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]77feb462011-05-16 23:37:2578 // 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]27a112c2011-01-06 04:19:3084 scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context;
[email protected]6104ea5d2011-04-27 21:37:1285 scoped_ptr<net::ProxyService> system_proxy_service;
[email protected]db0e86dd2011-03-16 14:47:2186 scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory;
[email protected]933bc5c62011-04-12 19:08:0287 scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory;
[email protected]db0e86dd2011-03-16 14:47:2188 scoped_refptr<net::URLRequestContext> system_request_context;
[email protected]273e37d2011-08-11 01:49:1289 // |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]3ce02412011-03-01 12:01:1593 scoped_refptr<ExtensionEventRouterForwarder>
94 extension_event_router_forwarder;
[email protected]d13c3272010-02-04 00:24:5195 };
96
[email protected]b2fcd0e2010-12-01 15:19:4097 // |net_log| must either outlive the IOThread or be NULL.
[email protected]3ce02412011-03-01 12:01:1598 IOThread(PrefService* local_state,
99 ChromeNetLog* net_log,
100 ExtensionEventRouterForwarder* extension_event_router_forwarder);
[email protected]0ac83682010-01-22 17:46:27101
102 virtual ~IOThread();
103
[email protected]d13c3272010-02-04 00:24:51104 // Can only be called on the IO thread.
105 Globals* globals();
[email protected]0ac83682010-01-22 17:46:27106
[email protected]b2fcd0e2010-12-01 15:19:40107 ChromeNetLog* net_log();
108
[email protected]b09f76d62011-12-07 01:51:06109 // Handles changing to On The Record mode, discarding confidential data.
110 void ChangedToOnTheRecord();
111
[email protected]db0e86dd2011-03-16 14:47:21112 // Returns a getter for the URLRequestContext. Only called on the UI thread.
[email protected]abe2c032011-03-31 18:49:34113 net::URLRequestContextGetter* system_url_request_context_getter();
[email protected]db0e86dd2011-03-16 14:47:21114
[email protected]67372ecf2011-09-10 01:30:46115 // 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]d6f37fc2011-02-13 23:58:41119
[email protected]2e5b60a22011-11-28 15:56:41120 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]0d5c08e2011-11-21 16:51:06124 virtual void Init() OVERRIDE;
125 virtual void CleanUp() OVERRIDE;
[email protected]0ac83682010-01-22 17:46:27126
[email protected]db0e86dd2011-03-16 14:47:21127 // Provide SystemURLRequestContextGetter with access to
128 // InitSystemRequestContext().
129 friend class SystemURLRequestContextGetter;
130
[email protected]2e5b60a22011-11-28 15:56:41131 // 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]bcefe0f2010-11-10 16:19:10141 static void RegisterPrefs(PrefService* local_state);
142
[email protected]65d34382010-07-01 18:12:26143 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(
144 net::HostResolver* resolver);
[email protected]eb3cac72010-02-26 21:07:45145
[email protected]4d45a6de2011-05-13 05:20:18146 // Returns an SSLConfigService instance.
147 net::SSLConfigService* GetSSLConfigService();
148
[email protected]b09f76d62011-12-07 01:51:06149 void ChangedToOnTheRecordOnIOThread();
150
[email protected]b2fcd0e2010-12-01 15:19:40151 // 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]3ce02412011-03-01 12:01:15155 // The ExtensionEventRouterForwarder allows for sending events to extensions
156 // from the IOThread.
157 ExtensionEventRouterForwarder* extension_event_router_forwarder_;
158
[email protected]0ac83682010-01-22 17:46:27159 // 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]b2fcd0e2010-12-01 15:19:40162 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27163
[email protected]d13c3272010-02-04 00:24:51164 // 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]58bc7042010-07-07 18:04:14169 // Observer that logs network changes to the ChromeNetLog.
[email protected]232a5812011-03-04 22:42:08170 scoped_ptr<net::NetworkChangeNotifier::IPAddressObserver>
171 network_change_observer_;
[email protected]58bc7042010-07-07 18:04:14172
[email protected]0a8db0d2011-04-13 15:15:40173 BooleanPrefMember system_enable_referrers_;
174
[email protected]bcefe0f2010-11-10 16:19:10175 // 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]ac7f3fdb2010-11-12 12:47:05181 std::string gssapi_library_name_;
[email protected]bcefe0f2010-11-10 16:19:10182
[email protected]4d45a6de2011-05-13 05:20:18183 // 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]d13c3272010-02-04 00:24:51187 // 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]db0e86dd2011-03-16 14:47:21189 scoped_ptr<net::ProxyConfigService> system_proxy_config_service_;
190
[email protected]6f96cbcb2011-11-04 02:26:07191 scoped_ptr<PrefProxyConfigTrackerImpl> pref_proxy_config_tracker_;
[email protected]db0e86dd2011-03-16 14:47:21192
[email protected]abe2c032011-03-31 18:49:34193 scoped_refptr<net::URLRequestContextGetter>
194 system_url_request_context_getter_;
[email protected]db0e86dd2011-03-16 14:47:21195
[email protected]3b543ab2011-09-17 21:47:00196 net::SdchManager* sdch_manager_;
197
[email protected]21ee224e2011-11-21 02:17:53198 base::WeakPtrFactory<IOThread> weak_factory_;
[email protected]addb3242011-06-13 21:39:16199
[email protected]0ac83682010-01-22 17:46:27200 DISALLOW_COPY_AND_ASSIGN(IOThread);
201};
202
[email protected]fa55e192010-02-15 14:25:50203#endif // CHROME_BROWSER_IO_THREAD_H_