blob: 09f4df4e8d283e1f274335acffccdde16bf2308b [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]86933612010-10-16 23:10:339#include <set>
[email protected]43590112010-10-25 18:48:0610
[email protected]0ac83682010-01-22 17:46:2711#include "base/basictypes.h"
[email protected]d13c3272010-02-04 00:24:5112#include "base/ref_counted.h"
13#include "base/scoped_ptr.h"
[email protected]0ac83682010-01-22 17:46:2714#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac039522010-06-15 16:39:4415#include "chrome/browser/net/chrome_network_delegate.h"
[email protected]3530cd92010-06-27 06:22:0116#include "chrome/common/net/predictor_common.h"
[email protected]58bc7042010-07-07 18:04:1417#include "net/base/network_change_notifier.h"
[email protected]0ac83682010-01-22 17:46:2718
[email protected]9e743cd2010-03-16 07:03:5319class ChromeNetLog;
[email protected]0ac83682010-01-22 17:46:2720class ListValue;
[email protected]86933612010-10-16 23:10:3321class URLRequestContext;
[email protected]0ac83682010-01-22 17:46:2722
23namespace chrome_browser_net {
[email protected]1889dc1b2010-10-14 22:03:1324class ConnectInterceptor;
[email protected]74be069e82010-06-25 00:12:4925class Predictor;
[email protected]0ac83682010-01-22 17:46:2726} // namespace chrome_browser_net
27
[email protected]d13c3272010-02-04 00:24:5128namespace net {
[email protected]2db580532010-10-08 14:32:3729class DnsRRResolver;
[email protected]1889dc1b2010-10-14 22:03:1330class HostResolver;
[email protected]fa55e192010-02-15 14:25:5031class HttpAuthHandlerFactory;
[email protected]86933612010-10-16 23:10:3332class ProxyScriptFetcher;
[email protected]b4955e7d2010-04-16 20:22:3033class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5134} // namespace net
35
[email protected]0ac83682010-01-22 17:46:2736class IOThread : public BrowserProcessSubThread {
37 public:
[email protected]d13c3272010-02-04 00:24:5138 struct Globals {
[email protected]1889dc1b2010-10-14 22:03:1339 Globals();
40 ~Globals();
41
[email protected]9e743cd2010-03-16 07:03:5342 scoped_ptr<ChromeNetLog> net_log;
[email protected]73c45322010-10-01 23:57:5443 scoped_ptr<net::HostResolver> host_resolver;
[email protected]2db580532010-10-08 14:32:3744 scoped_ptr<net::DnsRRResolver> dnsrr_resolver;
[email protected]fa55e192010-02-15 14:25:5045 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]b4955e7d2010-04-16 20:22:3046 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]ac039522010-06-15 16:39:4447 ChromeNetworkDelegate network_delegate;
[email protected]d13c3272010-02-04 00:24:5148 };
49
[email protected]0ac83682010-01-22 17:46:2750 IOThread();
51
52 virtual ~IOThread();
53
[email protected]d13c3272010-02-04 00:24:5154 // Can only be called on the IO thread.
55 Globals* globals();
[email protected]0ac83682010-01-22 17:46:2756
[email protected]c5629c32010-06-23 01:22:4357 // Initializes the network predictor, which induces DNS pre-resolution and/or
58 // TCP/IP preconnections. |prefetching_enabled| indicates whether or not DNS
59 // prefetching should be enabled, and |preconnect_enabled| controls whether
60 // TCP/IP preconnection is enabled. This should be called by the UI thread.
61 // It will post a task to the IO thread to perform the actual initialization.
[email protected]74be069e82010-06-25 00:12:4962 void InitNetworkPredictor(bool prefetching_enabled,
63 base::TimeDelta max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:5964 size_t max_speculative_parallel_resolves,
[email protected]74be069e82010-06-25 00:12:4965 const chrome_common_net::UrlList& startup_urls,
66 ListValue* referral_list,
67 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2768
69 // Handles changing to On The Record mode. Posts a task for this onto the
70 // IOThread's message loop.
71 void ChangedToOnTheRecord();
72
[email protected]86933612010-10-16 23:10:3373 // Creates a ProxyScriptFetcherImpl which will be automatically aborted
74 // during shutdown.
75 // This is used to avoid cycles between the ProxyScriptFetcher and the
76 // URLRequestContext that owns it (indirectly via the ProxyService).
77 net::ProxyScriptFetcher* CreateAndRegisterProxyScriptFetcher(
78 URLRequestContext* url_request_context);
79
[email protected]0ac83682010-01-22 17:46:2780 protected:
81 virtual void Init();
[email protected]2a92cd92010-04-27 00:01:4182 virtual void CleanUp();
[email protected]9aa33e82010-04-15 00:15:3983 virtual void CleanUpAfterMessageLoopDestruction();
[email protected]0ac83682010-01-22 17:46:2784
85 private:
[email protected]86933612010-10-16 23:10:3386 class ManagedProxyScriptFetcher;
87 typedef std::set<ManagedProxyScriptFetcher*> ProxyScriptFetchers;
88
[email protected]65d34382010-07-01 18:12:2689 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(
90 net::HostResolver* resolver);
[email protected]eb3cac72010-02-26 21:07:4591
[email protected]74be069e82010-06-25 00:12:4992 void InitNetworkPredictorOnIOThread(
[email protected]0ac83682010-01-22 17:46:2793 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:4994 base::TimeDelta max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:5995 size_t max_speculative_parallel_resolves,
96 const chrome_common_net::UrlList& startup_urls,
[email protected]760d970a2010-05-18 00:39:1897 ListValue* referral_list,
98 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2799
100 void ChangedToOnTheRecordOnIOThread();
101
102 // These member variables are basically global, but their lifetimes are tied
103 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
104 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]2a92cd92010-04-27 00:01:41105 // member variables should be deleted in CleanUp(), except ChromeNetLog
106 // which is deleted later in CleanUpAfterMessageLoopDestruction().
[email protected]0ac83682010-01-22 17:46:27107
[email protected]d13c3272010-02-04 00:24:51108 // These member variables are initialized in Init() and do not change for the
109 // lifetime of the IO thread.
110
111 Globals* globals_;
112
[email protected]2a92cd92010-04-27 00:01:41113 // This variable is only meaningful during shutdown. It is used to defer
114 // deletion of the NetLog to CleanUpAfterMessageLoopDestruction() even
115 // though |globals_| is reset by CleanUp().
116 scoped_ptr<ChromeNetLog> deferred_net_log_to_delete_;
117
[email protected]58bc7042010-07-07 18:04:14118 // Observer that logs network changes to the ChromeNetLog.
119 scoped_ptr<net::NetworkChangeNotifier::Observer> network_change_observer_;
120
[email protected]d13c3272010-02-04 00:24:51121 // These member variables are initialized by a task posted to the IO thread,
122 // which gets posted by calling certain member functions of IOThread.
[email protected]0ac83682010-01-22 17:46:27123
[email protected]c5629c32010-06-23 01:22:43124 // Note: we user explicit pointers rather than smart pointers to be more
125 // explicit about destruction order, and ensure that there is no chance that
126 // these observers would be used accidentally after we have begun to tear
127 // down.
128 chrome_browser_net::ConnectInterceptor* speculative_interceptor_;
[email protected]74be069e82010-06-25 00:12:49129 chrome_browser_net::Predictor* predictor_;
[email protected]0ac83682010-01-22 17:46:27130
[email protected]86933612010-10-16 23:10:33131 // List of live ProxyScriptFetchers.
132 ProxyScriptFetchers fetchers_;
133
[email protected]0ac83682010-01-22 17:46:27134 DISALLOW_COPY_AND_ASSIGN(IOThread);
135};
136
[email protected]fa55e192010-02-15 14:25:50137#endif // CHROME_BROWSER_IO_THREAD_H_