OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
mmenke
2013/05/23 15:28:36
See other comment about copyright notice.
kouhei (in TOK)
2013/05/24 00:34:37
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/net/timed_cache.h" | |
6 | |
7 #include "net/url_request/url_request.h" | |
mmenke
2013/05/23 15:28:36
I don't think we need this header. All we need is
| |
8 | |
9 namespace chrome_browser_net { | |
10 | |
11 TimedCache::TimedCache(const base::TimeDelta& max_duration) | |
12 : mru_cache_(UrlMruTimedCache::NO_AUTO_EVICT), | |
13 max_duration_(max_duration) { | |
14 } | |
15 | |
16 // Make Clang compilation happy with explicit destructor. | |
17 TimedCache::~TimedCache() {} | |
18 | |
19 bool TimedCache::WasRecentlySeen(const GURL& url) const { | |
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); | |
29 } | |
30 return mru_cache_.end() != mru_cache_.Peek(url); | |
31 } | |
32 | |
33 void TimedCache::SetRecentlySeen(const GURL& url) const { | |
34 DCHECK_EQ(url.GetWithEmptyPath(), url); | |
35 mru_cache_.Put(url, base::TimeTicks::Now()); | |
36 } | |
37 | |
38 } // namespace chrome_browser_net | |
OLD | NEW |