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 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); | 1718 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); |
1719 return rv; | 1719 return rv; |
1720 } | 1720 } |
1721 | 1721 |
1722 // Next we need to attach our request to a "job". This job is responsible for | 1722 // Next we need to attach our request to a "job". This job is responsible for |
1723 // calling "getaddrinfo(hostname)" on a worker thread. | 1723 // calling "getaddrinfo(hostname)" on a worker thread. |
1724 | 1724 |
1725 JobMap::iterator jobit = jobs_.find(key); | 1725 JobMap::iterator jobit = jobs_.find(key); |
1726 Job* job; | 1726 Job* job; |
1727 if (jobit == jobs_.end()) { | 1727 if (jobit == jobs_.end()) { |
1728 // If we couldn't find the desired address family, check to see if the | |
1729 // other family is in the cache or another job, which indicates waste, | |
1730 // and we should fix crbug.com/139811. | |
1731 { | |
1732 bool ipv4 = key.address_family == ADDRESS_FAMILY_IPV4; | |
1733 Key other_family_key = key; | |
1734 other_family_key.address_family = ipv4 ? | |
1735 ADDRESS_FAMILY_UNSPECIFIED : ADDRESS_FAMILY_IPV4; | |
1736 bool found_other_family_cache = false; | |
1737 bool found_other_family_job = false; | |
1738 if (default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED) { | |
1739 found_other_family_cache = cache_.get() && | |
1740 cache_->Lookup(other_family_key, base::TimeTicks::Now()) != NULL; | |
1741 if (!found_other_family_cache) | |
1742 found_other_family_job = jobs_.count(other_family_key) > 0; | |
1743 } | |
1744 enum { // Used in UMA_HISTOGRAM_ENUMERATION. | |
1745 AF_WASTE_IPV4_ONLY, | |
1746 AF_WASTE_CACHE_IPV4, | |
1747 AF_WASTE_CACHE_UNSPEC, | |
1748 AF_WASTE_JOB_IPV4, | |
1749 AF_WASTE_JOB_UNSPEC, | |
1750 AF_WASTE_NONE_IPV4, | |
1751 AF_WASTE_NONE_UNSPEC, | |
1752 AF_WASTE_MAX, // Bounding value. | |
1753 } category = AF_WASTE_MAX; | |
1754 if (default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | |
1755 category = AF_WASTE_IPV4_ONLY; | |
1756 } else if (found_other_family_cache) { | |
1757 category = ipv4 ? AF_WASTE_CACHE_IPV4 : AF_WASTE_CACHE_UNSPEC; | |
1758 } else if (found_other_family_job) { | |
1759 category = ipv4 ? AF_WASTE_JOB_IPV4 : AF_WASTE_JOB_UNSPEC; | |
1760 } else { | |
1761 category = ipv4 ? AF_WASTE_NONE_IPV4 : AF_WASTE_NONE_UNSPEC; | |
1762 } | |
1763 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveUnspecWaste", category, | |
1764 AF_WASTE_MAX); | |
1765 } | |
1766 | |
1767 job = new Job(weak_ptr_factory_.GetWeakPtr(), key, info.priority(), | 1728 job = new Job(weak_ptr_factory_.GetWeakPtr(), key, info.priority(), |
1768 request_net_log); | 1729 request_net_log); |
1769 job->Schedule(); | 1730 job->Schedule(); |
1770 | 1731 |
1771 // Check for queue overflow. | 1732 // Check for queue overflow. |
1772 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { | 1733 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { |
1773 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); | 1734 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); |
1774 DCHECK(evicted); | 1735 DCHECK(evicted); |
1775 evicted->OnEvicted(); // Deletes |evicted|. | 1736 evicted->OnEvicted(); // Deletes |evicted|. |
1776 if (evicted == job) { | 1737 if (evicted == job) { |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 } | 2129 } |
2169 DnsConfig dns_config; | 2130 DnsConfig dns_config; |
2170 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2131 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2171 dns_client_->SetConfig(dns_config); | 2132 dns_client_->SetConfig(dns_config); |
2172 num_dns_failures_ = 0; | 2133 num_dns_failures_ = 0; |
2173 if (dns_config.IsValid()) | 2134 if (dns_config.IsValid()) |
2174 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2135 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2175 } | 2136 } |
2176 | 2137 |
2177 } // namespace net | 2138 } // namespace net |
OLD | NEW |