| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 { |
| 11 | 11 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const HostCache::EntryMap& HostCache::entries() const { | 110 const HostCache::EntryMap& HostCache::entries() const { |
| 111 DCHECK(CalledOnValidThread()); | 111 DCHECK(CalledOnValidThread()); |
| 112 return entries_; | 112 return entries_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // static | 115 // static |
| 116 bool HostCache::CanUseEntry(const Entry* entry, const base::TimeTicks now) { | 116 bool HostCache::CanUseEntry(const Entry* entry, const base::TimeTicks now) { |
| 117 return entry->expiration > now; | 117 return entry->expiration > now; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // static |
| 121 HostCache* HostCache::CreateDefaultCache() { |
| 122 static const size_t kMaxHostCacheEntries = 100; |
| 123 |
| 124 HostCache* cache = new HostCache( |
| 125 kMaxHostCacheEntries, |
| 126 base::TimeDelta::FromMinutes(1), |
| 127 base::TimeDelta::FromSeconds(0)); // Disable caching of failed DNS. |
| 128 |
| 129 return cache; |
| 130 } |
| 131 |
| 120 void HostCache::Compact(base::TimeTicks now, const Entry* pinned_entry) { | 132 void HostCache::Compact(base::TimeTicks now, const Entry* pinned_entry) { |
| 121 // Clear out expired entries. | 133 // Clear out expired entries. |
| 122 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) { | 134 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) { |
| 123 Entry* entry = (it->second).get(); | 135 Entry* entry = (it->second).get(); |
| 124 if (entry != pinned_entry && !CanUseEntry(entry, now)) { | 136 if (entry != pinned_entry && !CanUseEntry(entry, now)) { |
| 125 entries_.erase(it++); | 137 entries_.erase(it++); |
| 126 } else { | 138 } else { |
| 127 ++it; | 139 ++it; |
| 128 } | 140 } |
| 129 } | 141 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 143 } else { | 155 } else { |
| 144 ++it; | 156 ++it; |
| 145 } | 157 } |
| 146 } | 158 } |
| 147 | 159 |
| 148 if (entries_.size() > max_entries_) | 160 if (entries_.size() > max_entries_) |
| 149 DLOG(WARNING) << "Still above max entries limit"; | 161 DLOG(WARNING) << "Still above max entries limit"; |
| 150 } | 162 } |
| 151 | 163 |
| 152 } // namespace net | 164 } // namespace net |
| OLD | NEW |