diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 01:00:16 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 01:00:16 +0000 |
commit | 1da70a5924f41d7e2682c43e175b1b05796d13d4 (patch) | |
tree | 7bcfc3707c6c9c9da2f09a67c8297ebe2b56f101 /chrome/browser/net/referrer.cc | |
parent | 8aedc4467d45c234ff5d201f1bc41fd18d8cb7c7 (diff) | |
download | chromium_src-1da70a5924f41d7e2682c43e175b1b05796d13d4.zip chromium_src-1da70a5924f41d7e2682c43e175b1b05796d13d4.tar.gz chromium_src-1da70a5924f41d7e2682c43e175b1b05796d13d4.tar.bz2 |
Handle race between deleting a low use referrer acruing value
Prevent a DCHECK from firing.
As we adaptively learn about referrers to enhance DNS
pre-resolution, we are forced to evict some entries
to prevent accidentally getting really large lists
(when we make mistakes). Sometimes we evict a
referred item from a list *while* that item is being
resolved (because it was in teh list). In that case,
we have to be careful when we try to acrue credit
(latency savings).
r=paulg
Review URL: http://codereview.chromium.org/18527
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8531 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/referrer.cc')
-rw-r--r-- | chrome/browser/net/referrer.cc | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/chrome/browser/net/referrer.cc b/chrome/browser/net/referrer.cc index 45982fa..464c990 100644 --- a/chrome/browser/net/referrer.cc +++ b/chrome/browser/net/referrer.cc @@ -9,11 +9,12 @@ namespace chrome_browser_net { void Referrer::SuggestHost(const std::string& host) { - // 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 + // Limit how large our list can get, in case we 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 then (mistakenly) appears to be a subresource on the page // hosting the ad). + // TODO(jar): Do experiments to optimize the max count of suggestions. static const size_t kMaxSuggestions = 8; if (host.empty()) @@ -57,12 +58,18 @@ void Referrer::DeleteLeastUseful() { least_useful_lifetime = lifetime; } erase(least_useful_name); + // Note: there is a small chance that we will discard a least_useful_name + // that is currently being prefetched because it *was* in this referer list. + // In that case, when a benefit appears in AccrueValue() below, we are careful + // to check before accessing the member. } void Referrer::AccrueValue(const base::TimeDelta& delta, const std::string host) { - DCHECK(this->find(host) != this->end()); - (*this)[host].AccrueValue(delta); + HostNameMap::iterator it = this->find(host); + // Be careful that we weren't evicted from this referrer in DeleteLeastUseful. + if (it != this->end()) + it->second.AccrueValue(delta); } } // namespace chrome_browser_net |