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

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

Issue 2701673003: HostCache: always evict stale entries before valid entries (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | net/dns/host_cache_unittest.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/dns/host_cache.h" 5 #include "net/dns/host_cache.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 if ((max_entries == 0) || (max_entries > kSaneMaxEntries)) 246 if ((max_entries == 0) || (max_entries > kSaneMaxEntries))
247 max_entries = kDefaultMaxEntries; 247 max_entries = kDefaultMaxEntries;
248 return base::WrapUnique(new HostCache(max_entries)); 248 return base::WrapUnique(new HostCache(max_entries));
249 } 249 }
250 250
251 void HostCache::EvictOneEntry(base::TimeTicks now) { 251 void HostCache::EvictOneEntry(base::TimeTicks now) {
252 DCHECK_LT(0u, entries_.size()); 252 DCHECK_LT(0u, entries_.size());
253 253
254 auto oldest_it = entries_.begin(); 254 auto oldest_it = entries_.begin();
255 for (auto it = entries_.begin(); it != entries_.end(); ++it) { 255 for (auto it = entries_.begin(); it != entries_.end(); ++it) {
256 if (it->second.expires() < oldest_it->second.expires()) 256 if ((it->second.expires() < oldest_it->second.expires()) &&
257 (it->second.IsStale(now, network_changes_) ||
258 !oldest_it->second.IsStale(now, network_changes_))) {
257 oldest_it = it; 259 oldest_it = it;
260 }
258 } 261 }
259 262
260 if (!eviction_callback_.is_null()) 263 if (!eviction_callback_.is_null())
261 eviction_callback_.Run(oldest_it->first, oldest_it->second); 264 eviction_callback_.Run(oldest_it->first, oldest_it->second);
262 RecordErase(ERASE_EVICT, now, oldest_it->second); 265 RecordErase(ERASE_EVICT, now, oldest_it->second);
263 entries_.erase(oldest_it); 266 entries_.erase(oldest_it);
264 } 267 }
265 268
266 void HostCache::RecordSet(SetOutcome outcome, 269 void HostCache::RecordSet(SetOutcome outcome,
267 base::TimeTicks now, 270 base::TimeTicks now,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); 361 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by);
359 } 362 }
360 } 363 }
361 364
362 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { 365 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) {
363 for (const auto& it : entries_) 366 for (const auto& it : entries_)
364 RecordErase(reason, now, it.second); 367 RecordErase(reason, now, it.second);
365 } 368 }
366 369
367 } // namespace net 370 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/host_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698