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

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: Fix IOS issue? Created 4 years, 4 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 proc_params_(NULL, options.max_retry_attempts), 1982 proc_params_(NULL, options.max_retry_attempts),
1978 net_log_(net_log), 1983 net_log_(net_log),
1979 received_dns_config_(false), 1984 received_dns_config_(false),
1980 num_dns_failures_(0), 1985 num_dns_failures_(0),
1981 use_local_ipv6_(false), 1986 use_local_ipv6_(false),
1982 last_ipv6_probe_result_(true), 1987 last_ipv6_probe_result_(true),
1983 resolved_known_ipv6_hostname_(false), 1988 resolved_known_ipv6_hostname_(false),
1984 additional_resolver_flags_(0), 1989 additional_resolver_flags_(0),
1985 fallback_to_proctask_(true), 1990 fallback_to_proctask_(true),
1986 worker_task_runner_(std::move(worker_task_runner)), 1991 worker_task_runner_(std::move(worker_task_runner)),
1992 persist_initialized_(false),
1987 weak_ptr_factory_(this), 1993 weak_ptr_factory_(this),
1988 probe_weak_ptr_factory_(this) { 1994 probe_weak_ptr_factory_(this) {
1989 if (options.enable_caching) 1995 if (options.enable_caching)
1990 cache_ = HostCache::CreateDefaultCache(); 1996 cache_ = HostCache::CreateDefaultCache();
1991 1997
1992 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); 1998 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits();
1993 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); 1999 dispatcher_.reset(new PrioritizedDispatcher(job_limits));
1994 max_queued_jobs_ = job_limits.total_jobs * 100u; 2000 max_queued_jobs_ = job_limits.total_jobs * 100u;
1995 2001
1996 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); 2002 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES));
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2548 NetworkChangeNotifier::GetDnsConfig(&dns_config); 2554 NetworkChangeNotifier::GetDnsConfig(&dns_config);
2549 dns_client_->SetConfig(dns_config); 2555 dns_client_->SetConfig(dns_config);
2550 num_dns_failures_ = 0; 2556 num_dns_failures_ = 0;
2551 if (dns_client_->GetConfig()) 2557 if (dns_client_->GetConfig())
2552 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2558 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2553 } 2559 }
2554 2560
2555 AbortDnsTasks(); 2561 AbortDnsTasks();
2556 } 2562 }
2557 2563
2564 void HostResolverImpl::InitializePersistence(
2565 const PersistCallback& persist_callback,
2566 std::unique_ptr<const base::Value> old_data) {
2567 DCHECK(!persist_initialized_);
2568 persist_callback_ = persist_callback;
2569 persist_initialized_ = true;
2570 if (old_data)
2571 ApplyPersistentData(std::move(old_data));
2572 }
2573
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>();
2592 }
2593
2558 } // namespace net 2594 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/net_common.gypi » ('j') | net/net_common.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698