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

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

Issue 2953483003: Add HostCachePersistenceManager for Cronet (Closed)
Patch Set: address comments Created 3 years, 6 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 DCHECK_GT(max_entries_, size()); 241 DCHECK_GT(max_entries_, size());
242 DCHECK_EQ(0u, entries_.count(key)); 242 DCHECK_EQ(0u, entries_.count(key));
243 entries_.insert(std::make_pair(key, entry)); 243 entries_.insert(std::make_pair(key, entry));
244 DCHECK_GE(max_entries_, size()); 244 DCHECK_GE(max_entries_, size());
245 } 245 }
246 246
247 void HostCache::OnNetworkChange() { 247 void HostCache::OnNetworkChange() {
248 ++network_changes_; 248 ++network_changes_;
249 } 249 }
250 250
251 void HostCache::set_persistence_delegate(PersistenceDelegate* delegate) {
252 // A PersistenceDelegate shouldn't be added if there already was one, and
253 // shouldn't be removed (by setting to nullptr) if it wasn't previously there.
254 DCHECK_NE(delegate == nullptr, delegate_ == nullptr);
255 delegate_ = delegate;
256 }
257
251 void HostCache::clear() { 258 void HostCache::clear() {
252 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 259 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
253 RecordEraseAll(ERASE_CLEAR, base::TimeTicks::Now()); 260 RecordEraseAll(ERASE_CLEAR, base::TimeTicks::Now());
254 261
255 // Don't bother scheduling a write if there's nothing to clear. 262 // Don't bother scheduling a write if there's nothing to clear.
256 if (size() == 0) 263 if (size() == 0)
257 return; 264 return;
258 265
259 entries_.clear(); 266 entries_.clear();
260 if (delegate_) 267 if (delegate_)
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); 537 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by);
531 } 538 }
532 } 539 }
533 540
534 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { 541 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) {
535 for (const auto& it : entries_) 542 for (const auto& it : entries_)
536 RecordErase(reason, now, it.second); 543 RecordErase(reason, now, it.second);
537 } 544 }
538 545
539 } // namespace net 546 } // namespace net
OLDNEW
« components/cronet/host_cache_persistence_manager_unittest.cc ('K') | « net/dns/host_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698