summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/referrer.cc
diff options
context:
space:
mode:
authorjar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 23:32:53 +0000
committerjar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 23:32:53 +0000
commit21dae9b9628a3a7ef481c1871d69e9b48ed90158 (patch)
treeda091a8ff8222d6bfbde888972752d289644b4f7 /chrome/browser/net/referrer.cc
parenta2633667fc8bf1429fe33f5dd89b550e484a03c9 (diff)
downloadchromium_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.cc')
-rw-r--r--chrome/browser/net/referrer.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/net/referrer.cc b/chrome/browser/net/referrer.cc
new file mode 100644
index 0000000..a4b0812
--- /dev/null
+++ b/chrome/browser/net/referrer.cc
@@ -0,0 +1,61 @@
+// 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.
+
+#include "chrome/browser/net/referrer.h"
+
+#include "base/logging.h"
+
+namespace chrome_browser_net {
+
+void Referrer::SuggestHost(const std::string& host) {
+ if (host.empty())
+ return;
+ if (kMaxSuggestions <= size()) {
+ DeleteLeastUseful();
+ DCHECK(kMaxSuggestions > size());
+ }
+ // Add in the new suggestion.
+ (*this)[host];
+}
+
+void Referrer::DeleteLeastUseful() {
+ std::string least_useful_name;
+ // We use longs for durations because we will use multiplication on them.
+ int64 least_useful_latency; // Duration in milliseconds.
+ int64 least_useful_lifetime; // Duration in milliseconds.
+
+ const base::Time kNow(base::Time::Now()); // Avoid multiple calls.
+ for (HostNameMap::iterator it = this->begin(); it != this->end(); ++it) {
+ int64 lifetime = (kNow - it->second.birth_time()).InMilliseconds();
+ int64 latency = it->second.latency().InMilliseconds();
+ if (!least_useful_name.empty()) {
+ if (!latency && !least_useful_latency) {
+ // Older name is less useful.
+ if (lifetime <= least_useful_lifetime)
+ continue;
+ } else {
+ // Compare the ratios latency/lifetime vs.
+ // least_useful_latency/least_useful_lifetime by cross multiplying (to
+ // avoid integer division hassles). Overflow's won't happen until
+ // both latency and lifetime pass about 49 days.
+ if (latency * least_useful_lifetime >=
+ least_useful_latency * lifetime) {
+ continue;
+ }
+ }
+ }
+ least_useful_name = it->first;
+ least_useful_latency = latency;
+ least_useful_lifetime = lifetime;
+ }
+ erase(least_useful_name);
+}
+
+void Referrer::AccrueValue(const base::TimeDelta& delta,
+ const std::string host) {
+ DCHECK(this->find(host) != this->end());
+ (*this)[host].AccrueValue(delta);
+}
+
+} // namespace chrome_browser_net