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.h" | 24 #include "base/stl_util.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" | |
34 #include "net/base/host_port_pair.h" | 33 #include "net/base/host_port_pair.h" |
35 #include "net/base/host_resolver_proc.h" | 34 #include "net/base/host_resolver_proc.h" |
36 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
37 #include "net/base/net_log.h" | 36 #include "net/base/net_log.h" |
38 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
39 | 38 |
40 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
41 #include "net/base/winsock_init.h" | 40 #include "net/base/winsock_init.h" |
42 #endif | 41 #endif |
43 | 42 |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); | 1083 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); |
1085 | 1084 |
1086 #if defined(OS_WIN) | 1085 #if defined(OS_WIN) |
1087 EnsureWinsockInit(); | 1086 EnsureWinsockInit(); |
1088 #endif | 1087 #endif |
1089 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 1088 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
1090 if (HaveOnlyLoopbackAddresses()) | 1089 if (HaveOnlyLoopbackAddresses()) |
1091 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1090 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
1092 #endif | 1091 #endif |
1093 NetworkChangeNotifier::AddIPAddressObserver(this); | 1092 NetworkChangeNotifier::AddIPAddressObserver(this); |
1094 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | |
1095 EnsureDnsReloaderInit(); | |
1096 NetworkChangeNotifier::AddDNSObserver(this); | |
1097 #endif | |
1098 } | 1093 } |
1099 | 1094 |
1100 HostResolverImpl::~HostResolverImpl() { | 1095 HostResolverImpl::~HostResolverImpl() { |
1101 // Cancel the outstanding jobs. Those jobs may contain several attached | 1096 // Cancel the outstanding jobs. Those jobs may contain several attached |
1102 // requests, which will also be cancelled. | 1097 // requests, which will also be cancelled. |
1103 DiscardIPv6ProbeJob(); | 1098 DiscardIPv6ProbeJob(); |
1104 | 1099 |
1105 CancelAllJobs(); | 1100 CancelAllJobs(); |
1106 | 1101 |
1107 // In case we are being deleted during the processing of a callback. | 1102 // In case we are being deleted during the processing of a callback. |
1108 if (cur_completing_job_) | 1103 if (cur_completing_job_) |
1109 cur_completing_job_->Cancel(); | 1104 cur_completing_job_->Cancel(); |
1110 | 1105 |
1111 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1106 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
1112 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | |
1113 NetworkChangeNotifier::RemoveDNSObserver(this); | |
1114 #endif | |
1115 | 1107 |
1116 // Delete the job pools. | 1108 // Delete the job pools. |
1117 for (size_t i = 0u; i < arraysize(job_pools_); ++i) | 1109 for (size_t i = 0u; i < arraysize(job_pools_); ++i) |
1118 delete job_pools_[i]; | 1110 delete job_pools_[i]; |
1119 } | 1111 } |
1120 | 1112 |
1121 void HostResolverImpl::ProbeIPv6Support() { | 1113 void HostResolverImpl::ProbeIPv6Support() { |
1122 DCHECK(CalledOnValidThread()); | 1114 DCHECK(CalledOnValidThread()); |
1123 DCHECK(!ipv6_probe_monitoring_); | 1115 DCHECK(!ipv6_probe_monitoring_); |
1124 ipv6_probe_monitoring_ = true; | 1116 ipv6_probe_monitoring_ = true; |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 if (HaveOnlyLoopbackAddresses()) { | 1637 if (HaveOnlyLoopbackAddresses()) { |
1646 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1638 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
1647 } else { | 1639 } else { |
1648 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; | 1640 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; |
1649 } | 1641 } |
1650 #endif | 1642 #endif |
1651 AbortAllInProgressJobs(); | 1643 AbortAllInProgressJobs(); |
1652 // |this| may be deleted inside AbortAllInProgressJobs(). | 1644 // |this| may be deleted inside AbortAllInProgressJobs(). |
1653 } | 1645 } |
1654 | 1646 |
1655 void HostResolverImpl::OnDNSChanged() { | |
1656 // If the DNS server has changed, existing cached info could be wrong so we | |
1657 // have to drop our internal cache :( Note that OS level DNS caches, such | |
1658 // as NSCD's cache should be dropped automatically by the OS when | |
1659 // resolv.conf changes so we don't need to do anything to clear that cache. | |
1660 if (cache_.get()) | |
1661 cache_->clear(); | |
1662 // Existing jobs will have been sent to the original server so they need to | |
1663 // be aborted. TODO(Craig): Should these jobs be restarted? | |
1664 AbortAllInProgressJobs(); | |
1665 // |this| may be deleted inside AbortAllInProgressJobs(). | |
1666 } | |
1667 | |
1668 } // namespace net | 1647 } // namespace net |
OLD | NEW |