[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 1 | // 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] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 11 | #include "base/ref_counted.h" |
| 12 | #include "base/scoped_ptr.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 13 | #include "base/task.h" |
| 14 | #include "chrome/browser/browser_process_sub_thread.h" |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 15 | #include "chrome/browser/net/chrome_network_delegate.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 16 | #include "chrome/common/net/dns.h" |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 17 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 18 | #include "net/base/host_resolver.h" |
| 19 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 20 | class ChromeNetLog; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 21 | class ListValue; |
| 22 | |
| 23 | namespace chrome_browser_net { |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame^] | 24 | class Predictor; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 25 | } // namespace chrome_browser_net |
| 26 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 27 | namespace net { |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 28 | class HttpAuthHandlerFactory; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 29 | class NetworkChangeNotifier; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 30 | class URLSecurityManager; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 31 | } // namespace net |
| 32 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 33 | class IOThread : public BrowserProcessSubThread { |
| 34 | public: |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 35 | struct Globals { |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 36 | scoped_ptr<ChromeNetLog> net_log; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 37 | 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] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 41 | scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 42 | scoped_ptr<net::URLSecurityManager> url_security_manager; |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 43 | ChromeNetworkDelegate network_delegate; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 44 | }; |
| 45 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 46 | IOThread(); |
| 47 | |
| 48 | virtual ~IOThread(); |
| 49 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 50 | // Can only be called on the IO thread. |
| 51 | Globals* globals(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 52 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 53 | // 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] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame^] | 58 | 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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 64 | |
| 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] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 71 | virtual void CleanUp(); |
[email protected] | 9aa33e8 | 2010-04-15 00:15:39 | [diff] [blame] | 72 | virtual void CleanUpAfterMessageLoopDestruction(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 73 | |
| 74 | private: |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 75 | net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(); |
| 76 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame^] | 77 | void InitNetworkPredictorOnIOThread( |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 78 | bool prefetching_enabled, |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame^] | 79 | base::TimeDelta max_dns_queue_delay, |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 80 | size_t max_concurrent, |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 81 | const chrome_common_net::UrlList& startup_urls, |
| 82 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 83 | ListValue* referral_list, |
| 84 | bool preconnect_enabled); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 85 | |
| 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] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 91 | // member variables should be deleted in CleanUp(), except ChromeNetLog |
| 92 | // which is deleted later in CleanUpAfterMessageLoopDestruction(). |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 93 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 94 | // 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] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 99 | // 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] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 104 | // 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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 106 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 107 | // 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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 112 | net::HostResolver::Observer* prefetch_observer_; |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame^] | 113 | chrome_browser_net::Predictor* predictor_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 114 | |
| 115 | DISALLOW_COPY_AND_ASSIGN(IOThread); |
| 116 | }; |
| 117 | |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 118 | #endif // CHROME_BROWSER_IO_THREAD_H_ |