| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |