BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / net / timed_cache.cc
blob2d0dd94c2317f6dc7c4e6135e532d0a8253efcb4
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/net/timed_cache.h"
7 #include "url/gurl.h"
9 namespace chrome_browser_net {
11 TimedCache::TimedCache(const base::TimeDelta& max_duration)
12 : mru_cache_(UrlMruTimedCache::NO_AUTO_EVICT),
13 max_duration_(max_duration) {
16 // Make Clang compilation happy with explicit destructor.
17 TimedCache::~TimedCache() {}
19 bool TimedCache::WasRecentlySeen(const GURL& url) {
20 DCHECK_EQ(url.GetWithEmptyPath(), url);
21 // Evict any overly old entries.
22 base::TimeTicks now = base::TimeTicks::Now();
23 UrlMruTimedCache::reverse_iterator eldest = mru_cache_.rbegin();
24 while (!mru_cache_.empty()) {
25 DCHECK(eldest == mru_cache_.rbegin());
26 if (now - eldest->second < max_duration_)
27 break;
28 eldest = mru_cache_.Erase(eldest);
30 return mru_cache_.end() != mru_cache_.Peek(url);
33 void TimedCache::SetRecentlySeen(const GURL& url) {
34 DCHECK_EQ(url.GetWithEmptyPath(), url);
35 mru_cache_.Put(url, base::TimeTicks::Now());
38 } // namespace chrome_browser_net