| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 void HostCache::OnNetworkChange() { | 191 void HostCache::OnNetworkChange() { |
| 192 ++network_changes_; | 192 ++network_changes_; |
| 193 } | 193 } |
| 194 | 194 |
| 195 void HostCache::clear() { | 195 void HostCache::clear() { |
| 196 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
| 197 RecordEraseAll(ERASE_CLEAR, base::TimeTicks::Now()); | 197 RecordEraseAll(ERASE_CLEAR, base::TimeTicks::Now()); |
| 198 entries_.clear(); | 198 entries_.clear(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void HostCache::ClearForHosts( |
| 202 const base::Callback<bool(const std::string&)>& host_filter) { |
| 203 DCHECK(CalledOnValidThread()); |
| 204 |
| 205 if (host_filter.is_null()) { |
| 206 clear(); |
| 207 return; |
| 208 } |
| 209 |
| 210 base::TimeTicks now = base::TimeTicks::Now(); |
| 211 for (EntryMap::iterator it = entries_.begin(); it != entries_.end();) { |
| 212 EntryMap::iterator next_it = std::next(it); |
| 213 |
| 214 if (host_filter.Run(it->first.hostname)) { |
| 215 RecordErase(ERASE_CLEAR, now, it->second); |
| 216 entries_.erase(it); |
| 217 } |
| 218 |
| 219 it = next_it; |
| 220 } |
| 221 } |
| 222 |
| 201 size_t HostCache::size() const { | 223 size_t HostCache::size() const { |
| 202 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
| 203 return entries_.size(); | 225 return entries_.size(); |
| 204 } | 226 } |
| 205 | 227 |
| 206 size_t HostCache::max_entries() const { | 228 size_t HostCache::max_entries() const { |
| 207 DCHECK(CalledOnValidThread()); | 229 DCHECK(CalledOnValidThread()); |
| 208 return max_entries_; | 230 return max_entries_; |
| 209 } | 231 } |
| 210 | 232 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); | 357 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); |
| 336 } | 358 } |
| 337 } | 359 } |
| 338 | 360 |
| 339 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { | 361 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { |
| 340 for (const auto& it : entries_) | 362 for (const auto& it : entries_) |
| 341 RecordErase(reason, now, it.second); | 363 RecordErase(reason, now, it.second); |
| 342 } | 364 } |
| 343 | 365 |
| 344 } // namespace net | 366 } // namespace net |
| OLD | NEW |