OLD | NEW |
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 "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 // Note that this map may contain expired entries. | 78 // Note that this map may contain expired entries. |
79 const HostCache::EntryMap& HostCache::entries() const { | 79 const HostCache::EntryMap& HostCache::entries() const { |
80 DCHECK(CalledOnValidThread()); | 80 DCHECK(CalledOnValidThread()); |
81 return entries_; | 81 return entries_; |
82 } | 82 } |
83 | 83 |
84 // static | 84 // static |
85 scoped_ptr<HostCache> HostCache::CreateDefaultCache() { | 85 scoped_ptr<HostCache> HostCache::CreateDefaultCache() { |
86 // Cache capacity is determined by the field trial. | 86 // Cache capacity is determined by the field trial. |
| 87 #if defined(ENABLE_BUILT_IN_DNS) |
| 88 const size_t kDefaultMaxEntries = 1000; |
| 89 #else |
| 90 const size_t kDefaultMaxEntries = 100; |
| 91 #endif |
87 const size_t kSaneMaxEntries = 1 << 20; | 92 const size_t kSaneMaxEntries = 1 << 20; |
88 size_t max_entries = 0; | 93 size_t max_entries = 0; |
89 base::StringToSizeT(base::FieldTrialList::FindFullName("HostCacheSize"), | 94 base::StringToSizeT(base::FieldTrialList::FindFullName("HostCacheSize"), |
90 &max_entries); | 95 &max_entries); |
91 if ((max_entries == 0) || (max_entries > kSaneMaxEntries)) | 96 if ((max_entries == 0) || (max_entries > kSaneMaxEntries)) |
92 max_entries = 100; | 97 max_entries = kDefaultMaxEntries; |
93 return make_scoped_ptr(new HostCache(max_entries)); | 98 return make_scoped_ptr(new HostCache(max_entries)); |
94 } | 99 } |
95 | 100 |
96 void HostCache::EvictionHandler::Handle( | 101 void HostCache::EvictionHandler::Handle( |
97 const Key& key, | 102 const Key& key, |
98 const Entry& entry, | 103 const Entry& entry, |
99 const base::TimeTicks& expiration, | 104 const base::TimeTicks& expiration, |
100 const base::TimeTicks& now, | 105 const base::TimeTicks& now, |
101 bool on_get) const { | 106 bool on_get) const { |
102 if (on_get) { | 107 if (on_get) { |
103 DCHECK(now >= expiration); | 108 DCHECK(now >= expiration); |
104 UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheExpiredOnGet", now - expiration, | 109 UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheExpiredOnGet", now - expiration, |
105 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100); | 110 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100); |
106 return; | 111 return; |
107 } | 112 } |
108 if (expiration > now) { | 113 if (expiration > now) { |
109 UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheEvicted", expiration - now, | 114 UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheEvicted", expiration - now, |
110 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100); | 115 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100); |
111 } else { | 116 } else { |
112 UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheExpired", now - expiration, | 117 UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheExpired", now - expiration, |
113 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100); | 118 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100); |
114 } | 119 } |
115 } | 120 } |
116 | 121 |
117 } // namespace net | 122 } // namespace net |
OLD | NEW |