Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: net/base/host_cache.cc

Issue 9197009: Adds custom ttl argument to HostCache::Set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo change for when TTL == 0. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« net/base/host_cache.h ('K') | « net/base/host_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/host_cache.h" 5 #include "net/base/host_cache.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 Entry* entry = it->second.get(); 46 Entry* entry = it->second.get();
47 if (CanUseEntry(entry, now)) 47 if (CanUseEntry(entry, now))
48 return entry; 48 return entry;
49 49
50 return NULL; 50 return NULL;
51 } 51 }
52 52
53 HostCache::Entry* HostCache::Set(const Key& key, 53 HostCache::Entry* HostCache::Set(const Key& key,
54 int error, 54 int error,
55 const AddressList& addrlist, 55 const AddressList& addrlist,
56 base::TimeDelta ttl,
56 base::TimeTicks now) { 57 base::TimeTicks now) {
57 DCHECK(CalledOnValidThread()); 58 DCHECK(CalledOnValidThread());
58 if (caching_is_disabled()) 59 if (caching_is_disabled())
59 return NULL; 60 return NULL;
60 61
61 base::TimeTicks expiration = now + 62 if (ttl == base::TimeDelta())
62 (error == OK ? success_entry_ttl_ : failure_entry_ttl_); 63 ttl = (error == OK ? success_entry_ttl_ : failure_entry_ttl_);
64
65 base::TimeTicks expiration = now + ttl;
63 66
64 scoped_refptr<Entry>& entry = entries_[key]; 67 scoped_refptr<Entry>& entry = entries_[key];
65 if (!entry) { 68 if (!entry) {
66 // Entry didn't exist, creating one now. 69 // Entry didn't exist, creating one now.
67 Entry* ptr = new Entry(error, addrlist, expiration); 70 Entry* ptr = new Entry(error, addrlist, expiration);
68 entry = ptr; 71 entry = ptr;
69 72
70 // Compact the cache if we grew it beyond limit -- exclude |entry| from 73 // Compact the cache if we grew it beyond limit -- exclude |entry| from
71 // being pruned though! 74 // being pruned though!
72 if (entries_.size() > max_entries_) 75 if (entries_.size() > max_entries_)
73 Compact(now, ptr); 76 Compact(now, ptr);
74 return ptr; 77 return ptr;
75 } else { 78 } else {
76 // Update an existing cache entry. 79 // Update an existing cache entry.
77 entry->error = error; 80 entry->error = error;
78 entry->addrlist = addrlist; 81 entry->addrlist = addrlist;
79 entry->expiration = expiration; 82 entry->expiration = expiration;
80 return entry.get(); 83 return entry.get();
81 } 84 }
82 } 85 }
83 86
87 HostCache::Entry* HostCache::Set(const Key& key,
88 int error,
89 const AddressList& addrlist,
90 base::TimeTicks now) {
91 return Set(key, error, addrlist, base::TimeDelta(), now);
92 }
93
84 void HostCache::clear() { 94 void HostCache::clear() {
85 DCHECK(CalledOnValidThread()); 95 DCHECK(CalledOnValidThread());
86 entries_.clear(); 96 entries_.clear();
87 } 97 }
88 98
89 size_t HostCache::size() const { 99 size_t HostCache::size() const {
90 DCHECK(CalledOnValidThread()); 100 DCHECK(CalledOnValidThread());
91 return entries_.size(); 101 return entries_.size();
92 } 102 }
93 103
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } else { 165 } else {
156 ++it; 166 ++it;
157 } 167 }
158 } 168 }
159 169
160 if (entries_.size() > max_entries_) 170 if (entries_.size() > max_entries_)
161 DLOG(WARNING) << "Still above max entries limit"; 171 DLOG(WARNING) << "Still above max entries limit";
162 } 172 }
163 173
164 } // namespace net 174 } // namespace net
OLDNEW
« net/base/host_cache.h ('K') | « net/base/host_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698