| 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 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1715 DCHECK(addresses); | 1715 DCHECK(addresses); |
| 1716 DCHECK(net_error); | 1716 DCHECK(net_error); |
| 1717 if (!info.allow_cached_response() || !cache_.get()) | 1717 if (!info.allow_cached_response() || !cache_.get()) |
| 1718 return false; | 1718 return false; |
| 1719 | 1719 |
| 1720 const HostCache::Entry* cache_entry = cache_->Lookup( | 1720 const HostCache::Entry* cache_entry = cache_->Lookup( |
| 1721 key, base::TimeTicks::Now()); | 1721 key, base::TimeTicks::Now()); |
| 1722 if (!cache_entry) | 1722 if (!cache_entry) |
| 1723 return false; | 1723 return false; |
| 1724 | 1724 |
| 1725 | |
| 1726 *net_error = cache_entry->error; | 1725 *net_error = cache_entry->error; |
| 1727 if (*net_error == OK) | 1726 if (*net_error == OK) |
| 1728 *addresses = CreateAddressListUsingPort(cache_entry->addrlist, info.port()); | 1727 *addresses = CreateAddressListUsingPort(cache_entry->addrlist, info.port()); |
| 1729 return true; | 1728 return true; |
| 1730 } | 1729 } |
| 1731 | 1730 |
| 1732 bool HostResolverImpl::ServeFromHosts(const Key& key, | 1731 bool HostResolverImpl::ServeFromHosts(const Key& key, |
| 1733 const RequestInfo& info, | 1732 const RequestInfo& info, |
| 1734 AddressList* addresses) { | 1733 AddressList* addresses) { |
| 1735 DCHECK(addresses); | 1734 DCHECK(addresses); |
| 1736 if (!HaveDnsConfig()) | 1735 if (!HaveDnsConfig()) |
| 1737 return false; | 1736 return false; |
| 1738 | 1737 |
| 1738 // HOSTS lookups are case-insensitive. |
| 1739 std::string hostname = StringToLowerASCII(key.hostname); |
| 1740 |
| 1739 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations | 1741 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations |
| 1740 // (glibc and c-ares) return the first matching line. We have more | 1742 // (glibc and c-ares) return the first matching line. We have more |
| 1741 // flexibility, but lose implicit ordering. | 1743 // flexibility, but lose implicit ordering. |
| 1742 // TODO(szym) http://crbug.com/117850 | 1744 // TODO(szym) http://crbug.com/117850 |
| 1743 const DnsHosts& hosts = dns_client_->GetConfig()->hosts; | 1745 const DnsHosts& hosts = dns_client_->GetConfig()->hosts; |
| 1744 DnsHosts::const_iterator it = hosts.find( | 1746 DnsHosts::const_iterator it = hosts.find( |
| 1745 DnsHostsKey(key.hostname, | 1747 DnsHostsKey(hostname, |
| 1746 key.address_family == ADDRESS_FAMILY_UNSPECIFIED ? | 1748 key.address_family == ADDRESS_FAMILY_UNSPECIFIED ? |
| 1747 ADDRESS_FAMILY_IPV4 : key.address_family)); | 1749 ADDRESS_FAMILY_IPV4 : key.address_family)); |
| 1748 | 1750 |
| 1749 if (it == hosts.end()) { | 1751 if (it == hosts.end()) { |
| 1750 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED) | 1752 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED) |
| 1751 return false; | 1753 return false; |
| 1752 | 1754 |
| 1753 it = hosts.find(DnsHostsKey(key.hostname, ADDRESS_FAMILY_IPV6)); | 1755 it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6)); |
| 1754 if (it == hosts.end()) | 1756 if (it == hosts.end()) |
| 1755 return false; | 1757 return false; |
| 1756 } | 1758 } |
| 1757 | 1759 |
| 1758 *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); | 1760 *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); |
| 1759 return true; | 1761 return true; |
| 1760 } | 1762 } |
| 1761 | 1763 |
| 1762 void HostResolverImpl::CacheResult(const Key& key, | 1764 void HostResolverImpl::CacheResult(const Key& key, |
| 1763 int net_error, | 1765 int net_error, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 | 1912 |
| 1911 if (self && dns_config.IsValid()) | 1913 if (self && dns_config.IsValid()) |
| 1912 TryServingAllJobsFromHosts(); | 1914 TryServingAllJobsFromHosts(); |
| 1913 } | 1915 } |
| 1914 | 1916 |
| 1915 bool HostResolverImpl::HaveDnsConfig() const { | 1917 bool HostResolverImpl::HaveDnsConfig() const { |
| 1916 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 1918 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
| 1917 } | 1919 } |
| 1918 | 1920 |
| 1919 } // namespace net | 1921 } // namespace net |
| OLD | NEW |