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" |
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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); | 1084 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); |
1084 | 1085 |
1085 #if defined(OS_WIN) | 1086 #if defined(OS_WIN) |
1086 EnsureWinsockInit(); | 1087 EnsureWinsockInit(); |
1087 #endif | 1088 #endif |
1088 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 1089 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
1089 if (HaveOnlyLoopbackAddresses()) | 1090 if (HaveOnlyLoopbackAddresses()) |
1090 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1091 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
1091 #endif | 1092 #endif |
1092 NetworkChangeNotifier::AddIPAddressObserver(this); | 1093 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 1094 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
| 1095 EnsureDnsReloaderInit(); |
| 1096 NetworkChangeNotifier::AddDNSObserver(this); |
| 1097 #endif |
1093 } | 1098 } |
1094 | 1099 |
1095 HostResolverImpl::~HostResolverImpl() { | 1100 HostResolverImpl::~HostResolverImpl() { |
1096 // Cancel the outstanding jobs. Those jobs may contain several attached | 1101 // Cancel the outstanding jobs. Those jobs may contain several attached |
1097 // requests, which will also be cancelled. | 1102 // requests, which will also be cancelled. |
1098 DiscardIPv6ProbeJob(); | 1103 DiscardIPv6ProbeJob(); |
1099 | 1104 |
1100 CancelAllJobs(); | 1105 CancelAllJobs(); |
1101 | 1106 |
1102 // In case we are being deleted during the processing of a callback. | 1107 // In case we are being deleted during the processing of a callback. |
1103 if (cur_completing_job_) | 1108 if (cur_completing_job_) |
1104 cur_completing_job_->Cancel(); | 1109 cur_completing_job_->Cancel(); |
1105 | 1110 |
1106 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1111 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1112 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
| 1113 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 1114 #endif |
1107 | 1115 |
1108 // Delete the job pools. | 1116 // Delete the job pools. |
1109 for (size_t i = 0u; i < arraysize(job_pools_); ++i) | 1117 for (size_t i = 0u; i < arraysize(job_pools_); ++i) |
1110 delete job_pools_[i]; | 1118 delete job_pools_[i]; |
1111 } | 1119 } |
1112 | 1120 |
1113 void HostResolverImpl::ProbeIPv6Support() { | 1121 void HostResolverImpl::ProbeIPv6Support() { |
1114 DCHECK(CalledOnValidThread()); | 1122 DCHECK(CalledOnValidThread()); |
1115 DCHECK(!ipv6_probe_monitoring_); | 1123 DCHECK(!ipv6_probe_monitoring_); |
1116 ipv6_probe_monitoring_ = true; | 1124 ipv6_probe_monitoring_ = true; |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 if (HaveOnlyLoopbackAddresses()) { | 1645 if (HaveOnlyLoopbackAddresses()) { |
1638 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1646 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
1639 } else { | 1647 } else { |
1640 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; | 1648 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; |
1641 } | 1649 } |
1642 #endif | 1650 #endif |
1643 AbortAllInProgressJobs(); | 1651 AbortAllInProgressJobs(); |
1644 // |this| may be deleted inside AbortAllInProgressJobs(). | 1652 // |this| may be deleted inside AbortAllInProgressJobs(). |
1645 } | 1653 } |
1646 | 1654 |
| 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 |
1647 } // namespace net | 1668 } // namespace net |
OLD | NEW |