summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 00:24:51 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 00:24:51 +0000
commitd13c32787737f1822202802f062c41c38b90e5f5 (patch)
treef616a6dcf08fee7cc6f5c023e53be4fa501e9ef2 /chrome
parent9becad4ad1adcd4e4339b45f8b90d299fd968a08 (diff)
downloadchromium_src-d13c32787737f1822202802f062c41c38b90e5f5.zip
chromium_src-d13c32787737f1822202802f062c41c38b90e5f5.tar.gz
chromium_src-d13c32787737f1822202802f062c41c38b90e5f5.tar.bz2
Pass the NetworkChangeNotifier to HostResolver.
This requires the following refactors: (1) NetworkChangeNotifier moves out of HttpNetworkSession into IOThread. (2) HostResolver gets initialized with NetworkChangeNotifier. (3) NetworkChangeNotifier needs to get passed into HttpCache and HttpNetworkSession (required updating a lot of files). (4) NetworkChangeNotifier is no longer reference counted. It is owned by IOThread. (5) IOThread gains a new struct: Globals. It can only be used on the io thread. (6) ChromeURLRequestContextFactory uses IOThread::Globals to initialize ChromeURLRequest objects with the host resolver and network change notifier. BUG=26159 Review URL: http://codereview.chromium.org/552117 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/io_thread.cc42
-rw-r--r--chrome/browser/io_thread.h27
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc18
-rw-r--r--chrome/browser/net/chrome_url_request_context.h2
4 files changed, 59 insertions, 30 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 82e2f50..da4bb20 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -15,11 +15,13 @@
#include "net/base/host_cache.h"
#include "net/base/host_resolver.h"
#include "net/base/host_resolver_impl.h"
+#include "net/base/network_change_notifier.h"
#include "net/url_request/url_request.h"
namespace {
-net::HostResolver* CreateGlobalHostResolver() {
+net::HostResolver* CreateGlobalHostResolver(
+ net::NetworkChangeNotifier* network_change_notifier) {
net::HostResolver* global_host_resolver = NULL;
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
@@ -31,7 +33,8 @@ net::HostResolver* CreateGlobalHostResolver() {
command_line.GetSwitchValueASCII(switches::kFixedHost);
global_host_resolver = new net::FixedHostResolver(host);
} else {
- global_host_resolver = net::CreateSystemHostResolver();
+ global_host_resolver =
+ net::CreateSystemHostResolver(network_change_notifier);
if (command_line.HasSwitch(switches::kDisableIPv6))
global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
@@ -52,7 +55,7 @@ struct RunnableMethodTraits<IOThread> {
IOThread::IOThread()
: BrowserProcessSubThread(ChromeThread::IO),
- host_resolver_(NULL),
+ globals_(NULL),
prefetch_observer_(NULL),
dns_master_(NULL) {}
@@ -60,11 +63,12 @@ IOThread::~IOThread() {
// We cannot rely on our base class to stop the thread since we want our
// CleanUp function to run.
Stop();
+ DCHECK(!globals_);
}
-net::HostResolver* IOThread::host_resolver() {
+IOThread::Globals* IOThread::globals() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- return host_resolver_;
+ return globals_;
}
void IOThread::InitDnsMaster(
@@ -95,9 +99,13 @@ void IOThread::ChangedToOnTheRecord() {
void IOThread::Init() {
BrowserProcessSubThread::Init();
- DCHECK(!host_resolver_);
- host_resolver_ = CreateGlobalHostResolver();
- host_resolver_->AddRef();
+ DCHECK(!globals_);
+ globals_ = new Globals;
+
+ globals_->network_change_notifier.reset(
+ net::NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier());
+ globals_->host_resolver =
+ CreateGlobalHostResolver(globals_->network_change_notifier.get());
}
void IOThread::CleanUp() {
@@ -116,18 +124,16 @@ void IOThread::CleanUp() {
// Not initialized in Init(). May not be initialized.
if (prefetch_observer_) {
- host_resolver_->RemoveObserver(prefetch_observer_);
+ globals_->host_resolver->RemoveObserver(prefetch_observer_);
delete prefetch_observer_;
prefetch_observer_ = NULL;
}
// TODO(eroman): temp hack for http://crbug.com/15513
- host_resolver_->Shutdown();
+ globals_->host_resolver->Shutdown();
- // TODO(willchan): Stop reference counting HostResolver. It's owned by
- // IOThread now.
- host_resolver_->Release();
- host_resolver_ = NULL;
+ delete globals_;
+ globals_ = NULL;
// URLFetcher and URLRequest instances must NOT outlive the IO thread.
//
@@ -157,12 +163,12 @@ void IOThread::InitDnsMasterOnIOThread(
chrome_browser_net::EnableDnsPrefetch(prefetching_enabled);
dns_master_ = new chrome_browser_net::DnsMaster(
- host_resolver_, max_queue_delay, max_concurrent);
+ globals_->host_resolver, max_queue_delay, max_concurrent);
dns_master_->AddRef();
DCHECK(!prefetch_observer_);
prefetch_observer_ = chrome_browser_net::CreatePrefetchObserver();
- host_resolver_->AddObserver(prefetch_observer_);
+ globals_->host_resolver->AddObserver(prefetch_observer_);
FinalizeDnsPrefetchInitialization(
dns_master_, prefetch_observer_, hostnames_to_prefetch, referral_list);
@@ -178,9 +184,9 @@ void IOThread::ChangedToOnTheRecordOnIOThread() {
// Clear the host cache to avoid showing entries from the OTR session
// in about:net-internals.
- if (host_resolver_->IsHostResolverImpl()) {
+ if (globals_->host_resolver->IsHostResolverImpl()) {
net::HostCache* host_cache = static_cast<net::HostResolverImpl*>(
- host_resolver_)->cache();
+ globals_->host_resolver.get())->cache();
if (host_cache)
host_cache->clear();
}
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index f93f748..373d118 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_IO_THREAD_H_
#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
#include "base/task.h"
#include "chrome/browser/browser_process_sub_thread.h"
#include "chrome/common/net/dns.h"
@@ -17,13 +19,25 @@ namespace chrome_browser_net {
class DnsMaster;
} // namespace chrome_browser_net
+namespace net {
+class NetworkChangeNotifier;
+} // namespace net
+
class IOThread : public BrowserProcessSubThread {
public:
+ struct Globals {
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier;
+ // TODO(willchan): Stop reference counting HostResolver. It's owned by
+ // IOThread now.
+ scoped_refptr<net::HostResolver> host_resolver;
+ };
+
IOThread();
virtual ~IOThread();
- net::HostResolver* host_resolver();
+ // Can only be called on the IO thread.
+ Globals* globals();
// Initializes the DnsMaster. |prefetching_enabled| indicates whether or
// not dns prefetching should be enabled. This should be called by the UI
@@ -56,10 +70,15 @@ class IOThread : public BrowserProcessSubThread {
// These member variables are basically global, but their lifetimes are tied
// to the IOThread. IOThread owns them all, despite not using scoped_ptr.
// This is because the destructor of IOThread runs on the wrong thread. All
- // member variables should be deleted in CleanUp(). Most of these will be
- // initialized in Init().
+ // member variables should be deleted in CleanUp().
+
+ // These member variables are initialized in Init() and do not change for the
+ // lifetime of the IO thread.
+
+ Globals* globals_;
- net::HostResolver* host_resolver_;
+ // These member variables are initialized by a task posted to the IO thread,
+ // which gets posted by calling certain member functions of IOThread.
net::HostResolver::Observer* prefetch_observer_;
chrome_browser_net::DnsMaster* dns_master_;
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 8013800..a8349e8 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -141,7 +141,7 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
ApplyProfileParametersToContext(context);
// Global host resolver for the context.
- context->set_host_resolver(io_thread()->host_resolver());
+ context->set_host_resolver(io_thread()->globals()->host_resolver);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
@@ -152,7 +152,8 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
MessageLoop::current() /*io_loop*/));
net::HttpCache* cache =
- new net::HttpCache(context->host_resolver(),
+ new net::HttpCache(io_thread()->globals()->network_change_notifier.get(),
+ context->host_resolver(),
context->proxy_service(),
context->ssl_config_service(),
disk_cache_path_, cache_size_);
@@ -262,7 +263,8 @@ ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
context->set_proxy_service(original_context->proxy_service());
net::HttpCache* cache =
- new net::HttpCache(context->host_resolver(), context->proxy_service(),
+ new net::HttpCache(io_thread()->globals()->network_change_notifier.get(),
+ context->host_resolver(), context->proxy_service(),
context->ssl_config_service(), 0);
context->set_cookie_store(new net::CookieMonster);
context->set_cookie_policy(
@@ -371,10 +373,12 @@ ChromeURLRequestContext* FactoryForMedia::Create() {
} else {
// If original HttpCache doesn't exist, simply construct one with a whole
// new set of network stack.
- cache = new net::HttpCache(main_context->host_resolver(),
- main_context->proxy_service(),
- main_context->ssl_config_service(),
- disk_cache_path_, cache_size_);
+ cache = new net::HttpCache(
+ io_thread()->globals()->network_change_notifier.get(),
+ main_context->host_resolver(),
+ main_context->proxy_service(),
+ main_context->ssl_config_service(),
+ disk_cache_path_, cache_size_);
}
if (CommandLine::ForCurrentProcess()->HasSwitch(
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index f52029e..99aed21 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -10,6 +10,7 @@
#include "net/base/cookie_policy.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/host_zoom_map.h"
+#include "chrome/browser/io_thread.h"
#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/browser/net/chrome_cookie_policy.h"
#include "chrome/browser/net/url_request_context_getter.h"
@@ -28,7 +29,6 @@ class ProxyConfig;
class ChromeURLRequestContext;
class ChromeURLRequestContextFactory;
-class IOThread;
// Subclass of URLRequestContext which can be used to store extra information
// for requests.