[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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 8 | |
| 9 | #include "base/basictypes.h" |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 10 | #include "base/ref_counted.h" |
| 11 | #include "base/scoped_ptr.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 12 | #include "chrome/browser/browser_process_sub_thread.h" |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 13 | #include "chrome/browser/net/chrome_network_delegate.h" |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 14 | #include "chrome/common/net/predictor_common.h" |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 15 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 16 | #include "net/base/host_resolver.h" |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 17 | #include "net/base/network_change_notifier.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 18 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 19 | class ChromeNetLog; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 20 | class ListValue; |
| 21 | |
| 22 | namespace chrome_browser_net { |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 23 | class Predictor; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 24 | } // namespace chrome_browser_net |
| 25 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 26 | namespace net { |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame^] | 27 | class DnsRRResolver; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 28 | class HttpAuthHandlerFactory; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 29 | class URLSecurityManager; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 30 | } // namespace net |
| 31 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 32 | class IOThread : public BrowserProcessSubThread { |
| 33 | public: |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 34 | struct Globals { |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 35 | scoped_ptr<ChromeNetLog> net_log; |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 36 | scoped_ptr<net::HostResolver> host_resolver; |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame^] | 37 | scoped_ptr<net::DnsRRResolver> dnsrr_resolver; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 38 | scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 39 | scoped_ptr<net::URLSecurityManager> url_security_manager; |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 40 | ChromeNetworkDelegate network_delegate; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 41 | }; |
| 42 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 43 | IOThread(); |
| 44 | |
| 45 | virtual ~IOThread(); |
| 46 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 47 | // Can only be called on the IO thread. |
| 48 | Globals* globals(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 49 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 50 | // Initializes the network predictor, which induces DNS pre-resolution and/or |
| 51 | // TCP/IP preconnections. |prefetching_enabled| indicates whether or not DNS |
| 52 | // prefetching should be enabled, and |preconnect_enabled| controls whether |
| 53 | // TCP/IP preconnection is enabled. This should be called by the UI thread. |
| 54 | // 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] | 55 | void InitNetworkPredictor(bool prefetching_enabled, |
| 56 | base::TimeDelta max_dns_queue_delay, |
| 57 | size_t max_concurrent, |
| 58 | const chrome_common_net::UrlList& startup_urls, |
| 59 | ListValue* referral_list, |
| 60 | bool preconnect_enabled); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 61 | |
| 62 | // Handles changing to On The Record mode. Posts a task for this onto the |
| 63 | // IOThread's message loop. |
| 64 | void ChangedToOnTheRecord(); |
| 65 | |
| 66 | protected: |
| 67 | virtual void Init(); |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 68 | virtual void CleanUp(); |
[email protected] | 9aa33e8 | 2010-04-15 00:15:39 | [diff] [blame] | 69 | virtual void CleanUpAfterMessageLoopDestruction(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 70 | |
| 71 | private: |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 72 | net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory( |
| 73 | net::HostResolver* resolver); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 74 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 75 | void InitNetworkPredictorOnIOThread( |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 76 | bool prefetching_enabled, |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 77 | base::TimeDelta max_dns_queue_delay, |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 78 | size_t max_concurrent, |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 79 | const chrome_common_net::UrlList& startup_urls, |
| 80 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 81 | ListValue* referral_list, |
| 82 | bool preconnect_enabled); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 83 | |
| 84 | void ChangedToOnTheRecordOnIOThread(); |
| 85 | |
| 86 | // These member variables are basically global, but their lifetimes are tied |
| 87 | // to the IOThread. IOThread owns them all, despite not using scoped_ptr. |
| 88 | // This is because the destructor of IOThread runs on the wrong thread. All |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 89 | // member variables should be deleted in CleanUp(), except ChromeNetLog |
| 90 | // which is deleted later in CleanUpAfterMessageLoopDestruction(). |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 91 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 92 | // These member variables are initialized in Init() and do not change for the |
| 93 | // lifetime of the IO thread. |
| 94 | |
| 95 | Globals* globals_; |
| 96 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 97 | // This variable is only meaningful during shutdown. It is used to defer |
| 98 | // deletion of the NetLog to CleanUpAfterMessageLoopDestruction() even |
| 99 | // though |globals_| is reset by CleanUp(). |
| 100 | scoped_ptr<ChromeNetLog> deferred_net_log_to_delete_; |
| 101 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 102 | // Observer that logs network changes to the ChromeNetLog. |
| 103 | scoped_ptr<net::NetworkChangeNotifier::Observer> network_change_observer_; |
| 104 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 105 | // These member variables are initialized by a task posted to the IO thread, |
| 106 | // which gets posted by calling certain member functions of IOThread. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 107 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 108 | // Note: we user explicit pointers rather than smart pointers to be more |
| 109 | // explicit about destruction order, and ensure that there is no chance that |
| 110 | // these observers would be used accidentally after we have begun to tear |
| 111 | // down. |
| 112 | chrome_browser_net::ConnectInterceptor* speculative_interceptor_; |
[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_ |