blob: 3443af120ef2a8bfbb81ecbc221c867ece3aa721 [file] [log] [blame]
[email protected]0ac83682010-01-22 17:46:271// Copyright (c) 2010 The Chromium Authors. All rights reserved.
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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]0ac83682010-01-22 17:46:278
[email protected]0ee7a3b2010-11-09 06:13:409#include <list>
[email protected]86933612010-10-16 23:10:3310#include <set>
[email protected]bcefe0f2010-11-10 16:19:1011#include <string>
[email protected]0ac83682010-01-22 17:46:2712#include "base/basictypes.h"
[email protected]d13c3272010-02-04 00:24:5113#include "base/ref_counted.h"
14#include "base/scoped_ptr.h"
[email protected]0ac83682010-01-22 17:46:2715#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac039522010-06-15 16:39:4416#include "chrome/browser/net/chrome_network_delegate.h"
[email protected]3530cd92010-06-27 06:22:0117#include "chrome/common/net/predictor_common.h"
[email protected]58bc7042010-07-07 18:04:1418#include "net/base/network_change_notifier.h"
[email protected]0ac83682010-01-22 17:46:2719
[email protected]9e743cd2010-03-16 07:03:5320class ChromeNetLog;
[email protected]0ee7a3b2010-11-09 06:13:4021class ChromeURLRequestContextGetter;
[email protected]0ac83682010-01-22 17:46:2722class ListValue;
[email protected]bcefe0f2010-11-10 16:19:1023class PrefService;
[email protected]86933612010-10-16 23:10:3324class URLRequestContext;
[email protected]0ac83682010-01-22 17:46:2725
26namespace chrome_browser_net {
[email protected]1889dc1b2010-10-14 22:03:1327class ConnectInterceptor;
[email protected]74be069e82010-06-25 00:12:4928class Predictor;
[email protected]1d14ba552010-11-19 19:07:4029class PrerenderInterceptor;
[email protected]0ac83682010-01-22 17:46:2730} // namespace chrome_browser_net
31
[email protected]d13c3272010-02-04 00:24:5132namespace net {
[email protected]2db580532010-10-08 14:32:3733class DnsRRResolver;
[email protected]1889dc1b2010-10-14 22:03:1334class HostResolver;
[email protected]fa55e192010-02-15 14:25:5035class HttpAuthHandlerFactory;
[email protected]86933612010-10-16 23:10:3336class ProxyScriptFetcher;
[email protected]b4955e7d2010-04-16 20:22:3037class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5138} // namespace net
39
[email protected]0ac83682010-01-22 17:46:2740class IOThread : public BrowserProcessSubThread {
41 public:
[email protected]d13c3272010-02-04 00:24:5142 struct Globals {
[email protected]1889dc1b2010-10-14 22:03:1343 Globals();
44 ~Globals();
45
[email protected]73c45322010-10-01 23:57:5446 scoped_ptr<net::HostResolver> host_resolver;
[email protected]2db580532010-10-08 14:32:3747 scoped_ptr<net::DnsRRResolver> dnsrr_resolver;
[email protected]fa55e192010-02-15 14:25:5048 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]b4955e7d2010-04-16 20:22:3049 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]ac039522010-06-15 16:39:4450 ChromeNetworkDelegate network_delegate;
[email protected]d13c3272010-02-04 00:24:5151 };
52
[email protected]b2fcd0e2010-12-01 15:19:4053 // |net_log| must either outlive the IOThread or be NULL.
54 IOThread(PrefService* local_state, ChromeNetLog* net_log);
[email protected]0ac83682010-01-22 17:46:2755
56 virtual ~IOThread();
57
[email protected]d13c3272010-02-04 00:24:5158 // Can only be called on the IO thread.
59 Globals* globals();
[email protected]0ac83682010-01-22 17:46:2760
[email protected]b2fcd0e2010-12-01 15:19:4061 ChromeNetLog* net_log();
62
[email protected]c5629c32010-06-23 01:22:4363 // Initializes the network predictor, which induces DNS pre-resolution and/or
64 // TCP/IP preconnections. |prefetching_enabled| indicates whether or not DNS
65 // prefetching should be enabled, and |preconnect_enabled| controls whether
66 // TCP/IP preconnection is enabled. This should be called by the UI thread.
67 // It will post a task to the IO thread to perform the actual initialization.
[email protected]74be069e82010-06-25 00:12:4968 void InitNetworkPredictor(bool prefetching_enabled,
69 base::TimeDelta max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:5970 size_t max_speculative_parallel_resolves,
[email protected]74be069e82010-06-25 00:12:4971 const chrome_common_net::UrlList& startup_urls,
72 ListValue* referral_list,
73 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2774
[email protected]0ee7a3b2010-11-09 06:13:4075 // Registers |url_request_context_getter| into the IO thread. During
76 // IOThread::CleanUp(), IOThread will iterate through known getters and
77 // release their URLRequestContexts. Only called on the IO thread. It does
78 // not acquire a refcount for |url_request_context_getter|. If
79 // |url_request_context_getter| is being deleted before IOThread::CleanUp() is
80 // invoked, then this needs to be balanced with a call to
81 // UnregisterURLRequestContextGetter().
82 void RegisterURLRequestContextGetter(
83 ChromeURLRequestContextGetter* url_request_context_getter);
84
85 // Unregisters |url_request_context_getter| from the IO thread. Only called
86 // on the IO thread.
87 void UnregisterURLRequestContextGetter(
88 ChromeURLRequestContextGetter* url_request_context_getter);
89
[email protected]0ac83682010-01-22 17:46:2790 // Handles changing to On The Record mode. Posts a task for this onto the
91 // IOThread's message loop.
92 void ChangedToOnTheRecord();
93
[email protected]86933612010-10-16 23:10:3394 // Creates a ProxyScriptFetcherImpl which will be automatically aborted
95 // during shutdown.
96 // This is used to avoid cycles between the ProxyScriptFetcher and the
97 // URLRequestContext that owns it (indirectly via the ProxyService).
98 net::ProxyScriptFetcher* CreateAndRegisterProxyScriptFetcher(
99 URLRequestContext* url_request_context);
100
[email protected]0ac83682010-01-22 17:46:27101 protected:
102 virtual void Init();
[email protected]2a92cd92010-04-27 00:01:41103 virtual void CleanUp();
[email protected]9aa33e82010-04-15 00:15:39104 virtual void CleanUpAfterMessageLoopDestruction();
[email protected]0ac83682010-01-22 17:46:27105
106 private:
[email protected]86933612010-10-16 23:10:33107 class ManagedProxyScriptFetcher;
108 typedef std::set<ManagedProxyScriptFetcher*> ProxyScriptFetchers;
109
[email protected]bcefe0f2010-11-10 16:19:10110 static void RegisterPrefs(PrefService* local_state);
111
[email protected]65d34382010-07-01 18:12:26112 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(
113 net::HostResolver* resolver);
[email protected]eb3cac72010-02-26 21:07:45114
[email protected]74be069e82010-06-25 00:12:49115 void InitNetworkPredictorOnIOThread(
[email protected]0ac83682010-01-22 17:46:27116 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:49117 base::TimeDelta max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:59118 size_t max_speculative_parallel_resolves,
119 const chrome_common_net::UrlList& startup_urls,
[email protected]760d970a2010-05-18 00:39:18120 ListValue* referral_list,
121 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:27122
123 void ChangedToOnTheRecordOnIOThread();
124
[email protected]b2fcd0e2010-12-01 15:19:40125 // The NetLog is owned by the browser process, to allow logging from other
126 // threads during shutdown, but is used most frequently on the IOThread.
127 ChromeNetLog* net_log_;
128
[email protected]0ac83682010-01-22 17:46:27129 // These member variables are basically global, but their lifetimes are tied
130 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
131 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]b2fcd0e2010-12-01 15:19:40132 // member variables should be deleted in CleanUp().
[email protected]0ac83682010-01-22 17:46:27133
[email protected]d13c3272010-02-04 00:24:51134 // These member variables are initialized in Init() and do not change for the
135 // lifetime of the IO thread.
136
137 Globals* globals_;
138
[email protected]58bc7042010-07-07 18:04:14139 // Observer that logs network changes to the ChromeNetLog.
140 scoped_ptr<net::NetworkChangeNotifier::Observer> network_change_observer_;
141
[email protected]bcefe0f2010-11-10 16:19:10142 // Store HTTP Auth-related policies in this thread.
143 std::string auth_schemes_;
144 bool negotiate_disable_cname_lookup_;
145 bool negotiate_enable_port_;
146 std::string auth_server_whitelist_;
147 std::string auth_delegate_whitelist_;
[email protected]ac7f3fdb2010-11-12 12:47:05148 std::string gssapi_library_name_;
[email protected]bcefe0f2010-11-10 16:19:10149
[email protected]d13c3272010-02-04 00:24:51150 // These member variables are initialized by a task posted to the IO thread,
151 // which gets posted by calling certain member functions of IOThread.
[email protected]0ac83682010-01-22 17:46:27152
[email protected]c5629c32010-06-23 01:22:43153 // Note: we user explicit pointers rather than smart pointers to be more
154 // explicit about destruction order, and ensure that there is no chance that
155 // these observers would be used accidentally after we have begun to tear
156 // down.
157 chrome_browser_net::ConnectInterceptor* speculative_interceptor_;
[email protected]74be069e82010-06-25 00:12:49158 chrome_browser_net::Predictor* predictor_;
[email protected]1d14ba552010-11-19 19:07:40159 scoped_ptr<chrome_browser_net::PrerenderInterceptor>
160 prerender_interceptor_;
[email protected]0ac83682010-01-22 17:46:27161
[email protected]86933612010-10-16 23:10:33162 // List of live ProxyScriptFetchers.
163 ProxyScriptFetchers fetchers_;
164
[email protected]0ee7a3b2010-11-09 06:13:40165 // Keeps track of all live ChromeURLRequestContextGetters, so the
166 // ChromeURLRequestContexts can be released during
167 // IOThread::CleanUpAfterMessageLoopDestruction().
168 std::list<ChromeURLRequestContextGetter*> url_request_context_getters_;
169
[email protected]0ac83682010-01-22 17:46:27170 DISALLOW_COPY_AND_ASSIGN(IOThread);
171};
172
[email protected]fa55e192010-02-15 14:25:50173#endif // CHROME_BROWSER_IO_THREAD_H_