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 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <Winsock2.h> | 10 #include <Winsock2.h> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 #include "url/url_canon_ip.h" | 58 #include "url/url_canon_ip.h" |
| 59 | 59 |
| 60 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 61 #include "net/base/winsock_init.h" | 61 #include "net/base/winsock_init.h" |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 namespace net { | 64 namespace net { |
| 65 | 65 |
| 66 namespace { | 66 namespace { |
| 67 | 67 |
| 68 // Default delay between calls to the system resolver for the same hostname. | |
| 69 // (Can be overridden by field trial.) | |
| 70 const int64_t kDnsDefaultUnresponsiveDelayMs = 6000; | |
| 71 | |
| 68 // Limit the size of hostnames that will be resolved to combat issues in | 72 // Limit the size of hostnames that will be resolved to combat issues in |
| 69 // some platform's resolvers. | 73 // some platform's resolvers. |
| 70 const size_t kMaxHostLength = 4096; | 74 const size_t kMaxHostLength = 4096; |
| 71 | 75 |
| 72 // Default TTL for successful resolutions with ProcTask. | 76 // Default TTL for successful resolutions with ProcTask. |
| 73 const unsigned kCacheEntryTTLSeconds = 60; | 77 const unsigned kCacheEntryTTLSeconds = 60; |
| 74 | 78 |
| 75 // Default TTL for unsuccessful resolutions with ProcTask. | 79 // Default TTL for unsuccessful resolutions with ProcTask. |
| 76 const unsigned kNegativeCacheEntryTTLSeconds = 0; | 80 const unsigned kNegativeCacheEntryTTLSeconds = 0; |
| 77 | 81 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 if (total_count_ == 0) | 484 if (total_count_ == 0) |
| 481 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); | 485 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); |
| 482 } | 486 } |
| 483 | 487 |
| 484 private: | 488 private: |
| 485 RequestPriority highest_priority_; | 489 RequestPriority highest_priority_; |
| 486 size_t total_count_; | 490 size_t total_count_; |
| 487 size_t counts_[NUM_PRIORITIES]; | 491 size_t counts_[NUM_PRIORITIES]; |
| 488 }; | 492 }; |
| 489 | 493 |
| 494 base::TimeDelta GetUnresponsiveDelay( | |
|
Randy Smith (Not in Mondays)
2016/03/16 20:11:07
Same comment as before (up to you, but simple enou
Deprecated (see juliatuttle)
2016/03/17 16:29:46
Done.
| |
| 495 NetworkChangeNotifier::ConnectionType type) { | |
| 496 return GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( | |
| 497 "DnsUnresponsiveDelayMsByConnectionType", | |
| 498 base::TimeDelta::FromMilliseconds(kDnsDefaultUnresponsiveDelayMs), type); | |
| 499 } | |
| 500 | |
| 490 } // namespace | 501 } // namespace |
| 491 | 502 |
| 492 //----------------------------------------------------------------------------- | 503 //----------------------------------------------------------------------------- |
| 493 | 504 |
| 494 bool ResolveLocalHostname(base::StringPiece host, | 505 bool ResolveLocalHostname(base::StringPiece host, |
| 495 uint16_t port, | 506 uint16_t port, |
| 496 AddressList* address_list) { | 507 AddressList* address_list) { |
| 497 address_list->clear(); | 508 address_list->clear(); |
| 498 | 509 |
| 499 bool is_local6; | 510 bool is_local6; |
| (...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1829 PrioritizedDispatcher::Handle handle_; | 1840 PrioritizedDispatcher::Handle handle_; |
| 1830 }; | 1841 }; |
| 1831 | 1842 |
| 1832 //----------------------------------------------------------------------------- | 1843 //----------------------------------------------------------------------------- |
| 1833 | 1844 |
| 1834 HostResolverImpl::ProcTaskParams::ProcTaskParams( | 1845 HostResolverImpl::ProcTaskParams::ProcTaskParams( |
| 1835 HostResolverProc* resolver_proc, | 1846 HostResolverProc* resolver_proc, |
| 1836 size_t max_retry_attempts) | 1847 size_t max_retry_attempts) |
| 1837 : resolver_proc(resolver_proc), | 1848 : resolver_proc(resolver_proc), |
| 1838 max_retry_attempts(max_retry_attempts), | 1849 max_retry_attempts(max_retry_attempts), |
| 1839 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), | 1850 unresponsive_delay( |
| 1851 base::TimeDelta::FromMilliseconds(kDnsDefaultUnresponsiveDelayMs)), | |
| 1840 retry_factor(2) { | 1852 retry_factor(2) { |
| 1841 // Maximum of 4 retry attempts for host resolution. | 1853 // Maximum of 4 retry attempts for host resolution. |
| 1842 static const size_t kDefaultMaxRetryAttempts = 4u; | 1854 static const size_t kDefaultMaxRetryAttempts = 4u; |
| 1843 if (max_retry_attempts == HostResolver::kDefaultRetryAttempts) | 1855 if (max_retry_attempts == HostResolver::kDefaultRetryAttempts) |
| 1844 max_retry_attempts = kDefaultMaxRetryAttempts; | 1856 max_retry_attempts = kDefaultMaxRetryAttempts; |
| 1845 } | 1857 } |
| 1846 | 1858 |
| 1847 HostResolverImpl::ProcTaskParams::ProcTaskParams(const ProcTaskParams& other) = | 1859 HostResolverImpl::ProcTaskParams::ProcTaskParams(const ProcTaskParams& other) = |
| 1848 default; | 1860 default; |
| 1849 | 1861 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1871 | 1883 |
| 1872 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); | 1884 DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); |
| 1873 | 1885 |
| 1874 #if defined(OS_WIN) | 1886 #if defined(OS_WIN) |
| 1875 EnsureWinsockInit(); | 1887 EnsureWinsockInit(); |
| 1876 #endif | 1888 #endif |
| 1877 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 1889 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 1878 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr()); | 1890 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr()); |
| 1879 #endif | 1891 #endif |
| 1880 NetworkChangeNotifier::AddIPAddressObserver(this); | 1892 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 1893 NetworkChangeNotifier::AddConnectionTypeObserver(this); | |
| 1881 NetworkChangeNotifier::AddDNSObserver(this); | 1894 NetworkChangeNotifier::AddDNSObserver(this); |
| 1882 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | 1895 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
| 1883 !defined(OS_ANDROID) | 1896 !defined(OS_ANDROID) |
| 1884 EnsureDnsReloaderInit(); | 1897 EnsureDnsReloaderInit(); |
| 1885 #endif | 1898 #endif |
| 1886 | 1899 |
| 1900 OnConnectionTypeChanged(NetworkChangeNotifier::GetConnectionType()); | |
| 1901 | |
| 1887 { | 1902 { |
| 1888 DnsConfig dns_config; | 1903 DnsConfig dns_config; |
| 1889 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 1904 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 1890 received_dns_config_ = dns_config.IsValid(); | 1905 received_dns_config_ = dns_config.IsValid(); |
| 1891 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. | 1906 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. |
| 1892 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; | 1907 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; |
| 1893 } | 1908 } |
| 1894 | 1909 |
| 1895 fallback_to_proctask_ = !ConfigureAsyncDnsNoFallbackFieldTrial(); | 1910 fallback_to_proctask_ = !ConfigureAsyncDnsNoFallbackFieldTrial(); |
| 1896 } | 1911 } |
| 1897 | 1912 |
| 1898 HostResolverImpl::~HostResolverImpl() { | 1913 HostResolverImpl::~HostResolverImpl() { |
| 1899 // Prevent the dispatcher from starting new jobs. | 1914 // Prevent the dispatcher from starting new jobs. |
| 1900 dispatcher_->SetLimitsToZero(); | 1915 dispatcher_->SetLimitsToZero(); |
| 1901 // It's now safe for Jobs to call KillDsnTask on destruction, because | 1916 // It's now safe for Jobs to call KillDsnTask on destruction, because |
| 1902 // OnJobComplete will not start any new jobs. | 1917 // OnJobComplete will not start any new jobs. |
| 1903 STLDeleteValues(&jobs_); | 1918 STLDeleteValues(&jobs_); |
| 1904 | 1919 |
| 1905 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1920 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1921 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | |
| 1906 NetworkChangeNotifier::RemoveDNSObserver(this); | 1922 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 1907 } | 1923 } |
| 1908 | 1924 |
| 1909 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { | 1925 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { |
| 1910 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); | 1926 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); |
| 1911 DCHECK_GT(value, 0u); | 1927 DCHECK_GT(value, 0u); |
| 1912 max_queued_jobs_ = value; | 1928 max_queued_jobs_ = value; |
| 1913 } | 1929 } |
| 1914 | 1930 |
| 1915 int HostResolverImpl::Resolve(const RequestInfo& info, | 1931 int HostResolverImpl::Resolve(const RequestInfo& info, |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2334 probe_weak_ptr_factory_.InvalidateWeakPtrs(); | 2350 probe_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 2335 if (cache_.get()) | 2351 if (cache_.get()) |
| 2336 cache_->clear(); | 2352 cache_->clear(); |
| 2337 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 2353 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 2338 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); | 2354 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); |
| 2339 #endif | 2355 #endif |
| 2340 AbortAllInProgressJobs(); | 2356 AbortAllInProgressJobs(); |
| 2341 // |this| may be deleted inside AbortAllInProgressJobs(). | 2357 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 2342 } | 2358 } |
| 2343 | 2359 |
| 2360 void HostResolverImpl::OnConnectionTypeChanged( | |
| 2361 NetworkChangeNotifier::ConnectionType type) { | |
| 2362 proc_params_.unresponsive_delay = GetUnresponsiveDelay(type); | |
| 2363 } | |
| 2364 | |
| 2344 void HostResolverImpl::OnInitialDNSConfigRead() { | 2365 void HostResolverImpl::OnInitialDNSConfigRead() { |
| 2345 UpdateDNSConfig(false); | 2366 UpdateDNSConfig(false); |
| 2346 } | 2367 } |
| 2347 | 2368 |
| 2348 void HostResolverImpl::OnDNSChanged() { | 2369 void HostResolverImpl::OnDNSChanged() { |
| 2349 UpdateDNSConfig(true); | 2370 UpdateDNSConfig(true); |
| 2350 } | 2371 } |
| 2351 | 2372 |
| 2352 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { | 2373 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { |
| 2353 DnsConfig dns_config; | 2374 DnsConfig dns_config; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2442 dns_client_->SetConfig(dns_config); | 2463 dns_client_->SetConfig(dns_config); |
| 2443 num_dns_failures_ = 0; | 2464 num_dns_failures_ = 0; |
| 2444 if (dns_client_->GetConfig()) | 2465 if (dns_client_->GetConfig()) |
| 2445 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2466 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2446 } | 2467 } |
| 2447 | 2468 |
| 2448 AbortDnsTasks(); | 2469 AbortDnsTasks(); |
| 2449 } | 2470 } |
| 2450 | 2471 |
| 2451 } // namespace net | 2472 } // namespace net |
| OLD | NEW |