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

Side by Side 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: rebase and fix bad merge. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 }; 492 };
493 493
494 void MakeNotStale(HostCache::EntryStaleness* stale_info) { 494 void MakeNotStale(HostCache::EntryStaleness* stale_info) {
495 if (!stale_info) 495 if (!stale_info)
496 return; 496 return;
497 stale_info->expired_by = base::TimeDelta::FromSeconds(-1); 497 stale_info->expired_by = base::TimeDelta::FromSeconds(-1);
498 stale_info->network_changes = 0; 498 stale_info->network_changes = 0;
499 stale_info->stale_hits = 0; 499 stale_info->stale_hits = 0;
500 } 500 }
501 501
502 // Persist data every five minutes (potentially, cache and learned RTT).
503 const int64_t kPersistDelaySec = 300;
504
502 } // namespace 505 } // namespace
503 506
504 //----------------------------------------------------------------------------- 507 //-----------------------------------------------------------------------------
505 508
506 bool ResolveLocalHostname(base::StringPiece host, 509 bool ResolveLocalHostname(base::StringPiece host,
507 uint16_t port, 510 uint16_t port,
508 AddressList* address_list) { 511 AddressList* address_list) {
509 address_list->clear(); 512 address_list->clear();
510 513
511 bool is_local6; 514 bool is_local6;
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 if (num_active_requests() == 0) { 1755 if (num_active_requests() == 0) {
1753 net_log_.AddEvent(NetLog::TYPE_CANCELLED); 1756 net_log_.AddEvent(NetLog::TYPE_CANCELLED);
1754 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, 1757 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB,
1755 OK); 1758 OK);
1756 return; 1759 return;
1757 } 1760 }
1758 1761
1759 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, 1762 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB,
1760 entry.error()); 1763 entry.error());
1761 1764
1765 resolver_->SchedulePersist();
1766
1762 DCHECK(!requests_.empty()); 1767 DCHECK(!requests_.empty());
1763 1768
1764 if (entry.error() == OK) { 1769 if (entry.error() == OK) {
1765 // Record this histogram here, when we know the system has a valid DNS 1770 // Record this histogram here, when we know the system has a valid DNS
1766 // configuration. 1771 // configuration.
1767 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", 1772 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig",
1768 resolver_->received_dns_config_); 1773 resolver_->received_dns_config_);
1769 } 1774 }
1770 1775
1771 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) && 1776 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) &&
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 1896 NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
1892 NetworkChangeNotifier::RemoveDNSObserver(this); 1897 NetworkChangeNotifier::RemoveDNSObserver(this);
1893 } 1898 }
1894 1899
1895 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { 1900 void HostResolverImpl::SetMaxQueuedJobs(size_t value) {
1896 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); 1901 DCHECK_EQ(0u, dispatcher_->num_queued_jobs());
1897 DCHECK_GT(value, 0u); 1902 DCHECK_GT(value, 0u);
1898 max_queued_jobs_ = value; 1903 max_queued_jobs_ = value;
1899 } 1904 }
1900 1905
1906 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.
1907 // DnsClient and config must be updated before aborting DnsTasks, since doing
1908 // so may start new jobs.
1909 dns_client_ = std::move(dns_client);
1910 if (dns_client_ && !dns_client_->GetConfig() &&
1911 num_dns_failures_ < kMaximumDnsFailures) {
1912 DnsConfig dns_config;
1913 NetworkChangeNotifier::GetDnsConfig(&dns_config);
1914 dns_client_->SetConfig(dns_config);
1915 num_dns_failures_ = 0;
1916 if (dns_client_->GetConfig())
1917 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
1918 }
1919
1920 AbortDnsTasks();
1921 }
1922
1901 int HostResolverImpl::Resolve(const RequestInfo& info, 1923 int HostResolverImpl::Resolve(const RequestInfo& info,
1902 RequestPriority priority, 1924 RequestPriority priority,
1903 AddressList* addresses, 1925 AddressList* addresses,
1904 const CompletionCallback& callback, 1926 const CompletionCallback& callback,
1905 RequestHandle* out_req, 1927 RequestHandle* out_req,
1906 const BoundNetLog& source_net_log) { 1928 const BoundNetLog& source_net_log) {
1907 DCHECK(addresses); 1929 DCHECK(addresses);
1908 DCHECK(CalledOnValidThread()); 1930 DCHECK(CalledOnValidThread());
1909 DCHECK_EQ(false, callback.is_null()); 1931 DCHECK_EQ(false, callback.is_null());
1910 1932
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 proc_params_(NULL, options.max_retry_attempts), 1999 proc_params_(NULL, options.max_retry_attempts),
1978 net_log_(net_log), 2000 net_log_(net_log),
1979 received_dns_config_(false), 2001 received_dns_config_(false),
1980 num_dns_failures_(0), 2002 num_dns_failures_(0),
1981 use_local_ipv6_(false), 2003 use_local_ipv6_(false),
1982 last_ipv6_probe_result_(true), 2004 last_ipv6_probe_result_(true),
1983 resolved_known_ipv6_hostname_(false), 2005 resolved_known_ipv6_hostname_(false),
1984 additional_resolver_flags_(0), 2006 additional_resolver_flags_(0),
1985 fallback_to_proctask_(true), 2007 fallback_to_proctask_(true),
1986 worker_task_runner_(std::move(worker_task_runner)), 2008 worker_task_runner_(std::move(worker_task_runner)),
2009 persist_initialized_(false),
1987 weak_ptr_factory_(this), 2010 weak_ptr_factory_(this),
1988 probe_weak_ptr_factory_(this) { 2011 probe_weak_ptr_factory_(this) {
1989 if (options.enable_caching) 2012 if (options.enable_caching)
1990 cache_ = HostCache::CreateDefaultCache(); 2013 cache_ = HostCache::CreateDefaultCache();
1991 2014
1992 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); 2015 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits();
1993 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); 2016 dispatcher_.reset(new PrioritizedDispatcher(job_limits));
1994 max_queued_jobs_ = job_limits.total_jobs * 100u; 2017 max_queued_jobs_ = job_limits.total_jobs * 100u;
1995 2018
1996 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); 2019 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES));
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2531 dns_client_->SetConfig(DnsConfig()); 2554 dns_client_->SetConfig(DnsConfig());
2532 2555
2533 // Switch jobs with active DnsTasks over to using ProcTasks. 2556 // Switch jobs with active DnsTasks over to using ProcTasks.
2534 AbortDnsTasks(); 2557 AbortDnsTasks();
2535 2558
2536 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", false); 2559 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", false);
2537 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.DnsClientDisabledReason", 2560 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.DnsClientDisabledReason",
2538 std::abs(net_error)); 2561 std::abs(net_error));
2539 } 2562 }
2540 2563
2541 void HostResolverImpl::SetDnsClient(std::unique_ptr<DnsClient> dns_client) { 2564 void HostResolverImpl::InitializePersistence(
2542 // DnsClient and config must be updated before aborting DnsTasks, since doing 2565 const PersistCallback& persist_callback,
2543 // so may start new jobs. 2566 std::unique_ptr<const base::Value> old_data) {
2544 dns_client_ = std::move(dns_client); 2567 DCHECK(!persist_initialized_);
2545 if (dns_client_ && !dns_client_->GetConfig() && 2568 persist_callback_ = persist_callback;
2546 num_dns_failures_ < kMaximumDnsFailures) { 2569 persist_initialized_ = true;
2547 DnsConfig dns_config; 2570 if (old_data)
2548 NetworkChangeNotifier::GetDnsConfig(&dns_config); 2571 ApplyPersistentData(std::move(old_data));
2549 dns_client_->SetConfig(dns_config); 2572 }
2550 num_dns_failures_ = 0;
2551 if (dns_client_->GetConfig())
2552 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2553 }
2554 2573
2555 AbortDnsTasks(); 2574 void HostResolverImpl::SchedulePersist() {
2575 if (!persist_initialized_ || persist_timer_.IsRunning())
2576 return;
2577 persist_timer_.Start(
2578 FROM_HERE, base::TimeDelta::FromSeconds(kPersistDelaySec),
2579 base::Bind(&HostResolverImpl::DoPersist, weak_ptr_factory_.GetWeakPtr()));
2580 }
2581
2582 void HostResolverImpl::DoPersist() {
2583 DCHECK(persist_initialized_);
2584 persist_callback_.Run(GetPersistentData());
2585 }
2586
2587 void HostResolverImpl::ApplyPersistentData(
2588 std::unique_ptr<const base::Value> data) {}
2589
2590 std::unique_ptr<const base::Value> HostResolverImpl::GetPersistentData() {
2591 return std::unique_ptr<const base::Value>();
2556 } 2592 }
2557 2593
2558 } // namespace net 2594 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698