diff options
Diffstat (limited to 'chrome')
-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, 31 insertions, 19 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 4b788c5..1e01821 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -462,4 +462,7 @@ 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 4b821c6..9e4c8f6 100644 --- a/chrome/browser/net/dns_global.cc +++ b/chrome/browser/net/dns_global.cc @@ -435,13 +435,9 @@ void InitDnsPrefetch(size_t max_concurrent, PrefService* user_prefs) { } void EnsureDnsPrefetchShutdown() { - if (NULL != dns_master) { + if (NULL != dns_master) dns_master->Shutdown(); - - // 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); - } + FreeGlobalHostResolver(); } void FreeDnsPrefetchResources() { @@ -473,6 +469,14 @@ 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 e27062e..c9a864f 100644 --- a/chrome/browser/net/dns_global.h +++ b/chrome/browser/net/dns_global.h @@ -36,9 +36,13 @@ void EnsureDnsPrefetchShutdown(); void FreeDnsPrefetchResources(); // Lazily allocates a HostResolver to be used by the DNS prefetch system, on -// the IO thread. +// the IO thread. Must be matched by a call to FreeGlobalHostResolver(). 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 04fc56f..fa1c783 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_|. - scoped_refptr<net::HostResolver> host_resolver_; + 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 da720fe..e056555 100644 --- a/chrome/browser/net/dns_master_unittest.cc +++ b/chrome/browser/net/dns_master_unittest.cc @@ -82,6 +82,7 @@ class DnsMasterTest : public testing::Test { MessageLoop::current()->Run(); } + net::HostResolver host_resolver_; scoped_refptr<net::RuleBasedHostMapper> mapper_; private: @@ -110,10 +111,10 @@ static std::string GetNonexistantDomain() { TimeDelta BlockingDnsLookup(const std::string& hostname) { Time start = Time::Now(); - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; 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; } @@ -162,13 +163,13 @@ TEST_F(DnsMasterTest, OsCachesLookupsTest) { } TEST_F(DnsMasterTest, StartupShutdownTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); testing_master->Shutdown(); } TEST_F(DnsMasterTest, BenefitLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string goog("www.google.com"), @@ -231,7 +232,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(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string localhost("127.0.0.1"); @@ -254,7 +255,7 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { } TEST_F(DnsMasterTest, SingleLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string goog("www.google.com"); @@ -283,7 +284,7 @@ TEST_F(DnsMasterTest, SingleLookupTest) { TEST_F(DnsMasterTest, ConcurrentLookupTest) { mapper_->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string goog("www.google.com"), @@ -337,7 +338,7 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) { TEST_F(DnsMasterTest, DISABLED_MassiveConcurrentLookupTest) { mapper_->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); NameList names; @@ -441,7 +442,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(new net::HostResolver, + scoped_refptr<DnsMaster> master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); ListValue referral_list; master->SerializeReferrers(&referral_list); @@ -456,7 +457,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(new net::HostResolver, + scoped_refptr<DnsMaster> master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string motivation_hostname = "www.google.com"; std::string subresource_hostname = "icons.google.com"; @@ -480,7 +481,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { // Make sure the Trim() functionality works as expected. TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> master = new DnsMaster(&host_resolver_, MessageLoop::current(), DnsPrefetcherInit::kMaxConcurrentLookups); std::string motivation_hostname = "www.google.com"; std::string icon_subresource_hostname = "icons.google.com"; |