Chromium Code Reviews| Index: net/dns/host_cache.h |
| diff --git a/net/dns/host_cache.h b/net/dns/host_cache.h |
| index 752ebeb6c0732f32e6677babe7b517d11ebf0354..1e8b9052cdd6a1ea71e52f81f3a9b9129041844f 100644 |
| --- a/net/dns/host_cache.h |
| +++ b/net/dns/host_cache.h |
| @@ -64,18 +64,19 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| HostResolverFlags host_resolver_flags; |
| }; |
| - struct EvictionHandler { |
| - void Handle(const Key& key, |
| - const Entry& entry, |
| - const base::TimeTicks& expiration, |
| - const base::TimeTicks& now, |
| - bool onGet) const; |
| + struct NET_EXPORT EntryStaleness { |
| + // Time since the entry's TTL has expired. Negative if not expired. |
| + base::TimeDelta expired_by; |
| + // Number of network changes since this result was cached. |
| + int network_changes; |
| + // Number of hits to the cache entry while stale (expired or past-network). |
| + int stale_hits; |
| + |
| + bool is_stale() const { |
| + return network_changes > 0 || expired_by >= base::TimeDelta(); |
| + } |
| }; |
| - typedef ExpiringCache<Key, Entry, base::TimeTicks, |
| - std::less<base::TimeTicks>, |
| - EvictionHandler> EntryMap; |
|
Randy Smith (Not in Mondays)
2016/05/04 18:15:25
I don't have a sense as to the usage of ExpiringCa
Julia Tuttle
2016/05/05 14:35:53
The host cache isn't using it because the expirati
|
| - |
| // Constructs a HostCache that stores up to |max_entries|. |
| explicit HostCache(size_t max_entries); |
| @@ -85,6 +86,13 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| // |now|. If there is no such entry, returns NULL. |
| const Entry* Lookup(const Key& key, base::TimeTicks now); |
| + // Returns a pointer to the entry for |key|, whether it is valid or stale at |
| + // time |now|. Fills in |stale_out| with information about how stale it is. |
| + // If there is no entry for |key| at all, returns NULL. |
| + const Entry* LookupStale(const Key& key, |
| + base::TimeTicks now, |
| + EntryStaleness* stale_out); |
| + |
| // Overwrites or creates an entry for |key|. |
| // |entry| is the value to set, |now| is the current time |
| // |ttl| is the "time to live". |
| @@ -93,6 +101,9 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| base::TimeTicks now, |
| base::TimeDelta ttl); |
| + // Marks all entries as stale on account of a network change. |
| + void OnNetworkChange(); |
| + |
| // Empties the cache |
| void clear(); |
| @@ -102,7 +113,7 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| // Following are used by net_internals UI. |
| size_t max_entries() const; |
| - const EntryMap& entries() const; |
| + std::unique_ptr<base::Value> GetEntriesAsValue() const; |
| // Creates a default cache. |
| static std::unique_ptr<HostCache> CreateDefaultCache(); |
| @@ -110,14 +121,41 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| private: |
| FRIEND_TEST_ALL_PREFIXES(HostCacheTest, NoCache); |
| + struct EntryInternal; |
| + typedef std::map<Key, EntryInternal> EntryMap; |
| + enum SetOutcome : int; |
| + enum LookupOutcome : int; |
| + enum EraseReason : int; |
| + |
| + EntryInternal* LookupInternal(const Key& key); |
| + |
| + void RecordSet(SetOutcome outcome, |
| + base::TimeTicks now, |
| + const EntryInternal* old_entry, |
| + const Entry& new_entry); |
| + void RecordUpdateStale(const EntryInternal& old_entry, |
| + const Entry& new_entry, |
| + base::TimeDelta expired_by, |
| + int network_changes, |
| + int stale_hits); |
| + void RecordLookup(LookupOutcome outcome, |
| + base::TimeTicks now, |
| + const EntryInternal* entry); |
| + void RecordErase(EraseReason reason, |
| + base::TimeTicks now, |
| + const EntryInternal& entry); |
| + void RecordEraseAll(EraseReason reason, base::TimeTicks now); |
| + |
| // Returns true if this HostCache can contain no entries. |
| - bool caching_is_disabled() const { |
| - return entries_.max_entries() == 0; |
| - } |
| + bool caching_is_disabled() const { return max_entries_ == 0; } |
| + |
| + void EvictOneEntry(base::TimeTicks now); |
| // Map from hostname (presumably in lowercase canonicalized format) to |
| // a resolved result entry. |
| EntryMap entries_; |
| + size_t max_entries_; |
| + int network_changes_; |
| DISALLOW_COPY_AND_ASSIGN(HostCache); |
| }; |