diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 00:12:49 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 00:12:49 +0000 |
commit | 74be069e808f687ab33d7bec52d1c9687af1b3ec (patch) | |
tree | 9b830fa01634cb18cd886ea8758cf62e747fc480 | |
parent | d07f0c801dbb2fdb6fcfaa671afa13400a615c85 (diff) | |
download | chromium_src-74be069e808f687ab33d7bec52d1c9687af1b3ec.zip chromium_src-74be069e808f687ab33d7bec52d1c9687af1b3ec.tar.gz chromium_src-74be069e808f687ab33d7bec52d1c9687af1b3ec.tar.bz2 |
Change classes and functions for DNS Prefetching to Predictor*
The DNS prefetching system has been extended to handle TCP/IP
preconnection. As a result, class names and function names will
be migrated to variations on Predictor* and Predict* to better
indicate functionality.
This change is only meant to include name changes, comment
updates, and no semantic changes.
r=mbelshe
Review URL: http://codereview.chromium.org/2813031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50792 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 454 insertions, 439 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index a7d32ed..1a736ac 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -637,9 +637,9 @@ void AutocompleteEditModel::Observe(NotificationType type, } if (!match->destination_url.SchemeIs(chrome::kExtensionScheme)) { - // Warm up DNS Prefetch Cache. - chrome_browser_net::DnsPrefetchUrl(match->destination_url, - IsPreconnectable(match->type)); + // Warm up DNS Prefetch cache, or preconnect to a search service. + chrome_browser_net::AnticipateUrl(match->destination_url, + IsPreconnectable(match->type)); } // We could prefetch the alternate nav URL, if any, but because there diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index c81e496..afe5117 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -243,7 +243,7 @@ class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); std::string data; - chrome_browser_net::DnsPrefetchGetHtmlInfo(&data); + chrome_browser_net::PredictorGetHtmlInfo(&data); ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 63b6d32..ac231bb 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -488,9 +488,9 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, profile_ = profile; if (command_line_.HasSwitch(switches::kDnsLogDetails)) - chrome_browser_net::EnableDnsDetailedLog(true); + chrome_browser_net::EnablePredictorDetailedLog(true); if (command_line_.HasSwitch(switches::kDnsPrefetchDisable)) - chrome_browser_net::EnableDnsPrefetch(false); + chrome_browser_net::EnablePredictor(false); if (command_line_.HasSwitch(switches::kDumpHistogramsOnExit)) StatisticsRecorder::set_dump_on_exit(true); diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index a2bc534..ca77eb6 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1022,7 +1022,7 @@ int BrowserMain(const MainFunctionParams& parameters) { BrowserInit browser_init; - // On first run, we need to process the master preferences before the + // On first run, we need to process the predictor preferences before the // browser's profile_manager object is created, but after ResourceBundle // is initialized. FirstRun::MasterPrefs master_prefs = { 0 }; @@ -1265,9 +1265,11 @@ int BrowserMain(const MainFunctionParams& parameters) { // testing against a bunch of special cases that are taken care early on. PrepareRestartOnCrashEnviroment(parsed_command_line); - // Initialize and maintain DNS prefetcher module. Also registers an observer - // to clear the host cache when closing incognito mode. - chrome_browser_net::DnsGlobalInit dns_prefetch( + // Initialize and maintain network predictor module, which handles DNS + // pre-resolution, as well as TCP/IP connection pre-warming. + // This also registers an observer to discard data when closing incognito + // mode. + chrome_browser_net::PredictorInit dns_prefetch( user_prefs, local_state, parsed_command_line.HasSwitch(switches::kEnablePreconnect)); diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index d77f654..373b47f 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -112,7 +112,7 @@ void Shutdown() { PrefService* prefs = g_browser_process->local_state(); - chrome_browser_net::SaveDnsPrefetchStateForNextStartupAndTrim(prefs); + chrome_browser_net::SavePredictorStateForNextStartupAndTrim(prefs); MetricsService* metrics = g_browser_process->metrics_service(); if (metrics) { diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index b432a5b..3707ebe 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -1561,7 +1561,7 @@ const int kDisabledIndex = 1; [self recordUserAction:UserMetricsAction( "Options_DnsPrefetchCheckbox_Disable")]; dnsPrefetch_.SetValue(value ? true : false); - chrome_browser_net::EnableDnsPrefetch(value ? true : false); + chrome_browser_net::EnablePredictor(value ? true : false); } // Returns whether the DNS prefetch checkbox should be enabled. diff --git a/chrome/browser/gtk/options/advanced_contents_gtk.cc b/chrome/browser/gtk/options/advanced_contents_gtk.cc index 2c6d639..03f4524 100644 --- a/chrome/browser/gtk/options/advanced_contents_gtk.cc +++ b/chrome/browser/gtk/options/advanced_contents_gtk.cc @@ -821,7 +821,7 @@ void PrivacySection::OnDNSPrefetchingChange(GtkWidget* widget, UserMetricsAction("Options_DnsPrefetchCheckbox_Disable"), privacy_section->profile()->GetPrefs()); privacy_section->dns_prefetch_enabled_.SetValue(enabled); - chrome_browser_net::EnableDnsPrefetch(enabled); + chrome_browser_net::EnablePredictor(enabled); } // static @@ -882,7 +882,7 @@ void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { bool enabled = dns_prefetch_enabled_.GetValue(); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(enable_dns_prefetching_checkbox_), enabled); - chrome_browser_net::EnableDnsPrefetch(enabled); + chrome_browser_net::EnablePredictor(enabled); } if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) { gtk_toggle_button_set_active( diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index d2b8fdd..bf6f83e 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -88,7 +88,7 @@ IOThread::IOThread() globals_(NULL), speculative_interceptor_(NULL), prefetch_observer_(NULL), - dns_master_(NULL) {} + predictor_(NULL) {} IOThread::~IOThread() { // We cannot rely on our base class to stop the thread since we want our @@ -102,9 +102,9 @@ IOThread::Globals* IOThread::globals() { return globals_; } -void IOThread::InitDnsMaster( +void IOThread::InitNetworkPredictor( bool prefetching_enabled, - base::TimeDelta max_queue_delay, + base::TimeDelta max_dns_queue_delay, size_t max_concurrent, const chrome_common_net::UrlList& startup_urls, ListValue* referral_list, @@ -114,8 +114,8 @@ void IOThread::InitDnsMaster( FROM_HERE, NewRunnableMethod( this, - &IOThread::InitDnsMasterOnIOThread, - prefetching_enabled, max_queue_delay, max_concurrent, + &IOThread::InitNetworkPredictorOnIOThread, + prefetching_enabled, max_dns_queue_delay, max_concurrent, startup_urls, referral_list, preconnect_enabled)); } @@ -149,14 +149,14 @@ void IOThread::CleanUp() { ChildProcessHost::TerminateAll(); // Not initialized in Init(). May not be initialized. - if (dns_master_) { - dns_master_->Shutdown(); + if (predictor_) { + predictor_->Shutdown(); - // TODO(willchan): Stop reference counting DnsMaster. It's owned by + // TODO(willchan): Stop reference counting Predictor. It's owned by // IOThread now. - dns_master_->Release(); - dns_master_ = NULL; - chrome_browser_net::FreeDnsPrefetchResources(); + predictor_->Release(); + predictor_ = NULL; + chrome_browser_net::FreePredictorResources(); } // Deletion will unregister this interceptor. @@ -240,24 +240,24 @@ net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory() { return registry_factory; } -void IOThread::InitDnsMasterOnIOThread( +void IOThread::InitNetworkPredictorOnIOThread( bool prefetching_enabled, - base::TimeDelta max_queue_delay, + base::TimeDelta max_dns_queue_delay, size_t max_concurrent, const chrome_common_net::UrlList& startup_urls, ListValue* referral_list, bool preconnect_enabled) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - CHECK(!dns_master_); + CHECK(!predictor_); - chrome_browser_net::EnableDnsPrefetch(prefetching_enabled); + chrome_browser_net::EnablePredictor(prefetching_enabled); - dns_master_ = new chrome_browser_net::DnsMaster( + predictor_ = new chrome_browser_net::Predictor( globals_->host_resolver, - max_queue_delay, + max_dns_queue_delay, max_concurrent, preconnect_enabled); - dns_master_->AddRef(); + predictor_->AddRef(); // TODO(jar): Until connection notification and DNS observation handling are // properly combined into a learning model, we'll only use one observation @@ -267,20 +267,20 @@ void IOThread::InitDnsMasterOnIOThread( speculative_interceptor_ = new chrome_browser_net::ConnectInterceptor; } else { DCHECK(!prefetch_observer_); - prefetch_observer_ = chrome_browser_net::CreatePrefetchObserver(); + prefetch_observer_ = chrome_browser_net::CreateResolverObserver(); globals_->host_resolver->AddObserver(prefetch_observer_); } - FinalizeDnsPrefetchInitialization( - dns_master_, prefetch_observer_, startup_urls, referral_list); + FinalizePredictorInitialization( + predictor_, prefetch_observer_, startup_urls, referral_list); } void IOThread::ChangedToOnTheRecordOnIOThread() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (dns_master_) { + if (predictor_) { // Destroy all evidence of our OTR session. - dns_master_->DnsMaster::DiscardAllResults(); + predictor_->Predictor::DiscardAllResults(); } // Clear the host cache to avoid showing entries from the OTR session diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index 83a781d..9708509 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -21,7 +21,7 @@ class ChromeNetLog; class ListValue; namespace chrome_browser_net { -class DnsMaster; +class Predictor; } // namespace chrome_browser_net namespace net { @@ -55,12 +55,12 @@ class IOThread : public BrowserProcessSubThread { // prefetching should be enabled, and |preconnect_enabled| controls whether // TCP/IP preconnection is enabled. This should be called by the UI thread. // It will post a task to the IO thread to perform the actual initialization. - void InitDnsMaster(bool prefetching_enabled, - base::TimeDelta max_queue_delay, - size_t max_concurrent, - const chrome_common_net::UrlList& startup_urls, - ListValue* referral_list, - bool preconnect_enabled); + void InitNetworkPredictor(bool prefetching_enabled, + base::TimeDelta max_dns_queue_delay, + size_t max_concurrent, + const chrome_common_net::UrlList& startup_urls, + ListValue* referral_list, + bool preconnect_enabled); // Handles changing to On The Record mode. Posts a task for this onto the // IOThread's message loop. @@ -74,9 +74,9 @@ class IOThread : public BrowserProcessSubThread { private: net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory(); - void InitDnsMasterOnIOThread( + void InitNetworkPredictorOnIOThread( bool prefetching_enabled, - base::TimeDelta max_queue_delay, + base::TimeDelta max_dns_queue_delay, size_t max_concurrent, const chrome_common_net::UrlList& startup_urls, @@ -110,7 +110,7 @@ class IOThread : public BrowserProcessSubThread { // down. chrome_browser_net::ConnectInterceptor* speculative_interceptor_; net::HostResolver::Observer* prefetch_observer_; - chrome_browser_net::DnsMaster* dns_master_; + chrome_browser_net::Predictor* predictor_; DISALLOW_COPY_AND_ASSIGN(IOThread); }; diff --git a/chrome/browser/net/connect_interceptor.cc b/chrome/browser/net/connect_interceptor.cc index ab45ddb..d96a070 100644 --- a/chrome/browser/net/connect_interceptor.cc +++ b/chrome/browser/net/connect_interceptor.cc @@ -24,7 +24,7 @@ URLRequestJob* ConnectInterceptor::MaybeIntercept(URLRequest* request) { // link navigation. For now, we'll "learn" that to preconnect when a user // actually does a click... which will probably waste space in our referrers // table (since it probably won't be that deterministic). - NonlinkNavigation(referring_url, request->url().GetWithEmptyPath()); + LearnFromNavigation(referring_url, request->url().GetWithEmptyPath()); } // Now we use previous learning and setup for our subresources. if (request->was_fetched_via_proxy()) @@ -34,7 +34,7 @@ URLRequestJob* ConnectInterceptor::MaybeIntercept(URLRequest* request) { // foo.jpg or goo.gif etc.), but better would be to get this info from webkit // and have it add the info to the request (we currently only set the // priority, but we could record whether it was a frame). - NavigatingToFrame(request->url().GetWithEmptyPath()); + PredictFrameSubresources(request->url().GetWithEmptyPath()); return NULL; } diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc index fa33217..1fae92f 100644 --- a/chrome/browser/net/dns_global.cc +++ b/chrome/browser/net/dns_global.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,23 +36,23 @@ using base::TimeDelta; namespace chrome_browser_net { static void DnsMotivatedPrefetch(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation); + UrlInfo::ResolutionMotivation motivation); static void DnsPrefetchMotivatedList(const UrlList& urls, - DnsHostInfo::ResolutionMotivation motivation); + UrlInfo::ResolutionMotivation motivation); -static UrlList GetPrefetchUrlListAtStartup( +static UrlList GetPredictedUrlListAtStartup( PrefService* user_prefs, PrefService* local_state); // static -const size_t DnsGlobalInit::kMaxPrefetchConcurrentLookups = 8; +const size_t PredictorInit::kMaxPrefetchConcurrentLookups = 8; // static -const int DnsGlobalInit::kMaxPrefetchQueueingDelayMs = 500; +const int PredictorInit::kMaxPrefetchQueueingDelayMs = 500; // A version number for prefs that are saved. This should be incremented when // we change the format so that we discard old data. -static const int kDnsStartupFormatVersion = 1; +static const int kPredictorStartupFormatVersion = 1; //------------------------------------------------------------------------------ // Static helper functions @@ -96,7 +96,7 @@ static bool dns_prefetch_enabled = true; static bool on_the_record_switch = true; // Enable/disable Dns prefetch activity (either via command line, or via pref). -void EnableDnsPrefetch(bool enable) { +void EnablePredictor(bool enable) { // NOTE: this is invoked on the UI thread. dns_prefetch_enabled = enable; } @@ -122,7 +122,7 @@ void RegisterUserPrefs(PrefService* user_prefs) { // When enabled, we use the following instance to service all requests in the // browser process. // TODO(willchan): Look at killing this. -static DnsMaster* dns_master = NULL; +static Predictor* predictor = NULL; // This API is only used in the browser process. // It is called from an IPC message originating in the renderer. It currently @@ -138,32 +138,32 @@ void DnsPrefetchList(const NameList& hostnames) { } DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - DnsPrefetchMotivatedList(urls, DnsHostInfo::PAGE_SCAN_MOTIVATED); + DnsPrefetchMotivatedList(urls, UrlInfo::PAGE_SCAN_MOTIVATED); } static void DnsPrefetchMotivatedList( const UrlList& urls, - DnsHostInfo::ResolutionMotivation motivation) { + UrlInfo::ResolutionMotivation motivation) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI) || ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (!dns_prefetch_enabled || NULL == dns_master) + if (!dns_prefetch_enabled || NULL == predictor) return; if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { - dns_master->ResolveList(urls, motivation); + predictor->ResolveList(urls, motivation); } else { ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, - NewRunnableMethod(dns_master, - &DnsMaster::ResolveList, urls, motivation)); + NewRunnableMethod(predictor, + &Predictor::ResolveList, urls, motivation)); } } // This API is used by the autocomplete popup box (where URLs are typed). -void DnsPrefetchUrl(const GURL& url, bool preconnectable) { +void AnticipateUrl(const GURL& url, bool preconnectable) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - if (!dns_prefetch_enabled || NULL == dns_master) + if (!dns_prefetch_enabled || NULL == predictor) return; if (!url.is_valid()) return; @@ -187,7 +187,7 @@ void DnsPrefetchUrl(const GURL& url, bool preconnectable) { GURL canonical_url(CanonicalizeUrl(url)); - if (dns_master->preconnect_enabled() && preconnectable) { + if (predictor->preconnect_enabled() && preconnectable) { static base::TimeTicks last_keepalive; // TODO(jar): The wild guess of 30 seconds could be tuned/tested, but it // currently is just a guess that most sockets will remain open for at least @@ -202,20 +202,20 @@ void DnsPrefetchUrl(const GURL& url, bool preconnectable) { } // Perform at least DNS pre-resolution. - DnsMotivatedPrefetch(canonical_url, DnsHostInfo::OMNIBOX_MOTIVATED); + DnsMotivatedPrefetch(canonical_url, UrlInfo::OMNIBOX_MOTIVATED); } static void DnsMotivatedPrefetch(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation) { + UrlInfo::ResolutionMotivation motivation) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - if (!dns_prefetch_enabled || NULL == dns_master || !url.has_host()) + if (!dns_prefetch_enabled || NULL == predictor || !url.has_host()) return; ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, - NewRunnableMethod(dns_master, - &DnsMaster::Resolve, url, motivation)); + NewRunnableMethod(predictor, + &Predictor::Resolve, url, motivation)); } //------------------------------------------------------------------------------ @@ -228,45 +228,45 @@ static void DnsMotivatedPrefetch(const GURL& url, // This function determines if there was a saving by prefetching the hostname // for which the navigation_info is supplied. static bool AccruePrefetchBenefits(const GURL& referrer_url, - DnsHostInfo* navigation_info) { + UrlInfo* navigation_info) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (!dns_prefetch_enabled || NULL == dns_master) + if (!dns_prefetch_enabled || NULL == predictor) return false; DCHECK(referrer_url == referrer_url.GetWithEmptyPath()); - return dns_master->AccruePrefetchBenefits(referrer_url, navigation_info); + return predictor->AccruePrefetchBenefits(referrer_url, navigation_info); } -void NavigatingTo(const GURL& url) { +void PredictSubresources(const GURL& url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (!dns_prefetch_enabled || NULL == dns_master) + if (!dns_prefetch_enabled || NULL == predictor) return; - dns_master->NavigatingTo(url); + predictor->PredictSubresources(url); } -void NavigatingToFrame(const GURL& url) { +void PredictFrameSubresources(const GURL& url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (!dns_prefetch_enabled || NULL == dns_master) + if (!dns_prefetch_enabled || NULL == predictor) return; - dns_master->NavigatingToFrame(url); + predictor->PredictFrameSubresources(url); } -void NonlinkNavigation(const GURL& referring_url, const GURL& target_url) { +void LearnFromNavigation(const GURL& referring_url, const GURL& target_url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (!dns_prefetch_enabled || NULL == dns_master) + if (!dns_prefetch_enabled || NULL == predictor) return; - dns_master->NonlinkNavigation(referring_url, target_url); + predictor->LearnFromNavigation(referring_url, target_url); } // The observer class needs to connect starts and finishes of HTTP network // resolutions. We use the following type for that map. -typedef std::map<int, DnsHostInfo> ObservedResolutionMap; +typedef std::map<int, UrlInfo> ObservedResolutionMap; // There will only be one instance ever created of the following Observer // class. The PrefetchObserver lives on the IO thread, and intercepts DNS // resolutions made by the network stack. class PrefetchObserver : public net::HostResolver::Observer { public: - typedef std::map<GURL, DnsHostInfo> FirstResolutionMap; + typedef std::map<GURL, UrlInfo> FirstResolutionMap; // net::HostResolver::Observer implementation: virtual void OnStartResolution( @@ -284,7 +284,7 @@ class PrefetchObserver : public net::HostResolver::Observer { void GetInitialDnsResolutionList(ListValue* startup_list); private: - void StartupListAppend(const DnsHostInfo& navigation_info); + void StartupListAppend(const UrlInfo& navigation_info); // Map of pending resolutions seen by observer. ObservedResolutionMap resolutions_; @@ -308,7 +308,7 @@ void PrefetchObserver::OnStartResolution( return; // One of our own requests. DCHECK_NE(0U, request_info.hostname().length()); - DnsHostInfo navigation_info; + UrlInfo navigation_info; // TODO(jar): Remove hack which guestimates ssl via port number, and perhaps // have actual URL passed down in request_info instead. bool is_ssl(443 == request_info.port()); @@ -331,7 +331,7 @@ void PrefetchObserver::OnFinishResolutionWithStatus( DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (request_info.is_speculative()) return; // One of our own requests. - DnsHostInfo navigation_info; + UrlInfo navigation_info; size_t startup_count = 0; { ObservedResolutionMap::iterator it = resolutions_.find(request_id); @@ -354,7 +354,7 @@ void PrefetchObserver::OnFinishResolutionWithStatus( std::string url_spec; StringAppendF(&url_spec, "http%s://%s:%d", "", request_info.hostname().c_str(), request_info.port()); - NavigatingTo(GURL(url_spec)); + PredictSubresources(GURL(url_spec)); if (kStartupResolutionCount <= startup_count || !was_resolved) return; @@ -380,10 +380,10 @@ void PrefetchObserver::OnCancelResolution( resolutions_.erase(it); } -void PrefetchObserver::StartupListAppend(const DnsHostInfo& navigation_info) { +void PrefetchObserver::StartupListAppend(const UrlInfo& navigation_info) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (!on_the_record_switch || NULL == dns_master) + if (!on_the_record_switch || NULL == predictor) return; if (kStartupResolutionCount <= first_resolutions_.size()) return; // Someone just added the last item. @@ -397,7 +397,7 @@ void PrefetchObserver::GetInitialDnsResolutionList(ListValue* startup_list) { DCHECK(startup_list); startup_list->Clear(); DCHECK_EQ(0u, startup_list->GetSize()); - startup_list->Append(new FundamentalValue(kDnsStartupFormatVersion)); + startup_list->Append(new FundamentalValue(kPredictorStartupFormatVersion)); for (FirstResolutionMap::iterator it = first_resolutions_.begin(); it != first_resolutions_.end(); ++it) { @@ -409,7 +409,7 @@ void PrefetchObserver::GetInitialDnsResolutionList(ListValue* startup_list) { void PrefetchObserver::DnsGetFirstResolutionsHtml(std::string* output) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - DnsHostInfo::DnsInfoTable resolution_list; + UrlInfo::DnsInfoTable resolution_list; { for (FirstResolutionMap::iterator it(first_resolutions_.begin()); it != first_resolutions_.end(); @@ -417,7 +417,7 @@ void PrefetchObserver::DnsGetFirstResolutionsHtml(std::string* output) { resolution_list.push_back(it->second); } } - DnsHostInfo::GetHtmlTable(resolution_list, + UrlInfo::GetHtmlTable(resolution_list, "Future startups will prefetch DNS records for ", false, output); } @@ -479,23 +479,23 @@ class OffTheRecordObserver : public NotificationObserver { //------------------------------------------------------------------------------ // Provide global support for the about:dns page. -void DnsPrefetchGetHtmlInfo(std::string* output) { +void PredictorGetHtmlInfo(std::string* output) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); output->append("<html><head><title>About DNS</title>" // We'd like the following no-cache... but it doesn't work. // "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" "</head><body>"); - if (!dns_prefetch_enabled || NULL == dns_master) { + if (!dns_prefetch_enabled || NULL == predictor) { output->append("Dns Prefetching is disabled."); } else { if (!on_the_record_switch) { output->append("Incognito mode is active in a window."); } else { - dns_master->GetHtmlInfo(output); + predictor->GetHtmlInfo(output); if (g_prefetch_observer) g_prefetch_observer->DnsGetFirstResolutionsHtml(output); - dns_master->GetHtmlReferrerLists(output); + predictor->GetHtmlReferrerLists(output); } } output->append("</body></html>"); @@ -505,8 +505,8 @@ void DnsPrefetchGetHtmlInfo(std::string* output) { // This section intializes global DNS prefetch services. //------------------------------------------------------------------------------ -static void InitDnsPrefetch(TimeDelta max_queue_delay, size_t max_concurrent, - PrefService* user_prefs, PrefService* local_state, +static void InitNetworkPredictor(TimeDelta max_dns_queue_delay, + size_t max_concurrent, PrefService* user_prefs, PrefService* local_state, bool preconnect_enabled) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); @@ -515,24 +515,24 @@ static void InitDnsPrefetch(TimeDelta max_queue_delay, size_t max_concurrent, // Gather the list of hostnames to prefetch on startup. UrlList urls = - GetPrefetchUrlListAtStartup(user_prefs, local_state); + GetPredictedUrlListAtStartup(user_prefs, local_state); ListValue* referral_list = static_cast<ListValue*>( local_state->GetMutableList(prefs::kDnsHostReferralList)->DeepCopy()); - g_browser_process->io_thread()->InitDnsMaster( - prefetching_enabled, max_queue_delay, max_concurrent, urls, + g_browser_process->io_thread()->InitNetworkPredictor( + prefetching_enabled, max_dns_queue_delay, max_concurrent, urls, referral_list, preconnect_enabled); } -void FinalizeDnsPrefetchInitialization( - DnsMaster* global_dns_master, +void FinalizePredictorInitialization( + Predictor* global_predictor, net::HostResolver::Observer* global_prefetch_observer, const UrlList& startup_urls, ListValue* referral_list) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - dns_master = global_dns_master; + predictor = global_predictor; g_prefetch_observer = static_cast<PrefetchObserver*>(global_prefetch_observer); @@ -540,18 +540,18 @@ void FinalizeDnsPrefetchInitialization( // Prefetch these hostnames on startup. DnsPrefetchMotivatedList(startup_urls, - DnsHostInfo::STARTUP_LIST_MOTIVATED); - dns_master->DeserializeReferrersThenDelete(referral_list); + UrlInfo::STARTUP_LIST_MOTIVATED); + predictor->DeserializeReferrersThenDelete(referral_list); } -void FreeDnsPrefetchResources() { - dns_master = NULL; +void FreePredictorResources() { + predictor = NULL; g_prefetch_observer = NULL; } //------------------------------------------------------------------------------ -net::HostResolver::Observer* CreatePrefetchObserver() { +net::HostResolver::Observer* CreateResolverObserver() { return new PrefetchObserver(); } @@ -565,7 +565,7 @@ static void SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread( base::WaitableEvent* completion) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - if (NULL == dns_master) { + if (NULL == predictor) { completion->Signal(); return; } @@ -577,16 +577,16 @@ static void SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread( // of physical time, or perhaps after 48 hours of running (excluding time // between sessions possibly). // For now, we'll just trim at shutdown. - dns_master->TrimReferrers(); - dns_master->SerializeReferrers(referral_list); + predictor->TrimReferrers(); + predictor->SerializeReferrers(referral_list); completion->Signal(); } -void SaveDnsPrefetchStateForNextStartupAndTrim(PrefService* prefs) { +void SavePredictorStateForNextStartupAndTrim(PrefService* prefs) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - if (!dns_prefetch_enabled || dns_master == NULL) + if (!dns_prefetch_enabled || predictor == NULL) return; base::WaitableEvent completion(true, false); @@ -604,8 +604,8 @@ void SaveDnsPrefetchStateForNextStartupAndTrim(PrefService* prefs) { completion.Wait(); } -static UrlList GetPrefetchUrlListAtStartup(PrefService* user_prefs, - PrefService* local_state) { +static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, + PrefService* local_state) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); UrlList urls; // Recall list of URLs we learned about during last session. @@ -619,7 +619,7 @@ static UrlList GetPrefetchUrlListAtStartup(PrefService* user_prefs, int format_version = -1; if (it != startup_list->end() && (*it)->GetAsInteger(&format_version) && - format_version == kDnsStartupFormatVersion) { + format_version == kPredictorStartupFormatVersion) { ++it; for (; it != startup_list->end(); ++it) { std::string url_spec; @@ -660,9 +660,9 @@ static UrlList GetPrefetchUrlListAtStartup(PrefService* user_prefs, //------------------------------------------------------------------------------ // Methods for the helper class that is used to startup and teardown the whole -// DNS prefetch system. +// predictor system (both DNS pre-resolution and TCP/IP connection prewarming). -DnsGlobalInit::DnsGlobalInit(PrefService* user_prefs, +PredictorInit::PredictorInit(PrefService* user_prefs, PrefService* local_state, bool preconnect_enabled) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); @@ -741,9 +741,9 @@ DnsGlobalInit::DnsGlobalInit(PrefService* user_prefs, TimeDelta max_queueing_delay( TimeDelta::FromMilliseconds(max_queueing_delay_ms)); - DCHECK(!dns_master); - InitDnsPrefetch(max_queueing_delay, max_concurrent, user_prefs, - local_state, preconnect_enabled); + DCHECK(!predictor); + InitNetworkPredictor(max_queueing_delay, max_concurrent, user_prefs, + local_state, preconnect_enabled); } } diff --git a/chrome/browser/net/dns_global.h b/chrome/browser/net/dns_global.h index 0abacc5..cc15734 100644 --- a/chrome/browser/net/dns_global.h +++ b/chrome/browser/net/dns_global.h @@ -1,11 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This is the global interface for the dns prefetch services. It centralizes // initialization, along with all the callbacks etc. to connect to the browser // process. This allows the more standard DNS prefetching services, such as -// provided by DnsMaster to be left as more generally usable code, and possibly +// provided by Predictor to be left as more generally usable code, and possibly // be shared across multiple client projects. #ifndef CHROME_BROWSER_NET_DNS_GLOBAL_H_ @@ -26,22 +26,22 @@ class PrefService; namespace chrome_browser_net { // Deletes |referral_list| when done. -void FinalizeDnsPrefetchInitialization( - DnsMaster* global_dns_master, +void FinalizePredictorInitialization( + Predictor* global_predictor, net::HostResolver::Observer* global_prefetch_observer, const std::vector<GURL>& urls_to_prefetch, ListValue* referral_list); -// Free all resources allocated by FinalizeDnsPrefetchInitialization. After that +// Free all resources allocated by FinalizePredictorInitialization. After that // you must not call any function from this file. -void FreeDnsPrefetchResources(); +void FreePredictorResources(); // Creates the HostResolver observer for the prefetching system. -net::HostResolver::Observer* CreatePrefetchObserver(); +net::HostResolver::Observer* CreateResolverObserver(); //------------------------------------------------------------------------------ -// Global APIs relating to Prefetching in browser -void EnableDnsPrefetch(bool enable); +// Global APIs relating to predictions in browser. +void EnablePredictor(bool enable); void RegisterPrefs(PrefService* local_state); void RegisterUserPrefs(PrefService* user_prefs); @@ -52,30 +52,30 @@ void DnsPrefetchList(const NameList& hostnames); // This API is used by the autocomplete popup box (as user types). // This will either preresolve the domain name, or possibly preconnect creating // an open TCP/IP connection to the host. -void DnsPrefetchUrl(const GURL& url, bool preconnectable); +void AnticipateUrl(const GURL& url, bool preconnectable); // When displaying info in about:dns, the following API is called. -void DnsPrefetchGetHtmlInfo(std::string* output); +void PredictorGetHtmlInfo(std::string* output); //------------------------------------------------------------------------------ -// When we navigate, we may know in advance some other domains that will need to +// When we navigate, we may know in advance some other URLs that will need to // be resolved. This function initiates those side effects. -void NavigatingTo(const GURL& url); +void PredictSubresources(const GURL& url); // When we navigate to a frame that may contain embedded resources, we may know // in advance some other URLs that will need to be connected to (via TCP and // sometimes SSL). This function initiates those connections -void NavigatingToFrame(const GURL& url); +void PredictFrameSubresources(const GURL& url); // Call when we should learn from a navigation about a relationship to a // subresource target, and its containing frame, which was loaded as a referring // URL. -void NonlinkNavigation(const GURL& referring_url, const GURL& target_url); +void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); //------------------------------------------------------------------------------ -void SaveDnsPrefetchStateForNextStartupAndTrim(PrefService* prefs); +void SavePredictorStateForNextStartupAndTrim(PrefService* prefs); // Helper class to handle global init and shutdown. -class DnsGlobalInit { +class PredictorInit { public: // Too many concurrent lookups negate benefits of prefetching by trashing // the OS cache before all resource loading is complete. @@ -87,14 +87,14 @@ class DnsGlobalInit { // of that state. The following is the suggested default time limit. static const int kMaxPrefetchQueueingDelayMs; - DnsGlobalInit(PrefService* user_prefs, PrefService* local_state, + PredictorInit(PrefService* user_prefs, PrefService* local_state, bool preconnect_enabled); private: // Maintain a field trial instance when we do A/B testing. scoped_refptr<FieldTrial> trial_; - DISALLOW_COPY_AND_ASSIGN(DnsGlobalInit); + DISALLOW_COPY_AND_ASSIGN(PredictorInit); }; } // namespace chrome_browser_net diff --git a/chrome/browser/net/dns_host_info.cc b/chrome/browser/net/dns_host_info.cc index 522b69e..5d1824e 100644 --- a/chrome/browser/net/dns_host_info.cc +++ b/chrome/browser/net/dns_host_info.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,15 +24,15 @@ namespace chrome_browser_net { static bool detailed_logging_enabled = false; // Use command line switch to enable detailed logging. -void EnableDnsDetailedLog(bool enable) { +void EnablePredictorDetailedLog(bool enable) { detailed_logging_enabled = enable; } // static -int DnsHostInfo::sequence_counter = 1; +int UrlInfo::sequence_counter = 1; -bool DnsHostInfo::NeedsDnsUpdate() { +bool UrlInfo::NeedsDnsUpdate() { switch (state_) { case PENDING: // Just now created info. return true; @@ -52,7 +52,7 @@ bool DnsHostInfo::NeedsDnsUpdate() { } } -const TimeDelta DnsHostInfo::kNullDuration(TimeDelta::FromMilliseconds(-1)); +const TimeDelta UrlInfo::kNullDuration(TimeDelta::FromMilliseconds(-1)); // Common low end TTL for sites is 5 minutes. However, DNS servers give us // the remaining time, not the original 5 minutes. Hence it doesn't much matter @@ -64,17 +64,17 @@ const TimeDelta DnsHostInfo::kNullDuration(TimeDelta::FromMilliseconds(-1)); // has a TON of copies of the same domain name, so that we don't thrash the OS // to death. Hopefully it is small enough that we're not hurting our cache hit // rate (i.e., we could always ask the OS). -TimeDelta DnsHostInfo::kCacheExpirationDuration(TimeDelta::FromSeconds(5)); +TimeDelta UrlInfo::kCacheExpirationDuration(TimeDelta::FromSeconds(5)); -const TimeDelta DnsHostInfo::kMaxNonNetworkDnsLookupDuration( +const TimeDelta UrlInfo::kMaxNonNetworkDnsLookupDuration( TimeDelta::FromMilliseconds(15)); // Used by test ONLY. The value is otherwise constant. -void DnsHostInfo::set_cache_expiration(TimeDelta time) { +void UrlInfo::set_cache_expiration(TimeDelta time) { kCacheExpirationDuration = time; } -void DnsHostInfo::SetQueuedState(ResolutionMotivation motivation) { +void UrlInfo::SetQueuedState(ResolutionMotivation motivation) { DCHECK(PENDING == state_ || FOUND == state_ || NO_SUCH_NAME == state_); old_prequeue_state_ = state_; state_ = QUEUED; @@ -84,7 +84,7 @@ void DnsHostInfo::SetQueuedState(ResolutionMotivation motivation) { DLogResultsStats("DNS Prefetch in queue"); } -void DnsHostInfo::SetAssignedState() { +void UrlInfo::SetAssignedState() { DCHECK(QUEUED == state_); state_ = ASSIGNED; queue_duration_ = GetDuration(); @@ -92,7 +92,7 @@ void DnsHostInfo::SetAssignedState() { UMA_HISTOGRAM_TIMES("DNS.PrefetchQueue", queue_duration_); } -void DnsHostInfo::RemoveFromQueue() { +void UrlInfo::RemoveFromQueue() { DCHECK(ASSIGNED == state_); state_ = old_prequeue_state_; DLogResultsStats("DNS Prefetch reset to prequeue"); @@ -110,12 +110,12 @@ void DnsHostInfo::RemoveFromQueue() { histogram->AddTime(queue_duration_); } -void DnsHostInfo::SetPendingDeleteState() { +void UrlInfo::SetPendingDeleteState() { DCHECK(ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_); state_ = ASSIGNED_BUT_MARKED; } -void DnsHostInfo::SetFoundState() { +void UrlInfo::SetFoundState() { DCHECK(ASSIGNED == state_); state_ = FOUND; resolve_duration_ = GetDuration(); @@ -141,7 +141,7 @@ void DnsHostInfo::SetFoundState() { DLogResultsStats("DNS PrefetchFound"); } -void DnsHostInfo::SetNoSuchNameState() { +void UrlInfo::SetNoSuchNameState() { DCHECK(ASSIGNED == state_); state_ = NO_SUCH_NAME; resolve_duration_ = GetDuration(); @@ -154,7 +154,7 @@ void DnsHostInfo::SetNoSuchNameState() { DLogResultsStats("DNS PrefetchNotFound"); } -void DnsHostInfo::SetStartedState() { +void UrlInfo::SetStartedState() { DCHECK(PENDING == state_); state_ = STARTED; queue_duration_ = resolve_duration_ = TimeDelta(); // 0ms. @@ -162,7 +162,7 @@ void DnsHostInfo::SetStartedState() { GetDuration(); // Set time. } -void DnsHostInfo::SetFinishedState(bool was_resolved) { +void UrlInfo::SetFinishedState(bool was_resolved) { DCHECK(STARTED == state_); state_ = was_resolved ? FINISHED : FINISHED_UNRESOLVED; resolve_duration_ = GetDuration(); @@ -170,7 +170,7 @@ void DnsHostInfo::SetFinishedState(bool was_resolved) { DLogResultsStats("DNS HTTP Finished"); } -void DnsHostInfo::SetUrl(const GURL& url) { +void UrlInfo::SetUrl(const GURL& url) { if (url_.is_empty()) // Not yet initialized. url_ = url; else @@ -179,7 +179,7 @@ void DnsHostInfo::SetUrl(const GURL& url) { // IsStillCached() guesses if the DNS cache still has IP data, // or at least remembers results about "not finding host." -bool DnsHostInfo::IsStillCached() const { +bool UrlInfo::IsStillCached() const { DCHECK(FOUND == state_ || NO_SUCH_NAME == state_); // Default MS OS does not cache failures. Hence we could return false almost @@ -187,7 +187,7 @@ bool DnsHostInfo::IsStillCached() const { // the value if we returned false that way. Hence we'll just let the lookup // time out the same way as FOUND case. - if (sequence_counter - sequence_number_ > kMaxGuaranteedCacheSize) + if (sequence_counter - sequence_number_ > kMaxGuaranteedDnsCacheSize) return false; TimeDelta time_since_resolution = TimeTicks::Now() - time_; @@ -197,7 +197,7 @@ bool DnsHostInfo::IsStillCached() const { // Compare the actual navigation DNS latency found in navigation_info, to the // previously prefetched info. -DnsBenefit DnsHostInfo::AccruePrefetchBenefits(DnsHostInfo* navigation_info) { +DnsBenefit UrlInfo::AccruePrefetchBenefits(UrlInfo* navigation_info) { DCHECK(FINISHED == navigation_info->state_ || FINISHED_UNRESOLVED == navigation_info->state_); DCHECK(navigation_info->url() == url_); @@ -247,7 +247,7 @@ DnsBenefit DnsHostInfo::AccruePrefetchBenefits(DnsHostInfo* navigation_info) { return PREFETCH_NAME_FOUND; } -void DnsHostInfo::DLogResultsStats(const char* message) const { +void UrlInfo::DLogResultsStats(const char* message) const { if (!detailed_logging_enabled) return; DLOG(INFO) << "\t" << message << "\tq=" @@ -329,7 +329,7 @@ static std::string HoursMinutesSeconds(int seconds) { } // static -void DnsHostInfo::GetHtmlTable(const DnsInfoTable host_infos, +void UrlInfo::GetHtmlTable(const DnsInfoTable host_infos, const char* description, const bool brief, std::string* output) { @@ -402,13 +402,13 @@ void DnsHostInfo::GetHtmlTable(const DnsInfoTable host_infos, output->append("<br>"); } -void DnsHostInfo::SetMotivation(ResolutionMotivation motivation) { +void UrlInfo::SetMotivation(ResolutionMotivation motivation) { motivation_ = motivation; if (motivation < LINKED_MAX_MOTIVATED) was_linked_ = true; } -std::string DnsHostInfo::GetAsciiMotivation() const { +std::string UrlInfo::GetAsciiMotivation() const { switch (motivation_) { case MOUSE_OVER_MOTIVATED: return "[mouse-over]"; diff --git a/chrome/browser/net/dns_host_info.h b/chrome/browser/net/dns_host_info.h index 6c34025..3ab9694 100644 --- a/chrome/browser/net/dns_host_info.h +++ b/chrome/browser/net/dns_host_info.h @@ -1,11 +1,17 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// A DnsHostInfo object is used to store status of a Dns lookup of a specific -// hostname. -// It includes progress, from placement in the DnsMaster's queue, to resolution -// by the DNS service as either FOUND or NO_SUCH_NAME. +// A UrlInfo object is used to store prediction related information about a host +// port and scheme triplet. When performing DNS pre-resolution of the host/port +// pair, its state is monitored as it is resolved. +// It includes progress, from placement in the Predictor's queue, to resolution +// by the DNS service as either FOUND or NO_SUCH_NAME. Each instance may also +// hold records of previous resolution times, which might later be shown to be +// savings relative to resolution time during a navigation. +// UrlInfo objects are also used to describe frames, and additional instances +// may describe associated subresources, for future speculative connections to +// those expected subresources. #ifndef CHROME_BROWSER_NET_DNS_HOST_INFO_H_ #define CHROME_BROWSER_NET_DNS_HOST_INFO_H_ @@ -20,7 +26,7 @@ namespace chrome_browser_net { // Use command line switch to enable detailed logging. -void EnableDnsDetailedLog(bool enable); +void EnablePredictorDetailedLog(bool enable); enum DnsBenefit { PREFETCH_NO_BENEFIT, // Prefetch never hit the network. Name was pre-cached. @@ -30,7 +36,7 @@ enum DnsBenefit { PREFETCH_OBLIVIOUS // No prefetch attempt was even made. }; -class DnsHostInfo { +class UrlInfo { public: // Reasons for a domain to be resolved. enum ResolutionMotivation { @@ -65,15 +71,15 @@ class DnsHostInfo { static const base::TimeDelta kMaxNonNetworkDnsLookupDuration; // The number of OS cache entries we can guarantee(?) before cache eviction // might likely take place. - static const int kMaxGuaranteedCacheSize = 50; + static const int kMaxGuaranteedDnsCacheSize = 50; - typedef std::vector<DnsHostInfo> DnsInfoTable; + typedef std::vector<UrlInfo> DnsInfoTable; static const base::TimeDelta kNullDuration; - // DnsHostInfo are usually made by the default constructor during - // initializing of the DnsMaster's map (of info for Hostnames). - DnsHostInfo() + // UrlInfo are usually made by the default constructor during + // initializing of the Predictor's map (of info for Hostnames). + UrlInfo() : state_(PENDING), old_prequeue_state_(state_), resolve_duration_(kNullDuration), @@ -84,7 +90,7 @@ class DnsHostInfo { was_linked_(false) { } - ~DnsHostInfo() {} + ~UrlInfo() {} // NeedDnsUpdate decides, based on our internal info, // if it would be valuable to attempt to update (prefectch) @@ -131,7 +137,7 @@ class DnsHostInfo { base::TimeDelta queue_duration() const { return queue_duration_;} base::TimeDelta benefits_remaining() const { return benefits_remaining_; } - DnsBenefit AccruePrefetchBenefits(DnsHostInfo* navigation_info); + DnsBenefit AccruePrefetchBenefits(UrlInfo* navigation_info); void DLogResultsStats(const char* message) const; @@ -194,7 +200,7 @@ class DnsHostInfo { // We put these objects into a std::map, and hence we // need some "evil" constructors. - // DISALLOW_COPY_AND_ASSIGN(DnsHostInfo); + // DISALLOW_COPY_AND_ASSIGN(UrlInfo); }; } // namespace chrome_browser_net diff --git a/chrome/browser/net/dns_host_info_unittest.cc b/chrome/browser/net/dns_host_info_unittest.cc index ffe122f..ba6964f 100644 --- a/chrome/browser/net/dns_host_info_unittest.cc +++ b/chrome/browser/net/dns_host_info_unittest.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Single threaded tests of DnsHostInfo functionality. +// Single threaded tests of UrlInfo functionality. #include <time.h> #include <string> @@ -18,17 +18,17 @@ namespace { class DnsHostInfoTest : public testing::Test { }; -typedef chrome_browser_net::DnsHostInfo DnsHostInfo; +typedef chrome_browser_net::UrlInfo UrlInfo; TEST(DnsHostInfoTest, StateChangeTest) { - DnsHostInfo info_practice, info; + UrlInfo info_practice, info; GURL url1("http://domain1.com:80"), url2("https://domain2.com:443"); // First load DLL, so that their load time won't interfere with tests. // Some tests involve timing function performance, and DLL time can overwhelm // test durations (which are considering network vs cache response times). info_practice.SetUrl(url2); - info_practice.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); + info_practice.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED); info_practice.SetAssignedState(); info_practice.SetFoundState(); PlatformThread::Sleep(500); // Allow time for DLLs to fully load. @@ -37,7 +37,7 @@ TEST(DnsHostInfoTest, StateChangeTest) { info.SetUrl(url1); EXPECT_TRUE(info.NeedsDnsUpdate()) << "error in construction state"; - info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); + info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED); EXPECT_FALSE(info.NeedsDnsUpdate()) << "update needed after being queued"; info.SetAssignedState(); @@ -51,7 +51,7 @@ TEST(DnsHostInfoTest, StateChangeTest) { // the required time till expiration will be halved (guessing that we were // half way through having the cache expire when we did the lookup. EXPECT_LT(info.resolve_duration().InMilliseconds(), - DnsHostInfo::kMaxNonNetworkDnsLookupDuration.InMilliseconds()) + UrlInfo::kMaxNonNetworkDnsLookupDuration.InMilliseconds()) << "Non-net time is set too low"; info.set_cache_expiration(TimeDelta::FromMilliseconds(300)); @@ -61,7 +61,7 @@ TEST(DnsHostInfoTest, StateChangeTest) { // That was a nice life when the object was found.... but next time it won't // be found. We'll sleep for a while, and then come back with not-found. - info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); + info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED); info.SetAssignedState(); EXPECT_FALSE(info.NeedsDnsUpdate()); // Greater than minimal expected network latency on DNS lookup. @@ -84,7 +84,7 @@ TEST(DnsHostInfoTest, StateChangeTest) { // When a system gets "congested" relative to DNS, it means it is doing too many // DNS resolutions, and bogging down the system. When we detect such a -// situation, we divert the sequence of states a DnsHostInfo instance moves +// situation, we divert the sequence of states a UrlInfo instance moves // through. Rather than proceeding from QUEUED (waiting in a name queue for a // worker thread that can resolve the name) to ASSIGNED (where a worker thread // actively resolves the name), we enter the ASSIGNED state (without actually @@ -92,11 +92,11 @@ TEST(DnsHostInfoTest, StateChangeTest) { // the corresponding name was put in the work_queue_. This test drives through // the state transitions used in such congestion handling. TEST(DnsHostInfoTest, CongestionResetStateTest) { - DnsHostInfo info; + UrlInfo info; GURL url("http://domain1.com:80"); info.SetUrl(url); - info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); + info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED); info.SetAssignedState(); EXPECT_TRUE(info.is_assigned()); @@ -109,13 +109,13 @@ TEST(DnsHostInfoTest, CongestionResetStateTest) { EXPECT_FALSE(info.was_nonexistant()); // Make sure we're completely re-usable, by going throug a normal flow. - info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); + info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED); info.SetAssignedState(); info.SetFoundState(); EXPECT_TRUE(info.was_found()); // Use the congestion flow, and check that we end up in the found state. - info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); + info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED); info.SetAssignedState(); info.RemoveFromQueue(); // Do the reset. EXPECT_FALSE(info.is_assigned()); diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc index 972759f..63e0772 100644 --- a/chrome/browser/net/dns_master.cc +++ b/chrome/browser/net/dns_master.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -26,14 +26,14 @@ using base::TimeDelta; namespace chrome_browser_net { -class DnsMaster::LookupRequest { +class Predictor::LookupRequest { public: - LookupRequest(DnsMaster* master, + LookupRequest(Predictor* predictor, net::HostResolver* host_resolver, const GURL& url) : ALLOW_THIS_IN_INITIALIZER_LIST( net_callback_(this, &LookupRequest::OnLookupFinished)), - master_(master), + predictor_(predictor), url_(url), resolver_(host_resolver) { } @@ -56,13 +56,13 @@ class DnsMaster::LookupRequest { private: void OnLookupFinished(int result) { - master_->OnLookupFinished(this, url_, result == net::OK); + predictor_->OnLookupFinished(this, url_, result == net::OK); } // HostResolver will call us using this callback when resolution is complete. net::CompletionCallbackImpl<LookupRequest> net_callback_; - DnsMaster* master_; // Master which started us. + Predictor* predictor_; // The predictor which started us. const GURL url_; // Hostname to resolve. net::SingleRequestHostResolver resolver_; @@ -71,24 +71,24 @@ class DnsMaster::LookupRequest { DISALLOW_COPY_AND_ASSIGN(LookupRequest); }; -DnsMaster::DnsMaster(net::HostResolver* host_resolver, - base::TimeDelta max_queue_delay, +Predictor::Predictor(net::HostResolver* host_resolver, + base::TimeDelta max_dns_queue_delay, size_t max_concurrent, bool preconnect_enabled) : peak_pending_lookups_(0), shutdown_(false), - max_concurrent_lookups_(max_concurrent), - max_queue_delay_(max_queue_delay), + max_concurrent_dns_lookups_(max_concurrent), + max_dns_queue_delay_(max_dns_queue_delay), host_resolver_(host_resolver), preconnect_enabled_(preconnect_enabled) { Referrer::SetUsePreconnectValuations(preconnect_enabled); } -DnsMaster::~DnsMaster() { +Predictor::~Predictor() { DCHECK(shutdown_); } -void DnsMaster::Shutdown() { +void Predictor::Shutdown() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(!shutdown_); shutdown_ = true; @@ -99,8 +99,8 @@ void DnsMaster::Shutdown() { } // Overloaded Resolve() to take a vector of names. -void DnsMaster::ResolveList(const UrlList& urls, - DnsHostInfo::ResolutionMotivation motivation) { +void Predictor::ResolveList(const UrlList& urls, + UrlInfo::ResolutionMotivation motivation) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); for (UrlList::const_iterator it = urls.begin(); it < urls.end(); ++it) { @@ -110,16 +110,16 @@ void DnsMaster::ResolveList(const UrlList& urls, // Basic Resolve() takes an invidual name, and adds it // to the queue. -void DnsMaster::Resolve(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation) { +void Predictor::Resolve(const GURL& url, + UrlInfo::ResolutionMotivation motivation) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (!url.has_host()) return; AppendToResolutionQueue(url, motivation); } -bool DnsMaster::AccruePrefetchBenefits(const GURL& referrer, - DnsHostInfo* navigation_info) { +bool Predictor::AccruePrefetchBenefits(const GURL& referrer, + UrlInfo* navigation_info) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); GURL url = navigation_info->url(); Results::iterator it = results_.find(url); @@ -129,10 +129,10 @@ bool DnsMaster::AccruePrefetchBenefits(const GURL& referrer, navigation_info->resolve_duration()); navigation_info->DLogResultsStats("DNS UnexpectedResolution"); - NonlinkNavigation(referrer, navigation_info->url()); + LearnFromNavigation(referrer, navigation_info->url()); return false; } - DnsHostInfo& prefetched_host_info(it->second); + UrlInfo& prefetched_host_info(it->second); // Sometimes a host is used as a subresource by several referrers, so it is // in our list, but was never motivated by a page-link-scan. In that case, it @@ -141,7 +141,7 @@ bool DnsMaster::AccruePrefetchBenefits(const GURL& referrer, bool referrer_based_prefetch = !prefetched_host_info.was_linked(); if (referrer_based_prefetch) { // This wasn't the first time this host refered to *some* referrer. - NonlinkNavigation(referrer, navigation_info->url()); + LearnFromNavigation(referrer, navigation_info->url()); } DnsBenefit benefit = prefetched_host_info.AccruePrefetchBenefits( @@ -149,7 +149,7 @@ bool DnsMaster::AccruePrefetchBenefits(const GURL& referrer, switch (benefit) { case PREFETCH_NAME_FOUND: case PREFETCH_NAME_NONEXISTANT: - cache_hits_.push_back(*navigation_info); + dns_cache_hits_.push_back(*navigation_info); if (referrer_based_prefetch) { if (referrer.has_host()) { referrers_[referrer].AccrueValue( @@ -172,8 +172,8 @@ bool DnsMaster::AccruePrefetchBenefits(const GURL& referrer, } } -void DnsMaster::NonlinkNavigation(const GURL& referring_url, - const GURL& target_url) { +void Predictor::LearnFromNavigation(const GURL& referring_url, + const GURL& target_url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (referring_url.has_host() && referring_url != target_url) { @@ -182,7 +182,7 @@ void DnsMaster::NonlinkNavigation(const GURL& referring_url, } } -void DnsMaster::NavigatingTo(const GURL& url) { +void Predictor::PredictSubresources(const GURL& url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); Referrers::iterator it = referrers_.find(url); if (referrers_.end() == it) @@ -191,15 +191,15 @@ void DnsMaster::NavigatingTo(const GURL& url) { referrer->IncrementUseCount(); for (Referrer::iterator future_url = referrer->begin(); future_url != referrer->end(); ++future_url) { - DnsHostInfo* queued_info = AppendToResolutionQueue( + UrlInfo* queued_info = AppendToResolutionQueue( future_url->first, - DnsHostInfo::LEARNED_REFERAL_MOTIVATED); + UrlInfo::LEARNED_REFERAL_MOTIVATED); if (queued_info) queued_info->SetReferringHostname(url); } } -void DnsMaster::NavigatingToFrame(const GURL& url) { +void Predictor::PredictFrameSubresources(const GURL& url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(url.GetWithEmptyPath() == url); Referrers::iterator it = referrers_.find(url); @@ -280,7 +280,7 @@ struct RightToLeftStringSorter { } }; -void DnsMaster::GetHtmlReferrerLists(std::string* output) { +void Predictor::GetHtmlReferrerLists(std::string* output) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (referrers_.empty()) return; @@ -331,21 +331,21 @@ void DnsMaster::GetHtmlReferrerLists(std::string* output) { output->append("</table>"); } -void DnsMaster::GetHtmlInfo(std::string* output) { +void Predictor::GetHtmlInfo(std::string* output) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - // Local lists for calling DnsHostInfo - DnsHostInfo::DnsInfoTable cache_hits; - DnsHostInfo::DnsInfoTable cache_evictions; - DnsHostInfo::DnsInfoTable name_not_found; - DnsHostInfo::DnsInfoTable network_hits; - DnsHostInfo::DnsInfoTable already_cached; + // Local lists for calling UrlInfo + UrlInfo::DnsInfoTable cache_hits; + UrlInfo::DnsInfoTable cache_evictions; + UrlInfo::DnsInfoTable name_not_found; + UrlInfo::DnsInfoTable network_hits; + UrlInfo::DnsInfoTable already_cached; // Get copies of all useful data. - typedef std::map<GURL, DnsHostInfo, RightToLeftStringSorter> + typedef std::map<GURL, UrlInfo, RightToLeftStringSorter> Snapshot; Snapshot snapshot; { - // DnsHostInfo supports value semantics, so we can do a shallow copy. + // UrlInfo supports value semantics, so we can do a shallow copy. for (Results::iterator it(results_.begin()); it != results_.end(); it++) { snapshot[it->first] = it->second; } @@ -355,14 +355,14 @@ void DnsMaster::GetHtmlInfo(std::string* output) { cache_evictions.push_back(it->second); } // Reverse list as we copy cache hits, so that new hits are at the top. - size_t index = cache_hits_.size(); + size_t index = dns_cache_hits_.size(); while (index > 0) { index--; - cache_hits.push_back(cache_hits_[index]); + cache_hits.push_back(dns_cache_hits_[index]); } } - // Partition the DnsHostInfo's into categories. + // Partition the UrlInfo's into categories. for (Snapshot::iterator it(snapshot.begin()); it != snapshot.end(); it++) { if (it->second.was_nonexistant()) { name_not_found.push_back(it->second); @@ -374,7 +374,7 @@ void DnsMaster::GetHtmlInfo(std::string* output) { network_hits.push_back(it->second); // With no benefit yet. continue; } - if (DnsHostInfo::kMaxNonNetworkDnsLookupDuration > + if (UrlInfo::kMaxNonNetworkDnsLookupDuration > it->second.resolve_duration()) { already_cached.push_back(it->second); continue; @@ -389,28 +389,28 @@ void DnsMaster::GetHtmlInfo(std::string* output) { #endif // NDEBUG // Call for display of each table, along with title. - DnsHostInfo::GetHtmlTable(cache_hits, + UrlInfo::GetHtmlTable(cache_hits, "Prefetching DNS records produced benefits for ", false, output); - DnsHostInfo::GetHtmlTable(cache_evictions, + UrlInfo::GetHtmlTable(cache_evictions, "Cache evictions negated DNS prefetching benefits for ", brief, output); - DnsHostInfo::GetHtmlTable(network_hits, + UrlInfo::GetHtmlTable(network_hits, "Prefetching DNS records was not yet beneficial for ", brief, output); - DnsHostInfo::GetHtmlTable(already_cached, + UrlInfo::GetHtmlTable(already_cached, "Previously cached resolutions were found for ", brief, output); - DnsHostInfo::GetHtmlTable(name_not_found, + UrlInfo::GetHtmlTable(name_not_found, "Prefetching DNS records revealed non-existance for ", brief, output); } -DnsHostInfo* DnsMaster::AppendToResolutionQueue( +UrlInfo* Predictor::AppendToResolutionQueue( const GURL& url, - DnsHostInfo::ResolutionMotivation motivation) { + UrlInfo::ResolutionMotivation motivation) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(url.has_host()); if (shutdown_) return NULL; - DnsHostInfo* info = &results_[url]; + UrlInfo* info = &results_[url]; info->SetUrl(url); // Initialize or DCHECK. // TODO(jar): I need to discard names that have long since expired. // Currently we only add to the domain map :-/ @@ -428,13 +428,13 @@ DnsHostInfo* DnsMaster::AppendToResolutionQueue( return info; } -void DnsMaster::StartSomeQueuedResolutions() { +void Predictor::StartSomeQueuedResolutions() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); while (!work_queue_.IsEmpty() && - pending_lookups_.size() < max_concurrent_lookups_) { + pending_lookups_.size() < max_concurrent_dns_lookups_) { const GURL url(work_queue_.Pop()); - DnsHostInfo* info = &results_[url]; + UrlInfo* info = &results_[url]; DCHECK(info->HasUrl(url)); info->SetAssignedState(); @@ -460,10 +460,10 @@ void DnsMaster::StartSomeQueuedResolutions() { } } -bool DnsMaster::CongestionControlPerformed(DnsHostInfo* info) { +bool Predictor::CongestionControlPerformed(UrlInfo* info) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); // Note: queue_duration is ONLY valid after we go to assigned state. - if (info->queue_duration() < max_queue_delay_) + if (info->queue_duration() < max_dns_queue_delay_) return false; // We need to discard all entries in our queue, as we're keeping them waiting // too long. By doing this, we'll have a chance to quickly service urgent @@ -478,7 +478,7 @@ bool DnsMaster::CongestionControlPerformed(DnsHostInfo* info) { return true; } -void DnsMaster::OnLookupFinished(LookupRequest* request, const GURL& url, +void Predictor::OnLookupFinished(LookupRequest* request, const GURL& url, bool found) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); @@ -489,10 +489,10 @@ void DnsMaster::OnLookupFinished(LookupRequest* request, const GURL& url, StartSomeQueuedResolutions(); } -void DnsMaster::LookupFinished(LookupRequest* request, const GURL& url, +void Predictor::LookupFinished(LookupRequest* request, const GURL& url, bool found) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - DnsHostInfo* info = &results_[url]; + UrlInfo* info = &results_[url]; DCHECK(info->HasUrl(url)); if (info->is_marked_to_delete()) { results_.erase(url); @@ -504,11 +504,11 @@ void DnsMaster::LookupFinished(LookupRequest* request, const GURL& url, } } -void DnsMaster::DiscardAllResults() { +void Predictor::DiscardAllResults() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); // Delete anything listed so far in this session that shows in about:dns. cache_eviction_map_.clear(); - cache_hits_.clear(); + dns_cache_hits_.clear(); referrers_.clear(); @@ -516,7 +516,7 @@ void DnsMaster::DiscardAllResults() { while (!work_queue_.IsEmpty()) { // Emulate processing cycle as though host was not found. GURL url = work_queue_.Pop(); - DnsHostInfo* info = &results_[url]; + UrlInfo* info = &results_[url]; DCHECK(info->HasUrl(url)); info->SetAssignedState(); info->SetNoSuchNameState(); @@ -529,14 +529,14 @@ void DnsMaster::DiscardAllResults() { Results assignees; for (Results::iterator it = results_.begin(); results_.end() != it; ++it) { GURL url(it->first); - DnsHostInfo* info = &it->second; + UrlInfo* info = &it->second; DCHECK(info->HasUrl(url)); if (info->is_assigned()) { info->SetPendingDeleteState(); assignees[url] = *info; } } - DCHECK(assignees.size() <= max_concurrent_lookups_); + DCHECK(assignees.size() <= max_concurrent_dns_lookups_); results_.clear(); // Put back in the names being worked on. for (Results::iterator it = assignees.begin(); assignees.end() != it; ++it) { @@ -545,7 +545,7 @@ void DnsMaster::DiscardAllResults() { } } -void DnsMaster::TrimReferrers() { +void Predictor::TrimReferrers() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); std::vector<GURL> urls; for (Referrers::const_iterator it = referrers_.begin(); @@ -556,7 +556,7 @@ void DnsMaster::TrimReferrers() { referrers_.erase(urls[i]); } -void DnsMaster::SerializeReferrers(ListValue* referral_list) { +void Predictor::SerializeReferrers(ListValue* referral_list) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); referral_list->Clear(); referral_list->Append(new FundamentalValue(DNS_REFERRER_VERSION)); @@ -574,7 +574,7 @@ void DnsMaster::SerializeReferrers(ListValue* referral_list) { } } -void DnsMaster::DeserializeReferrers(const ListValue& referral_list) { +void Predictor::DeserializeReferrers(const ListValue& referral_list) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); int format_version = -1; if (referral_list.GetSize() > 0 && @@ -606,18 +606,18 @@ void DnsMaster::DeserializeReferrers(const ListValue& referral_list) { //------------------------------------------------------------------------------ -DnsMaster::HostNameQueue::HostNameQueue() { +Predictor::HostNameQueue::HostNameQueue() { } -DnsMaster::HostNameQueue::~HostNameQueue() { +Predictor::HostNameQueue::~HostNameQueue() { } -void DnsMaster::HostNameQueue::Push(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation) { +void Predictor::HostNameQueue::Push(const GURL& url, + UrlInfo::ResolutionMotivation motivation) { switch (motivation) { - case DnsHostInfo::STATIC_REFERAL_MOTIVATED: - case DnsHostInfo::LEARNED_REFERAL_MOTIVATED: - case DnsHostInfo::MOUSE_OVER_MOTIVATED: + case UrlInfo::STATIC_REFERAL_MOTIVATED: + case UrlInfo::LEARNED_REFERAL_MOTIVATED: + case UrlInfo::MOUSE_OVER_MOTIVATED: rush_queue_.push(url); break; @@ -627,11 +627,11 @@ void DnsMaster::HostNameQueue::Push(const GURL& url, } } -bool DnsMaster::HostNameQueue::IsEmpty() const { +bool Predictor::HostNameQueue::IsEmpty() const { return rush_queue_.empty() && background_queue_.empty(); } -GURL DnsMaster::HostNameQueue::Pop() { +GURL Predictor::HostNameQueue::Pop() { DCHECK(!IsEmpty()); std::queue<GURL> *queue(rush_queue_.empty() ? &background_queue_ : &rush_queue_); diff --git a/chrome/browser/net/dns_master.h b/chrome/browser/net/dns_master.h index 29d3278..c059f86 100644 --- a/chrome/browser/net/dns_master.h +++ b/chrome/browser/net/dns_master.h @@ -1,15 +1,20 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// A DnsMaster object is instantiated once in the browser -// process, and manages asynchronous resolution of DNS hostnames. -// Most hostname lists are sent out by renderer processes, and -// involve lists of hostnames that *might* be used in the near -// future by the browsing user. The goal of this class is to -// cause the underlying DNS structure to lookup a hostname before -// it is really needed, and hence reduce latency in the standard -// lookup paths. +// A Predictor object is instantiated once in the browser process, and manages +// both preresolution of hostnames, as well as TCP/IP preconnection to expected +// subresources. +// Most hostname lists are provided by the renderer processes, and include URLs +// that *might* be used in the near future by the browsing user. One goal of +// this class is to cause the underlying DNS structure to lookup a hostname +// before it is really needed, and hence reduce latency in the standard lookup +// paths. +// Subresource relationships are usually acquired from the referrer field in a +// navigation. A subresource URL may be associated with a referrer URL. Later +// navigations may, if the likelihood of needing the subresource is high enough, +// cause this module to speculatively create a TCP/IP connection that will +// probably be needed to fetch the subresource. #ifndef CHROME_BROWSER_NET_DNS_MASTER_H_ #define CHROME_BROWSER_NET_DNS_MASTER_H_ @@ -35,11 +40,11 @@ namespace chrome_browser_net { typedef chrome_common_net::UrlList UrlList; typedef chrome_common_net::NameList NameList; -typedef std::map<GURL, DnsHostInfo> Results; +typedef std::map<GURL, UrlInfo> Results; -// Note that DNS master is not thread safe, and must only be called from +// Note that Predictor is not thread safe, and must only be called from // the IO thread. Failure to do so will result in a DCHECK at runtime. -class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { +class Predictor : public base::RefCountedThreadSafe<Predictor> { public: // A version number for prefs that are saved. This should be incremented when // we change the format so that we discard old data. @@ -47,7 +52,7 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { // |max_concurrent| specifies how many concurrent (parallel) prefetches will // be performed. Host lookups will be issued through |host_resolver|. - DnsMaster(net::HostResolver* host_resolver, + Predictor(net::HostResolver* host_resolver, base::TimeDelta max_queue_delay_ms, size_t max_concurrent, bool preconnect_enabled); @@ -63,30 +68,30 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { // Add hostname(s) to the queue for processing. void ResolveList(const UrlList& urls, - DnsHostInfo::ResolutionMotivation motivation); + UrlInfo::ResolutionMotivation motivation); void Resolve(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation); + UrlInfo::ResolutionMotivation motivation); // Get latency benefit of the prefetch that we are navigating to. bool AccruePrefetchBenefits(const GURL& referrer, - DnsHostInfo* navigation_info); + UrlInfo* navigation_info); // Instigate preresolution of any domains we predict will be needed after this // navigation. - void NavigatingTo(const GURL& url); + void PredictSubresources(const GURL& url); // Instigate pre-connection to any URLs we predict will be needed after this // navigation (typically more-embedded resources on a page). - void NavigatingToFrame(const GURL& url); + void PredictFrameSubresources(const GURL& url); // Record details of a navigation so that we can preresolve the host name // ahead of time the next time the users navigates to the indicated host. - void NonlinkNavigation(const GURL& referring_url, const GURL& target_url); + void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); // Dump HTML table containing list of referrers for about:dns. void GetHtmlReferrerLists(std::string* output); - // Dump the list of currently know referrer domains and related prefetchable + // Dump the list of currently known referrer domains and related prefetchable // domains. void GetHtmlInfo(std::string* output); @@ -112,23 +117,25 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { } // For unit test code only. - size_t max_concurrent_lookups() const { return max_concurrent_lookups_; } + size_t max_concurrent_dns_lookups() const { + return max_concurrent_dns_lookups_; + } // Flag setting to use preconnection instead of just DNS pre-fetching. bool preconnect_enabled() const { return preconnect_enabled_; } private: - friend class base::RefCountedThreadSafe<DnsMaster>; - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, BenefitLookupTest); - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, ShutdownWhenResolutionIsPendingTest); - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, SingleLookupTest); - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, ConcurrentLookupTest); - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, MassiveConcurrentLookupTest); - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, PriorityQueuePushPopTest); - FRIEND_TEST_ALL_PREFIXES(DnsMasterTest, PriorityQueueReorderTest); + friend class base::RefCountedThreadSafe<Predictor>; + FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); + FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); + FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); + FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); + FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); + FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); + FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); friend class WaitForResolutionHelper; // For testing. - ~DnsMaster(); + ~Predictor(); class LookupRequest; @@ -145,7 +152,7 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { HostNameQueue(); ~HostNameQueue(); void Push(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation); + UrlInfo::ResolutionMotivation motivation); bool IsEmpty() const; GURL Pop(); @@ -173,11 +180,10 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { } // Only for testing. Return how long was the resolution - // or DnsHostInfo::kNullDuration if it hasn't been resolved yet. + // or UrlInfo::kNullDuration if it hasn't been resolved yet. base::TimeDelta GetResolutionDuration(const GURL& url) { - if (results_.find(url) == results_.end()) - return DnsHostInfo::kNullDuration; + return UrlInfo::kNullDuration; return results_[url].resolve_duration(); } @@ -193,8 +199,8 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { // Queue hostname for resolution. If queueing was done, return the pointer // to the queued instance, otherwise return NULL. - DnsHostInfo* AppendToResolutionQueue(const GURL& url, - DnsHostInfo::ResolutionMotivation motivation); + UrlInfo* AppendToResolutionQueue(const GURL& url, + UrlInfo::ResolutionMotivation motivation); // Check to see if too much queuing delay has been noted for the given info, // which indicates that there is "congestion" or growing delay in handling the @@ -208,7 +214,7 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { // will greatly reduce the number of resolutions done, but it will assure that // any resolutions that are done, are in a timely and hence potentially // helpful manner. - bool CongestionControlPerformed(DnsHostInfo* info); + bool CongestionControlPerformed(UrlInfo* info); // Take lookup requests from work_queue_ and tell HostResolver to look them up // asynchronously, provided we don't exceed concurrent resolution limit. @@ -234,17 +240,17 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { bool shutdown_; // A list of successful events resulting from pre-fetching. - DnsHostInfo::DnsInfoTable cache_hits_; + UrlInfo::DnsInfoTable dns_cache_hits_; // A map of hosts that were evicted from our cache (after we prefetched them) // and before the HTTP stack tried to look them up. Results cache_eviction_map_; // The number of concurrent lookups currently allowed. - const size_t max_concurrent_lookups_; + const size_t max_concurrent_dns_lookups_; // The maximum queueing delay that is acceptable before we enter congestion // reduction mode, and discard all queued (but not yet assigned) resolutions. - const base::TimeDelta max_queue_delay_; + const base::TimeDelta max_dns_queue_delay_; // The host resovler we warm DNS entries for. scoped_refptr<net::HostResolver> host_resolver_; @@ -253,7 +259,7 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { // subresources and omni-box search URLs. bool preconnect_enabled_; - DISALLOW_COPY_AND_ASSIGN(DnsMaster); + DISALLOW_COPY_AND_ASSIGN(Predictor); }; } // namespace chrome_browser_net diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc index 63323bb..a918384 100644 --- a/chrome/browser/net/dns_master_unittest.cc +++ b/chrome/browser/net/dns_master_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,17 +32,17 @@ typedef base::RepeatingTimer<WaitForResolutionHelper> HelperTimer; class WaitForResolutionHelper { public: - WaitForResolutionHelper(DnsMaster* master, const UrlList& hosts, + WaitForResolutionHelper(Predictor* predictor, const UrlList& hosts, HelperTimer* timer) - : master_(master), + : predictor_(predictor), hosts_(hosts), timer_(timer) { } void Run() { for (UrlList::const_iterator i = hosts_.begin(); i != hosts_.end(); ++i) - if (master_->GetResolutionDuration(*i) == - DnsHostInfo::kNullDuration) + if (predictor_->GetResolutionDuration(*i) == + UrlInfo::kNullDuration) return; // We don't have resolution for that host. // When all hostnames have been resolved, exit the loop. @@ -53,18 +53,18 @@ class WaitForResolutionHelper { } private: - DnsMaster* master_; + Predictor* predictor_; const UrlList hosts_; HelperTimer* timer_; }; -class DnsMasterTest : public testing::Test { +class PredictorTest : public testing::Test { public: - DnsMasterTest() + PredictorTest() : io_thread_(ChromeThread::IO, &loop_), host_resolver_(new net::MockCachingHostResolver()), default_max_queueing_delay_(TimeDelta::FromMilliseconds( - DnsGlobalInit::kMaxPrefetchQueueingDelayMs)) { + PredictorInit::kMaxPrefetchQueueingDelayMs)) { } protected: @@ -82,10 +82,10 @@ class DnsMasterTest : public testing::Test { rules->AddRuleWithLatency("gmail.com", "127.0.0.1", 63); } - void WaitForResolution(DnsMaster* master, const UrlList& hosts) { + void WaitForResolution(Predictor* predictor, const UrlList& hosts) { HelperTimer* timer = new HelperTimer(); timer->Start(TimeDelta::FromMilliseconds(100), - new WaitForResolutionHelper(master, hosts, timer), + new WaitForResolutionHelper(predictor, hosts, timer), &WaitForResolutionHelper::Run); MessageLoop::current()->Run(); } @@ -100,33 +100,33 @@ class DnsMasterTest : public testing::Test { protected: scoped_refptr<net::MockCachingHostResolver> host_resolver_; - // Shorthand to access TimeDelta of DnsGlobalInit::kMaxQueueingDelayMs. + // Shorthand to access TimeDelta of PredictorInit::kMaxQueueingDelayMs. // (It would be a static constant... except style rules preclude that :-/ ). const TimeDelta default_max_queueing_delay_; }; //------------------------------------------------------------------------------ -TEST_F(DnsMasterTest, StartupShutdownTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, +TEST_F(PredictorTest, StartupShutdownTest) { + scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); testing_master->Shutdown(); } -TEST_F(DnsMasterTest, BenefitLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster( +TEST_F(PredictorTest, BenefitLookupTest) { + scoped_refptr<Predictor> testing_master = new Predictor( host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); GURL goog("http://www.google.com:80"), goog2("http://gmail.google.com.com:80"), goog3("http://mail.google.com:80"), goog4("http://gmail.com:80"); - DnsHostInfo goog_info, goog2_info, goog3_info, goog4_info; + UrlInfo goog_info, goog2_info, goog3_info, goog4_info; // Simulate getting similar names from a network observer goog_info.SetUrl(goog); @@ -150,7 +150,7 @@ TEST_F(DnsMasterTest, BenefitLookupTest) { names.push_back(goog3); names.push_back(goog4); - testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); + testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); WaitForResolution(testing_master, names); @@ -180,21 +180,21 @@ TEST_F(DnsMasterTest, BenefitLookupTest) { testing_master->Shutdown(); } -TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { +TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { scoped_refptr<net::WaitingHostResolverProc> resolver_proc = new net::WaitingHostResolverProc(NULL); host_resolver_->Reset(resolver_proc); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, + scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); GURL localhost("http://127.0.0.1:80"); UrlList names; names.push_back(localhost); - testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); + testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask(), 500); @@ -209,10 +209,10 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { MessageLoop::current()->RunAllPending(); } -TEST_F(DnsMasterTest, SingleLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, +TEST_F(PredictorTest, SingleLookupTest) { + scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); GURL goog("http://www.google.com:80"); @@ -220,9 +220,9 @@ TEST_F(DnsMasterTest, SingleLookupTest) { UrlList names; names.push_back(goog); - // Try to flood the master with many concurrent requests. + // Try to flood the predictor with many concurrent requests. for (int i = 0; i < 10; i++) - testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); + testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); WaitForResolution(testing_master, names); @@ -233,17 +233,17 @@ TEST_F(DnsMasterTest, SingleLookupTest) { EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); EXPECT_LE(testing_master->peak_pending_lookups(), - testing_master->max_concurrent_lookups()); + testing_master->max_concurrent_dns_lookups()); testing_master->Shutdown(); } -TEST_F(DnsMasterTest, ConcurrentLookupTest) { +TEST_F(PredictorTest, ConcurrentLookupTest) { host_resolver_->rules()->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, + scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); GURL goog("http://www.google.com:80"), @@ -262,9 +262,9 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) { names.push_back(goog4); names.push_back(goog); - // Try to flood the master with many concurrent requests. + // Try to flood the predictor with many concurrent requests. for (int i = 0; i < 10; i++) - testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); + testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); WaitForResolution(testing_master, names); @@ -283,27 +283,27 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) { EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); EXPECT_LE(testing_master->peak_pending_lookups(), - testing_master->max_concurrent_lookups()); + testing_master->max_concurrent_dns_lookups()); testing_master->Shutdown(); } -TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) { +TEST_F(PredictorTest, MassiveConcurrentLookupTest) { host_resolver_->rules()->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster( + scoped_refptr<Predictor> testing_master = new Predictor( host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); UrlList names; for (int i = 0; i < 100; i++) names.push_back(GURL("http://host" + IntToString(i) + ".notfound:80")); - // Try to flood the master with many concurrent requests. + // Try to flood the predictor with many concurrent requests. for (int i = 0; i < 10; i++) - testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); + testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); WaitForResolution(testing_master, names); @@ -311,7 +311,7 @@ TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) { EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); EXPECT_LE(testing_master->peak_pending_lookups(), - testing_master->max_concurrent_lookups()); + testing_master->max_concurrent_dns_lookups()); testing_master->Shutdown(); } @@ -327,7 +327,7 @@ static ListValue* FindSerializationMotivation( CHECK_LT(0u, referral_list.GetSize()); // Room for version. int format_version = -1; CHECK(referral_list.GetInteger(0, &format_version)); - CHECK_EQ(DnsMaster::DNS_REFERRER_VERSION, format_version); + CHECK_EQ(Predictor::DNS_REFERRER_VERSION, format_version); ListValue* motivation_list(NULL); for (size_t i = 1; i < referral_list.GetSize(); ++i) { referral_list.GetList(i, &motivation_list); @@ -342,7 +342,7 @@ static ListValue* FindSerializationMotivation( // Create a new empty serialization list. static ListValue* NewEmptySerializationList() { ListValue* list = new ListValue; - list->Append(new FundamentalValue(DnsMaster::DNS_REFERRER_VERSION)); + list->Append(new FundamentalValue(Predictor::DNS_REFERRER_VERSION)); return list; } @@ -413,28 +413,28 @@ static bool GetDataFromSerialization(const GURL& 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_, +TEST_F(PredictorTest, ReferrerSerializationNilTest) { + scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); - master->SerializeReferrers(referral_list.get()); + predictor->SerializeReferrers(referral_list.get()); EXPECT_EQ(1U, referral_list->GetSize()); EXPECT_FALSE(GetDataFromSerialization( GURL("http://a.com:79"), GURL("http://b.com:78"), *referral_list.get(), NULL, NULL)); - master->Shutdown(); + predictor->Shutdown(); } // Make sure that when a serialization list includes a value, that it can be // 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_, +TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { + scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); const GURL motivation_url("http://www.google.com:91"); const GURL subresource_url("http://icons.google.com:90"); @@ -445,10 +445,10 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { AddToSerializedList(motivation_url, subresource_url, kLatency, kRate, referral_list.get()); - master->DeserializeReferrers(*referral_list.get()); + predictor->DeserializeReferrers(*referral_list.get()); ListValue recovered_referral_list; - master->SerializeReferrers(&recovered_referral_list); + predictor->SerializeReferrers(&recovered_referral_list); EXPECT_EQ(2U, recovered_referral_list.GetSize()); int latency; double rate; @@ -458,14 +458,14 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { EXPECT_EQ(rate, kRate); EXPECT_EQ(latency, kLatency); - master->Shutdown(); + predictor->Shutdown(); } // Make sure the Trim() functionality works as expected. -TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, +TEST_F(PredictorTest, ReferrerSerializationTrimTest) { + scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, default_max_queueing_delay_, - DnsGlobalInit::kMaxPrefetchConcurrentLookups, + PredictorInit::kMaxPrefetchConcurrentLookups, false); GURL motivation_url("http://www.google.com:110"); @@ -484,10 +484,10 @@ TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { motivation_url, img_subresource_url, kLatencyImg, kRateImg, referral_list.get()); - master->DeserializeReferrers(*referral_list.get()); + predictor->DeserializeReferrers(*referral_list.get()); ListValue recovered_referral_list; - master->SerializeReferrers(&recovered_referral_list); + predictor->SerializeReferrers(&recovered_referral_list); EXPECT_EQ(2U, recovered_referral_list.GetSize()); int latency; double rate; @@ -505,8 +505,8 @@ TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { // Each time we Trim, the latency figures should reduce by a factor of two, // until they both are 0, an then a trim will delete the whole entry. - master->TrimReferrers(); - master->SerializeReferrers(&recovered_referral_list); + predictor->TrimReferrers(); + predictor->SerializeReferrers(&recovered_referral_list); EXPECT_EQ(2U, recovered_referral_list.GetSize()); EXPECT_TRUE(GetDataFromSerialization( motivation_url, icon_subresource_url, recovered_referral_list, @@ -520,8 +520,8 @@ TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { EXPECT_EQ(latency, kLatencyImg / 2); EXPECT_EQ(rate, kRateImg); - master->TrimReferrers(); - master->SerializeReferrers(&recovered_referral_list); + predictor->TrimReferrers(); + predictor->SerializeReferrers(&recovered_referral_list); EXPECT_EQ(2U, recovered_referral_list.GetSize()); EXPECT_TRUE(GetDataFromSerialization( motivation_url, icon_subresource_url, recovered_referral_list, @@ -536,8 +536,8 @@ TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { EXPECT_EQ(latency, kLatencyImg / 4); EXPECT_EQ(rate, kRateImg); - master->TrimReferrers(); - master->SerializeReferrers(&recovered_referral_list); + predictor->TrimReferrers(); + predictor->SerializeReferrers(&recovered_referral_list); EXPECT_EQ(2U, recovered_referral_list.GetSize()); EXPECT_TRUE(GetDataFromSerialization( motivation_url, icon_subresource_url, recovered_referral_list, @@ -553,8 +553,8 @@ TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { EXPECT_EQ(latency, kLatencyImg / 8); EXPECT_EQ(rate, kRateImg); - master->TrimReferrers(); - master->SerializeReferrers(&recovered_referral_list); + predictor->TrimReferrers(); + predictor->SerializeReferrers(&recovered_referral_list); // Icon is also trimmed away, so entire set gets discarded. EXPECT_EQ(1U, recovered_referral_list.GetSize()); EXPECT_FALSE(GetDataFromSerialization( @@ -564,20 +564,20 @@ TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { motivation_url, img_subresource_url, recovered_referral_list, &rate, &latency)); - master->Shutdown(); + predictor->Shutdown(); } -TEST_F(DnsMasterTest, PriorityQueuePushPopTest) { - DnsMaster::HostNameQueue queue; +TEST_F(PredictorTest, PriorityQueuePushPopTest) { + Predictor::HostNameQueue queue; GURL first("http://first:80"), second("http://second:90"); // First check high priority queue FIFO functionality. EXPECT_TRUE(queue.IsEmpty()); - queue.Push(first, DnsHostInfo::LEARNED_REFERAL_MOTIVATED); + queue.Push(first, UrlInfo::LEARNED_REFERAL_MOTIVATED); EXPECT_FALSE(queue.IsEmpty()); - queue.Push(second, DnsHostInfo::MOUSE_OVER_MOTIVATED); + queue.Push(second, UrlInfo::MOUSE_OVER_MOTIVATED); EXPECT_FALSE(queue.IsEmpty()); EXPECT_EQ(queue.Pop(), first); EXPECT_FALSE(queue.IsEmpty()); @@ -585,9 +585,9 @@ TEST_F(DnsMasterTest, PriorityQueuePushPopTest) { EXPECT_TRUE(queue.IsEmpty()); // Then check low priority queue FIFO functionality. - queue.Push(first, DnsHostInfo::PAGE_SCAN_MOTIVATED); + queue.Push(first, UrlInfo::PAGE_SCAN_MOTIVATED); EXPECT_FALSE(queue.IsEmpty()); - queue.Push(second, DnsHostInfo::OMNIBOX_MOTIVATED); + queue.Push(second, UrlInfo::OMNIBOX_MOTIVATED); EXPECT_FALSE(queue.IsEmpty()); EXPECT_EQ(queue.Pop(), first); EXPECT_FALSE(queue.IsEmpty()); @@ -595,8 +595,8 @@ TEST_F(DnsMasterTest, PriorityQueuePushPopTest) { EXPECT_TRUE(queue.IsEmpty()); } -TEST_F(DnsMasterTest, PriorityQueueReorderTest) { - DnsMaster::HostNameQueue queue; +TEST_F(PredictorTest, PriorityQueueReorderTest) { + Predictor::HostNameQueue queue; // Push all the low priority items. GURL low1("http://low1:80"), @@ -609,17 +609,17 @@ TEST_F(DnsMasterTest, PriorityQueueReorderTest) { hi3("http://hi3:80"); EXPECT_TRUE(queue.IsEmpty()); - queue.Push(low1, DnsHostInfo::PAGE_SCAN_MOTIVATED); - queue.Push(low2, DnsHostInfo::UNIT_TEST_MOTIVATED); - queue.Push(low3, DnsHostInfo::LINKED_MAX_MOTIVATED); - queue.Push(low4, DnsHostInfo::OMNIBOX_MOTIVATED); - queue.Push(low5, DnsHostInfo::STARTUP_LIST_MOTIVATED); - queue.Push(low4, DnsHostInfo::OMNIBOX_MOTIVATED); + queue.Push(low1, UrlInfo::PAGE_SCAN_MOTIVATED); + queue.Push(low2, UrlInfo::UNIT_TEST_MOTIVATED); + queue.Push(low3, UrlInfo::LINKED_MAX_MOTIVATED); + queue.Push(low4, UrlInfo::OMNIBOX_MOTIVATED); + queue.Push(low5, UrlInfo::STARTUP_LIST_MOTIVATED); + queue.Push(low4, UrlInfo::OMNIBOX_MOTIVATED); // Push all the high prority items - queue.Push(hi1, DnsHostInfo::LEARNED_REFERAL_MOTIVATED); - queue.Push(hi2, DnsHostInfo::STATIC_REFERAL_MOTIVATED); - queue.Push(hi3, DnsHostInfo::MOUSE_OVER_MOTIVATED); + queue.Push(hi1, UrlInfo::LEARNED_REFERAL_MOTIVATED); + queue.Push(hi2, UrlInfo::STATIC_REFERAL_MOTIVATED); + queue.Push(hi3, UrlInfo::MOUSE_OVER_MOTIVATED); // Check that high priority stuff comes out first, and in FIFO order. EXPECT_EQ(queue.Pop(), hi1); diff --git a/chrome/browser/net/referrer.h b/chrome/browser/net/referrer.h index 8b98a5c..3652e1f 100644 --- a/chrome/browser/net/referrer.h +++ b/chrome/browser/net/referrer.h @@ -1,15 +1,16 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This class helps to remember what domains may be needed to be resolved when a // navigation takes place to a given URL. This information is gathered when a -// navigation resolution was not foreseen by identifying the referrer field that -// induced the navigation. When future navigations take place to known referrer -// sites, then we automatically pre-resolve the expected set of useful domains. +// navigation to a subresource identifies a referring URL. +// When future navigations take place to known referrer sites, then we +// speculatively either pre-warm a TCP/IP conneciton, or at a minimum, resolve +// the host name via DNS. -// All access to this class is performed via the DnsMaster class, and is -// protected by the its lock. +// All access to this class is performed via the Predictor class, which only +// operates on the IO thread. #ifndef CHROME_BROWSER_NET_REFERRER_H_ #define CHROME_BROWSER_NET_REFERRER_H_ diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index b8b88cb..53e057c 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -503,7 +503,7 @@ void PrivacySection::ButtonPressed( "Options_DnsPrefetchCheckbox_Disable"), profile()->GetPrefs()); dns_prefetch_enabled_.SetValue(enabled); - chrome_browser_net::EnableDnsPrefetch(enabled); + chrome_browser_net::EnablePredictor(enabled); } else if (sender == enable_safe_browsing_checkbox_) { bool enabled = enable_safe_browsing_checkbox_->checked(); UserMetricsRecordAction(UserMetricsAction(enabled ? @@ -674,7 +674,7 @@ void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) { bool enabled = dns_prefetch_enabled_.GetValue(); enable_dns_prefetching_checkbox_->SetChecked(enabled); - chrome_browser_net::EnableDnsPrefetch(enabled); + chrome_browser_net::EnablePredictor(enabled); } if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) enable_safe_browsing_checkbox_->SetChecked(safe_browsing_.GetValue()); diff --git a/chrome/renderer/net/render_dns_master.cc b/chrome/renderer/net/render_dns_master.cc index 6eb3d13..3393a3e 100644 --- a/chrome/renderer/net/render_dns_master.cc +++ b/chrome/renderer/net/render_dns_master.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// See header file for description of RenderDnsMaster class +// See header file for description of RendererNetPredictor class #include "chrome/renderer/net/render_dns_master.h" @@ -26,13 +26,13 @@ void DnsPrefetchCString(const char* hostname, size_t length) { // SubmitHostsnames() (which reads names from our queue). static const size_t kMAX_SUBMISSION_PER_TASK = 30; -RenderDnsMaster::RenderDnsMaster() +RendererNetPredictor::RendererNetPredictor() : c_string_queue_(1000), - ALLOW_THIS_IN_INITIALIZER_LIST(render_dns_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(renderer_predictor_factory_(this)) { Reset(); } -void RenderDnsMaster::Reset() { +void RendererNetPredictor::Reset() { domain_map_.clear(); c_string_queue_.Clear(); buffer_full_discard_count_ = 0; @@ -41,7 +41,7 @@ void RenderDnsMaster::Reset() { } // Push names into queue quickly! -void RenderDnsMaster::Resolve(const char* name, size_t length) { +void RendererNetPredictor::Resolve(const char* name, size_t length) { if (!length) return; // Don't store empty strings in buffer. if (is_numeric_ip(name, length)) @@ -54,10 +54,10 @@ void RenderDnsMaster::Resolve(const char* name, size_t length) { DCHECK_EQ(old_size, 0u); if (0 != old_size) return; // Overkill safety net: Don't send too many InvokeLater's. - render_dns_factory_.RevokeAll(); + renderer_predictor_factory_.RevokeAll(); RenderThread::current()->message_loop()->PostDelayedTask(FROM_HERE, - render_dns_factory_.NewRunnableMethod( - &RenderDnsMaster::SubmitHostnames), 10); + renderer_predictor_factory_.NewRunnableMethod( + &RendererNetPredictor::SubmitHostnames), 10); } return; } @@ -70,7 +70,7 @@ void RenderDnsMaster::Resolve(const char* name, size_t length) { // Extract data from the Queue, and then send it off the the Browser process // to be resolved. -void RenderDnsMaster::SubmitHostnames() { +void RendererNetPredictor::SubmitHostnames() { // Get all names out of the C_string_queue (into our map) ExtractBufferedNames(); // TBD: IT could be that we should only extract about as many names as we are @@ -88,10 +88,10 @@ void RenderDnsMaster::SubmitHostnames() { // This will help to avoid overloads when a page has a TON of links. DnsPrefetchNames(kMAX_SUBMISSION_PER_TASK); if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) { - render_dns_factory_.RevokeAll(); + renderer_predictor_factory_.RevokeAll(); RenderThread::current()->message_loop()->PostDelayedTask(FROM_HERE, - render_dns_factory_.NewRunnableMethod( - &RenderDnsMaster::SubmitHostnames), 10); + renderer_predictor_factory_.NewRunnableMethod( + &RendererNetPredictor::SubmitHostnames), 10); } else { // TODO(JAR): Should we only clear the map when we navigate, or reload? domain_map_.clear(); @@ -99,7 +99,7 @@ void RenderDnsMaster::SubmitHostnames() { } // Pull some hostnames from the queue, and add them to our map. -void RenderDnsMaster::ExtractBufferedNames(size_t size_goal) { +void RendererNetPredictor::ExtractBufferedNames(size_t size_goal) { size_t count(0); // Number of entries to find (0 means find all). if (size_goal > 0) { if (size_goal <= domain_map_.size()) @@ -127,7 +127,7 @@ void RenderDnsMaster::ExtractBufferedNames(size_t size_goal) { } } -void RenderDnsMaster::DnsPrefetchNames(size_t max_count) { +void RendererNetPredictor::DnsPrefetchNames(size_t max_count) { // We are on the renderer thread, and just need to send things to the browser. chrome_common_net::NameList names; for (DomainUseMap::iterator it = domain_map_.begin(); @@ -151,7 +151,7 @@ void RenderDnsMaster::DnsPrefetchNames(size_t max_count) { // is_numeric_ip() checks to see if all characters in name are either numeric, // or dots. Such a name will not actually be passed to DNS, as it is an IP // address. -bool RenderDnsMaster::is_numeric_ip(const char* name, size_t length) { +bool RendererNetPredictor::is_numeric_ip(const char* name, size_t length) { // Scan for a character outside our lookup list. while (length-- > 0) { if (!isdigit(*name) && '.' != *name) diff --git a/chrome/renderer/net/render_dns_master.h b/chrome/renderer/net/render_dns_master.h index 15c100f..13f4463 100644 --- a/chrome/renderer/net/render_dns_master.h +++ b/chrome/renderer/net/render_dns_master.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// A RenderDnsMaster instance is maintained for each RenderThread. -// Hostnames are typically added to the embedded queue during rendering. +// A RendererNetPredictor instance is maintained for each RenderThread. +// URL strings are typically added to the embedded queue during rendering. // The first addition to the queue (transitioning from empty to having // some names) causes a processing task to be added to the Renderer Thread. // The processing task gathers all buffered names, and send them via IPC @@ -16,7 +16,7 @@ // If the processing task is not able to completely empty the queue, it // schedules a future continuation of the task, and keeps the map of already // sent names. If the entire queue is processed, then the list of "sent names" -// is cleared so that future gatherings may again pass along the same names. +// is cleared so that future gatherings might again pass along the same names. #ifndef CHROME_RENDERER_NET_RENDER_DNS_MASTER_H_ #define CHROME_RENDERER_NET_RENDER_DNS_MASTER_H_ @@ -33,11 +33,11 @@ // the Browser's global functions. void DnsPrefetchCString(const char* hostname, size_t length); -class RenderDnsMaster { +class RendererNetPredictor { public: - RenderDnsMaster(); + RendererNetPredictor(); - ~RenderDnsMaster() {} + ~RendererNetPredictor() {} // Push a name into the queue to be resolved. void Resolve(const char* name, size_t length); @@ -101,9 +101,9 @@ class RenderDnsMaster { int buffer_full_discard_count_; int numeric_ip_discard_count_; - ScopedRunnableMethodFactory<RenderDnsMaster> render_dns_factory_; + ScopedRunnableMethodFactory<RendererNetPredictor> renderer_predictor_factory_; - DISALLOW_COPY_AND_ASSIGN(RenderDnsMaster); -}; // class RenderDnsMaster + DISALLOW_COPY_AND_ASSIGN(RendererNetPredictor); +}; // class RendererNetPredictor #endif // CHROME_RENDERER_NET_RENDER_DNS_MASTER_H_ diff --git a/chrome/renderer/net/render_dns_master_unittest.cc b/chrome/renderer/net/render_dns_master_unittest.cc index 0a4b637..5f5ad01 100644 --- a/chrome/renderer/net/render_dns_master_unittest.cc +++ b/chrome/renderer/net/render_dns_master_unittest.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Single threaded tests of RenderDnsMaster functionality. +// Single threaded tests of RendererNetPredictor functionality. #include "chrome/renderer/net/render_dns_master.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,8 +20,8 @@ TEST(RenderDnsMasterTest, NumericIpDiscardCheck) { // Combination of digits plus dots. const std::string N1("1.3."), N2("5.5.7.12"); -#define TESTNAME(string) RenderDnsMaster::is_numeric_ip((string.data()), \ - (string).size()) +#define TESTNAME(string) RendererNetPredictor::is_numeric_ip((string.data()), \ + (string).size()) EXPECT_TRUE(TESTNAME(N1)); EXPECT_TRUE(TESTNAME(N2)); diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 844f852..545d693 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -235,7 +235,7 @@ void RenderThread::Init() { visited_link_slave_.reset(new VisitedLinkSlave()); user_script_slave_.reset(new UserScriptSlave()); - dns_master_.reset(new RenderDnsMaster()); + renderer_net_predictor_.reset(new RendererNetPredictor()); histogram_snapshots_.reset(new RendererHistogramSnapshots()); appcache_dispatcher_.reset(new AppCacheDispatcher(this)); indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); @@ -434,7 +434,7 @@ void RenderThread::DoNotNotifyWebKitOfModalLoop() { } void RenderThread::Resolve(const char* name, size_t length) { - return dns_master_->Resolve(name, length); + return renderer_net_predictor_->Resolve(name, length); } void RenderThread::SendHistograms(int sequence_number) { diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index 0dcd7d2..5b8d024 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -34,8 +34,8 @@ class FilePath; class IndexedDBDispatcher; class ListValue; class NullableString16; -class RenderDnsMaster; class RendererHistogram; +class RendererNetPredictor; class RendererWebKitClientImpl; class SpellCheck; class SkBitmap; @@ -310,7 +310,7 @@ class RenderThread : public RenderThreadBase, scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_; scoped_ptr<VisitedLinkSlave> visited_link_slave_; scoped_ptr<UserScriptSlave> user_script_slave_; - scoped_ptr<RenderDnsMaster> dns_master_; + scoped_ptr<RendererNetPredictor> renderer_net_predictor_; scoped_ptr<AppCacheDispatcher> appcache_dispatcher_; scoped_ptr<IndexedDBDispatcher> indexed_db_dispatcher_; scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_; |