diff options
author | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 23:32:53 +0000 |
---|---|---|
committer | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 23:32:53 +0000 |
commit | 21dae9b9628a3a7ef481c1871d69e9b48ed90158 (patch) | |
tree | da091a8ff8222d6bfbde888972752d289644b4f7 /chrome/browser/net/referrer.h | |
parent | a2633667fc8bf1429fe33f5dd89b550e484a03c9 (diff) | |
download | chromium_src-21dae9b9628a3a7ef481c1871d69e9b48ed90158.zip chromium_src-21dae9b9628a3a7ef481c1871d69e9b48ed90158.tar.gz chromium_src-21dae9b9628a3a7ef481c1871d69e9b48ed90158.tar.bz2 |
Adaptively identify URL subresources and pre-resolve hosts via DNS
Use the HTTP "referer" header to identify subresources used during a
page load. Store that info, and use it when next visiting the referenced
hosts to pre-resolve the (probably) needed subresources.
This set of changes will surely evolve as we see how it plays out
on broader distribution (via histogram measurments), but this should be
the foundation of the change.
In design specs, this was previously referred to as "adaptive correlated
DNS prefetching."
r=mbelshe
Review URL: http://codereview.chromium.org/9168
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/referrer.h')
-rw-r--r-- | chrome/browser/net/referrer.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/chrome/browser/net/referrer.h b/chrome/browser/net/referrer.h new file mode 100644 index 0000000..f0cf40c --- /dev/null +++ b/chrome/browser/net/referrer.h @@ -0,0 +1,92 @@ +// Copyright (c) 2006-2008 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. + +// All access to this class is performed via the DnsMaster class, and is +// protected by the its lock. + +#ifndef CHROME_BROWSER_NET_REFERRER_H_ +#define CHROME_BROWSER_NET_REFERRER_H_ + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "base/time.h" +#include "googleurl/src/gurl.h" + +namespace chrome_browser_net { + +//------------------------------------------------------------------------------ +// For each hostname in a Referrer, we have a ReferrerValue. It indicates +// exactly how much value (re: latency reduction) has resulted from having this +// entry. +class ReferrerValue { + public: + ReferrerValue() : birth_time_(base::Time::Now()) {} + + base::TimeDelta latency() const { return latency_; } + base::Time birth_time() const { return birth_time_; } + void AccrueValue(const base::TimeDelta& delta) { latency_ += delta; } + private: + base::TimeDelta latency_; // Accumulated latency savings. + const base::Time birth_time_; +}; + +//------------------------------------------------------------------------------ +// A list of domain names to pre-resolve. The names are the keys to this map, +// and the values indicate the amount of benefit derived from having each name +// around. +typedef std::map<std::string, ReferrerValue> HostNameMap; + +//------------------------------------------------------------------------------ +// There is one Referrer instance for each hostname that has acted as an HTTP +// referer (note mispelling is intentional) for a domain that was otherwise +// unexpectedly navgated towards ("unexpected" in the sense that the domain was +// probably for a subresource of a page, and was not otherwise predictable until +// the content with the reference arrived). Most typically, an outer page was a +// page fetched by the user, and this instance lists names in HostNameMap which +// are subresources and that were needed to complete the rendering of the outer +// page. +class Referrer : public HostNameMap { + public: + // Add the indicated host to the list of hosts that are resolved via DNS when + // the user navigates to this referrer. Note that if the list is long, an + // entry may be discarded to make room for this insertion. + void SuggestHost(const std::string& host); + + // Record additional usefulness of having this host name in the list. + // Value is expressed as positive latency of amount delta. + void AccrueValue(const base::TimeDelta& delta, const std::string host); + + private: + // Helper function for pruning list. Metric for usefulness is "large accrued + // value," in the form of latency_ savings associated with a host name. We + // also give credit for a name being newly added, by scalling latency per + // lifetime (time since birth). For instance, when to names have accrued + // the same latency_ savings, the older one is less valuable as it didn't + // accrue savings as quickly. + void Referrer::DeleteLeastUseful(); + + // Limit how large our list can get, in case we start make mistakes about + // what hostnames are in sub-resources (example: Some advertisments have + // a link to the ad agency, and then provide a "surprising" redirect to + // the advertised entity, which appears to be a subresource on the page + // hosting the ad). + static const int kMaxSuggestions = 8; + + // We put these into a std::map<>, so we need copy constructors. + // DISALLOW_COPY_AND_ASSIGN(Referrer); + // TODO(jar): Consider optimization to use pointers to these instances, and + // avoid deep copies during re-alloc of the containing map. +}; + +} // namespace chrome_browser_net + +#endif // CHROME_BROWSER_NET_REFERRER_H_ |