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

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

Issue 11065052: [net] Add AsyncDNS.TTL histogram. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add NET_EXPORT to HostCache::Entry Created 8 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
« no previous file with comments | « net/base/host_cache.h ('k') | net/base/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/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
12 //----------------------------------------------------------------------------- 12 //-----------------------------------------------------------------------------
13 13
14 HostCache::Entry::Entry(int error, const AddressList& addrlist,
15 base::TimeDelta ttl)
16 : error(error),
17 addrlist(addrlist),
18 ttl(ttl) {
19 DCHECK(ttl >= base::TimeDelta());
20 }
21
14 HostCache::Entry::Entry(int error, const AddressList& addrlist) 22 HostCache::Entry::Entry(int error, const AddressList& addrlist)
15 : error(error), 23 : error(error),
16 addrlist(addrlist) { 24 addrlist(addrlist),
25 ttl(base::TimeDelta::FromSeconds(-1)) {
17 } 26 }
18 27
19 HostCache::Entry::~Entry() { 28 HostCache::Entry::~Entry() {
20 } 29 }
21 30
22 //----------------------------------------------------------------------------- 31 //-----------------------------------------------------------------------------
23 32
24 HostCache::HostCache(size_t max_entries) 33 HostCache::HostCache(size_t max_entries)
25 : entries_(max_entries) { 34 : entries_(max_entries) {
26 } 35 }
27 36
28 HostCache::~HostCache() { 37 HostCache::~HostCache() {
29 } 38 }
30 39
31 const HostCache::Entry* HostCache::Lookup(const Key& key, 40 const HostCache::Entry* HostCache::Lookup(const Key& key,
32 base::TimeTicks now) { 41 base::TimeTicks now) {
33 DCHECK(CalledOnValidThread()); 42 DCHECK(CalledOnValidThread());
34 if (caching_is_disabled()) 43 if (caching_is_disabled())
35 return NULL; 44 return NULL;
36 45
37 return entries_.Get(key, now); 46 return entries_.Get(key, now);
38 } 47 }
39 48
40 void HostCache::Set(const Key& key, 49 void HostCache::Set(const Key& key,
41 int error, 50 const Entry& entry,
42 const AddressList& addrlist,
43 base::TimeTicks now, 51 base::TimeTicks now,
44 base::TimeDelta ttl) { 52 base::TimeDelta ttl) {
45 DCHECK(CalledOnValidThread()); 53 DCHECK(CalledOnValidThread());
46 if (caching_is_disabled()) 54 if (caching_is_disabled())
47 return; 55 return;
48 56
49 entries_.Put(key, Entry(error, addrlist), now, now + ttl); 57 entries_.Put(key, entry, now, now + ttl);
50 } 58 }
51 59
52 void HostCache::clear() { 60 void HostCache::clear() {
53 DCHECK(CalledOnValidThread()); 61 DCHECK(CalledOnValidThread());
54 entries_.Clear(); 62 entries_.Clear();
55 } 63 }
56 64
57 size_t HostCache::size() const { 65 size_t HostCache::size() const {
58 DCHECK(CalledOnValidThread()); 66 DCHECK(CalledOnValidThread());
59 return entries_.size(); 67 return entries_.size();
(...skipping 17 matching lines...) Expand all
77 // http://crbug.com/143454 85 // http://crbug.com/143454
78 // TODO(szym): Determine the best size. http://crbug.com/114277 86 // TODO(szym): Determine the best size. http://crbug.com/114277
79 static const size_t kMaxHostCacheEntries = 1000; 87 static const size_t kMaxHostCacheEntries = 1000;
80 #else 88 #else
81 static const size_t kMaxHostCacheEntries = 100; 89 static const size_t kMaxHostCacheEntries = 100;
82 #endif 90 #endif
83 return new HostCache(kMaxHostCacheEntries); 91 return new HostCache(kMaxHostCacheEntries);
84 } 92 }
85 93
86 } // namespace net 94 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_cache.h ('k') | net/base/host_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698