| Index: net/dns/host_cache.h
|
| diff --git a/net/dns/host_cache.h b/net/dns/host_cache.h
|
| index 752ebeb6c0732f32e6677babe7b517d11ebf0354..e37ce53a013b7892ceef5cf5222b3ab538a38dd0 100644
|
| --- a/net/dns/host_cache.h
|
| +++ b/net/dns/host_cache.h
|
| @@ -31,6 +31,7 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
|
| Entry(int error, const AddressList& addrlist, base::TimeDelta ttl);
|
| // Use when |ttl| is unknown.
|
| Entry(int error, const AddressList& addrlist);
|
| +
|
| ~Entry();
|
|
|
| bool has_ttl() const { return ttl >= base::TimeDelta(); }
|
| @@ -64,17 +65,40 @@ 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 StaleEntryInfo {
|
| + // 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, or 0u if none.
|
| + unsigned network_changes;
|
| + // Number of hits to the cache entry while stale (expired or past-network).
|
| + unsigned stale_hits;
|
| +
|
| + bool is_stale() const {
|
| + return expired_by >= base::TimeDelta() || network_changes > 0;
|
| + }
|
| + };
|
| +
|
| + // TODO: This should be private, but Histogram* functions in the .cc need to
|
| + // poke at it. At least it's not NET_EXPORTed.
|
| + struct EntryInternal : public Entry {
|
| + EntryInternal(const Entry& entry,
|
| + base::TimeTicks now,
|
| + base::TimeDelta ttl,
|
| + unsigned network_changes);
|
| +
|
| + base::TimeTicks added;
|
| + base::TimeTicks expires;
|
| + unsigned network_changes;
|
| + unsigned total_hits;
|
| + unsigned stale_hits;
|
| +
|
| + bool CheckStale(base::TimeTicks now,
|
| + unsigned network_changes,
|
| + StaleEntryInfo* out) const;
|
| };
|
|
|
| - typedef ExpiringCache<Key, Entry, base::TimeTicks,
|
| - std::less<base::TimeTicks>,
|
| - EvictionHandler> EntryMap;
|
| + // Ditto.
|
| + typedef std::map<Key, EntryInternal> EntryMap;
|
|
|
| // Constructs a HostCache that stores up to |max_entries|.
|
| explicit HostCache(size_t max_entries);
|
| @@ -85,6 +109,10 @@ 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);
|
|
|
| + const Entry* LookupStale(const Key& key,
|
| + base::TimeTicks now,
|
| + StaleEntryInfo* 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 +121,10 @@ 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.
|
| + // (Does not actually remove them from memory.)
|
| + void OnNetworkChange();
|
| +
|
| // Empties the cache
|
| void clear();
|
|
|
| @@ -102,7 +134,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();
|
| @@ -111,13 +143,17 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
|
| FRIEND_TEST_ALL_PREFIXES(HostCacheTest, NoCache);
|
|
|
| // 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 Evict(base::TimeTicks now);
|
| +
|
| + EntryMap::iterator SelectEntryToEvict();
|
|
|
| // Map from hostname (presumably in lowercase canonicalized format) to
|
| // a resolved result entry.
|
| EntryMap entries_;
|
| + size_t max_entries_;
|
| + unsigned network_changes_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(HostCache);
|
| };
|
|
|