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/dns/host_resolver_impl.h" | 5 #include "net/dns/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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 915 | 915 |
| 916 AddressList results_; | 916 AddressList results_; |
| 917 | 917 |
| 918 BoundNetLog net_log_; | 918 BoundNetLog net_log_; |
| 919 | 919 |
| 920 DISALLOW_COPY_AND_ASSIGN(ProcTask); | 920 DISALLOW_COPY_AND_ASSIGN(ProcTask); |
| 921 }; | 921 }; |
| 922 | 922 |
| 923 //----------------------------------------------------------------------------- | 923 //----------------------------------------------------------------------------- |
| 924 | 924 |
| 925 // Wraps a call to TestIPv6Support to be executed on the WorkerPool as it takes | |
| 926 // 40-100ms. | |
| 927 // TODO(szym): Remove altogether, if IPv6ActiveProbe works. | |
| 928 class HostResolverImpl::IPv6ProbeJob { | |
| 929 public: | |
| 930 IPv6ProbeJob(const base::WeakPtr<HostResolverImpl>& resolver, NetLog* net_log) | |
| 931 : resolver_(resolver), | |
| 932 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_IPV6_PROBE_JOB)), | |
| 933 result_(false, IPV6_SUPPORT_MAX, OK) { | |
| 934 DCHECK(resolver.get()); | |
| 935 net_log_.BeginEvent(NetLog::TYPE_IPV6_PROBE_RUNNING); | |
| 936 const bool kIsSlow = true; | |
| 937 base::WorkerPool::PostTaskAndReply( | |
| 938 FROM_HERE, | |
| 939 base::Bind(&IPv6ProbeJob::DoProbe, base::Unretained(this)), | |
| 940 base::Bind(&IPv6ProbeJob::OnProbeComplete, base::Owned(this)), | |
| 941 kIsSlow); | |
| 942 } | |
| 943 | |
| 944 virtual ~IPv6ProbeJob() {} | |
| 945 | |
| 946 private: | |
| 947 // Runs on worker thread. | |
| 948 void DoProbe() { | |
| 949 result_ = TestIPv6Support(); | |
| 950 } | |
| 951 | |
| 952 void OnProbeComplete() { | |
| 953 net_log_.EndEvent(NetLog::TYPE_IPV6_PROBE_RUNNING, | |
| 954 base::Bind(&IPv6SupportResult::ToNetLogValue, | |
| 955 base::Unretained(&result_))); | |
| 956 if (!resolver_.get()) | |
| 957 return; | |
| 958 resolver_->IPv6ProbeSetDefaultAddressFamily( | |
| 959 result_.ipv6_supported ? ADDRESS_FAMILY_UNSPECIFIED | |
| 960 : ADDRESS_FAMILY_IPV4); | |
| 961 } | |
| 962 | |
| 963 // Used/set only on origin thread. | |
| 964 base::WeakPtr<HostResolverImpl> resolver_; | |
| 965 | |
| 966 BoundNetLog net_log_; | |
| 967 | |
| 968 IPv6SupportResult result_; | |
| 969 | |
| 970 DISALLOW_COPY_AND_ASSIGN(IPv6ProbeJob); | |
| 971 }; | |
| 972 | |
| 973 // Wraps a call to HaveOnlyLoopbackAddresses to be executed on the WorkerPool as | 925 // Wraps a call to HaveOnlyLoopbackAddresses to be executed on the WorkerPool as |
| 974 // it takes 40-100ms and should not block initialization. | 926 // it takes 40-100ms and should not block initialization. |
| 975 class HostResolverImpl::LoopbackProbeJob { | 927 class HostResolverImpl::LoopbackProbeJob { |
| 976 public: | 928 public: |
| 977 explicit LoopbackProbeJob(const base::WeakPtr<HostResolverImpl>& resolver) | 929 explicit LoopbackProbeJob(const base::WeakPtr<HostResolverImpl>& resolver) |
| 978 : resolver_(resolver), | 930 : resolver_(resolver), |
| 979 result_(false) { | 931 result_(false) { |
| 980 DCHECK(resolver.get()); | 932 DCHECK(resolver.get()); |
| 981 const bool kIsSlow = true; | 933 const bool kIsSlow = true; |
| 982 base::WorkerPool::PostTaskAndReply( | 934 base::WorkerPool::PostTaskAndReply( |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1928 DCHECK(CalledOnValidThread()); | 1880 DCHECK(CalledOnValidThread()); |
| 1929 default_address_family_ = address_family; | 1881 default_address_family_ = address_family; |
| 1930 ipv6_probe_monitoring_ = false; | 1882 ipv6_probe_monitoring_ = false; |
| 1931 } | 1883 } |
| 1932 | 1884 |
| 1933 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { | 1885 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { |
| 1934 return default_address_family_; | 1886 return default_address_family_; |
| 1935 } | 1887 } |
| 1936 | 1888 |
| 1937 // TODO(szym): Remove this API altogether if IPv6ActiveProbe works. | 1889 // TODO(szym): Remove this API altogether if IPv6ActiveProbe works. |
| 1938 void HostResolverImpl::ProbeIPv6Support() { | 1890 void HostResolverImpl::ProbeIPv6Support() { |
|
mmenke
2013/07/16 17:48:04
Leaving this in for now? Seems like we could just
szym
2013/07/16 20:08:31
--enable-ipv6 => SetDefaultAddressFamily(UNSPEC)
| |
| 1939 DCHECK(CalledOnValidThread()); | 1891 DCHECK(CalledOnValidThread()); |
| 1940 DCHECK(!ipv6_probe_monitoring_); | 1892 DCHECK(!ipv6_probe_monitoring_); |
| 1941 ipv6_probe_monitoring_ = true; | 1893 ipv6_probe_monitoring_ = true; |
| 1942 OnIPAddressChanged(); | 1894 OnIPAddressChanged(); |
| 1943 } | 1895 } |
| 1944 | 1896 |
| 1945 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { | 1897 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { |
| 1946 DCHECK(CalledOnValidThread()); | 1898 DCHECK(CalledOnValidThread()); |
| 1947 #if defined(ENABLE_BUILT_IN_DNS) | 1899 #if defined(ENABLE_BUILT_IN_DNS) |
| 1948 if (enabled && !dns_client_) { | 1900 if (enabled && !dns_client_) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2076 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); | 2028 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); |
| 2077 } | 2029 } |
| 2078 | 2030 |
| 2079 void HostResolverImpl::RemoveJob(Job* job) { | 2031 void HostResolverImpl::RemoveJob(Job* job) { |
| 2080 DCHECK(job); | 2032 DCHECK(job); |
| 2081 JobMap::iterator it = jobs_.find(job->key()); | 2033 JobMap::iterator it = jobs_.find(job->key()); |
| 2082 if (it != jobs_.end() && it->second == job) | 2034 if (it != jobs_.end() && it->second == job) |
| 2083 jobs_.erase(it); | 2035 jobs_.erase(it); |
| 2084 } | 2036 } |
| 2085 | 2037 |
| 2086 void HostResolverImpl::IPv6ProbeSetDefaultAddressFamily( | |
| 2087 AddressFamily address_family) { | |
| 2088 DCHECK(address_family == ADDRESS_FAMILY_UNSPECIFIED || | |
| 2089 address_family == ADDRESS_FAMILY_IPV4); | |
| 2090 if (!ipv6_probe_monitoring_) | |
| 2091 return; | |
| 2092 if (default_address_family_ != address_family) { | |
| 2093 VLOG(1) << "IPv6Probe forced AddressFamily setting to " | |
| 2094 << ((address_family == ADDRESS_FAMILY_UNSPECIFIED) ? | |
| 2095 "ADDRESS_FAMILY_UNSPECIFIED" : "ADDRESS_FAMILY_IPV4"); | |
| 2096 } | |
| 2097 default_address_family_ = address_family; | |
| 2098 } | |
| 2099 | |
| 2100 void HostResolverImpl::SetHaveOnlyLoopbackAddresses(bool result) { | 2038 void HostResolverImpl::SetHaveOnlyLoopbackAddresses(bool result) { |
| 2101 if (result) { | 2039 if (result) { |
| 2102 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; | 2040 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
| 2103 } else { | 2041 } else { |
| 2104 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; | 2042 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; |
| 2105 } | 2043 } |
| 2106 } | 2044 } |
| 2107 | 2045 |
| 2108 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( | 2046 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( |
| 2109 const RequestInfo& info) const { | 2047 const RequestInfo& info) const { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2187 job->ServeFromHosts(); | 2125 job->ServeFromHosts(); |
| 2188 } | 2126 } |
| 2189 } | 2127 } |
| 2190 | 2128 |
| 2191 void HostResolverImpl::OnIPAddressChanged() { | 2129 void HostResolverImpl::OnIPAddressChanged() { |
| 2192 resolved_known_ipv6_hostname_ = false; | 2130 resolved_known_ipv6_hostname_ = false; |
| 2193 // Abandon all ProbeJobs. | 2131 // Abandon all ProbeJobs. |
| 2194 probe_weak_ptr_factory_.InvalidateWeakPtrs(); | 2132 probe_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 2195 if (cache_.get()) | 2133 if (cache_.get()) |
| 2196 cache_->clear(); | 2134 cache_->clear(); |
| 2197 if (ipv6_probe_monitoring_) | |
| 2198 new IPv6ProbeJob(probe_weak_ptr_factory_.GetWeakPtr(), net_log_); | |
| 2199 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 2135 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 2200 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); | 2136 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); |
| 2201 #endif | 2137 #endif |
| 2202 AbortAllInProgressJobs(); | 2138 AbortAllInProgressJobs(); |
| 2203 // |this| may be deleted inside AbortAllInProgressJobs(). | 2139 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 2204 } | 2140 } |
| 2205 | 2141 |
| 2206 void HostResolverImpl::OnDNSChanged() { | 2142 void HostResolverImpl::OnDNSChanged() { |
| 2207 DnsConfig dns_config; | 2143 DnsConfig dns_config; |
| 2208 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2144 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2286 } | 2222 } |
| 2287 DnsConfig dns_config; | 2223 DnsConfig dns_config; |
| 2288 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2224 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2289 dns_client_->SetConfig(dns_config); | 2225 dns_client_->SetConfig(dns_config); |
| 2290 num_dns_failures_ = 0; | 2226 num_dns_failures_ = 0; |
| 2291 if (dns_config.IsValid()) | 2227 if (dns_config.IsValid()) |
| 2292 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2228 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2293 } | 2229 } |
| 2294 | 2230 |
| 2295 } // namespace net | 2231 } // namespace net |
| OLD | NEW |