summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 05:08:42 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 05:08:42 +0000
commit2884a4619edeac1787e2b1d1b57e913f7e442cae (patch)
treef194f30877c49ce17031a29393143039eacfb496 /chrome/browser/net
parent202e7a773359b24943d7de0943dd9c7d257ab1cb (diff)
downloadchromium_src-2884a4619edeac1787e2b1d1b57e913f7e442cae.zip
chromium_src-2884a4619edeac1787e2b1d1b57e913f7e442cae.tar.gz
chromium_src-2884a4619edeac1787e2b1d1b57e913f7e442cae.tar.bz2
* Move the global "DnsResolutionObserver" code depended on by DNS prefetcher, into HostResolver. This has the advantage that consumers of DNS no longer have to remember to call "DidFinishDnsResolutionWithStatus()" followed by "DidStartDnsResolution()" in order for the prefetcher to observe the resolution. Instead it just happens automatically, and subscribers register via HostResolver::AddObserver() on a particular resolver instance.
* To accomodate the prefetcher's observer, HostResolver::Resolve() needs an additional "referrer" parameter. This is slightly awkward since "referrer" has nothing to do with the actual resolve request. To simplify plumbing through this and other optional parameters, Resolve() was changed to take a "RequestInfo&" parameter in place of say {hostname, port, flags}. * Added an option to HostResolver::Resolve() for disallowing cached responses (RequestInfo::allow_cached_response). This will be used when you refresh a page, to bypass the host cache. The code to do this has been added to HttpNetworkTransaction, but is commented out pending an appropriate unit-test to verify it. BUG=14056 Review URL: http://codereview.chromium.org/125107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18371 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r--chrome/browser/net/dns_global.cc51
-rw-r--r--chrome/browser/net/dns_master.cc12
-rw-r--r--chrome/browser/net/dns_master_unittest.cc3
3 files changed, 45 insertions, 21 deletions
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index c54b14d..1d808cb 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -133,7 +133,7 @@ static void NavigatingTo(const std::string& host_name) {
// The observer class needs to connect starts and finishes of HTTP network
// resolutions. We use the following type for that map.
-typedef std::map<void*, DnsHostInfo> ObservedResolutionMap;
+typedef std::map<int, DnsHostInfo> ObservedResolutionMap;
// There will only be one instance ever created of the following Observer
// class. As a result, we get away with using static members for data local
@@ -143,11 +143,13 @@ class PrefetchObserver : public net::DnsResolutionObserver {
PrefetchObserver();
~PrefetchObserver();
- virtual void OnStartResolution(const std::string& host_name,
- void* context);
- virtual void OnFinishResolutionWithStatus(bool was_resolved,
- const GURL& referrer,
- void* context);
+ virtual void OnStartResolution(
+ int request_id,
+ const net::HostResolver::RequestInfo& request_info);
+ virtual void OnFinishResolutionWithStatus(
+ int request_id,
+ bool was_resolved,
+ const net::HostResolver::RequestInfo& request_info);
static void DnsGetFirstResolutionsHtml(std::string* output);
static void SaveStartupListAsPref(PrefService* local_state);
@@ -189,27 +191,37 @@ PrefetchObserver::~PrefetchObserver() {
lock = NULL;
}
-void PrefetchObserver::OnStartResolution(const std::string& host_name,
- void* context) {
- DCHECK_NE(0U, host_name.length());
+void PrefetchObserver::OnStartResolution(
+ int request_id,
+ const net::HostResolver::RequestInfo& request_info) {
+ if (request_info.is_speculative())
+ return; // One of our own requests.
+ DCHECK_NE(0U, request_info.hostname().length());
DnsHostInfo navigation_info;
- navigation_info.SetHostname(host_name);
+ navigation_info.SetHostname(request_info.hostname());
navigation_info.SetStartedState();
- NavigatingTo(host_name);
+ NavigatingTo(request_info.hostname());
+
+ // TODO(eroman): If the resolve request is cancelled, then
+ // OnFinishResolutionWithStatus will not be called, and |resolutions| will
+ // grow unbounded!
AutoLock auto_lock(*lock);
- (*resolutions)[context] = navigation_info;
+ (*resolutions)[request_id] = navigation_info;
}
-void PrefetchObserver::OnFinishResolutionWithStatus(bool was_resolved,
- const GURL& referrer,
- void* context) {
+void PrefetchObserver::OnFinishResolutionWithStatus(
+ int request_id,
+ bool was_resolved,
+ const net::HostResolver::RequestInfo& request_info) {
+ if (request_info.is_speculative())
+ return; // One of our own requests.
DnsHostInfo navigation_info;
size_t startup_count;
{
AutoLock auto_lock(*lock);
- ObservedResolutionMap::iterator it = resolutions->find(context);
+ ObservedResolutionMap::iterator it = resolutions->find(request_id);
if (resolutions->end() == it) {
DCHECK(false);
return;
@@ -219,7 +231,7 @@ void PrefetchObserver::OnFinishResolutionWithStatus(bool was_resolved,
startup_count = first_resolutions->size();
}
navigation_info.SetFinishedState(was_resolved); // Get timing info
- AccruePrefetchBenefits(referrer, &navigation_info);
+ AccruePrefetchBenefits(request_info.referrer(), &navigation_info);
if (kStartupResolutionCount <= startup_count || !was_resolved)
return;
// TODO(jar): Don't add host to our list if it is a non-linked lookup, and
@@ -399,7 +411,10 @@ void InitDnsPrefetch(size_t max_concurrent, PrefService* user_prefs) {
DLOG(INFO) << "DNS Prefetch service started";
// Start observing real HTTP stack resolutions.
- net::AddDnsResolutionObserver(&dns_resolution_observer);
+ // TODO(eroman): really this should be called from IO thread (since that is
+ // where the host resolver lives). Since this occurs before requests have
+ // started it is not a race yet.
+ GetGlobalHostResolver()->AddObserver(&dns_resolution_observer);
}
}
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index 6151087..a256aa6 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -35,8 +35,16 @@ class DnsMaster::LookupRequest {
}
bool Start() {
- const int result = resolver_.Resolve(hostname_, 80, &addresses_,
- &net_callback_);
+ // Port doesn't really matter.
+ net::HostResolver::RequestInfo resolve_info(hostname_, 80);
+
+ // Make a note that this is a speculative resolve request. This allows us
+ // to separate it from real navigations in the observer's callback, and
+ // lets the HostResolver know it can de-prioritize it.
+ resolve_info.set_is_speculative(true);
+
+ const int result = resolver_.Resolve(
+ resolve_info, &addresses_, &net_callback_);
return (result == net::ERR_IO_PENDING);
}
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc
index be68dfb..e056555 100644
--- a/chrome/browser/net/dns_master_unittest.cc
+++ b/chrome/browser/net/dns_master_unittest.cc
@@ -113,7 +113,8 @@ TimeDelta BlockingDnsLookup(const std::string& hostname) {
net::HostResolver resolver;
net::AddressList addresses;
- resolver.Resolve(hostname, 80, &addresses, NULL, NULL);
+ net::HostResolver::RequestInfo info(hostname, 80);
+ resolver.Resolve(info, &addresses, NULL, NULL);
return Time::Now() - start;
}