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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/net/dns_global.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/dns_global.h" 5 #include "chrome/browser/net/dns_global.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/singleton.h" 10 #include "base/singleton.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } else { 110 } else {
111 ChromeThread::PostTask( 111 ChromeThread::PostTask(
112 ChromeThread::IO, 112 ChromeThread::IO,
113 FROM_HERE, 113 FROM_HERE,
114 NewRunnableMethod(dns_master, 114 NewRunnableMethod(dns_master,
115 &DnsMaster::ResolveList, hostnames, motivation)); 115 &DnsMaster::ResolveList, hostnames, motivation));
116 } 116 }
117 } 117 }
118 118
119 // This API is used by the autocomplete popup box (where URLs are typed). 119 // This API is used by the autocomplete popup box (where URLs are typed).
120 void DnsPrefetchUrl(const GURL& url) { 120 // It is only called on the UI thread.
121 void DnsPrefetchUrl(const GURL& url, bool is_search_url) {
121 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 122 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
122 if (!dns_prefetch_enabled || NULL == dns_master) 123 if (!dns_prefetch_enabled || NULL == dns_master)
123 return; 124 return;
124 if (url.is_valid()) 125 if (!url.is_valid())
125 DnsMotivatedPrefetch(url.host(), DnsHostInfo::OMNIBOX_MOTIVATED); 126 return;
127
128 static std::string last_host;
129 bool new_host = (url.host() != last_host);
130 if (new_host)
131 last_host = url.host();
132
133 // Omnibox tends to call in pairs (just a few milliseconds apart), and we
134 // really don't need to keep resolving a name that often.
135 static base::Time last_prefetch_for_host;
136 static base::Time last_tcp_warm_for_host;
137 base::Time now = base::Time::Now();
138 if (!new_host) {
139 const int kMinPreresolveSeconds(10);
140 if (kMinPreresolveSeconds > (now - last_prefetch_for_host).InSeconds())
141 return;
142 }
143 last_prefetch_for_host = now;
144 DnsMotivatedPrefetch(last_host, DnsHostInfo::OMNIBOX_MOTIVATED);
145
146 if (!is_search_url)
147 return;
148 static base::Time last_keepalive;
149 const int kMaxSearchKeepaliveSeconds(90); // TODO(jar): Track vendors.
150 if (!new_host &&
151 (now - last_keepalive).InSeconds() < kMaxSearchKeepaliveSeconds)
152 return;
153 last_keepalive = now;
154 // Prewarm connection to Search URL.
126 } 155 }
127 156
128 static void DnsMotivatedPrefetch(const std::string& hostname, 157 static void DnsMotivatedPrefetch(const std::string& hostname,
129 DnsHostInfo::ResolutionMotivation motivation) { 158 DnsHostInfo::ResolutionMotivation motivation) {
130 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
131 if (!dns_prefetch_enabled || NULL == dns_master || !hostname.size()) 160 if (!dns_prefetch_enabled || NULL == dns_master || !hostname.size())
132 return; 161 return;
133 162
134 ChromeThread::PostTask( 163 ChromeThread::PostTask(
135 ChromeThread::IO, 164 ChromeThread::IO,
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 TimeDelta max_queueing_delay( 643 TimeDelta max_queueing_delay(
615 TimeDelta::FromMilliseconds(max_queueing_delay_ms)); 644 TimeDelta::FromMilliseconds(max_queueing_delay_ms));
616 645
617 DCHECK(!dns_master); 646 DCHECK(!dns_master);
618 InitDnsPrefetch(max_queueing_delay, max_concurrent, user_prefs, 647 InitDnsPrefetch(max_queueing_delay, max_concurrent, user_prefs,
619 local_state); 648 local_state);
620 } 649 }
621 } 650 }
622 651
623 } // namespace chrome_browser_net 652 } // namespace chrome_browser_net
OLDNEW
« 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