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