summaryrefslogtreecommitdiffstats
path: root/net/base
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 /net/base
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 'net/base')
-rw-r--r--net/base/host_resolver.h6
-rw-r--r--net/base/host_resolver_impl.cc7
-rw-r--r--net/base/host_resolver_impl.h7
-rw-r--r--net/base/host_resolver_impl_unittest.cc7
-rw-r--r--net/base/network_change_notifier.cc4
-rw-r--r--net/base/network_change_notifier.h12
6 files changed, 22 insertions, 21 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h
index 6ce3c67..32706a0 100644
--- a/net/base/host_resolver.h
+++ b/net/base/host_resolver.h
@@ -20,6 +20,7 @@ namespace net {
class AddressList;
class HostCache;
class LoadLog;
+class NetworkChangeNotifier;
// This class represents the task of resolving hostnames (or IP address
// literal) to an AddressList object.
@@ -219,7 +220,10 @@ class SingleRequestHostResolver {
// Creates a HostResolver implementation that queries the underlying system.
// (Except if a unit-test has changed the global HostResolverProc using
// ScopedHostResolverProc to intercept requests to the system).
-HostResolver* CreateSystemHostResolver();
+// |network_change_notifier| must outlive HostResolver. It can optionally be
+// NULL, in which case HostResolver will not respond to network changes.
+HostResolver* CreateSystemHostResolver(
+ NetworkChangeNotifier* network_change_notifier);
} // namespace net
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index b654ad3..94c3857 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -43,14 +43,15 @@ HostCache* CreateDefaultCache() {
} // anonymous namespace
-HostResolver* CreateSystemHostResolver() {
+HostResolver* CreateSystemHostResolver(
+ NetworkChangeNotifier* network_change_notifier) {
// Maximum of 50 concurrent threads.
// TODO(eroman): Adjust this, do some A/B experiments.
static const size_t kMaxJobs = 50u;
// TODO(willchan): Pass in the NetworkChangeNotifier.
HostResolverImpl* resolver = new HostResolverImpl(
- NULL, CreateDefaultCache(), NULL, kMaxJobs);
+ NULL, CreateDefaultCache(), network_change_notifier, kMaxJobs);
return resolver;
}
@@ -525,7 +526,7 @@ class HostResolverImpl::JobPool {
HostResolverImpl::HostResolverImpl(
HostResolverProc* resolver_proc,
HostCache* cache,
- const scoped_refptr<NetworkChangeNotifier>& network_change_notifier,
+ NetworkChangeNotifier* network_change_notifier,
size_t max_jobs)
: cache_(cache),
max_jobs_(max_jobs),
diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h
index f3684b8..feedc05 100644
--- a/net/base/host_resolver_impl.h
+++ b/net/base/host_resolver_impl.h
@@ -69,12 +69,13 @@ class HostResolverImpl : public HostResolver,
// thread-safe since it is run from multiple worker threads. If
// |resolver_proc| is NULL then the default host resolver procedure is
// used (which is SystemHostResolverProc except if overridden).
- //
+ // |notifier| must outlive HostResolverImpl. It can optionally be NULL, in
+ // which case HostResolverImpl will not respond to network changes.
// |max_jobs| specifies the maximum number of threads that the host resolver
// will use. Use SetPoolConstraints() to specify finer-grain settings.
HostResolverImpl(HostResolverProc* resolver_proc,
HostCache* cache,
- const scoped_refptr<NetworkChangeNotifier>& notifier,
+ NetworkChangeNotifier* notifier,
size_t max_jobs);
// HostResolver methods:
@@ -236,7 +237,7 @@ class HostResolverImpl : public HostResolver,
// TODO(eroman): temp hack for http://crbug.com/15513
bool shutdown_;
- const scoped_refptr<NetworkChangeNotifier> network_change_notifier_;
+ NetworkChangeNotifier* const network_change_notifier_;
scoped_refptr<RequestsTrace> requests_trace_;
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc
index f3d350c..8ca58f0 100644
--- a/net/base/host_resolver_impl_unittest.cc
+++ b/net/base/host_resolver_impl_unittest.cc
@@ -978,11 +978,10 @@ TEST_F(HostResolverImplTest, CancellationObserver) {
// Test that IP address changes flush the cache.
TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) {
- scoped_refptr<MockNetworkChangeNotifier> mock_network_change_notifier(
- new MockNetworkChangeNotifier);
+ MockNetworkChangeNotifier mock_network_change_notifier;
scoped_refptr<HostResolver> host_resolver(
new HostResolverImpl(NULL, CreateDefaultCache(),
- mock_network_change_notifier,
+ &mock_network_change_notifier,
kMaxJobs));
AddressList addrlist;
@@ -1000,7 +999,7 @@ TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) {
ASSERT_EQ(OK, rv); // Should complete synchronously.
// Flush cache by triggering an IP address change.
- mock_network_change_notifier->NotifyIPAddressChange();
+ mock_network_change_notifier.NotifyIPAddressChange();
// Resolve "host1" again -- this time it won't be served from cache, so it
// will complete asynchronously.
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc
index 241f419..aeca2ab 100644
--- a/net/base/network_change_notifier.cc
+++ b/net/base/network_change_notifier.cc
@@ -15,8 +15,8 @@
namespace net {
// static
-scoped_refptr<NetworkChangeNotifier>
- NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier() {
+NetworkChangeNotifier*
+NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier() {
#if defined(OS_WIN)
return new NetworkChangeNotifierWin();
#elif defined(OS_LINUX)
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index d66830a..67d57ff 100644
--- a/net/base/network_change_notifier.h
+++ b/net/base/network_change_notifier.h
@@ -6,13 +6,13 @@
#define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_
#include "base/basictypes.h"
-#include "base/ref_counted.h"
+#include "base/non_thread_safe.h"
namespace net {
// NetworkChangeNotifier monitors the system for network changes, and notifies
// observers on those events.
-class NetworkChangeNotifier : public base::RefCounted<NetworkChangeNotifier> {
+class NetworkChangeNotifier : public NonThreadSafe {
public:
class Observer {
public:
@@ -30,6 +30,7 @@ class NetworkChangeNotifier : public base::RefCounted<NetworkChangeNotifier> {
};
NetworkChangeNotifier() {}
+ virtual ~NetworkChangeNotifier() {}
// These functions add and remove observers to/from the NetworkChangeNotifier.
// Each call to AddObserver() must be matched with a corresponding call to
@@ -40,12 +41,7 @@ class NetworkChangeNotifier : public base::RefCounted<NetworkChangeNotifier> {
virtual void RemoveObserver(Observer* observer) = 0;
// This will create the platform specific default NetworkChangeNotifier.
- static scoped_refptr<NetworkChangeNotifier>
- CreateDefaultNetworkChangeNotifier();
-
- protected:
- friend class base::RefCounted<NetworkChangeNotifier>;
- virtual ~NetworkChangeNotifier() {}
+ static NetworkChangeNotifier* CreateDefaultNetworkChangeNotifier();
private:
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);