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

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

Issue 2298173002: Implement host-based deletion for the hostname resolution cache. (Closed)
Patch Set: Updated callsite. Created 4 years, 3 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 | « net/dns/host_cache.h ('k') | 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 for (EntryMap::iterator it = entries_.begin(); it != entries_.end();) {
211 EntryMap::iterator next_it = std::next(it);
212
213 if (host_filter.Run(it->first.hostname)) {
214 RecordErase(ERASE_CLEAR, base::TimeTicks::Now(), it->second);
mmenke 2016/08/31 15:24:37 Maybe just call base::TimeTicks::Now() once, outsi
msramek 2016/08/31 16:02:55 Done. Good point - it's even better for consistenc
215 entries_.erase(it);
216 }
217
218 it = next_it;
219 }
220 }
221
201 size_t HostCache::size() const { 222 size_t HostCache::size() const {
202 DCHECK(CalledOnValidThread()); 223 DCHECK(CalledOnValidThread());
203 return entries_.size(); 224 return entries_.size();
204 } 225 }
205 226
206 size_t HostCache::max_entries() const { 227 size_t HostCache::max_entries() const {
207 DCHECK(CalledOnValidThread()); 228 DCHECK(CalledOnValidThread());
208 return max_entries_; 229 return max_entries_;
209 } 230 }
210 231
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); 356 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by);
336 } 357 }
337 } 358 }
338 359
339 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { 360 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) {
340 for (const auto& it : entries_) 361 for (const auto& it : entries_)
341 RecordErase(reason, now, it.second); 362 RecordErase(reason, now, it.second);
342 } 363 }
343 364
344 } // namespace net 365 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_cache.h ('k') | net/dns/host_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698