| 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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/trace_constants.h" |
| 14 #include "net/dns/dns_util.h" | 15 #include "net/dns/dns_util.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 #define CACHE_HISTOGRAM_TIME(name, time) \ | 21 #define CACHE_HISTOGRAM_TIME(name, time) \ |
| 21 UMA_HISTOGRAM_LONG_TIMES("DNS.HostCache." name, time) | 22 UMA_HISTOGRAM_LONG_TIMES("DNS.HostCache." name, time) |
| 22 | 23 |
| 23 #define CACHE_HISTOGRAM_COUNT(name, count) \ | 24 #define CACHE_HISTOGRAM_COUNT(name, count) \ |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 156 |
| 156 HostCache::Entry* HostCache::LookupInternal(const Key& key) { | 157 HostCache::Entry* HostCache::LookupInternal(const Key& key) { |
| 157 auto it = entries_.find(key); | 158 auto it = entries_.find(key); |
| 158 return (it != entries_.end()) ? &it->second : nullptr; | 159 return (it != entries_.end()) ? &it->second : nullptr; |
| 159 } | 160 } |
| 160 | 161 |
| 161 void HostCache::Set(const Key& key, | 162 void HostCache::Set(const Key& key, |
| 162 const Entry& entry, | 163 const Entry& entry, |
| 163 base::TimeTicks now, | 164 base::TimeTicks now, |
| 164 base::TimeDelta ttl) { | 165 base::TimeDelta ttl) { |
| 165 TRACE_EVENT0("net", "HostCache::Set"); | 166 TRACE_EVENT0(kNetTracingCategory, "HostCache::Set"); |
| 166 DCHECK(CalledOnValidThread()); | 167 DCHECK(CalledOnValidThread()); |
| 167 if (caching_is_disabled()) | 168 if (caching_is_disabled()) |
| 168 return; | 169 return; |
| 169 | 170 |
| 170 auto it = entries_.find(key); | 171 auto it = entries_.find(key); |
| 171 if (it != entries_.end()) { | 172 if (it != entries_.end()) { |
| 172 bool is_stale = it->second.IsStale(now, network_changes_); | 173 bool is_stale = it->second.IsStale(now, network_changes_); |
| 173 RecordSet(is_stale ? SET_UPDATE_STALE : SET_UPDATE_VALID, now, &it->second, | 174 RecordSet(is_stale ? SET_UPDATE_STALE : SET_UPDATE_VALID, now, &it->second, |
| 174 entry); | 175 entry); |
| 175 // TODO(juliatuttle): Remember some old metadata (hit count or frequency or | 176 // TODO(juliatuttle): Remember some old metadata (hit count or frequency or |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); | 358 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); |
| 358 } | 359 } |
| 359 } | 360 } |
| 360 | 361 |
| 361 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { | 362 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { |
| 362 for (const auto& it : entries_) | 363 for (const auto& it : entries_) |
| 363 RecordErase(reason, now, it.second); | 364 RecordErase(reason, now, it.second); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace net | 367 } // namespace net |
| OLD | NEW |