Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: net/dns/host_cache.h

Issue 2791653002: Serialize and deserialize HostCache for persistence (Closed)
Patch Set: fix warning Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/host_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_cache.h
diff --git a/net/dns/host_cache.h b/net/dns/host_cache.h
index 37cf204e3ccb653aa3d642ad560a4ed361d7d5d9..c0ba45674d3890b27bffe2db661f7d70b60b3327 100644
--- a/net/dns/host_cache.h
+++ b/net/dns/host_cache.h
@@ -8,6 +8,7 @@
#include <stddef.h>
#include <functional>
+#include <map>
#include <memory>
#include <string>
#include <tuple>
@@ -22,6 +23,10 @@
#include "net/base/net_export.h"
#include "net/dns/dns_util.h"
+namespace base {
+class ListValue;
+}
+
namespace net {
// Cache used by HostResolver to map hostnames to their resolved result.
@@ -90,6 +95,11 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
base::TimeDelta ttl,
int network_changes);
+ Entry(int error,
+ const AddressList& addresses,
+ base::TimeTicks expires,
+ int network_changes);
+
int total_hits() const { return total_hits_; }
int stale_hits() const { return stale_hits_; }
@@ -155,6 +165,14 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
void ClearForHosts(
const base::Callback<bool(const std::string&)>& host_filter);
+ // Returns the contents of the cache represented as a base::ListValue for
+ // serialization.
+ std::unique_ptr<base::ListValue> GetAsListValue(bool include_staleness) const;
+ // Takes a base::ListValue representing cache entries and stores them in the
+ // cache, skipping any that already have entries. Returns true on success,
+ // false on failure.
+ bool RestoreFromListValue(base::ListValue& old_cache);
+
// Returns the number of entries in the cache.
size_t size() const;
@@ -191,6 +209,8 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
bool caching_is_disabled() const { return max_entries_ == 0; }
void EvictOneEntry(base::TimeTicks now);
+ // Helper to insert an Entry into the cache.
+ void AddEntry(const Key& key, const Entry& entry);
// Map from hostname (presumably in lowercase canonicalized format) to
// a resolved result entry.
« no previous file with comments | « no previous file | net/dns/host_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698