Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "base/callback_helpers.h" | 21 #include "base/callback_helpers.h" |
| 22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
| 23 #include "base/debug/debugger.h" | 23 #include "base/debug/debugger.h" |
| 24 #include "base/debug/leak_annotations.h" | 24 #include "base/debug/leak_annotations.h" |
| 25 #include "base/debug/stack_trace.h" | 25 #include "base/debug/stack_trace.h" |
| 26 #include "base/macros.h" | 26 #include "base/macros.h" |
| 27 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
| 28 #include "base/metrics/field_trial.h" | 28 #include "base/metrics/field_trial.h" |
| 29 #include "base/metrics/histogram_macros.h" | 29 #include "base/metrics/histogram_macros.h" |
| 30 #include "base/metrics/sparse_histogram.h" | 30 #include "base/metrics/sparse_histogram.h" |
| 31 #include "base/power_monitor/power_monitor.h" | |
| 31 #include "base/profiler/scoped_tracker.h" | 32 #include "base/profiler/scoped_tracker.h" |
| 32 #include "base/single_thread_task_runner.h" | 33 #include "base/single_thread_task_runner.h" |
| 33 #include "base/stl_util.h" | 34 #include "base/stl_util.h" |
| 34 #include "base/strings/string_util.h" | 35 #include "base/strings/string_util.h" |
| 35 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
| 36 #include "base/threading/thread_task_runner_handle.h" | 37 #include "base/threading/thread_task_runner_handle.h" |
| 37 #include "base/threading/worker_pool.h" | 38 #include "base/threading/worker_pool.h" |
| 38 #include "base/time/time.h" | 39 #include "base/time/time.h" |
| 39 #include "base/trace_event/trace_event.h" | 40 #include "base/trace_event/trace_event.h" |
| 40 #include "base/values.h" | 41 #include "base/values.h" |
| (...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 HostResolverImpl::~HostResolverImpl() { | 1896 HostResolverImpl::~HostResolverImpl() { |
| 1896 // Prevent the dispatcher from starting new jobs. | 1897 // Prevent the dispatcher from starting new jobs. |
| 1897 dispatcher_->SetLimitsToZero(); | 1898 dispatcher_->SetLimitsToZero(); |
| 1898 // It's now safe for Jobs to call KillDsnTask on destruction, because | 1899 // It's now safe for Jobs to call KillDsnTask on destruction, because |
| 1899 // OnJobComplete will not start any new jobs. | 1900 // OnJobComplete will not start any new jobs. |
| 1900 base::STLDeleteValues(&jobs_); | 1901 base::STLDeleteValues(&jobs_); |
| 1901 | 1902 |
| 1902 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1903 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1903 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 1904 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 1904 NetworkChangeNotifier::RemoveDNSObserver(this); | 1905 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 1906 | |
| 1907 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | |
| 1908 if (power_monitor) | |
| 1909 power_monitor->RemoveObserver(this); | |
| 1905 } | 1910 } |
| 1906 | 1911 |
| 1907 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { | 1912 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { |
| 1908 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); | 1913 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); |
| 1909 DCHECK_GT(value, 0u); | 1914 DCHECK_GT(value, 0u); |
| 1910 max_queued_jobs_ = value; | 1915 max_queued_jobs_ = value; |
| 1911 } | 1916 } |
| 1912 | 1917 |
| 1913 int HostResolverImpl::Resolve(const RequestInfo& info, | 1918 int HostResolverImpl::Resolve(const RequestInfo& info, |
| 1914 RequestPriority priority, | 1919 RequestPriority priority, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2004 | 2009 |
| 2005 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); | 2010 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); |
| 2006 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); | 2011 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); |
| 2007 max_queued_jobs_ = job_limits.total_jobs * 100u; | 2012 max_queued_jobs_ = job_limits.total_jobs * 100u; |
| 2008 | 2013 |
| 2009 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); | 2014 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); |
| 2010 | 2015 |
| 2011 #if defined(OS_WIN) | 2016 #if defined(OS_WIN) |
| 2012 EnsureWinsockInit(); | 2017 EnsureWinsockInit(); |
| 2013 #endif | 2018 #endif |
| 2019 | |
| 2020 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | |
| 2021 if (power_monitor) | |
| 2022 power_monitor->AddObserver(this); | |
| 2023 | |
| 2014 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 2024 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 2015 RunLoopbackProbeJob(); | 2025 RunLoopbackProbeJob(); |
| 2016 #endif | 2026 #endif |
| 2017 NetworkChangeNotifier::AddIPAddressObserver(this); | 2027 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 2018 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 2028 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 2019 NetworkChangeNotifier::AddDNSObserver(this); | 2029 NetworkChangeNotifier::AddDNSObserver(this); |
| 2020 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | 2030 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
| 2021 !defined(OS_ANDROID) | 2031 !defined(OS_ANDROID) |
| 2022 EnsureDnsReloaderInit(); | 2032 EnsureDnsReloaderInit(); |
| 2023 #endif | 2033 #endif |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2439 | 2449 |
| 2440 void HostResolverImpl::OnConnectionTypeChanged( | 2450 void HostResolverImpl::OnConnectionTypeChanged( |
| 2441 NetworkChangeNotifier::ConnectionType type) { | 2451 NetworkChangeNotifier::ConnectionType type) { |
| 2442 proc_params_.unresponsive_delay = | 2452 proc_params_.unresponsive_delay = |
| 2443 GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( | 2453 GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( |
| 2444 "DnsUnresponsiveDelayMsByConnectionType", | 2454 "DnsUnresponsiveDelayMsByConnectionType", |
| 2445 base::TimeDelta::FromMilliseconds(kDnsDefaultUnresponsiveDelayMs), | 2455 base::TimeDelta::FromMilliseconds(kDnsDefaultUnresponsiveDelayMs), |
| 2446 type); | 2456 type); |
| 2447 } | 2457 } |
| 2448 | 2458 |
| 2459 void HostResolverImpl::OnDNSChanged() { | |
| 2460 UpdateDNSConfig(true); | |
| 2461 } | |
| 2462 | |
| 2449 void HostResolverImpl::OnInitialDNSConfigRead() { | 2463 void HostResolverImpl::OnInitialDNSConfigRead() { |
| 2450 UpdateDNSConfig(false); | 2464 UpdateDNSConfig(false); |
| 2451 } | 2465 } |
| 2452 | 2466 |
| 2453 void HostResolverImpl::OnDNSChanged() { | 2467 void HostResolverImpl::OnSuspend() { |
| 2454 UpdateDNSConfig(true); | 2468 // Existing jobs are unlikely to receive a response, so they need to be |
| 2469 // aborted. | |
| 2470 // TODO(mmenke): This can result in starting new jobs just before suspend | |
| 2471 // mode starts. Would it make more sense to do this on resume? | |
| 2472 AbortAllInProgressJobs(); | |
|
eroman
2016/10/27 19:26:26
This is going to fail the requests with ERR_NETWOR
| |
| 2455 } | 2473 } |
| 2456 | 2474 |
| 2457 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { | 2475 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { |
| 2458 DnsConfig dns_config; | 2476 DnsConfig dns_config; |
| 2459 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2477 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2460 | 2478 |
| 2461 if (net_log_) { | 2479 if (net_log_) { |
| 2462 net_log_->AddGlobalEntry(NetLogEventType::DNS_CONFIG_CHANGED, | 2480 net_log_->AddGlobalEntry(NetLogEventType::DNS_CONFIG_CHANGED, |
| 2463 base::Bind(&NetLogDnsConfigCallback, &dns_config)); | 2481 base::Bind(&NetLogDnsConfigCallback, &dns_config)); |
| 2464 } | 2482 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2609 if (job_) | 2627 if (job_) |
| 2610 job_->CancelRequest(this); | 2628 job_->CancelRequest(this); |
| 2611 } | 2629 } |
| 2612 | 2630 |
| 2613 void HostResolverImpl::RequestImpl::ChangeRequestPriority( | 2631 void HostResolverImpl::RequestImpl::ChangeRequestPriority( |
| 2614 RequestPriority priority) { | 2632 RequestPriority priority) { |
| 2615 job_->ChangeRequestPriority(this, priority); | 2633 job_->ChangeRequestPriority(this, priority); |
| 2616 } | 2634 } |
| 2617 | 2635 |
| 2618 } // namespace net | 2636 } // namespace net |
| OLD | NEW |