Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: chrome/browser/net/dns_global.cc

Issue 38007: Tell DNS prefetch when search URL is likely so that prewarming can be done... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/dns_global.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/dns_global.cc
===================================================================
--- chrome/browser/net/dns_global.cc (revision 43988)
+++ chrome/browser/net/dns_global.cc (working copy)
@@ -117,12 +117,41 @@
}
// This API is used by the autocomplete popup box (where URLs are typed).
-void DnsPrefetchUrl(const GURL& url) {
+// It is only called on the UI thread.
+void DnsPrefetchUrl(const GURL& url, bool is_search_url) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
if (!dns_prefetch_enabled || NULL == dns_master)
return;
- if (url.is_valid())
- DnsMotivatedPrefetch(url.host(), DnsHostInfo::OMNIBOX_MOTIVATED);
+ if (!url.is_valid())
+ return;
+
+ static std::string last_host;
+ bool new_host = (url.host() != last_host);
+ if (new_host)
+ last_host = url.host();
+
+ // Omnibox tends to call in pairs (just a few milliseconds apart), and we
+ // really don't need to keep resolving a name that often.
+ static base::Time last_prefetch_for_host;
+ static base::Time last_tcp_warm_for_host;
+ base::Time now = base::Time::Now();
+ if (!new_host) {
+ const int kMinPreresolveSeconds(10);
+ if (kMinPreresolveSeconds > (now - last_prefetch_for_host).InSeconds())
+ return;
+ }
+ last_prefetch_for_host = now;
+ DnsMotivatedPrefetch(last_host, DnsHostInfo::OMNIBOX_MOTIVATED);
+
+ if (!is_search_url)
+ return;
+ static base::Time last_keepalive;
+ const int kMaxSearchKeepaliveSeconds(90); // TODO(jar): Track vendors.
+ if (!new_host &&
+ (now - last_keepalive).InSeconds() < kMaxSearchKeepaliveSeconds)
+ return;
+ last_keepalive = now;
+ // Prewarm connection to Search URL.
}
static void DnsMotivatedPrefetch(const std::string& hostname,
« no previous file with comments | « chrome/browser/net/dns_global.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698