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

Unified Diff: net/dns/host_resolver_impl.cc

Issue 1898033006: DNS: Add stubs for persisting data across restarts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: *silently glares at editor, reuploads with proper spacing* Created 4 years, 5 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 | « net/dns/host_resolver_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl.cc
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
index 527eaad1f2e0686d7a840b4a59e26d4f1a9767dd..8d1cfdaeb0a1f64ba6fa492b0a8ee9de6f458551 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -500,6 +500,9 @@ void MakeNotStale(HostCache::EntryStaleness* stale_info) {
stale_info->stale_hits = 0;
}
+// Persist data every five minutes (potentially, cache and learned RTT).
+const int64_t kPersistDelaySec = 300;
+
} // namespace
//-----------------------------------------------------------------------------
@@ -1759,6 +1762,8 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB,
entry.error());
+ resolver_->SchedulePersist();
+
DCHECK(!requests_.empty());
if (entry.error() == OK) {
@@ -1984,6 +1989,7 @@ HostResolverImpl::HostResolverImpl(
additional_resolver_flags_(0),
fallback_to_proctask_(true),
worker_task_runner_(std::move(worker_task_runner)),
+ persist_initialized_(false),
weak_ptr_factory_(this),
probe_weak_ptr_factory_(this) {
if (options.enable_caching)
@@ -2536,6 +2542,36 @@ void HostResolverImpl::SetDnsClient(std::unique_ptr<DnsClient> dns_client) {
AbortDnsTasks();
}
+void HostResolverImpl::InitializePersistence(
+ const PersistCallback& persist_callback,
+ std::unique_ptr<const base::Value> old_data) {
+ DCHECK(!persist_initialized_);
+ persist_callback_ = persist_callback;
+ persist_initialized_ = true;
+ if (old_data)
+ ApplyPersistentData(std::move(old_data));
+}
+
+void HostResolverImpl::SchedulePersist() {
+ if (!persist_initialized_ || persist_timer_.IsRunning())
+ return;
+ persist_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromSeconds(kPersistDelaySec),
+ base::Bind(&HostResolverImpl::DoPersist, weak_ptr_factory_.GetWeakPtr()));
+}
+
+void HostResolverImpl::DoPersist() {
+ DCHECK(persist_initialized_);
+ persist_callback_.Run(GetPersistentData());
+}
+
+void HostResolverImpl::ApplyPersistentData(
+ std::unique_ptr<const base::Value> data) {}
+
+std::unique_ptr<const base::Value> HostResolverImpl::GetPersistentData() {
+ return std::unique_ptr<const base::Value>();
+}
+
HostResolverImpl::RequestImpl::~RequestImpl() {
if (job_)
job_->CancelRequest(this);
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698