| 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 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 if (num_active_requests() == 0) { | 1743 if (num_active_requests() == 0) { |
| 1744 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 1744 net_log_.AddEvent(NetLog::TYPE_CANCELLED); |
| 1745 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1745 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 1746 OK); | 1746 OK); |
| 1747 return; | 1747 return; |
| 1748 } | 1748 } |
| 1749 | 1749 |
| 1750 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1750 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 1751 entry.error); | 1751 entry.error()); |
| 1752 | 1752 |
| 1753 DCHECK(!requests_.empty()); | 1753 DCHECK(!requests_.empty()); |
| 1754 | 1754 |
| 1755 if (entry.error == OK) { | 1755 if (entry.error() == OK) { |
| 1756 // Record this histogram here, when we know the system has a valid DNS | 1756 // Record this histogram here, when we know the system has a valid DNS |
| 1757 // configuration. | 1757 // configuration. |
| 1758 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", | 1758 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", |
| 1759 resolver_->received_dns_config_); | 1759 resolver_->received_dns_config_); |
| 1760 } | 1760 } |
| 1761 | 1761 |
| 1762 bool did_complete = (entry.error != ERR_NETWORK_CHANGED) && | 1762 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) && |
| 1763 (entry.error != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); | 1763 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); |
| 1764 if (did_complete) | 1764 if (did_complete) |
| 1765 resolver_->CacheResult(key_, entry, ttl); | 1765 resolver_->CacheResult(key_, entry, ttl); |
| 1766 | 1766 |
| 1767 // Complete all of the requests that were attached to the job. | 1767 // Complete all of the requests that were attached to the job. |
| 1768 for (const std::unique_ptr<Request>& req : requests_) { | 1768 for (const std::unique_ptr<Request>& req : requests_) { |
| 1769 if (req->was_canceled()) | 1769 if (req->was_canceled()) |
| 1770 continue; | 1770 continue; |
| 1771 | 1771 |
| 1772 DCHECK_EQ(this, req->job()); | 1772 DCHECK_EQ(this, req->job()); |
| 1773 // Update the net log and notify registered observers. | 1773 // Update the net log and notify registered observers. |
| 1774 LogFinishRequest(req->source_net_log(), req->info(), entry.error); | 1774 LogFinishRequest(req->source_net_log(), req->info(), entry.error()); |
| 1775 if (did_complete) { | 1775 if (did_complete) { |
| 1776 // Record effective total time from creation to completion. | 1776 // Record effective total time from creation to completion. |
| 1777 RecordTotalTime(had_dns_config_, req->info().is_speculative(), | 1777 RecordTotalTime(had_dns_config_, req->info().is_speculative(), |
| 1778 base::TimeTicks::Now() - req->request_time()); | 1778 base::TimeTicks::Now() - req->request_time()); |
| 1779 } | 1779 } |
| 1780 req->OnComplete(entry.error, entry.addrlist); | 1780 req->OnComplete(entry.error(), entry.addresses()); |
| 1781 | 1781 |
| 1782 // Check if the resolver was destroyed as a result of running the | 1782 // Check if the resolver was destroyed as a result of running the |
| 1783 // callback. If it was, we could continue, but we choose to bail. | 1783 // callback. If it was, we could continue, but we choose to bail. |
| 1784 if (!resolver_.get()) | 1784 if (!resolver_.get()) |
| 1785 return; | 1785 return; |
| 1786 } | 1786 } |
| 1787 } | 1787 } |
| 1788 | 1788 |
| 1789 // Convenience wrapper for CompleteRequests in case of failure. | 1789 // Convenience wrapper for CompleteRequests in case of failure. |
| 1790 void CompleteRequestsWithError(int net_error) { | 1790 void CompleteRequestsWithError(int net_error) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2134 DCHECK(addresses); | 2134 DCHECK(addresses); |
| 2135 DCHECK(net_error); | 2135 DCHECK(net_error); |
| 2136 if (!info.allow_cached_response() || !cache_.get()) | 2136 if (!info.allow_cached_response() || !cache_.get()) |
| 2137 return false; | 2137 return false; |
| 2138 | 2138 |
| 2139 const HostCache::Entry* cache_entry = cache_->Lookup( | 2139 const HostCache::Entry* cache_entry = cache_->Lookup( |
| 2140 key, base::TimeTicks::Now()); | 2140 key, base::TimeTicks::Now()); |
| 2141 if (!cache_entry) | 2141 if (!cache_entry) |
| 2142 return false; | 2142 return false; |
| 2143 | 2143 |
| 2144 *net_error = cache_entry->error; | 2144 *net_error = cache_entry->error(); |
| 2145 if (*net_error == OK) { | 2145 if (*net_error == OK) { |
| 2146 if (cache_entry->has_ttl()) | 2146 if (cache_entry->has_ttl()) |
| 2147 RecordTTL(cache_entry->ttl); | 2147 RecordTTL(cache_entry->ttl()); |
| 2148 *addresses = EnsurePortOnAddressList(cache_entry->addrlist, info.port()); | 2148 *addresses = EnsurePortOnAddressList(cache_entry->addresses(), info.port()); |
| 2149 } | 2149 } |
| 2150 return true; | 2150 return true; |
| 2151 } | 2151 } |
| 2152 | 2152 |
| 2153 bool HostResolverImpl::ServeFromHosts(const Key& key, | 2153 bool HostResolverImpl::ServeFromHosts(const Key& key, |
| 2154 const RequestInfo& info, | 2154 const RequestInfo& info, |
| 2155 AddressList* addresses) { | 2155 AddressList* addresses) { |
| 2156 DCHECK(addresses); | 2156 DCHECK(addresses); |
| 2157 if (!HaveDnsConfig()) | 2157 if (!HaveDnsConfig()) |
| 2158 return false; | 2158 return false; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2482 dns_client_->SetConfig(dns_config); | 2482 dns_client_->SetConfig(dns_config); |
| 2483 num_dns_failures_ = 0; | 2483 num_dns_failures_ = 0; |
| 2484 if (dns_client_->GetConfig()) | 2484 if (dns_client_->GetConfig()) |
| 2485 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2485 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2486 } | 2486 } |
| 2487 | 2487 |
| 2488 AbortDnsTasks(); | 2488 AbortDnsTasks(); |
| 2489 } | 2489 } |
| 2490 | 2490 |
| 2491 } // namespace net | 2491 } // namespace net |
| OLD | NEW |