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 #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 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 return true; | 1944 return true; |
1945 } | 1945 } |
1946 | 1946 |
1947 bool HostResolverImpl::ServeFromHosts(const Key& key, | 1947 bool HostResolverImpl::ServeFromHosts(const Key& key, |
1948 const RequestInfo& info, | 1948 const RequestInfo& info, |
1949 AddressList* addresses) { | 1949 AddressList* addresses) { |
1950 DCHECK(addresses); | 1950 DCHECK(addresses); |
1951 if (!HaveDnsConfig()) | 1951 if (!HaveDnsConfig()) |
1952 return false; | 1952 return false; |
1953 | 1953 |
| 1954 addresses->clear(); |
| 1955 |
1954 // HOSTS lookups are case-insensitive. | 1956 // HOSTS lookups are case-insensitive. |
1955 std::string hostname = StringToLowerASCII(key.hostname); | 1957 std::string hostname = StringToLowerASCII(key.hostname); |
1956 | 1958 |
| 1959 const DnsHosts& hosts = dns_client_->GetConfig()->hosts; |
| 1960 |
1957 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations | 1961 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations |
1958 // (glibc and c-ares) return the first matching line. We have more | 1962 // (glibc and c-ares) return the first matching line. We have more |
1959 // flexibility, but lose implicit ordering. | 1963 // flexibility, but lose implicit ordering. |
1960 // TODO(szym) http://crbug.com/117850 | 1964 // We prefer IPv6 because "happy eyeballs" will fall back to IPv4 if |
1961 const DnsHosts& hosts = dns_client_->GetConfig()->hosts; | 1965 // necessary. |
1962 DnsHosts::const_iterator it = hosts.find( | 1966 if (key.address_family == ADDRESS_FAMILY_IPV6 || |
1963 DnsHostsKey(hostname, | 1967 key.address_family == ADDRESS_FAMILY_UNSPECIFIED) { |
1964 key.address_family == ADDRESS_FAMILY_UNSPECIFIED ? | 1968 DnsHosts::const_iterator it = hosts.find( |
1965 ADDRESS_FAMILY_IPV4 : key.address_family)); | 1969 DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6)); |
1966 | 1970 if (it != hosts.end()) |
1967 if (it == hosts.end()) { | 1971 addresses->push_back(IPEndPoint(it->second, info.port())); |
1968 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED) | |
1969 return false; | |
1970 | |
1971 it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6)); | |
1972 if (it == hosts.end()) | |
1973 return false; | |
1974 } | 1972 } |
1975 | 1973 |
1976 *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); | 1974 if (key.address_family == ADDRESS_FAMILY_IPV4 || |
1977 return true; | 1975 key.address_family == ADDRESS_FAMILY_UNSPECIFIED) { |
| 1976 DnsHosts::const_iterator it = hosts.find( |
| 1977 DnsHostsKey(hostname, ADDRESS_FAMILY_IPV4)); |
| 1978 if (it != hosts.end()) |
| 1979 addresses->push_back(IPEndPoint(it->second, info.port())); |
| 1980 } |
| 1981 |
| 1982 return !addresses->empty(); |
1978 } | 1983 } |
1979 | 1984 |
1980 void HostResolverImpl::CacheResult(const Key& key, | 1985 void HostResolverImpl::CacheResult(const Key& key, |
1981 const HostCache::Entry& entry, | 1986 const HostCache::Entry& entry, |
1982 base::TimeDelta ttl) { | 1987 base::TimeDelta ttl) { |
1983 if (cache_.get()) | 1988 if (cache_.get()) |
1984 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); | 1989 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); |
1985 } | 1990 } |
1986 | 1991 |
1987 void HostResolverImpl::RemoveJob(Job* job) { | 1992 void HostResolverImpl::RemoveJob(Job* job) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2171 } | 2176 } |
2172 DnsConfig dns_config; | 2177 DnsConfig dns_config; |
2173 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2178 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2174 dns_client_->SetConfig(dns_config); | 2179 dns_client_->SetConfig(dns_config); |
2175 num_dns_failures_ = 0; | 2180 num_dns_failures_ = 0; |
2176 if (dns_config.IsValid()) | 2181 if (dns_config.IsValid()) |
2177 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2182 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2178 } | 2183 } |
2179 | 2184 |
2180 } // namespace net | 2185 } // namespace net |
OLD | NEW |