| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/host_resolver_impl.h" | 5 #include "net/base/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 12 matching lines...) Expand all Loading... |
| 23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
| 24 #include "base/stl_util-inl.h" | 24 #include "base/stl_util-inl.h" |
| 25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 26 #include "base/task.h" | 26 #include "base/task.h" |
| 27 #include "base/threading/worker_pool.h" | 27 #include "base/threading/worker_pool.h" |
| 28 #include "base/time.h" | 28 #include "base/time.h" |
| 29 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
| 30 #include "base/values.h" | 30 #include "base/values.h" |
| 31 #include "net/base/address_list.h" | 31 #include "net/base/address_list.h" |
| 32 #include "net/base/address_list_net_log_param.h" | 32 #include "net/base/address_list_net_log_param.h" |
| 33 #include "net/base/dns_reloader.h" |
| 33 #include "net/base/host_port_pair.h" | 34 #include "net/base/host_port_pair.h" |
| 34 #include "net/base/host_resolver_proc.h" | 35 #include "net/base/host_resolver_proc.h" |
| 35 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
| 36 #include "net/base/net_log.h" | 37 #include "net/base/net_log.h" |
| 37 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
| 38 | 39 |
| 39 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 40 #include "net/base/winsock_init.h" | 41 #include "net/base/winsock_init.h" |
| 41 #endif | 42 #endif |
| 42 | 43 |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); | 1105 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); |
| 1105 | 1106 |
| 1106 #if defined(OS_WIN) | 1107 #if defined(OS_WIN) |
| 1107 EnsureWinsockInit(); | 1108 EnsureWinsockInit(); |
| 1108 #endif | 1109 #endif |
| 1109 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 1110 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 1110 if (HaveOnlyLoopbackAddresses()) | 1111 if (HaveOnlyLoopbackAddresses()) |
| 1111 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1112 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
| 1112 #endif | 1113 #endif |
| 1113 NetworkChangeNotifier::AddIPAddressObserver(this); | 1114 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 1115 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
| 1116 DnsReloaderInit(); |
| 1117 NetworkChangeNotifier::AddDNSObserver(this); |
| 1118 #endif |
| 1114 } | 1119 } |
| 1115 | 1120 |
| 1116 HostResolverImpl::~HostResolverImpl() { | 1121 HostResolverImpl::~HostResolverImpl() { |
| 1117 // Cancel the outstanding jobs. Those jobs may contain several attached | 1122 // Cancel the outstanding jobs. Those jobs may contain several attached |
| 1118 // requests, which will also be cancelled. | 1123 // requests, which will also be cancelled. |
| 1119 DiscardIPv6ProbeJob(); | 1124 DiscardIPv6ProbeJob(); |
| 1120 | 1125 |
| 1121 CancelAllJobs(); | 1126 CancelAllJobs(); |
| 1122 | 1127 |
| 1123 // In case we are being deleted during the processing of a callback. | 1128 // In case we are being deleted during the processing of a callback. |
| 1124 if (cur_completing_job_) | 1129 if (cur_completing_job_) |
| 1125 cur_completing_job_->Cancel(); | 1130 cur_completing_job_->Cancel(); |
| 1126 | 1131 |
| 1127 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1132 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1133 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
| 1134 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 1135 #endif |
| 1128 | 1136 |
| 1129 // Delete the job pools. | 1137 // Delete the job pools. |
| 1130 for (size_t i = 0u; i < arraysize(job_pools_); ++i) | 1138 for (size_t i = 0u; i < arraysize(job_pools_); ++i) |
| 1131 delete job_pools_[i]; | 1139 delete job_pools_[i]; |
| 1132 } | 1140 } |
| 1133 | 1141 |
| 1134 void HostResolverImpl::ProbeIPv6Support() { | 1142 void HostResolverImpl::ProbeIPv6Support() { |
| 1135 DCHECK(CalledOnValidThread()); | 1143 DCHECK(CalledOnValidThread()); |
| 1136 DCHECK(!ipv6_probe_monitoring_); | 1144 DCHECK(!ipv6_probe_monitoring_); |
| 1137 ipv6_probe_monitoring_ = true; | 1145 ipv6_probe_monitoring_ = true; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 if (HaveOnlyLoopbackAddresses()) { | 1634 if (HaveOnlyLoopbackAddresses()) { |
| 1627 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1635 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
| 1628 } else { | 1636 } else { |
| 1629 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; | 1637 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; |
| 1630 } | 1638 } |
| 1631 #endif | 1639 #endif |
| 1632 AbortAllInProgressJobs(); | 1640 AbortAllInProgressJobs(); |
| 1633 // |this| may be deleted inside AbortAllInProgressJobs(). | 1641 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 1634 } | 1642 } |
| 1635 | 1643 |
| 1644 void HostResolverImpl::OnDNSChanged() { |
| 1645 // If the DNS server has changed, existing cached info could be wrong so we |
| 1646 // have to drop our internal cache :( Note that OS level DNS caches, such |
| 1647 // as NSCD's cache should be dropped automatically by the OS when |
| 1648 // resolv.conf changes so we don't need to do anything to clear that cache. |
| 1649 if (cache_.get()) |
| 1650 cache_->clear(); |
| 1651 // Existing jobs will have been sent to the original server so they need to |
| 1652 // be aborted. TODO(Craig): Should these jobs be restarted? |
| 1653 AbortAllInProgressJobs(); |
| 1654 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 1655 } |
| 1656 |
| 1636 } // namespace net | 1657 } // namespace net |
| OLD | NEW |