| 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,
|
|
|