Chromium Code Reviews| 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 #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 <functional> | 8 #include <functional> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 22 class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 23 public: | 23 public: |
| 24 // Stores the latest address list that was looked up for a hostname. | 24 // Stores the latest address list that was looked up for a hostname. |
| 25 struct Entry { | 25 struct Entry { |
| 26 Entry(int error, const AddressList& addrlist); | 26 Entry(int error, const AddressList& addrlist); |
| 27 ~Entry(); | 27 ~Entry(); |
| 28 | 28 |
| 29 // The resolve results for this entry. | 29 // The resolve results for this entry. |
| 30 int error; | 30 int error; |
| 31 AddressList addrlist; | 31 AddressList addrlist; |
| 32 base::TimeDelta original_ttl; | |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 struct Key { | 35 struct Key { |
| 35 Key(const std::string& hostname, AddressFamily address_family, | 36 Key(const std::string& hostname, AddressFamily address_family, |
| 36 HostResolverFlags host_resolver_flags) | 37 HostResolverFlags host_resolver_flags) |
| 37 : hostname(hostname), | 38 : hostname(hostname), |
| 38 address_family(address_family), | 39 address_family(address_family), |
| 39 host_resolver_flags(host_resolver_flags) {} | 40 host_resolver_flags(host_resolver_flags) {} |
| 40 | 41 |
| 41 bool operator<(const Key& other) const { | 42 bool operator<(const Key& other) const { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 61 explicit HostCache(size_t max_entries); | 62 explicit HostCache(size_t max_entries); |
| 62 | 63 |
| 63 ~HostCache(); | 64 ~HostCache(); |
| 64 | 65 |
| 65 // Returns a pointer to the entry for |key|, which is valid at time | 66 // Returns a pointer to the entry for |key|, which is valid at time |
| 66 // |now|. If there is no such entry, returns NULL. | 67 // |now|. If there is no such entry, returns NULL. |
| 67 const Entry* Lookup(const Key& key, base::TimeTicks now); | 68 const Entry* Lookup(const Key& key, base::TimeTicks now); |
| 68 | 69 |
| 69 // Overwrites or creates an entry for |key|. | 70 // Overwrites or creates an entry for |key|. |
| 70 // (|error|, |addrlist|) is the value to set, |now| is the current time | 71 // (|error|, |addrlist|) is the value to set, |now| is the current time |
| 71 // |ttl| is the "time to live". | 72 // |ttl| is the "time to live". Returns a pointer to the created entry. |
| 72 void Set(const Key& key, | 73 Entry* Set(const Key& key, |
| 73 int error, | 74 int error, |
| 74 const AddressList& addrlist, | 75 const AddressList& addrlist, |
| 75 base::TimeTicks now, | 76 base::TimeTicks now, |
| 76 base::TimeDelta ttl); | 77 base::TimeDelta ttl); |
|
cbentzel
2012/10/11 18:27:30
Could this just take a base::TimeDelta original_tt
szym
2012/10/11 18:33:21
The rationale was that changing the signature of S
| |
| 77 | 78 |
| 78 // Empties the cache | 79 // Empties the cache |
| 79 void clear(); | 80 void clear(); |
| 80 | 81 |
| 81 // Returns the number of entries in the cache. | 82 // Returns the number of entries in the cache. |
| 82 size_t size() const; | 83 size_t size() const; |
| 83 | 84 |
| 84 // Following are used by net_internals UI. | 85 // Following are used by net_internals UI. |
| 85 size_t max_entries() const; | 86 size_t max_entries() const; |
| 86 | 87 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 100 // Map from hostname (presumably in lowercase canonicalized format) to | 101 // Map from hostname (presumably in lowercase canonicalized format) to |
| 101 // a resolved result entry. | 102 // a resolved result entry. |
| 102 EntryMap entries_; | 103 EntryMap entries_; |
| 103 | 104 |
| 104 DISALLOW_COPY_AND_ASSIGN(HostCache); | 105 DISALLOW_COPY_AND_ASSIGN(HostCache); |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 } // namespace net | 108 } // namespace net |
| 108 | 109 |
| 109 #endif // NET_BASE_HOST_CACHE_H_ | 110 #endif // NET_BASE_HOST_CACHE_H_ |
| OLD | NEW |