OLD | NEW |
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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 }; | 493 }; |
494 | 494 |
495 void MakeNotStale(HostCache::EntryStaleness* stale_info) { | 495 void MakeNotStale(HostCache::EntryStaleness* stale_info) { |
496 if (!stale_info) | 496 if (!stale_info) |
497 return; | 497 return; |
498 stale_info->expired_by = base::TimeDelta::FromSeconds(-1); | 498 stale_info->expired_by = base::TimeDelta::FromSeconds(-1); |
499 stale_info->network_changes = 0; | 499 stale_info->network_changes = 0; |
500 stale_info->stale_hits = 0; | 500 stale_info->stale_hits = 0; |
501 } | 501 } |
502 | 502 |
| 503 // Persist data every five minutes (potentially, cache and learned RTT). |
| 504 const int64_t kPersistDelaySec = 300; |
| 505 |
503 } // namespace | 506 } // namespace |
504 | 507 |
505 //----------------------------------------------------------------------------- | 508 //----------------------------------------------------------------------------- |
506 | 509 |
507 bool ResolveLocalHostname(base::StringPiece host, | 510 bool ResolveLocalHostname(base::StringPiece host, |
508 uint16_t port, | 511 uint16_t port, |
509 AddressList* address_list) { | 512 AddressList* address_list) { |
510 address_list->clear(); | 513 address_list->clear(); |
511 | 514 |
512 bool is_local6; | 515 bool is_local6; |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2529 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2535 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2530 dns_client_->SetConfig(dns_config); | 2536 dns_client_->SetConfig(dns_config); |
2531 num_dns_failures_ = 0; | 2537 num_dns_failures_ = 0; |
2532 if (dns_client_->GetConfig()) | 2538 if (dns_client_->GetConfig()) |
2533 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2539 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2534 } | 2540 } |
2535 | 2541 |
2536 AbortDnsTasks(); | 2542 AbortDnsTasks(); |
2537 } | 2543 } |
2538 | 2544 |
| 2545 void HostResolverImpl::InitializePersistence( |
| 2546 const PersistCallback& persist_callback, |
| 2547 std::unique_ptr<const base::Value> old_data) { |
| 2548 DCHECK(!persist_initialized_); |
| 2549 persist_callback_ = persist_callback; |
| 2550 persist_initialized_ = true; |
| 2551 if (old_data) |
| 2552 ApplyPersistentData(std::move(old_data)); |
| 2553 } |
| 2554 |
| 2555 void HostResolverImpl::SchedulePersist() { |
| 2556 if (!persist_initialized_ || persist_timer_.IsRunning()) |
| 2557 return; |
| 2558 persist_timer_.Start( |
| 2559 FROM_HERE, base::TimeDelta::FromSeconds(kPersistDelaySec), |
| 2560 base::Bind(&HostResolverImpl::DoPersist, weak_ptr_factory_.GetWeakPtr())); |
| 2561 } |
| 2562 |
| 2563 void HostResolverImpl::DoPersist() { |
| 2564 DCHECK(persist_initialized_); |
| 2565 persist_callback_.Run(GetPersistentData()); |
| 2566 } |
| 2567 |
| 2568 void HostResolverImpl::ApplyPersistentData( |
| 2569 std::unique_ptr<const base::Value> data) {} |
| 2570 |
| 2571 std::unique_ptr<const base::Value> HostResolverImpl::GetPersistentData() { |
| 2572 return std::unique_ptr<const base::Value>(); |
| 2573 } |
| 2574 |
2539 HostResolverImpl::RequestImpl::~RequestImpl() { | 2575 HostResolverImpl::RequestImpl::~RequestImpl() { |
2540 if (job_) | 2576 if (job_) |
2541 job_->CancelRequest(this); | 2577 job_->CancelRequest(this); |
2542 } | 2578 } |
2543 | 2579 |
2544 void HostResolverImpl::RequestImpl::ChangeRequestPriority( | 2580 void HostResolverImpl::RequestImpl::ChangeRequestPriority( |
2545 RequestPriority priority) { | 2581 RequestPriority priority) { |
2546 job_->ChangeRequestPriority(this, priority); | 2582 job_->ChangeRequestPriority(this, priority); |
2547 } | 2583 } |
2548 | 2584 |
2549 } // namespace net | 2585 } // namespace net |
OLD | NEW |