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 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 dispatcher_(job_limits), | 1792 dispatcher_(job_limits), |
1793 max_queued_jobs_(job_limits.total_jobs * 100u), | 1793 max_queued_jobs_(job_limits.total_jobs * 100u), |
1794 proc_params_(proc_params), | 1794 proc_params_(proc_params), |
1795 net_log_(net_log), | 1795 net_log_(net_log), |
1796 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 1796 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
1797 weak_ptr_factory_(this), | 1797 weak_ptr_factory_(this), |
1798 probe_weak_ptr_factory_(this), | 1798 probe_weak_ptr_factory_(this), |
1799 received_dns_config_(false), | 1799 received_dns_config_(false), |
1800 num_dns_failures_(0), | 1800 num_dns_failures_(0), |
1801 probe_ipv6_support_(true), | 1801 probe_ipv6_support_(true), |
| 1802 use_local_ipv6_(false), |
1802 resolved_known_ipv6_hostname_(false), | 1803 resolved_known_ipv6_hostname_(false), |
1803 additional_resolver_flags_(0), | 1804 additional_resolver_flags_(0), |
1804 fallback_to_proctask_(true) { | 1805 fallback_to_proctask_(true) { |
1805 | 1806 |
1806 DCHECK_GE(dispatcher_.num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); | 1807 DCHECK_GE(dispatcher_.num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); |
1807 | 1808 |
1808 // Maximum of 4 retry attempts for host resolution. | 1809 // Maximum of 4 retry attempts for host resolution. |
1809 static const size_t kDefaultMaxRetryAttempts = 4u; | 1810 static const size_t kDefaultMaxRetryAttempts = 4u; |
1810 | 1811 |
1811 if (proc_params_.max_retry_attempts == HostResolver::kDefaultRetryAttempts) | 1812 if (proc_params_.max_retry_attempts == HostResolver::kDefaultRetryAttempts) |
1812 proc_params_.max_retry_attempts = kDefaultMaxRetryAttempts; | 1813 proc_params_.max_retry_attempts = kDefaultMaxRetryAttempts; |
1813 | 1814 |
1814 #if defined(OS_WIN) | 1815 #if defined(OS_WIN) |
1815 EnsureWinsockInit(); | 1816 EnsureWinsockInit(); |
1816 #endif | 1817 #endif |
1817 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 1818 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
1818 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr()); | 1819 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr()); |
1819 #endif | 1820 #endif |
1820 NetworkChangeNotifier::AddIPAddressObserver(this); | 1821 NetworkChangeNotifier::AddIPAddressObserver(this); |
1821 NetworkChangeNotifier::AddDNSObserver(this); | 1822 NetworkChangeNotifier::AddDNSObserver(this); |
1822 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | 1823 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
1823 !defined(OS_ANDROID) | 1824 !defined(OS_ANDROID) |
1824 EnsureDnsReloaderInit(); | 1825 EnsureDnsReloaderInit(); |
1825 #endif | 1826 #endif |
1826 | 1827 |
1827 // TODO(szym): Remove when received_dns_config_ is removed, once | |
1828 // http://crbug.com/137914 is resolved. | |
1829 { | 1828 { |
1830 DnsConfig dns_config; | 1829 DnsConfig dns_config; |
1831 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 1830 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
1832 received_dns_config_ = dns_config.IsValid(); | 1831 received_dns_config_ = dns_config.IsValid(); |
| 1832 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. |
| 1833 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; |
1833 } | 1834 } |
1834 | 1835 |
1835 fallback_to_proctask_ = !ConfigureAsyncDnsNoFallbackFieldTrial(); | 1836 fallback_to_proctask_ = !ConfigureAsyncDnsNoFallbackFieldTrial(); |
1836 } | 1837 } |
1837 | 1838 |
1838 HostResolverImpl::~HostResolverImpl() { | 1839 HostResolverImpl::~HostResolverImpl() { |
1839 // Prevent the dispatcher from starting new jobs. | 1840 // Prevent the dispatcher from starting new jobs. |
1840 dispatcher_.SetLimitsToZero(); | 1841 dispatcher_.SetLimitsToZero(); |
1841 // It's now safe for Jobs to call KillDsnTask on destruction, because | 1842 // It's now safe for Jobs to call KillDsnTask on destruction, because |
1842 // OnJobComplete will not start any new jobs. | 1843 // OnJobComplete will not start any new jobs. |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 } | 2136 } |
2136 } | 2137 } |
2137 | 2138 |
2138 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( | 2139 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( |
2139 const RequestInfo& info, const BoundNetLog& net_log) const { | 2140 const RequestInfo& info, const BoundNetLog& net_log) const { |
2140 HostResolverFlags effective_flags = | 2141 HostResolverFlags effective_flags = |
2141 info.host_resolver_flags() | additional_resolver_flags_; | 2142 info.host_resolver_flags() | additional_resolver_flags_; |
2142 AddressFamily effective_address_family = info.address_family(); | 2143 AddressFamily effective_address_family = info.address_family(); |
2143 | 2144 |
2144 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { | 2145 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { |
2145 if (probe_ipv6_support_) { | 2146 if (probe_ipv6_support_ && !use_local_ipv6_) { |
2146 base::TimeTicks start_time = base::TimeTicks::Now(); | 2147 base::TimeTicks start_time = base::TimeTicks::Now(); |
2147 // Google DNS address. | 2148 // Google DNS address. |
2148 const uint8 kIPv6Address[] = | 2149 const uint8 kIPv6Address[] = |
2149 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, | 2150 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, |
2150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 }; | 2151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 }; |
2151 IPAddressNumber address(kIPv6Address, | 2152 IPAddressNumber address(kIPv6Address, |
2152 kIPv6Address + arraysize(kIPv6Address)); | 2153 kIPv6Address + arraysize(kIPv6Address)); |
2153 bool rv6 = IsGloballyReachable(address, net_log); | 2154 bool rv6 = IsGloballyReachable(address, net_log); |
2154 if (rv6) | 2155 if (rv6) |
2155 net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_SUPPORTED); | 2156 net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_SUPPORTED); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2260 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2260 | 2261 |
2261 if (net_log_) { | 2262 if (net_log_) { |
2262 net_log_->AddGlobalEntry( | 2263 net_log_->AddGlobalEntry( |
2263 NetLog::TYPE_DNS_CONFIG_CHANGED, | 2264 NetLog::TYPE_DNS_CONFIG_CHANGED, |
2264 base::Bind(&NetLogDnsConfigCallback, &dns_config)); | 2265 base::Bind(&NetLogDnsConfigCallback, &dns_config)); |
2265 } | 2266 } |
2266 | 2267 |
2267 // TODO(szym): Remove once http://crbug.com/137914 is resolved. | 2268 // TODO(szym): Remove once http://crbug.com/137914 is resolved. |
2268 received_dns_config_ = dns_config.IsValid(); | 2269 received_dns_config_ = dns_config.IsValid(); |
| 2270 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. |
| 2271 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; |
2269 | 2272 |
2270 num_dns_failures_ = 0; | 2273 num_dns_failures_ = 0; |
2271 | 2274 |
2272 // We want a new DnsSession in place, before we Abort running Jobs, so that | 2275 // We want a new DnsSession in place, before we Abort running Jobs, so that |
2273 // the newly started jobs use the new config. | 2276 // the newly started jobs use the new config. |
2274 if (dns_client_.get()) { | 2277 if (dns_client_.get()) { |
2275 dns_client_->SetConfig(dns_config); | 2278 dns_client_->SetConfig(dns_config); |
2276 if (dns_client_->GetConfig()) | 2279 if (dns_client_->GetConfig()) |
2277 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2280 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2278 } | 2281 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2340 dns_client_->SetConfig(dns_config); | 2343 dns_client_->SetConfig(dns_config); |
2341 num_dns_failures_ = 0; | 2344 num_dns_failures_ = 0; |
2342 if (dns_client_->GetConfig()) | 2345 if (dns_client_->GetConfig()) |
2343 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2346 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2344 } | 2347 } |
2345 | 2348 |
2346 AbortDnsTasks(); | 2349 AbortDnsTasks(); |
2347 } | 2350 } |
2348 | 2351 |
2349 } // namespace net | 2352 } // namespace net |
OLD | NEW |