blob: 9708509af258aace8f244f43d7a7c4c4adb622a6 [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_
7
[email protected]c5629c32010-06-23 01:22:438#include <vector>
9
[email protected]0ac83682010-01-22 17:46:2710#include "base/basictypes.h"
[email protected]d13c3272010-02-04 00:24:5111#include "base/ref_counted.h"
12#include "base/scoped_ptr.h"
[email protected]0ac83682010-01-22 17:46:2713#include "base/task.h"
14#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]0ac83682010-01-22 17:46:2716#include "chrome/common/net/dns.h"
[email protected]c5629c32010-06-23 01:22:4317#include "chrome/browser/net/connect_interceptor.h"
[email protected]0ac83682010-01-22 17:46:2718#include "net/base/host_resolver.h"
19
[email protected]9e743cd2010-03-16 07:03:5320class ChromeNetLog;
[email protected]0ac83682010-01-22 17:46:2721class ListValue;
22
23namespace chrome_browser_net {
[email protected]74be069e82010-06-25 00:12:4924class Predictor;
[email protected]0ac83682010-01-22 17:46:2725} // namespace chrome_browser_net
26
[email protected]d13c3272010-02-04 00:24:5127namespace net {
[email protected]fa55e192010-02-15 14:25:5028class HttpAuthHandlerFactory;
[email protected]d13c3272010-02-04 00:24:5129class NetworkChangeNotifier;
[email protected]b4955e7d2010-04-16 20:22:3030class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5131} // namespace net
32
[email protected]0ac83682010-01-22 17:46:2733class IOThread : public BrowserProcessSubThread {
34 public:
[email protected]d13c3272010-02-04 00:24:5135 struct Globals {
[email protected]9e743cd2010-03-16 07:03:5336 scoped_ptr<ChromeNetLog> net_log;
[email protected]d13c3272010-02-04 00:24:5137 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier;
38 // TODO(willchan): Stop reference counting HostResolver. It's owned by
39 // IOThread now.
40 scoped_refptr<net::HostResolver> host_resolver;
[email protected]fa55e192010-02-15 14:25:5041 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]b4955e7d2010-04-16 20:22:3042 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]ac039522010-06-15 16:39:4443 ChromeNetworkDelegate network_delegate;
[email protected]d13c3272010-02-04 00:24:5144 };
45
[email protected]0ac83682010-01-22 17:46:2746 IOThread();
47
48 virtual ~IOThread();
49
[email protected]d13c3272010-02-04 00:24:5150 // Can only be called on the IO thread.
51 Globals* globals();
[email protected]0ac83682010-01-22 17:46:2752
[email protected]c5629c32010-06-23 01:22:4353 // Initializes the network predictor, which induces DNS pre-resolution and/or
54 // TCP/IP preconnections. |prefetching_enabled| indicates whether or not DNS
55 // prefetching should be enabled, and |preconnect_enabled| controls whether
56 // TCP/IP preconnection is enabled. This should be called by the UI thread.
57 // It will post a task to the IO thread to perform the actual initialization.
[email protected]74be069e82010-06-25 00:12:4958 void InitNetworkPredictor(bool prefetching_enabled,
59 base::TimeDelta max_dns_queue_delay,
60 size_t max_concurrent,
61 const chrome_common_net::UrlList& startup_urls,
62 ListValue* referral_list,
63 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2764
65 // Handles changing to On The Record mode. Posts a task for this onto the
66 // IOThread's message loop.
67 void ChangedToOnTheRecord();
68
69 protected:
70 virtual void Init();
[email protected]2a92cd92010-04-27 00:01:4171 virtual void CleanUp();
[email protected]9aa33e82010-04-15 00:15:3972 virtual void CleanUpAfterMessageLoopDestruction();
[email protected]0ac83682010-01-22 17:46:2773
74 private:
[email protected]eb3cac72010-02-26 21:07:4575 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory();
76
[email protected]74be069e82010-06-25 00:12:4977 void InitNetworkPredictorOnIOThread(
[email protected]0ac83682010-01-22 17:46:2778 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:4979 base::TimeDelta max_dns_queue_delay,
[email protected]0ac83682010-01-22 17:46:2780 size_t max_concurrent,
[email protected]c5629c32010-06-23 01:22:4381 const chrome_common_net::UrlList& startup_urls,
82
[email protected]760d970a2010-05-18 00:39:1883 ListValue* referral_list,
84 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2785
86 void ChangedToOnTheRecordOnIOThread();
87
88 // These member variables are basically global, but their lifetimes are tied
89 // to the IOThread. IOThread owns them all, despite not using scoped_ptr.
90 // This is because the destructor of IOThread runs on the wrong thread. All
[email protected]2a92cd92010-04-27 00:01:4191 // member variables should be deleted in CleanUp(), except ChromeNetLog
92 // which is deleted later in CleanUpAfterMessageLoopDestruction().
[email protected]0ac83682010-01-22 17:46:2793
[email protected]d13c3272010-02-04 00:24:5194 // These member variables are initialized in Init() and do not change for the
95 // lifetime of the IO thread.
96
97 Globals* globals_;
98
[email protected]2a92cd92010-04-27 00:01:4199 // This variable is only meaningful during shutdown. It is used to defer
100 // deletion of the NetLog to CleanUpAfterMessageLoopDestruction() even
101 // though |globals_| is reset by CleanUp().
102 scoped_ptr<ChromeNetLog> deferred_net_log_to_delete_;
103
[email protected]d13c3272010-02-04 00:24:51104 // These member variables are initialized by a task posted to the IO thread,
105 // which gets posted by calling certain member functions of IOThread.
[email protected]0ac83682010-01-22 17:46:27106
[email protected]c5629c32010-06-23 01:22:43107 // Note: we user explicit pointers rather than smart pointers to be more
108 // explicit about destruction order, and ensure that there is no chance that
109 // these observers would be used accidentally after we have begun to tear
110 // down.
111 chrome_browser_net::ConnectInterceptor* speculative_interceptor_;
[email protected]0ac83682010-01-22 17:46:27112 net::HostResolver::Observer* prefetch_observer_;
[email protected]74be069e82010-06-25 00:12:49113 chrome_browser_net::Predictor* predictor_;
[email protected]0ac83682010-01-22 17:46:27114
115 DISALLOW_COPY_AND_ASSIGN(IOThread);
116};
117
[email protected]fa55e192010-02-15 14:25:50118#endif // CHROME_BROWSER_IO_THREAD_H_