| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 void HostCache::EvictOneEntry(base::TimeTicks now) { | 228 void HostCache::EvictOneEntry(base::TimeTicks now) { |
| 229 DCHECK_LT(0u, entries_.size()); | 229 DCHECK_LT(0u, entries_.size()); |
| 230 | 230 |
| 231 auto oldest_it = entries_.begin(); | 231 auto oldest_it = entries_.begin(); |
| 232 for (auto it = entries_.begin(); it != entries_.end(); ++it) { | 232 for (auto it = entries_.begin(); it != entries_.end(); ++it) { |
| 233 if (it->second.expires() < oldest_it->second.expires()) | 233 if (it->second.expires() < oldest_it->second.expires()) |
| 234 oldest_it = it; | 234 oldest_it = it; |
| 235 } | 235 } |
| 236 | 236 |
| 237 if (!eviction_callback_.is_null()) |
| 238 eviction_callback_.Run(oldest_it->first, oldest_it->second); |
| 237 RecordErase(ERASE_EVICT, now, oldest_it->second); | 239 RecordErase(ERASE_EVICT, now, oldest_it->second); |
| 238 entries_.erase(oldest_it); | 240 entries_.erase(oldest_it); |
| 239 } | 241 } |
| 240 | 242 |
| 241 void HostCache::RecordSet(SetOutcome outcome, | 243 void HostCache::RecordSet(SetOutcome outcome, |
| 242 base::TimeTicks now, | 244 base::TimeTicks now, |
| 243 const Entry* old_entry, | 245 const Entry* old_entry, |
| 244 const Entry& new_entry) { | 246 const Entry& new_entry) { |
| 245 CACHE_HISTOGRAM_ENUM("Set", outcome, MAX_SET_OUTCOME); | 247 CACHE_HISTOGRAM_ENUM("Set", outcome, MAX_SET_OUTCOME); |
| 246 switch (outcome) { | 248 switch (outcome) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); | 335 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); |
| 334 } | 336 } |
| 335 } | 337 } |
| 336 | 338 |
| 337 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { | 339 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { |
| 338 for (const auto& it : entries_) | 340 for (const auto& it : entries_) |
| 339 RecordErase(reason, now, it.second); | 341 RecordErase(reason, now, it.second); |
| 340 } | 342 } |
| 341 | 343 |
| 342 } // namespace net | 344 } // namespace net |
| OLD | NEW |