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" |
| 9 #include "base/string_number_conversions.h" |
8 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
9 | 11 |
10 namespace net { | 12 namespace net { |
11 | 13 |
12 //----------------------------------------------------------------------------- | 14 //----------------------------------------------------------------------------- |
13 | 15 |
14 HostCache::Entry::Entry(int error, const AddressList& addrlist, | 16 HostCache::Entry::Entry(int error, const AddressList& addrlist, |
15 base::TimeDelta ttl) | 17 base::TimeDelta ttl) |
16 : error(error), | 18 : error(error), |
17 addrlist(addrlist), | 19 addrlist(addrlist), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 75 } |
74 | 76 |
75 // Note that this map may contain expired entries. | 77 // Note that this map may contain expired entries. |
76 const HostCache::EntryMap& HostCache::entries() const { | 78 const HostCache::EntryMap& HostCache::entries() const { |
77 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
78 return entries_; | 80 return entries_; |
79 } | 81 } |
80 | 82 |
81 // static | 83 // static |
82 scoped_ptr<HostCache> HostCache::CreateDefaultCache() { | 84 scoped_ptr<HostCache> HostCache::CreateDefaultCache() { |
83 #if defined(OS_CHROMEOS) | 85 // Cache capacity is determined by the field trial. |
84 // Increase HostCache size for the duration of the async DNS field trial. | 86 const size_t kSaneMaxEntries = 1 << 20; |
85 // http://crbug.com/143454 | 87 size_t max_entries = 0; |
86 // TODO(szym): Determine the best size. http://crbug.com/114277 | 88 if (!base::StringToSizeT(base::FieldTrialList::FindFullName("HostCacheSize"), |
87 static const size_t kMaxHostCacheEntries = 1000; | 89 &max_entries) || max_entries > kSaneMaxEntries) { |
88 #else | 90 max_entries = 100; |
89 static const size_t kMaxHostCacheEntries = 100; | 91 } |
90 #endif | 92 return make_scoped_ptr(new HostCache(max_entries)); |
91 return make_scoped_ptr(new HostCache(kMaxHostCacheEntries)); | |
92 } | 93 } |
93 | 94 |
94 } // namespace net | 95 } // namespace net |
OLD | NEW |