diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 22:06:52 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 22:06:52 +0000 |
commit | 862a92ee0afc1be6470beed3e19465c24da223e2 (patch) | |
tree | dec2efaa94cf3e1eae580599e87f84e7af082594 /chrome/browser/net | |
parent | f816c01e9c6f6f0365ba80ba3f661e38461a0537 (diff) | |
download | chromium_src-862a92ee0afc1be6470beed3e19465c24da223e2.zip chromium_src-862a92ee0afc1be6470beed3e19465c24da223e2.tar.gz chromium_src-862a92ee0afc1be6470beed3e19465c24da223e2.tar.bz2 |
Make net::HostResolver refcounted.
This way it can be properly shared between the url request contexts, and the dns prefetcher, and dns observer.
BUG=http://crbug.com/14664
TEST=existing unit tests.
Review URL: http://codereview.chromium.org/149053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 3 | ||||
-rw-r--r-- | chrome/browser/net/dns_global.cc | 16 | ||||
-rw-r--r-- | chrome/browser/net/dns_global.h | 6 | ||||
-rw-r--r-- | chrome/browser/net/dns_master.h | 2 | ||||
-rw-r--r-- | chrome/browser/net/dns_master_unittest.cc | 23 |
5 files changed, 19 insertions, 31 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 1e01821..4b788c5 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -462,7 +462,4 @@ ChromeURLRequestContext::~ChromeURLRequestContext() { // it is owned by the original URLRequestContext. if (!is_off_the_record_ && !is_media_) delete proxy_service_; - - // Do not delete host_resolver_; it will be freed by FreeGlobalHostResolver() - // during the teardown of DNS prefetching. } diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc index 9e4c8f6..4b821c6 100644 --- a/chrome/browser/net/dns_global.cc +++ b/chrome/browser/net/dns_global.cc @@ -435,9 +435,13 @@ void InitDnsPrefetch(size_t max_concurrent, PrefService* user_prefs) { } void EnsureDnsPrefetchShutdown() { - if (NULL != dns_master) + if (NULL != dns_master) { dns_master->Shutdown(); - FreeGlobalHostResolver(); + + // Stop observing DNS resolutions. Note that dns_master holds a reference + // to the global host resolver, so is guaranteed to be live. + GetGlobalHostResolver()->RemoveObserver(&dns_resolution_observer); + } } void FreeDnsPrefetchResources() { @@ -469,14 +473,6 @@ net::HostResolver* GetGlobalHostResolver() { return global_host_resolver; } -void FreeGlobalHostResolver() { - if (global_host_resolver) { - // Called from IO thread. - delete global_host_resolver; - global_host_resolver = NULL; - } -} - //------------------------------------------------------------------------------ // Functions to handle saving of hostnames from one session to the next, to // expedite startup times. diff --git a/chrome/browser/net/dns_global.h b/chrome/browser/net/dns_global.h index c9a864f..e27062e 100644 --- a/chrome/browser/net/dns_global.h +++ b/chrome/browser/net/dns_global.h @@ -36,13 +36,9 @@ void EnsureDnsPrefetchShutdown(); void FreeDnsPrefetchResources(); // Lazily allocates a HostResolver to be used by the DNS prefetch system, on -// the IO thread. Must be matched by a call to FreeGlobalHostResolver(). +// the IO thread. net::HostResolver* GetGlobalHostResolver(); -// Frees the HostResolver allocated by GetGlobalHostResolver(). Must be called -// on the IO thread. -void FreeGlobalHostResolver(); - //------------------------------------------------------------------------------ // Global APIs relating to Prefetching in browser void EnableDnsPrefetch(bool enable); diff --git a/chrome/browser/net/dns_master.h b/chrome/browser/net/dns_master.h index fa1c783..04fc56f 100644 --- a/chrome/browser/net/dns_master.h +++ b/chrome/browser/net/dns_master.h @@ -229,7 +229,7 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { // The host resovler we warm DNS entries for. The resolver (which is not // thread safe) should be accessed only on |host_resolver_loop_|. - net::HostResolver* host_resolver_; + scoped_refptr<net::HostResolver> host_resolver_; MessageLoop* host_resolver_loop_; DISALLOW_COPY_AND_ASSIGN(DnsMaster); diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc index e056555..da720fe 100644 --- a/chrome/browser/net/dns_master_unittest.cc +++ b/chrome/browser/net/dns_master_unittest.cc @@ -82,7 +82,6 @@ class DnsMasterTest : public testing::Test { MessageLoop::current()->Run(); } - net::HostResolver host_resolver_; scoped_refptr<net::RuleBasedHostMapper> mapper_; private: @@ -111,10 +110,10 @@ static std::string GetNonexistantDomain() { TimeDelta BlockingDnsLookup(const std::string& hostname) { Time start = Time::Now(); - net::HostResolver resolver; + scoped_refptr<net::HostResolver> resolver(new net::HostResolver); net::AddressList addresses; net::HostResolver::RequestInfo info(hostname, 80); - resolver.Resolve(info, &addresses, NULL, NULL); + resolver->Resolve(info, &addresses, NULL, NULL); return Time::Now() - start; } @@ -163,13 +162,13 @@ TEST_F(DnsMasterTest, OsCachesLookupsTest) { } TEST_F(DnsMasterTest, StartupShutdownTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); testing_master->Shutdown(); } TEST_F(DnsMasterTest, BenefitLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string goog("www.google.com"), @@ -232,7 +231,7 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { scoped_refptr<net::WaitingHostMapper> mapper = new net::WaitingHostMapper(); net::ScopedHostMapper scoped_mapper(mapper.get()); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string localhost("127.0.0.1"); @@ -255,7 +254,7 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { } TEST_F(DnsMasterTest, SingleLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string goog("www.google.com"); @@ -284,7 +283,7 @@ TEST_F(DnsMasterTest, SingleLookupTest) { TEST_F(DnsMasterTest, ConcurrentLookupTest) { mapper_->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string goog("www.google.com"), @@ -338,7 +337,7 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) { TEST_F(DnsMasterTest, DISABLED_MassiveConcurrentLookupTest) { mapper_->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); NameList names; @@ -442,7 +441,7 @@ int GetLatencyFromSerialization(const std::string& motivation, // Make sure nil referral lists really have no entries, and no latency listed. TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); ListValue referral_list; master->SerializeReferrers(&referral_list); @@ -457,7 +456,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { // deserialized into the database, and can be extracted back out via // serialization without being changed. TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string motivation_hostname = "www.google.com"; std::string subresource_hostname = "icons.google.com"; @@ -481,7 +480,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { // Make sure the Trim() functionality works as expected. TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(&host_resolver_, + scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string motivation_hostname = "www.google.com"; std::string icon_subresource_hostname = "icons.google.com"; |