diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 3 | ||||
-rw-r--r-- | chrome/browser/net/dns_global.cc | 26 | ||||
-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, 26 insertions, 34 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index dda5449..0ddd745 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -464,7 +464,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..795b79d 100644 --- a/chrome/browser/net/dns_global.cc +++ b/chrome/browser/net/dns_global.cc @@ -38,6 +38,9 @@ static void DnsPrefetchMotivatedList( // static const size_t DnsPrefetcherInit::kMaxConcurrentLookups = 8; +// Host resolver shared by DNS prefetcher, and the main URLRequestContext. +static net::HostResolver* global_host_resolver = NULL; + //------------------------------------------------------------------------------ // This section contains all the globally accessable API entry points for the // DNS Prefetching feature. @@ -435,9 +438,17 @@ 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); + } + + // TODO(eroman): This is a hack so the in process browser tests work if + // BrowserMain() is to be called again. + global_host_resolver = NULL; } void FreeDnsPrefetchResources() { @@ -454,9 +465,6 @@ static void DiscardAllPrefetchState() { //------------------------------------------------------------------------------ -// Host resolver shared by DNS prefetcher, and the main URLRequestContext. -static net::HostResolver* global_host_resolver = NULL; - net::HostResolver* GetGlobalHostResolver() { // Called from UI thread. if (!global_host_resolver) { @@ -469,14 +477,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"; |