OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef NET_BASE_HOST_CACHE_H_ | 5 #ifndef NET_BASE_HOST_CACHE_H_ |
6 #define NET_BASE_HOST_CACHE_H_ | 6 #define NET_BASE_HOST_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
(...skipping 18 matching lines...) Expand all Loading... |
30 // The time when this entry expires. | 30 // The time when this entry expires. |
31 base::TimeTicks expiration; | 31 base::TimeTicks expiration; |
32 | 32 |
33 private: | 33 private: |
34 friend class base::RefCounted<Entry>; | 34 friend class base::RefCounted<Entry>; |
35 | 35 |
36 ~Entry(); | 36 ~Entry(); |
37 }; | 37 }; |
38 | 38 |
39 struct Key { | 39 struct Key { |
40 Key(const std::string& hostname, AddressFamily address_family) | 40 Key(const std::string& hostname, AddressFamily address_family, |
41 : hostname(hostname), address_family(address_family) {} | 41 HostResolverFlags host_resolver_flags) |
| 42 : hostname(hostname), |
| 43 address_family(address_family), |
| 44 host_resolver_flags(host_resolver_flags) {} |
42 | 45 |
43 bool operator==(const Key& other) const { | 46 bool operator==(const Key& other) const { |
44 return other.hostname == hostname && | 47 // |address_family| and |host_resolver_flags| are compared before |
45 other.address_family == address_family; | 48 // |hostname| under assumption that integer comparisons are faster than |
| 49 // string comparisons. |
| 50 return (other.address_family == address_family && |
| 51 other.host_resolver_flags == host_resolver_flags && |
| 52 other.hostname == hostname); |
46 } | 53 } |
47 | 54 |
48 bool operator<(const Key& other) const { | 55 bool operator<(const Key& other) const { |
49 if (address_family == other.address_family) | 56 // |address_family| and |host_resolver_flags| are compared before |
50 return hostname < other.hostname; | 57 // |hostname| under assumption that integer comparisons are faster than |
51 return address_family < other.address_family; | 58 // string comparisons. |
| 59 if (address_family != other.address_family) |
| 60 return address_family < other.address_family; |
| 61 if (host_resolver_flags != other.host_resolver_flags) |
| 62 return host_resolver_flags < other.host_resolver_flags; |
| 63 return hostname < other.hostname; |
52 } | 64 } |
53 | 65 |
54 std::string hostname; | 66 std::string hostname; |
55 AddressFamily address_family; | 67 AddressFamily address_family; |
| 68 HostResolverFlags host_resolver_flags; |
56 }; | 69 }; |
57 | 70 |
58 typedef std::map<Key, scoped_refptr<Entry> > EntryMap; | 71 typedef std::map<Key, scoped_refptr<Entry> > EntryMap; |
59 | 72 |
60 // Constructs a HostCache that caches successful host resolves for | 73 // Constructs a HostCache that caches successful host resolves for |
61 // |success_entry_ttl| time, and failed host resolves for | 74 // |success_entry_ttl| time, and failed host resolves for |
62 // |failure_entry_ttl|. The cache will store up to |max_entries|. | 75 // |failure_entry_ttl|. The cache will store up to |max_entries|. |
63 HostCache(size_t max_entries, | 76 HostCache(size_t max_entries, |
64 base::TimeDelta success_entry_ttl, | 77 base::TimeDelta success_entry_ttl, |
65 base::TimeDelta failure_entry_ttl); | 78 base::TimeDelta failure_entry_ttl); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Map from hostname (presumably in lowercase canonicalized format) to | 145 // Map from hostname (presumably in lowercase canonicalized format) to |
133 // a resolved result entry. | 146 // a resolved result entry. |
134 EntryMap entries_; | 147 EntryMap entries_; |
135 | 148 |
136 DISALLOW_COPY_AND_ASSIGN(HostCache); | 149 DISALLOW_COPY_AND_ASSIGN(HostCache); |
137 }; | 150 }; |
138 | 151 |
139 } // namespace net | 152 } // namespace net |
140 | 153 |
141 #endif // NET_BASE_HOST_CACHE_H_ | 154 #endif // NET_BASE_HOST_CACHE_H_ |
OLD | NEW |