OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "net/base/address_family.h" | 13 #include "net/base/address_family.h" |
14 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
15 #include "testing/gtest/include/gtest/gtest_prod.h" | 15 #include "testing/gtest/include/gtest/gtest_prod.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 // Cache used by HostResolver to map hostnames to their resolved result. | 19 // Cache used by HostResolver to map hostnames to their resolved result. |
20 class HostCache { | 20 class HostCache { |
21 public: | 21 public: |
22 // Stores the latest address list that was looked up for a hostname. | 22 // Stores the latest address list that was looked up for a hostname. |
23 struct Entry : public base::RefCounted<Entry> { | 23 struct Entry : public base::RefCounted<Entry> { |
24 Entry(int error, const AddressList& addrlist, base::TimeTicks expiration); | 24 Entry(int error, const AddressList& addrlist, base::TimeTicks expiration); |
25 ~Entry(); | |
26 | 25 |
27 // The resolve results for this entry. | 26 // The resolve results for this entry. |
28 int error; | 27 int error; |
29 AddressList addrlist; | 28 AddressList addrlist; |
30 | 29 |
31 // The time when this entry expires. | 30 // The time when this entry expires. |
32 base::TimeTicks expiration; | 31 base::TimeTicks expiration; |
| 32 |
| 33 private: |
| 34 friend class base::RefCounted<Entry>; |
| 35 |
| 36 ~Entry(); |
33 }; | 37 }; |
34 | 38 |
35 struct Key { | 39 struct Key { |
36 Key(const std::string& hostname, AddressFamily address_family) | 40 Key(const std::string& hostname, AddressFamily address_family) |
37 : hostname(hostname), address_family(address_family) {} | 41 : hostname(hostname), address_family(address_family) {} |
38 | 42 |
39 bool operator==(const Key& other) const { | 43 bool operator==(const Key& other) const { |
40 return other.hostname == hostname && | 44 return other.hostname == hostname && |
41 other.address_family == address_family; | 45 other.address_family == address_family; |
42 } | 46 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // Map from hostname (presumably in lowercase canonicalized format) to | 119 // Map from hostname (presumably in lowercase canonicalized format) to |
116 // a resolved result entry. | 120 // a resolved result entry. |
117 EntryMap entries_; | 121 EntryMap entries_; |
118 | 122 |
119 DISALLOW_COPY_AND_ASSIGN(HostCache); | 123 DISALLOW_COPY_AND_ASSIGN(HostCache); |
120 }; | 124 }; |
121 | 125 |
122 } // namespace net | 126 } // namespace net |
123 | 127 |
124 #endif // NET_BASE_HOST_CACHE_H_ | 128 #endif // NET_BASE_HOST_CACHE_H_ |
OLD | NEW |