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 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 | 1815 |
1816 bool HostResolverImpl::ServeFromCache(const Key& key, | 1816 bool HostResolverImpl::ServeFromCache(const Key& key, |
1817 const RequestInfo& info, | 1817 const RequestInfo& info, |
1818 int* net_error, | 1818 int* net_error, |
1819 AddressList* addresses) { | 1819 AddressList* addresses) { |
1820 DCHECK(addresses); | 1820 DCHECK(addresses); |
1821 DCHECK(net_error); | 1821 DCHECK(net_error); |
1822 if (!info.allow_cached_response() || !cache_.get()) | 1822 if (!info.allow_cached_response() || !cache_.get()) |
1823 return false; | 1823 return false; |
1824 | 1824 |
1825 const HostCache::Entry* cache_entry = cache_->Lookup( | 1825 base::TimeTicks current_time = base::TimeTicks::Now(); |
1826 key, base::TimeTicks::Now()); | 1826 const HostCache::Entry* cache_entry = cache_->Lookup(key, current_time); |
| 1827 |
| 1828 { |
| 1829 bool found = cache_entry != NULL; |
| 1830 bool ipv4 = key.address_family == ADDRESS_FAMILY_IPV4; |
| 1831 // If we couldn't find the desired address family, check to see if the |
| 1832 // other family is in the cache, which indicates waste, and we should fix |
| 1833 // crbug.com/139811. |
| 1834 bool found_other_family = false; |
| 1835 if (!found && default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED) { |
| 1836 Key other_family_key = key; |
| 1837 other_family_key.address_family = ipv4 ? |
| 1838 ADDRESS_FAMILY_UNSPECIFIED : ADDRESS_FAMILY_IPV4; |
| 1839 found_other_family = |
| 1840 cache_->Lookup(other_family_key, current_time) != NULL; |
| 1841 } |
| 1842 enum { // Used in HISTOGRAM_ENUMERATION. |
| 1843 CACHE_IPV4_ONLY_FOUND, |
| 1844 CACHE_IPV4_ONLY_MISS, |
| 1845 CACHE_FOUND_IPV4, |
| 1846 CACHE_FOUND_UNSPEC, |
| 1847 CACHE_WASTE_IPV4, |
| 1848 CACHE_WASTE_UNSPEC, |
| 1849 CACHE_MISS_IPV4, |
| 1850 CACHE_MISS_UNSPEC, |
| 1851 CACHE_MAX, // Bounding value. |
| 1852 } category = CACHE_MAX; |
| 1853 if (default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { |
| 1854 category = found ? CACHE_IPV4_ONLY_FOUND : CACHE_IPV4_ONLY_MISS; |
| 1855 } else if (found) { |
| 1856 category = ipv4 ? CACHE_FOUND_IPV4 : CACHE_FOUND_UNSPEC; |
| 1857 } else if (found_other_family) { |
| 1858 category = ipv4 ? CACHE_WASTE_IPV4 : CACHE_WASTE_UNSPEC; |
| 1859 } else { |
| 1860 category = ipv4 ? CACHE_MISS_IPV4 : CACHE_MISS_UNSPEC; |
| 1861 } |
| 1862 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveCacheCategory", category, CACHE_MAX); |
| 1863 } |
| 1864 |
1827 if (!cache_entry) | 1865 if (!cache_entry) |
1828 return false; | 1866 return false; |
1829 | 1867 |
1830 *net_error = cache_entry->error; | 1868 *net_error = cache_entry->error; |
1831 if (*net_error == OK) { | 1869 if (*net_error == OK) { |
1832 *addresses = cache_entry->addrlist; | 1870 *addresses = cache_entry->addrlist; |
1833 EnsurePortOnAddressList(info.port(), addresses); | 1871 EnsurePortOnAddressList(info.port(), addresses); |
1834 } | 1872 } |
1835 return true; | 1873 return true; |
1836 } | 1874 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2024 if (self) | 2062 if (self) |
2025 TryServingAllJobsFromHosts(); | 2063 TryServingAllJobsFromHosts(); |
2026 } | 2064 } |
2027 } | 2065 } |
2028 | 2066 |
2029 bool HostResolverImpl::HaveDnsConfig() const { | 2067 bool HostResolverImpl::HaveDnsConfig() const { |
2030 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 2068 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
2031 } | 2069 } |
2032 | 2070 |
2033 } // namespace net | 2071 } // namespace net |
OLD | NEW |