blob: 4c7374e7b82c55025fc1ae827b29bf129cd80931 [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
8#include "base/basictypes.h"
[email protected]d13c3272010-02-04 00:24:519#include "base/ref_counted.h"
10#include "base/scoped_ptr.h"
[email protected]0ac83682010-01-22 17:46:2711#include "base/task.h"
12#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac039522010-06-15 16:39:4413#include "chrome/browser/net/chrome_network_delegate.h"
[email protected]0ac83682010-01-22 17:46:2714#include "chrome/common/net/dns.h"
15#include "net/base/host_resolver.h"
16
[email protected]9e743cd2010-03-16 07:03:5317class ChromeNetLog;
[email protected]0ac83682010-01-22 17:46:2718class ListValue;
19
20namespace chrome_browser_net {
21class DnsMaster;
22} // namespace chrome_browser_net
23
[email protected]d13c3272010-02-04 00:24:5124namespace net {
[email protected]fa55e192010-02-15 14:25:5025class HttpAuthHandlerFactory;
[email protected]d13c3272010-02-04 00:24:5126class NetworkChangeNotifier;
[email protected]b4955e7d2010-04-16 20:22:3027class URLSecurityManager;
[email protected]d13c3272010-02-04 00:24:5128} // namespace net
29
[email protected]0ac83682010-01-22 17:46:2730class IOThread : public BrowserProcessSubThread {
31 public:
[email protected]d13c3272010-02-04 00:24:5132 struct Globals {
[email protected]9e743cd2010-03-16 07:03:5333 scoped_ptr<ChromeNetLog> net_log;
[email protected]d13c3272010-02-04 00:24:5134 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]fa55e192010-02-15 14:25:5038 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
[email protected]b4955e7d2010-04-16 20:22:3039 scoped_ptr<net::URLSecurityManager> url_security_manager;
[email protected]ac039522010-06-15 16:39:4440 ChromeNetworkDelegate network_delegate;
[email protected]d13c3272010-02-04 00:24:5141 };
42
[email protected]0ac83682010-01-22 17:46:2743 IOThread();
44
45 virtual ~IOThread();
46
[email protected]d13c3272010-02-04 00:24:5147 // Can only be called on the IO thread.
48 Globals* globals();
[email protected]0ac83682010-01-22 17:46:2749
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]760d970a2010-05-18 00:39:1858 ListValue* referral_list,
59 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2760
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]2a92cd92010-04-27 00:01:4167 virtual void CleanUp();
[email protected]9aa33e82010-04-15 00:15:3968 virtual void CleanUpAfterMessageLoopDestruction();
[email protected]0ac83682010-01-22 17:46:2769
70 private:
[email protected]eb3cac72010-02-26 21:07:4571 net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory();
72
[email protected]0ac83682010-01-22 17:46:2773 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]760d970a2010-05-18 00:39:1878 ListValue* referral_list,
79 bool preconnect_enabled);
[email protected]0ac83682010-01-22 17:46:2780
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]2a92cd92010-04-27 00:01:4186 // member variables should be deleted in CleanUp(), except ChromeNetLog
87 // which is deleted later in CleanUpAfterMessageLoopDestruction().
[email protected]0ac83682010-01-22 17:46:2788
[email protected]d13c3272010-02-04 00:24:5189 // 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]2a92cd92010-04-27 00:01:4194 // 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]d13c3272010-02-04 00:24:5199 // 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]0ac83682010-01-22 17:46:27101
102 net::HostResolver::Observer* prefetch_observer_;
103 chrome_browser_net::DnsMaster* dns_master_;
104
105 DISALLOW_COPY_AND_ASSIGN(IOThread);
106};
107
[email protected]fa55e192010-02-15 14:25:50108#endif // CHROME_BROWSER_IO_THREAD_H_