[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 | |
| 8 | #include "base/basictypes.h" |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 9 | #include "base/ref_counted.h" |
| 10 | #include "base/scoped_ptr.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 11 | #include "base/task.h" |
| 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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 14 | #include "chrome/common/net/dns.h" |
| 15 | #include "net/base/host_resolver.h" |
| 16 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 17 | class ChromeNetLog; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 18 | class ListValue; |
| 19 | |
| 20 | namespace chrome_browser_net { |
| 21 | class DnsMaster; |
| 22 | } // namespace chrome_browser_net |
| 23 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 24 | namespace net { |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 25 | class HttpAuthHandlerFactory; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 26 | class NetworkChangeNotifier; |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 27 | class URLSecurityManager; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 28 | } // namespace net |
| 29 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 30 | class IOThread : public BrowserProcessSubThread { |
| 31 | public: |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 32 | struct Globals { |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 33 | scoped_ptr<ChromeNetLog> net_log; |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 34 | scoped_ptr<net::NetworkChangeNotifier> network_change_notifier; |
| 35 | // TODO(willchan): Stop reference counting HostResolver. It's owned by |
| 36 | // IOThread now. |
| 37 | scoped_refptr<net::HostResolver> host_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 | |
| 50 | // Initializes the DnsMaster. |prefetching_enabled| indicates whether or |
| 51 | // not dns prefetching should be enabled. This should be called by the UI |
| 52 | // thread. It will post a task to the IO thread to perform the actual |
| 53 | // initialization. |
| 54 | void InitDnsMaster(bool prefetching_enabled, |
| 55 | base::TimeDelta max_queue_delay, |
| 56 | size_t max_concurrent, |
| 57 | const chrome_common_net::NameList& hostnames_to_prefetch, |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 58 | ListValue* referral_list, |
| 59 | bool preconnect_enabled); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 60 | |
| 61 | // Handles changing to On The Record mode. Posts a task for this onto the |
| 62 | // IOThread's message loop. |
| 63 | void ChangedToOnTheRecord(); |
| 64 | |
| 65 | protected: |
| 66 | virtual void Init(); |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 67 | virtual void CleanUp(); |
[email protected] | 9aa33e8 | 2010-04-15 00:15:39 | [diff] [blame] | 68 | virtual void CleanUpAfterMessageLoopDestruction(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 69 | |
| 70 | private: |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 71 | net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(); |
| 72 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 73 | void InitDnsMasterOnIOThread( |
| 74 | bool prefetching_enabled, |
| 75 | base::TimeDelta max_queue_delay, |
| 76 | size_t max_concurrent, |
| 77 | chrome_common_net::NameList hostnames_to_prefetch, |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 78 | ListValue* referral_list, |
| 79 | bool preconnect_enabled); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 80 | |
| 81 | void ChangedToOnTheRecordOnIOThread(); |
| 82 | |
| 83 | // These member variables are basically global, but their lifetimes are tied |
| 84 | // to the IOThread. IOThread owns them all, despite not using scoped_ptr. |
| 85 | // This is because the destructor of IOThread runs on the wrong thread. All |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 86 | // member variables should be deleted in CleanUp(), except ChromeNetLog |
| 87 | // which is deleted later in CleanUpAfterMessageLoopDestruction(). |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 88 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 89 | // These member variables are initialized in Init() and do not change for the |
| 90 | // lifetime of the IO thread. |
| 91 | |
| 92 | Globals* globals_; |
| 93 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 94 | // This variable is only meaningful during shutdown. It is used to defer |
| 95 | // deletion of the NetLog to CleanUpAfterMessageLoopDestruction() even |
| 96 | // though |globals_| is reset by CleanUp(). |
| 97 | scoped_ptr<ChromeNetLog> deferred_net_log_to_delete_; |
| 98 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 99 | // These member variables are initialized by a task posted to the IO thread, |
| 100 | // which gets posted by calling certain member functions of IOThread. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 101 | |
| 102 | net::HostResolver::Observer* prefetch_observer_; |
| 103 | chrome_browser_net::DnsMaster* dns_master_; |
| 104 | |
| 105 | DISALLOW_COPY_AND_ASSIGN(IOThread); |
| 106 | }; |
| 107 | |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 108 | #endif // CHROME_BROWSER_IO_THREAD_H_ |