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 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); | 1652 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); |
1653 return rv; | 1653 return rv; |
1654 } | 1654 } |
1655 | 1655 |
1656 // Next we need to attach our request to a "job". This job is responsible for | 1656 // Next we need to attach our request to a "job". This job is responsible for |
1657 // calling "getaddrinfo(hostname)" on a worker thread. | 1657 // calling "getaddrinfo(hostname)" on a worker thread. |
1658 | 1658 |
1659 JobMap::iterator jobit = jobs_.find(key); | 1659 JobMap::iterator jobit = jobs_.find(key); |
1660 Job* job; | 1660 Job* job; |
1661 if (jobit == jobs_.end()) { | 1661 if (jobit == jobs_.end()) { |
1662 // If we couldn't find the desired address family, check to see if the | |
1663 // other family is in the cache or another job, which indicates waste, | |
1664 // and we should fix crbug.com/139811. | |
1665 { | |
1666 bool ipv4 = key.address_family == ADDRESS_FAMILY_IPV4; | |
1667 Key other_family_key = key; | |
1668 other_family_key.address_family = ipv4 ? | |
1669 ADDRESS_FAMILY_UNSPECIFIED : ADDRESS_FAMILY_IPV4; | |
1670 bool found_other_family_cache = false, found_other_family_job = false; | |
szym
2012/08/14 22:05:03
nit: Although I can't find anything explicit in th
| |
1671 if (default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED) { | |
1672 found_other_family_cache = | |
1673 cache_->Lookup(other_family_key, base::TimeTicks::Now()) != NULL; | |
1674 if (!found_other_family_cache) | |
1675 found_other_family_job = jobs_.find(other_family_key) != jobs_.end(); | |
szym
2012/08/14 22:05:03
I suggest |jobs_.count(other_family_key) > 0|
| |
1676 } | |
1677 enum { // Used in HISTOGRAM_ENUMERATION. | |
szym
2012/08/14 22:05:03
nit: UMA_HISTOGRAM_ENUMERATION
| |
1678 AF_WASTE_IPV4_ONLY, | |
1679 AF_WASTE_CACHE_IPV4, | |
1680 AF_WASTE_CACHE_UNSPEC, | |
1681 AF_WASTE_JOB_IPV4, | |
1682 AF_WASTE_JOB_UNSPEC, | |
1683 AF_WASTE_MISS_IPV4, | |
szym
2012/08/14 22:05:03
How about AF_WASTE_NONE_* to indicate that there i
| |
1684 AF_WASTE_MISS_UNSPEC, | |
1685 AF_WASTE_MAX, // Bounding value. | |
1686 } category = AF_WASTE_MAX; | |
1687 if (default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | |
1688 category = AF_WASTE_IPV4_ONLY; | |
1689 } else if (found_other_family_cache) { | |
1690 category = ipv4 ? AF_WASTE_CACHE_IPV4 : AF_WASTE_CACHE_UNSPEC; | |
1691 } else if (found_other_family_job) { | |
1692 category = ipv4 ? AF_WASTE_JOB_IPV4 : AF_WASTE_JOB_UNSPEC; | |
1693 } else { | |
1694 category = ipv4 ? AF_WASTE_MISS_IPV4 : AF_WASTE_MISS_UNSPEC; | |
1695 } | |
1696 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveUnspecWasteCategory", category, | |
szym
2012/08/14 22:05:03
nit: I don't think you need "Category". "Waste" se
| |
1697 AF_WASTE_MAX); | |
1698 } | |
1699 | |
1662 // Create new Job. | 1700 // Create new Job. |
1663 job = new Job(this, key, info.priority(), request_net_log); | 1701 job = new Job(this, key, info.priority(), request_net_log); |
1664 job->Schedule(); | 1702 job->Schedule(); |
1665 | 1703 |
1666 // Check for queue overflow. | 1704 // Check for queue overflow. |
1667 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { | 1705 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { |
1668 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); | 1706 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); |
1669 DCHECK(evicted); | 1707 DCHECK(evicted); |
1670 evicted->OnEvicted(); // Deletes |evicted|. | 1708 evicted->OnEvicted(); // Deletes |evicted|. |
1671 if (evicted == job) { | 1709 if (evicted == job) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1813 | 1851 |
1814 bool HostResolverImpl::ServeFromCache(const Key& key, | 1852 bool HostResolverImpl::ServeFromCache(const Key& key, |
1815 const RequestInfo& info, | 1853 const RequestInfo& info, |
1816 int* net_error, | 1854 int* net_error, |
1817 AddressList* addresses) { | 1855 AddressList* addresses) { |
1818 DCHECK(addresses); | 1856 DCHECK(addresses); |
1819 DCHECK(net_error); | 1857 DCHECK(net_error); |
1820 if (!info.allow_cached_response() || !cache_.get()) | 1858 if (!info.allow_cached_response() || !cache_.get()) |
1821 return false; | 1859 return false; |
1822 | 1860 |
1823 base::TimeTicks current_time = base::TimeTicks::Now(); | 1861 const HostCache::Entry* cache_entry = cache_->Lookup( |
1824 const HostCache::Entry* cache_entry = cache_->Lookup(key, current_time); | 1862 key, base::TimeTicks::Now()); |
1825 | |
1826 { | |
1827 bool found = cache_entry != NULL; | |
1828 bool ipv4 = key.address_family == ADDRESS_FAMILY_IPV4; | |
1829 // If we couldn't find the desired address family, check to see if the | |
1830 // other family is in the cache, which indicates waste, and we should fix | |
1831 // crbug.com/139811. | |
1832 bool found_other_family = false; | |
1833 if (!found && default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED) { | |
1834 Key other_family_key = key; | |
1835 other_family_key.address_family = ipv4 ? | |
1836 ADDRESS_FAMILY_UNSPECIFIED : ADDRESS_FAMILY_IPV4; | |
1837 found_other_family = | |
1838 cache_->Lookup(other_family_key, current_time) != NULL; | |
1839 } | |
1840 enum { // Used in HISTOGRAM_ENUMERATION. | |
1841 CACHE_IPV4_ONLY_FOUND, | |
1842 CACHE_IPV4_ONLY_MISS, | |
1843 CACHE_FOUND_IPV4, | |
1844 CACHE_FOUND_UNSPEC, | |
1845 CACHE_WASTE_IPV4, | |
1846 CACHE_WASTE_UNSPEC, | |
1847 CACHE_MISS_IPV4, | |
1848 CACHE_MISS_UNSPEC, | |
1849 CACHE_MAX, // Bounding value. | |
1850 } category = CACHE_MAX; | |
1851 if (default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | |
1852 category = found ? CACHE_IPV4_ONLY_FOUND : CACHE_IPV4_ONLY_MISS; | |
1853 } else if (found) { | |
1854 category = ipv4 ? CACHE_FOUND_IPV4 : CACHE_FOUND_UNSPEC; | |
1855 } else if (found_other_family) { | |
1856 category = ipv4 ? CACHE_WASTE_IPV4 : CACHE_WASTE_UNSPEC; | |
1857 } else { | |
1858 category = ipv4 ? CACHE_MISS_IPV4 : CACHE_MISS_UNSPEC; | |
1859 } | |
1860 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveCacheCategory", category, CACHE_MAX); | |
1861 } | |
1862 | |
1863 if (!cache_entry) | 1863 if (!cache_entry) |
1864 return false; | 1864 return false; |
1865 | 1865 |
1866 *net_error = cache_entry->error; | 1866 *net_error = cache_entry->error; |
1867 if (*net_error == OK) { | 1867 if (*net_error == OK) { |
1868 *addresses = cache_entry->addrlist; | 1868 *addresses = cache_entry->addrlist; |
1869 EnsurePortOnAddressList(info.port(), addresses); | 1869 EnsurePortOnAddressList(info.port(), addresses); |
1870 } | 1870 } |
1871 return true; | 1871 return true; |
1872 } | 1872 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2051 // |this| may be deleted inside AbortAllInProgressJobs(). | 2051 // |this| may be deleted inside AbortAllInProgressJobs(). |
2052 if (self) | 2052 if (self) |
2053 TryServingAllJobsFromHosts(); | 2053 TryServingAllJobsFromHosts(); |
2054 } | 2054 } |
2055 | 2055 |
2056 bool HostResolverImpl::HaveDnsConfig() const { | 2056 bool HostResolverImpl::HaveDnsConfig() const { |
2057 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 2057 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
2058 } | 2058 } |
2059 | 2059 |
2060 } // namespace net | 2060 } // namespace net |
OLD | NEW |