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 bool found = cache_entry != NULL; | |
szym
2012/08/07 23:17:32
I suggest adding braces around this whole block so
| |
1829 bool ipv4 = key.address_family == ADDRESS_FAMILY_IPV4; | |
1830 // If we couldn't find the desired address family, check to see if the other | |
1831 // family is in the cache, which indicates waste, and we should fix | |
1832 // crbug.com/139811. | |
1833 bool found_other_family = false; | |
1834 if (!found && default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED) { | |
1835 Key other_family_key = key; | |
1836 other_family_key.address_family = ipv4 ? | |
1837 ADDRESS_FAMILY_UNSPECIFIED : ADDRESS_FAMILY_IPV4; | |
1838 found_other_family = | |
1839 cache_->Lookup(other_family_key, current_time) != NULL; | |
1840 } | |
1841 enum { // Used in HISTOGRAM_ENUMERATION. | |
1842 CACHE_IPV4_ONLY_FOUND, | |
1843 CACHE_IPV4_ONLY_MISS, | |
1844 CACHE_FOUND_IPV4, | |
1845 CACHE_FOUND_UNSPEC, | |
1846 CACHE_WASTE_IPV4, | |
1847 CACHE_WASTE_UNSPEC, | |
1848 CACHE_MISS_IPV4, | |
1849 CACHE_MISS_UNSPEC, | |
1850 CACHE_MAX, // Bounding value. | |
1851 } category = CACHE_MAX; | |
1852 if (default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) | |
1853 category = found ? CACHE_IPV4_ONLY_FOUND : CACHE_IPV4_ONLY_MISS; | |
1854 else if (found) | |
szym
2012/08/07 23:17:32
nit: Use braces whenever if has an else clause.
| |
1855 category = ipv4 ? CACHE_FOUND_IPV4 : CACHE_FOUND_UNSPEC; | |
1856 else if (found_other_family) | |
1857 category = ipv4 ? CACHE_WASTE_IPV4 : CACHE_WASTE_UNSPEC; | |
1858 else | |
1859 category = ipv4 ? CACHE_MISS_IPV4 : CACHE_MISS_UNSPEC; | |
1860 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveCacheCategory", category, CACHE_MAX); | |
1861 | |
1827 if (!cache_entry) | 1862 if (!cache_entry) |
1828 return false; | 1863 return false; |
1829 | 1864 |
1830 *net_error = cache_entry->error; | 1865 *net_error = cache_entry->error; |
1831 if (*net_error == OK) { | 1866 if (*net_error == OK) { |
1832 *addresses = cache_entry->addrlist; | 1867 *addresses = cache_entry->addrlist; |
1833 EnsurePortOnAddressList(info.port(), addresses); | 1868 EnsurePortOnAddressList(info.port(), addresses); |
1834 } | 1869 } |
1835 return true; | 1870 return true; |
1836 } | 1871 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2024 if (self) | 2059 if (self) |
2025 TryServingAllJobsFromHosts(); | 2060 TryServingAllJobsFromHosts(); |
2026 } | 2061 } |
2027 } | 2062 } |
2028 | 2063 |
2029 bool HostResolverImpl::HaveDnsConfig() const { | 2064 bool HostResolverImpl::HaveDnsConfig() const { |
2030 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 2065 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
2031 } | 2066 } |
2032 | 2067 |
2033 } // namespace net | 2068 } // namespace net |
OLD | NEW |