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

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

Issue 302010: Add a mechanism to disable IPv6.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address darin's comments Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/base/host_cache.h" 5 #include "net/base/host_cache.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 11 matching lines...) Expand all
22 22
23 //----------------------------------------------------------------------------- 23 //-----------------------------------------------------------------------------
24 24
25 HostCache::HostCache(size_t max_entries, size_t cache_duration_ms) 25 HostCache::HostCache(size_t max_entries, size_t cache_duration_ms)
26 : max_entries_(max_entries), cache_duration_ms_(cache_duration_ms) { 26 : max_entries_(max_entries), cache_duration_ms_(cache_duration_ms) {
27 } 27 }
28 28
29 HostCache::~HostCache() { 29 HostCache::~HostCache() {
30 } 30 }
31 31
32 const HostCache::Entry* HostCache::Lookup(const std::string& hostname, 32 const HostCache::Entry* HostCache::Lookup(const Key& key,
33 base::TimeTicks now) const { 33 base::TimeTicks now) const {
34 if (caching_is_disabled()) 34 if (caching_is_disabled())
35 return NULL; 35 return NULL;
36 36
37 EntryMap::const_iterator it = entries_.find(hostname); 37 EntryMap::const_iterator it = entries_.find(key);
38 if (it == entries_.end()) 38 if (it == entries_.end())
39 return NULL; // Not found. 39 return NULL; // Not found.
40 40
41 Entry* entry = it->second.get(); 41 Entry* entry = it->second.get();
42 if (CanUseEntry(entry, now)) 42 if (CanUseEntry(entry, now))
43 return entry; 43 return entry;
44 44
45 return NULL; 45 return NULL;
46 } 46 }
47 47
48 HostCache::Entry* HostCache::Set(const std::string& hostname, 48 HostCache::Entry* HostCache::Set(const Key& key,
49 int error, 49 int error,
50 const AddressList addrlist, 50 const AddressList addrlist,
51 base::TimeTicks now) { 51 base::TimeTicks now) {
52 if (caching_is_disabled()) 52 if (caching_is_disabled())
53 return NULL; 53 return NULL;
54 54
55 base::TimeTicks expiration = now + 55 base::TimeTicks expiration = now +
56 base::TimeDelta::FromMilliseconds(cache_duration_ms_); 56 base::TimeDelta::FromMilliseconds(cache_duration_ms_);
57 57
58 scoped_refptr<Entry>& entry = entries_[hostname]; 58 scoped_refptr<Entry>& entry = entries_[key];
59 if (!entry) { 59 if (!entry) {
60 // Entry didn't exist, creating one now. 60 // Entry didn't exist, creating one now.
61 Entry* ptr = new Entry(error, addrlist, expiration); 61 Entry* ptr = new Entry(error, addrlist, expiration);
62 entry = ptr; 62 entry = ptr;
63 63
64 // Compact the cache if we grew it beyond limit -- exclude |entry| from 64 // Compact the cache if we grew it beyond limit -- exclude |entry| from
65 // being pruned though! 65 // being pruned though!
66 if (entries_.size() > max_entries_) 66 if (entries_.size() > max_entries_)
67 Compact(now, ptr); 67 Compact(now, ptr);
68 return ptr; 68 return ptr;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } else { 106 } else {
107 ++it; 107 ++it;
108 } 108 }
109 } 109 }
110 110
111 if (entries_.size() > max_entries_) 111 if (entries_.size() > max_entries_)
112 DLOG(WARNING) << "Still above max entries limit"; 112 DLOG(WARNING) << "Still above max entries limit";
113 } 113 }
114 114
115 } // namespace net 115 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698