Chromium Code Reviews| Index: net/dns/host_resolver_impl.cc |
| diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc |
| index 2345dad8c741a17ab5ca385cf92380be2f90ef8c..5a46d5803ba425747bd47414d2902f8fb0010a67 100644 |
| --- a/net/dns/host_resolver_impl.cc |
| +++ b/net/dns/host_resolver_impl.cc |
| @@ -499,6 +499,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) { |
| @@ -1898,6 +1903,23 @@ void HostResolverImpl::SetMaxQueuedJobs(size_t value) { |
| max_queued_jobs_ = value; |
| } |
| +void HostResolverImpl::SetDnsClient(std::unique_ptr<DnsClient> dns_client) { |
|
Charlie Harrison
2016/07/26 13:49:42
Did this need to move?
Julia Tuttle
2016/07/26 21:10:13
Nope.
|
| + // DnsClient and config must be updated before aborting DnsTasks, since doing |
| + // so may start new jobs. |
| + dns_client_ = std::move(dns_client); |
| + if (dns_client_ && !dns_client_->GetConfig() && |
| + num_dns_failures_ < kMaximumDnsFailures) { |
| + DnsConfig dns_config; |
| + NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| + dns_client_->SetConfig(dns_config); |
| + num_dns_failures_ = 0; |
| + if (dns_client_->GetConfig()) |
| + UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| + } |
| + |
| + AbortDnsTasks(); |
| +} |
| + |
| int HostResolverImpl::Resolve(const RequestInfo& info, |
| RequestPriority priority, |
| AddressList* addresses, |
| @@ -1984,6 +2006,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) |
| @@ -2538,21 +2561,34 @@ void HostResolverImpl::OnDnsTaskResolve(int net_error) { |
| std::abs(net_error)); |
| } |
| -void HostResolverImpl::SetDnsClient(std::unique_ptr<DnsClient> dns_client) { |
| - // DnsClient and config must be updated before aborting DnsTasks, since doing |
| - // so may start new jobs. |
| - dns_client_ = std::move(dns_client); |
| - if (dns_client_ && !dns_client_->GetConfig() && |
| - num_dns_failures_ < kMaximumDnsFailures) { |
| - DnsConfig dns_config; |
| - NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| - dns_client_->SetConfig(dns_config); |
| - num_dns_failures_ = 0; |
| - if (dns_client_->GetConfig()) |
| - UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| - } |
| +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)); |
| +} |
| - AbortDnsTasks(); |
| +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>(); |
| } |
| } // namespace net |