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/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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 protected: | 229 protected: |
230 virtual ~CallSystemHostResolverProc() {} | 230 virtual ~CallSystemHostResolverProc() {} |
231 }; | 231 }; |
232 | 232 |
233 AddressList EnsurePortOnAddressList(const AddressList& list, uint16 port) { | 233 AddressList EnsurePortOnAddressList(const AddressList& list, uint16 port) { |
234 if (list.empty() || list.front().port() == port) | 234 if (list.empty() || list.front().port() == port) |
235 return list; | 235 return list; |
236 return AddressList::CopyWithPort(list, port); | 236 return AddressList::CopyWithPort(list, port); |
237 } | 237 } |
238 | 238 |
239 // Wraps a call to HaveOnlyLoopbackAddresses to be executed on the WorkerPool as | |
240 // it takes 40-100ms and should not block initialization. | |
241 class HaveOnlyLoopbackProbeJob | |
242 : public base::RefCountedThreadSafe<HaveOnlyLoopbackProbeJob> { | |
243 public: | |
244 typedef base::Callback<void(bool)> CallbackType; | |
245 explicit HaveOnlyLoopbackProbeJob(const CallbackType& callback) | |
246 : result_(false) { | |
247 const bool kIsSlow = true; | |
248 base::WorkerPool::PostTaskAndReply( | |
249 FROM_HERE, | |
250 base::Bind(&HaveOnlyLoopbackProbeJob::DoProbe, this), | |
251 base::Bind(&HaveOnlyLoopbackProbeJob::OnProbeComplete, this, callback), | |
252 kIsSlow); | |
253 } | |
254 | |
255 private: | |
256 friend class base::RefCountedThreadSafe<HaveOnlyLoopbackProbeJob>; | |
257 | |
258 virtual ~HaveOnlyLoopbackProbeJob() {} | |
259 | |
260 // Runs on worker thread. | |
261 void DoProbe() { | |
262 result_ = HaveOnlyLoopbackAddresses(); | |
263 } | |
264 | |
265 void OnProbeComplete(const CallbackType& callback) { | |
266 callback.Run(result_); | |
267 } | |
268 | |
269 bool result_; | |
270 | |
271 DISALLOW_COPY_AND_ASSIGN(HaveOnlyLoopbackProbeJob); | |
272 }; | |
273 | |
274 | |
275 // Creates NetLog parameters when the resolve failed. | 239 // Creates NetLog parameters when the resolve failed. |
276 base::Value* NetLogProcTaskFailedCallback(uint32 attempt_number, | 240 base::Value* NetLogProcTaskFailedCallback(uint32 attempt_number, |
277 int net_error, | 241 int net_error, |
278 int os_error, | 242 int os_error, |
279 NetLog::LogLevel /* log_level */) { | 243 NetLog::LogLevel /* log_level */) { |
280 DictionaryValue* dict = new DictionaryValue(); | 244 DictionaryValue* dict = new DictionaryValue(); |
281 if (attempt_number) | 245 if (attempt_number) |
282 dict->SetInteger("attempt_number", attempt_number); | 246 dict->SetInteger("attempt_number", attempt_number); |
283 | 247 |
284 dict->SetInteger("net_error", net_error); | 248 dict->SetInteger("net_error", net_error); |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 | 875 |
912 AddressList results_; | 876 AddressList results_; |
913 | 877 |
914 BoundNetLog net_log_; | 878 BoundNetLog net_log_; |
915 | 879 |
916 DISALLOW_COPY_AND_ASSIGN(ProcTask); | 880 DISALLOW_COPY_AND_ASSIGN(ProcTask); |
917 }; | 881 }; |
918 | 882 |
919 //----------------------------------------------------------------------------- | 883 //----------------------------------------------------------------------------- |
920 | 884 |
921 // Represents a request to the worker pool for a "probe for IPv6 support" call. | 885 // Wraps a call to TestIPv6Support to be executed on the WorkerPool as it takes |
922 // | 886 // 40-100ms. |
923 // TODO(szym): This could also be replaced with PostTaskAndReply and Callbacks. | 887 class HostResolverImpl::IPv6ProbeJob { |
924 class HostResolverImpl::IPv6ProbeJob | |
925 : public base::RefCountedThreadSafe<HostResolverImpl::IPv6ProbeJob> { | |
926 public: | 888 public: |
927 IPv6ProbeJob(HostResolverImpl* resolver, NetLog* net_log) | 889 IPv6ProbeJob(const base::WeakPtr<HostResolverImpl>& resolver, NetLog* net_log) |
928 : resolver_(resolver), | 890 : resolver_(resolver), |
929 origin_loop_(base::MessageLoopProxy::current()), | 891 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_IPV6_PROBE_JOB)), |
930 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_IPV6_PROBE_JOB)) { | 892 result_(false, IPV6_SUPPORT_MAX, OK) { |
931 DCHECK(resolver); | 893 DCHECK(resolver); |
| 894 net_log_.BeginEvent(NetLog::TYPE_IPV6_PROBE_RUNNING); |
| 895 const bool kIsSlow = true; |
| 896 base::WorkerPool::PostTaskAndReply( |
| 897 FROM_HERE, |
| 898 base::Bind(&IPv6ProbeJob::DoProbe, base::Unretained(this)), |
| 899 base::Bind(&IPv6ProbeJob::OnProbeComplete, base::Owned(this)), |
| 900 kIsSlow); |
932 } | 901 } |
933 | 902 |
934 void Start() { | 903 virtual ~IPv6ProbeJob() {} |
935 DCHECK(origin_loop_->BelongsToCurrentThread()); | 904 |
936 if (was_canceled()) | 905 private: |
937 return; | 906 // Runs on worker thread. |
938 net_log_.BeginEvent(NetLog::TYPE_IPV6_PROBE_RUNNING); | 907 void DoProbe() { |
939 const bool kIsSlow = true; | 908 result_ = TestIPv6Support(); |
940 base::WorkerPool::PostTask( | |
941 FROM_HERE, base::Bind(&IPv6ProbeJob::DoProbe, this), kIsSlow); | |
942 } | 909 } |
943 | 910 |
944 // Cancels the current job. | 911 void OnProbeComplete() { |
945 void Cancel() { | 912 net_log_.EndEvent(NetLog::TYPE_IPV6_PROBE_RUNNING, |
946 DCHECK(origin_loop_->BelongsToCurrentThread()); | 913 base::Bind(&IPv6SupportResult::ToNetLogValue, |
947 if (was_canceled()) | 914 base::Unretained(&result_))); |
| 915 if (!resolver_) |
948 return; | 916 return; |
949 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 917 resolver_->IPv6ProbeSetDefaultAddressFamily( |
950 resolver_ = NULL; // Read/write ONLY on origin thread. | 918 result_.ipv6_supported ? ADDRESS_FAMILY_UNSPECIFIED |
951 } | |
952 | |
953 private: | |
954 friend class base::RefCountedThreadSafe<HostResolverImpl::IPv6ProbeJob>; | |
955 | |
956 ~IPv6ProbeJob() { | |
957 } | |
958 | |
959 // Returns true if cancelled or if probe results have already been received | |
960 // on the origin thread. | |
961 bool was_canceled() const { | |
962 DCHECK(origin_loop_->BelongsToCurrentThread()); | |
963 return !resolver_; | |
964 } | |
965 | |
966 // Run on worker thread. | |
967 void DoProbe() { | |
968 // Do actual testing on this thread, as it takes 40-100ms. | |
969 origin_loop_->PostTask( | |
970 FROM_HERE, | |
971 base::Bind(&IPv6ProbeJob::OnProbeComplete, this, TestIPv6Support())); | |
972 } | |
973 | |
974 // Callback for when DoProbe() completes. | |
975 void OnProbeComplete(const IPv6SupportResult& support_result) { | |
976 DCHECK(origin_loop_->BelongsToCurrentThread()); | |
977 net_log_.EndEvent( | |
978 NetLog::TYPE_IPV6_PROBE_RUNNING, | |
979 base::Bind(&IPv6SupportResult::ToNetLogValue, | |
980 base::Unretained(&support_result))); | |
981 if (was_canceled()) | |
982 return; | |
983 | |
984 // Clear |resolver_| so that no cancel event is logged. | |
985 HostResolverImpl* resolver = resolver_; | |
986 resolver_ = NULL; | |
987 | |
988 resolver->IPv6ProbeSetDefaultAddressFamily( | |
989 support_result.ipv6_supported ? ADDRESS_FAMILY_UNSPECIFIED | |
990 : ADDRESS_FAMILY_IPV4); | 919 : ADDRESS_FAMILY_IPV4); |
991 } | 920 } |
992 | 921 |
993 // Used/set only on origin thread. | 922 // Used/set only on origin thread. |
994 HostResolverImpl* resolver_; | 923 base::WeakPtr<HostResolverImpl> resolver_; |
995 | |
996 // Used to post ourselves onto the origin thread. | |
997 scoped_refptr<base::MessageLoopProxy> origin_loop_; | |
998 | 924 |
999 BoundNetLog net_log_; | 925 BoundNetLog net_log_; |
1000 | 926 |
| 927 IPv6SupportResult result_; |
| 928 |
1001 DISALLOW_COPY_AND_ASSIGN(IPv6ProbeJob); | 929 DISALLOW_COPY_AND_ASSIGN(IPv6ProbeJob); |
1002 }; | 930 }; |
1003 | 931 |
| 932 // Wraps a call to HaveOnlyLoopbackAddresses to be executed on the WorkerPool as |
| 933 // it takes 40-100ms and should not block initialization. |
| 934 class HostResolverImpl::LoopbackProbeJob { |
| 935 public: |
| 936 explicit LoopbackProbeJob(const base::WeakPtr<HostResolverImpl>& resolver) |
| 937 : resolver_(resolver), |
| 938 result_(false) { |
| 939 DCHECK(resolver); |
| 940 const bool kIsSlow = true; |
| 941 base::WorkerPool::PostTaskAndReply( |
| 942 FROM_HERE, |
| 943 base::Bind(&LoopbackProbeJob::DoProbe, base::Unretained(this)), |
| 944 base::Bind(&LoopbackProbeJob::OnProbeComplete, base::Owned(this)), |
| 945 kIsSlow); |
| 946 } |
| 947 |
| 948 virtual ~LoopbackProbeJob() {} |
| 949 |
| 950 private: |
| 951 // Runs on worker thread. |
| 952 void DoProbe() { |
| 953 result_ = HaveOnlyLoopbackAddresses(); |
| 954 } |
| 955 |
| 956 void OnProbeComplete() { |
| 957 if (!resolver_) |
| 958 return; |
| 959 resolver_->SetHaveOnlyLoopbackAddresses(result_); |
| 960 } |
| 961 |
| 962 // Used/set only on origin thread. |
| 963 base::WeakPtr<HostResolverImpl> resolver_; |
| 964 |
| 965 bool result_; |
| 966 |
| 967 DISALLOW_COPY_AND_ASSIGN(LoopbackProbeJob); |
| 968 }; |
| 969 |
1004 //----------------------------------------------------------------------------- | 970 //----------------------------------------------------------------------------- |
1005 | 971 |
1006 // Resolves the hostname using DnsTransaction. | 972 // Resolves the hostname using DnsTransaction. |
1007 // TODO(szym): This could be moved to separate source file as well. | 973 // TODO(szym): This could be moved to separate source file as well. |
1008 class HostResolverImpl::DnsTask : public base::SupportsWeakPtr<DnsTask> { | 974 class HostResolverImpl::DnsTask : public base::SupportsWeakPtr<DnsTask> { |
1009 public: | 975 public: |
1010 typedef base::Callback<void(int net_error, | 976 typedef base::Callback<void(int net_error, |
1011 const AddressList& addr_list, | 977 const AddressList& addr_list, |
1012 base::TimeDelta ttl)> Callback; | 978 base::TimeDelta ttl)> Callback; |
1013 | 979 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 DISALLOW_COPY_AND_ASSIGN(DnsTask); | 1140 DISALLOW_COPY_AND_ASSIGN(DnsTask); |
1175 }; | 1141 }; |
1176 | 1142 |
1177 //----------------------------------------------------------------------------- | 1143 //----------------------------------------------------------------------------- |
1178 | 1144 |
1179 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. | 1145 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. |
1180 class HostResolverImpl::Job : public PrioritizedDispatcher::Job { | 1146 class HostResolverImpl::Job : public PrioritizedDispatcher::Job { |
1181 public: | 1147 public: |
1182 // Creates new job for |key| where |request_net_log| is bound to the | 1148 // Creates new job for |key| where |request_net_log| is bound to the |
1183 // request that spawned it. | 1149 // request that spawned it. |
1184 Job(HostResolverImpl* resolver, | 1150 Job(const base::WeakPtr<HostResolverImpl>& resolver, |
1185 const Key& key, | 1151 const Key& key, |
1186 RequestPriority priority, | 1152 RequestPriority priority, |
1187 const BoundNetLog& request_net_log) | 1153 const BoundNetLog& request_net_log) |
1188 : resolver_(resolver->weak_ptr_factory_.GetWeakPtr()), | 1154 : resolver_(resolver), |
1189 key_(key), | 1155 key_(key), |
1190 priority_tracker_(priority), | 1156 priority_tracker_(priority), |
1191 had_non_speculative_request_(false), | 1157 had_non_speculative_request_(false), |
1192 had_dns_config_(false), | 1158 had_dns_config_(false), |
1193 dns_task_error_(OK), | 1159 dns_task_error_(OK), |
1194 creation_time_(base::TimeTicks::Now()), | 1160 creation_time_(base::TimeTicks::Now()), |
1195 priority_change_time_(creation_time_), | 1161 priority_change_time_(creation_time_), |
1196 net_log_(BoundNetLog::Make(request_net_log.net_log(), | 1162 net_log_(BoundNetLog::Make(request_net_log.net_log(), |
1197 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { | 1163 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { |
1198 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); | 1164 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 const PrioritizedDispatcher::Limits& job_limits, | 1620 const PrioritizedDispatcher::Limits& job_limits, |
1655 const ProcTaskParams& proc_params, | 1621 const ProcTaskParams& proc_params, |
1656 scoped_ptr<DnsClient> dns_client, | 1622 scoped_ptr<DnsClient> dns_client, |
1657 NetLog* net_log) | 1623 NetLog* net_log) |
1658 : cache_(cache.Pass()), | 1624 : cache_(cache.Pass()), |
1659 dispatcher_(job_limits), | 1625 dispatcher_(job_limits), |
1660 max_queued_jobs_(job_limits.total_jobs * 100u), | 1626 max_queued_jobs_(job_limits.total_jobs * 100u), |
1661 proc_params_(proc_params), | 1627 proc_params_(proc_params), |
1662 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 1628 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
1663 weak_ptr_factory_(this), | 1629 weak_ptr_factory_(this), |
| 1630 probe_weak_ptr_factory_(this), |
1664 dns_client_(dns_client.Pass()), | 1631 dns_client_(dns_client.Pass()), |
1665 received_dns_config_(false), | 1632 received_dns_config_(false), |
1666 ipv6_probe_monitoring_(false), | 1633 ipv6_probe_monitoring_(false), |
1667 additional_resolver_flags_(0), | 1634 additional_resolver_flags_(0), |
1668 net_log_(net_log) { | 1635 net_log_(net_log) { |
1669 | 1636 |
1670 DCHECK_GE(dispatcher_.num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); | 1637 DCHECK_GE(dispatcher_.num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); |
1671 | 1638 |
1672 // Maximum of 4 retry attempts for host resolution. | 1639 // Maximum of 4 retry attempts for host resolution. |
1673 static const size_t kDefaultMaxRetryAttempts = 4u; | 1640 static const size_t kDefaultMaxRetryAttempts = 4u; |
1674 | 1641 |
1675 if (proc_params_.max_retry_attempts == HostResolver::kDefaultRetryAttempts) | 1642 if (proc_params_.max_retry_attempts == HostResolver::kDefaultRetryAttempts) |
1676 proc_params_.max_retry_attempts = kDefaultMaxRetryAttempts; | 1643 proc_params_.max_retry_attempts = kDefaultMaxRetryAttempts; |
1677 | 1644 |
1678 #if defined(OS_WIN) | 1645 #if defined(OS_WIN) |
1679 EnsureWinsockInit(); | 1646 EnsureWinsockInit(); |
1680 #endif | 1647 #endif |
1681 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 1648 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
1682 new HaveOnlyLoopbackProbeJob( | 1649 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr()); |
1683 base::Bind(&HostResolverImpl::SetHaveOnlyLoopbackAddresses, | |
1684 weak_ptr_factory_.GetWeakPtr())); | |
1685 #endif | 1650 #endif |
1686 NetworkChangeNotifier::AddIPAddressObserver(this); | 1651 NetworkChangeNotifier::AddIPAddressObserver(this); |
1687 NetworkChangeNotifier::AddDNSObserver(this); | 1652 NetworkChangeNotifier::AddDNSObserver(this); |
1688 if (!HaveDnsConfig()) | 1653 if (!HaveDnsConfig()) |
1689 OnDNSChanged(); | 1654 OnDNSChanged(); |
1690 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | 1655 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
1691 !defined(OS_ANDROID) | 1656 !defined(OS_ANDROID) |
1692 EnsureDnsReloaderInit(); | 1657 EnsureDnsReloaderInit(); |
1693 #endif | 1658 #endif |
1694 } | 1659 } |
1695 | 1660 |
1696 HostResolverImpl::~HostResolverImpl() { | 1661 HostResolverImpl::~HostResolverImpl() { |
1697 DiscardIPv6ProbeJob(); | |
1698 | |
1699 // This will also cancel all outstanding requests. | 1662 // This will also cancel all outstanding requests. |
1700 STLDeleteValues(&jobs_); | 1663 STLDeleteValues(&jobs_); |
1701 | 1664 |
1702 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1665 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
1703 NetworkChangeNotifier::RemoveDNSObserver(this); | 1666 NetworkChangeNotifier::RemoveDNSObserver(this); |
1704 } | 1667 } |
1705 | 1668 |
1706 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { | 1669 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { |
1707 DCHECK_EQ(0u, dispatcher_.num_queued_jobs()); | 1670 DCHECK_EQ(0u, dispatcher_.num_queued_jobs()); |
1708 DCHECK_GT(value, 0u); | 1671 DCHECK_GT(value, 0u); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 category = ipv4 ? AF_WASTE_CACHE_IPV4 : AF_WASTE_CACHE_UNSPEC; | 1736 category = ipv4 ? AF_WASTE_CACHE_IPV4 : AF_WASTE_CACHE_UNSPEC; |
1774 } else if (found_other_family_job) { | 1737 } else if (found_other_family_job) { |
1775 category = ipv4 ? AF_WASTE_JOB_IPV4 : AF_WASTE_JOB_UNSPEC; | 1738 category = ipv4 ? AF_WASTE_JOB_IPV4 : AF_WASTE_JOB_UNSPEC; |
1776 } else { | 1739 } else { |
1777 category = ipv4 ? AF_WASTE_NONE_IPV4 : AF_WASTE_NONE_UNSPEC; | 1740 category = ipv4 ? AF_WASTE_NONE_IPV4 : AF_WASTE_NONE_UNSPEC; |
1778 } | 1741 } |
1779 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveUnspecWaste", category, | 1742 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveUnspecWaste", category, |
1780 AF_WASTE_MAX); | 1743 AF_WASTE_MAX); |
1781 } | 1744 } |
1782 | 1745 |
1783 // Create new Job. | 1746 job = new Job(weak_ptr_factory_.GetWeakPtr(), key, info.priority(), |
1784 job = new Job(this, key, info.priority(), request_net_log); | 1747 request_net_log); |
1785 job->Schedule(); | 1748 job->Schedule(); |
1786 | 1749 |
1787 // Check for queue overflow. | 1750 // Check for queue overflow. |
1788 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { | 1751 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { |
1789 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); | 1752 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); |
1790 DCHECK(evicted); | 1753 DCHECK(evicted); |
1791 evicted->OnEvicted(); // Deletes |evicted|. | 1754 evicted->OnEvicted(); // Deletes |evicted|. |
1792 if (evicted == job) { | 1755 if (evicted == job) { |
1793 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1756 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
1794 LogFinishRequest(source_net_log, request_net_log, info, rv); | 1757 LogFinishRequest(source_net_log, request_net_log, info, rv); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 DCHECK(CalledOnValidThread()); | 1827 DCHECK(CalledOnValidThread()); |
1865 Request* req = reinterpret_cast<Request*>(req_handle); | 1828 Request* req = reinterpret_cast<Request*>(req_handle); |
1866 DCHECK(req); | 1829 DCHECK(req); |
1867 Job* job = req->job(); | 1830 Job* job = req->job(); |
1868 DCHECK(job); | 1831 DCHECK(job); |
1869 job->CancelRequest(req); | 1832 job->CancelRequest(req); |
1870 } | 1833 } |
1871 | 1834 |
1872 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { | 1835 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { |
1873 DCHECK(CalledOnValidThread()); | 1836 DCHECK(CalledOnValidThread()); |
| 1837 default_address_family_ = address_family; |
1874 ipv6_probe_monitoring_ = false; | 1838 ipv6_probe_monitoring_ = false; |
1875 DiscardIPv6ProbeJob(); | |
1876 default_address_family_ = address_family; | |
1877 } | 1839 } |
1878 | 1840 |
1879 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { | 1841 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { |
1880 return default_address_family_; | 1842 return default_address_family_; |
1881 } | 1843 } |
1882 | 1844 |
1883 void HostResolverImpl::ProbeIPv6Support() { | 1845 void HostResolverImpl::ProbeIPv6Support() { |
1884 DCHECK(CalledOnValidThread()); | 1846 DCHECK(CalledOnValidThread()); |
1885 DCHECK(!ipv6_probe_monitoring_); | 1847 DCHECK(!ipv6_probe_monitoring_); |
1886 ipv6_probe_monitoring_ = true; | 1848 ipv6_probe_monitoring_ = true; |
1887 OnIPAddressChanged(); // Give initial setup call. | 1849 OnIPAddressChanged(); |
1888 } | 1850 } |
1889 | 1851 |
1890 HostCache* HostResolverImpl::GetHostCache() { | 1852 HostCache* HostResolverImpl::GetHostCache() { |
1891 return cache_.get(); | 1853 return cache_.get(); |
1892 } | 1854 } |
1893 | 1855 |
1894 base::Value* HostResolverImpl::GetDnsConfigAsValue() const { | 1856 base::Value* HostResolverImpl::GetDnsConfigAsValue() const { |
1895 // Check if async DNS is disabled. | 1857 // Check if async DNS is disabled. |
1896 if (!dns_client_.get()) | 1858 if (!dns_client_.get()) |
1897 return NULL; | 1859 return NULL; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1995 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); | 1957 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); |
1996 } | 1958 } |
1997 | 1959 |
1998 void HostResolverImpl::RemoveJob(Job* job) { | 1960 void HostResolverImpl::RemoveJob(Job* job) { |
1999 DCHECK(job); | 1961 DCHECK(job); |
2000 JobMap::iterator it = jobs_.find(job->key()); | 1962 JobMap::iterator it = jobs_.find(job->key()); |
2001 if (it != jobs_.end() && it->second == job) | 1963 if (it != jobs_.end() && it->second == job) |
2002 jobs_.erase(it); | 1964 jobs_.erase(it); |
2003 } | 1965 } |
2004 | 1966 |
2005 void HostResolverImpl::DiscardIPv6ProbeJob() { | |
2006 if (ipv6_probe_job_.get()) { | |
2007 ipv6_probe_job_->Cancel(); | |
2008 ipv6_probe_job_ = NULL; | |
2009 } | |
2010 } | |
2011 | |
2012 void HostResolverImpl::IPv6ProbeSetDefaultAddressFamily( | 1967 void HostResolverImpl::IPv6ProbeSetDefaultAddressFamily( |
2013 AddressFamily address_family) { | 1968 AddressFamily address_family) { |
2014 DCHECK(address_family == ADDRESS_FAMILY_UNSPECIFIED || | 1969 DCHECK(address_family == ADDRESS_FAMILY_UNSPECIFIED || |
2015 address_family == ADDRESS_FAMILY_IPV4); | 1970 address_family == ADDRESS_FAMILY_IPV4); |
| 1971 if (!ipv6_probe_monitoring_) |
| 1972 return; |
2016 if (default_address_family_ != address_family) { | 1973 if (default_address_family_ != address_family) { |
2017 VLOG(1) << "IPv6Probe forced AddressFamily setting to " | 1974 VLOG(1) << "IPv6Probe forced AddressFamily setting to " |
2018 << ((address_family == ADDRESS_FAMILY_UNSPECIFIED) ? | 1975 << ((address_family == ADDRESS_FAMILY_UNSPECIFIED) ? |
2019 "ADDRESS_FAMILY_UNSPECIFIED" : "ADDRESS_FAMILY_IPV4"); | 1976 "ADDRESS_FAMILY_UNSPECIFIED" : "ADDRESS_FAMILY_IPV4"); |
2020 } | 1977 } |
2021 default_address_family_ = address_family; | 1978 default_address_family_ = address_family; |
2022 // Drop reference since the job has called us back. | |
2023 DiscardIPv6ProbeJob(); | |
2024 } | 1979 } |
2025 | 1980 |
2026 void HostResolverImpl::SetHaveOnlyLoopbackAddresses(bool result) { | 1981 void HostResolverImpl::SetHaveOnlyLoopbackAddresses(bool result) { |
2027 if (result) { | 1982 if (result) { |
2028 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 1983 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
2029 } else { | 1984 } else { |
2030 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; | 1985 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; |
2031 } | 1986 } |
2032 } | 1987 } |
2033 | 1988 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2085 | 2040 |
2086 for (JobMap::iterator it = jobs_.begin(); self && it != jobs_.end(); ) { | 2041 for (JobMap::iterator it = jobs_.begin(); self && it != jobs_.end(); ) { |
2087 Job* job = it->second; | 2042 Job* job = it->second; |
2088 ++it; | 2043 ++it; |
2089 // This could remove |job| from |jobs_|, but iterator will remain valid. | 2044 // This could remove |job| from |jobs_|, but iterator will remain valid. |
2090 job->ServeFromHosts(); | 2045 job->ServeFromHosts(); |
2091 } | 2046 } |
2092 } | 2047 } |
2093 | 2048 |
2094 void HostResolverImpl::OnIPAddressChanged() { | 2049 void HostResolverImpl::OnIPAddressChanged() { |
| 2050 // Abandon all ProbeJobs. |
| 2051 probe_weak_ptr_factory_.InvalidateWeakPtrs(); |
2095 if (cache_.get()) | 2052 if (cache_.get()) |
2096 cache_->clear(); | 2053 cache_->clear(); |
2097 if (ipv6_probe_monitoring_) { | 2054 if (ipv6_probe_monitoring_) |
2098 DiscardIPv6ProbeJob(); | 2055 new IPv6ProbeJob(probe_weak_ptr_factory_.GetWeakPtr(), net_log_); |
2099 ipv6_probe_job_ = new IPv6ProbeJob(this, net_log_); | |
2100 ipv6_probe_job_->Start(); | |
2101 } | |
2102 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 2056 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
2103 // TODO(szym): Use HaveOnlyLoopbackProbeJob. http://crbug.com/157933 | 2057 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); |
2104 SetHaveOnlyLoopbackAddresses(HaveOnlyLoopbackAddresses()); | |
2105 #endif | 2058 #endif |
2106 AbortAllInProgressJobs(); | 2059 AbortAllInProgressJobs(); |
2107 // |this| may be deleted inside AbortAllInProgressJobs(). | 2060 // |this| may be deleted inside AbortAllInProgressJobs(). |
2108 } | 2061 } |
2109 | 2062 |
2110 void HostResolverImpl::OnDNSChanged() { | 2063 void HostResolverImpl::OnDNSChanged() { |
2111 DnsConfig dns_config; | 2064 DnsConfig dns_config; |
2112 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2065 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2113 if (net_log_) { | 2066 if (net_log_) { |
2114 net_log_->AddGlobalEntry( | 2067 net_log_->AddGlobalEntry( |
(...skipping 26 matching lines...) Expand all Loading... |
2141 // |this| may be deleted inside AbortAllInProgressJobs(). | 2094 // |this| may be deleted inside AbortAllInProgressJobs(). |
2142 if (self) | 2095 if (self) |
2143 TryServingAllJobsFromHosts(); | 2096 TryServingAllJobsFromHosts(); |
2144 } | 2097 } |
2145 | 2098 |
2146 bool HostResolverImpl::HaveDnsConfig() const { | 2099 bool HostResolverImpl::HaveDnsConfig() const { |
2147 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 2100 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
2148 } | 2101 } |
2149 | 2102 |
2150 } // namespace net | 2103 } // namespace net |
OLD | NEW |