Chromium Code Reviews| 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.h" | 5 #include "net/dns/host_resolver.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "net/base/net_errors.h" | |
| 12 #include "net/dns/dns_client.h" | 13 #include "net/dns/dns_client.h" |
| 13 #include "net/dns/dns_config_service.h" | 14 #include "net/dns/dns_config_service.h" |
| 14 #include "net/dns/host_cache.h" | 15 #include "net/dns/host_cache.h" |
| 15 #include "net/dns/host_resolver_impl.h" | 16 #include "net/dns/host_resolver_impl.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Maximum of 6 concurrent resolver threads (excluding retries). | 22 // Maximum of 6 concurrent resolver threads (excluding retries). |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 : host_port_pair_(host_port_pair), | 94 : host_port_pair_(host_port_pair), |
| 94 address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 95 address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 95 host_resolver_flags_(0), | 96 host_resolver_flags_(0), |
| 96 allow_cached_response_(true), | 97 allow_cached_response_(true), |
| 97 is_speculative_(false), | 98 is_speculative_(false), |
| 98 is_my_ip_address_(false) {} | 99 is_my_ip_address_(false) {} |
| 99 | 100 |
| 100 HostResolver::~HostResolver() { | 101 HostResolver::~HostResolver() { |
| 101 } | 102 } |
| 102 | 103 |
| 104 int HostResolver::ResolveStaleFromCache(const RequestInfo& info, | |
| 105 AddressList* addresses, | |
| 106 HostCache::EntryStaleness* stale_info, | |
| 107 const BoundNetLog& net_log) { | |
| 108 // If a resolver doesn't know how to get potentially-stale results from the | |
| 109 // cache, blank |*stale_info| and just get fresh results instead. | |
| 110 stale_info->expired_by = base::TimeDelta::FromSeconds(-1); | |
| 111 stale_info->network_changes = 0u; | |
| 112 stale_info->stale_hits = 0u; | |
|
Randy Smith (Not in Mondays)
2016/05/07 01:36:31
The interface spec says that |*stale_info| is only
Julia Tuttle
2016/05/11 20:19:47
Oh, good call. Fixed to set those only if ResolveF
| |
| 113 return ResolveFromCache(info, addresses, net_log); | |
| 114 } | |
| 115 | |
| 116 int HostResolver::ResolveStale(const RequestInfo& info, | |
| 117 RequestPriority priority, | |
| 118 AddressList* addresses, | |
| 119 const CompletionCallback& callback, | |
| 120 RequestHandle* out_req, | |
| 121 int* stale_error, | |
| 122 AddressList* stale_addresses, | |
| 123 HostCache::EntryStaleness* stale_info, | |
| 124 const BoundNetLog& net_log) { | |
| 125 AddressList cache_addresses; | |
| 126 int cache_rv = | |
| 127 ResolveStaleFromCache(info, &cache_addresses, stale_info, net_log); | |
| 128 // If it's a fresh cache hit (or literal), return it synchronously. | |
| 129 if (cache_rv != ERR_DNS_CACHE_MISS && !stale_info->is_stale()) { | |
| 130 *stale_error = ERR_UNEXPECTED; | |
| 131 *addresses = cache_addresses; | |
| 132 return cache_rv; | |
| 133 } | |
| 134 | |
| 135 // If it's a stale cache hit, fill in |*stale_addresses| but run the network | |
| 136 // request anyway. | |
| 137 if (cache_rv != ERR_DNS_CACHE_MISS) | |
| 138 *stale_addresses = cache_addresses; | |
| 139 | |
| 140 *stale_error = cache_rv; | |
| 141 | |
| 142 // Don't check the cache again. | |
| 143 RequestInfo no_cache_info(info); | |
| 144 no_cache_info.set_allow_cached_response(false); | |
| 145 return Resolve(no_cache_info, priority, addresses, callback, out_req, | |
| 146 net_log); | |
| 147 } | |
| 148 | |
| 103 void HostResolver::SetDnsClientEnabled(bool enabled) { | 149 void HostResolver::SetDnsClientEnabled(bool enabled) { |
| 104 } | 150 } |
| 105 | 151 |
| 106 void HostResolver::ChangeRequestPriority(RequestHandle req, | 152 void HostResolver::ChangeRequestPriority(RequestHandle req, |
| 107 RequestPriority priority) { | 153 RequestPriority priority) { |
| 108 NOTIMPLEMENTED(); | 154 NOTIMPLEMENTED(); |
| 109 } | 155 } |
| 110 | 156 |
| 111 HostCache* HostResolver::GetHostCache() { | 157 HostCache* HostResolver::GetHostCache() { |
| 112 return NULL; | 158 return nullptr; |
| 113 } | 159 } |
| 114 | 160 |
| 115 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { | 161 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { |
| 116 return nullptr; | 162 return nullptr; |
| 117 } | 163 } |
| 118 | 164 |
| 119 // static | 165 // static |
| 120 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( | 166 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( |
| 121 const Options& options, | 167 const Options& options, |
| 122 NetLog* net_log) { | 168 NetLog* net_log) { |
| 123 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); | 169 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); |
| 124 } | 170 } |
| 125 | 171 |
| 126 // static | 172 // static |
| 127 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( | 173 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( |
| 128 NetLog* net_log) { | 174 NetLog* net_log) { |
| 129 return std::unique_ptr<HostResolver>( | 175 return std::unique_ptr<HostResolver>( |
| 130 new HostResolverImpl(Options(), net_log)); | 176 new HostResolverImpl(Options(), net_log)); |
| 131 } | 177 } |
| 132 | 178 |
| 133 HostResolver::HostResolver() { | 179 HostResolver::HostResolver() { |
| 134 } | 180 } |
| 135 | 181 |
| 136 } // namespace net | 182 } // namespace net |
| OLD | NEW |