| 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 20 matching lines...) Expand all Loading... |
| 31 #include "base/callback_helpers.h" | 31 #include "base/callback_helpers.h" |
| 32 #include "base/compiler_specific.h" | 32 #include "base/compiler_specific.h" |
| 33 #include "base/debug/debugger.h" | 33 #include "base/debug/debugger.h" |
| 34 #include "base/debug/leak_annotations.h" | 34 #include "base/debug/leak_annotations.h" |
| 35 #include "base/debug/stack_trace.h" | 35 #include "base/debug/stack_trace.h" |
| 36 #include "base/macros.h" | 36 #include "base/macros.h" |
| 37 #include "base/memory/ptr_util.h" | 37 #include "base/memory/ptr_util.h" |
| 38 #include "base/metrics/field_trial.h" | 38 #include "base/metrics/field_trial.h" |
| 39 #include "base/metrics/histogram_macros.h" | 39 #include "base/metrics/histogram_macros.h" |
| 40 #include "base/metrics/sparse_histogram.h" | 40 #include "base/metrics/sparse_histogram.h" |
| 41 #include "base/power_monitor/power_monitor.h" |
| 41 #include "base/profiler/scoped_tracker.h" | 42 #include "base/profiler/scoped_tracker.h" |
| 42 #include "base/single_thread_task_runner.h" | 43 #include "base/single_thread_task_runner.h" |
| 43 #include "base/strings/string_util.h" | 44 #include "base/strings/string_util.h" |
| 44 #include "base/strings/utf_string_conversions.h" | 45 #include "base/strings/utf_string_conversions.h" |
| 45 #include "base/threading/thread_task_runner_handle.h" | 46 #include "base/threading/thread_task_runner_handle.h" |
| 46 #include "base/threading/worker_pool.h" | 47 #include "base/threading/worker_pool.h" |
| 47 #include "base/time/time.h" | 48 #include "base/time/time.h" |
| 48 #include "base/trace_event/trace_event.h" | 49 #include "base/trace_event/trace_event.h" |
| 49 #include "base/values.h" | 50 #include "base/values.h" |
| 50 #include "net/base/address_family.h" | 51 #include "net/base/address_family.h" |
| (...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 HostResolverImpl::~HostResolverImpl() { | 1952 HostResolverImpl::~HostResolverImpl() { |
| 1952 // Prevent the dispatcher from starting new jobs. | 1953 // Prevent the dispatcher from starting new jobs. |
| 1953 dispatcher_->SetLimitsToZero(); | 1954 dispatcher_->SetLimitsToZero(); |
| 1954 // It's now safe for Jobs to call KillDnsTask on destruction, because | 1955 // It's now safe for Jobs to call KillDnsTask on destruction, because |
| 1955 // OnJobComplete will not start any new jobs. | 1956 // OnJobComplete will not start any new jobs. |
| 1956 jobs_.clear(); | 1957 jobs_.clear(); |
| 1957 | 1958 |
| 1958 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1959 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1959 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 1960 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 1960 NetworkChangeNotifier::RemoveDNSObserver(this); | 1961 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 1962 |
| 1963 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 1964 if (power_monitor) |
| 1965 power_monitor->RemoveObserver(this); |
| 1961 } | 1966 } |
| 1962 | 1967 |
| 1963 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { | 1968 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { |
| 1964 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); | 1969 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); |
| 1965 DCHECK_GT(value, 0u); | 1970 DCHECK_GT(value, 0u); |
| 1966 max_queued_jobs_ = value; | 1971 max_queued_jobs_ = value; |
| 1967 } | 1972 } |
| 1968 | 1973 |
| 1969 int HostResolverImpl::Resolve(const RequestInfo& info, | 1974 int HostResolverImpl::Resolve(const RequestInfo& info, |
| 1970 RequestPriority priority, | 1975 RequestPriority priority, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 | 2066 |
| 2062 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); | 2067 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); |
| 2063 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); | 2068 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); |
| 2064 max_queued_jobs_ = job_limits.total_jobs * 100u; | 2069 max_queued_jobs_ = job_limits.total_jobs * 100u; |
| 2065 | 2070 |
| 2066 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); | 2071 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); |
| 2067 | 2072 |
| 2068 #if defined(OS_WIN) | 2073 #if defined(OS_WIN) |
| 2069 EnsureWinsockInit(); | 2074 EnsureWinsockInit(); |
| 2070 #endif | 2075 #endif |
| 2076 |
| 2077 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 2078 if (power_monitor) |
| 2079 power_monitor->AddObserver(this); |
| 2080 |
| 2071 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 2081 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 2072 RunLoopbackProbeJob(); | 2082 RunLoopbackProbeJob(); |
| 2073 #endif | 2083 #endif |
| 2074 NetworkChangeNotifier::AddIPAddressObserver(this); | 2084 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 2075 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 2085 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 2076 NetworkChangeNotifier::AddDNSObserver(this); | 2086 NetworkChangeNotifier::AddDNSObserver(this); |
| 2077 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | 2087 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
| 2078 !defined(OS_ANDROID) | 2088 !defined(OS_ANDROID) |
| 2079 EnsureDnsReloaderInit(); | 2089 EnsureDnsReloaderInit(); |
| 2080 #endif | 2090 #endif |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2547 | 2557 |
| 2548 void HostResolverImpl::OnConnectionTypeChanged( | 2558 void HostResolverImpl::OnConnectionTypeChanged( |
| 2549 NetworkChangeNotifier::ConnectionType type) { | 2559 NetworkChangeNotifier::ConnectionType type) { |
| 2550 proc_params_.unresponsive_delay = | 2560 proc_params_.unresponsive_delay = |
| 2551 GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( | 2561 GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( |
| 2552 "DnsUnresponsiveDelayMsByConnectionType", | 2562 "DnsUnresponsiveDelayMsByConnectionType", |
| 2553 base::TimeDelta::FromMilliseconds(kDnsDefaultUnresponsiveDelayMs), | 2563 base::TimeDelta::FromMilliseconds(kDnsDefaultUnresponsiveDelayMs), |
| 2554 type); | 2564 type); |
| 2555 } | 2565 } |
| 2556 | 2566 |
| 2567 void HostResolverImpl::OnDNSChanged() { |
| 2568 UpdateDNSConfig(true); |
| 2569 } |
| 2570 |
| 2557 void HostResolverImpl::OnInitialDNSConfigRead() { | 2571 void HostResolverImpl::OnInitialDNSConfigRead() { |
| 2558 UpdateDNSConfig(false); | 2572 UpdateDNSConfig(false); |
| 2559 } | 2573 } |
| 2560 | 2574 |
| 2561 void HostResolverImpl::OnDNSChanged() { | 2575 void HostResolverImpl::OnSuspend() { |
| 2562 UpdateDNSConfig(true); | 2576 // Existing jobs are unlikely to receive a response, so they need to be |
| 2577 // aborted. |
| 2578 // TODO(mmenke): This can result in starting new jobs just before suspend |
| 2579 // mode starts. Would it make more sense to do this on resume? |
| 2580 AbortAllInProgressJobs(); |
| 2563 } | 2581 } |
| 2564 | 2582 |
| 2565 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { | 2583 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { |
| 2566 DnsConfig dns_config; | 2584 DnsConfig dns_config; |
| 2567 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2585 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2568 | 2586 |
| 2569 if (net_log_) { | 2587 if (net_log_) { |
| 2570 net_log_->AddGlobalEntry(NetLogEventType::DNS_CONFIG_CHANGED, | 2588 net_log_->AddGlobalEntry(NetLogEventType::DNS_CONFIG_CHANGED, |
| 2571 base::Bind(&NetLogDnsConfigCallback, &dns_config)); | 2589 base::Bind(&NetLogDnsConfigCallback, &dns_config)); |
| 2572 } | 2590 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2717 if (job_) | 2735 if (job_) |
| 2718 job_->CancelRequest(this); | 2736 job_->CancelRequest(this); |
| 2719 } | 2737 } |
| 2720 | 2738 |
| 2721 void HostResolverImpl::RequestImpl::ChangeRequestPriority( | 2739 void HostResolverImpl::RequestImpl::ChangeRequestPriority( |
| 2722 RequestPriority priority) { | 2740 RequestPriority priority) { |
| 2723 job_->ChangeRequestPriority(this, priority); | 2741 job_->ChangeRequestPriority(this, priority); |
| 2724 } | 2742 } |
| 2725 | 2743 |
| 2726 } // namespace net | 2744 } // namespace net |
| OLD | NEW |