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 #ifndef NET_DNS_HOST_RESOLVER_IMPL_H_ | 5 #ifndef NET_DNS_HOST_RESOLVER_IMPL_H_ |
6 #define NET_DNS_HOST_RESOLVER_IMPL_H_ | 6 #define NET_DNS_HOST_RESOLVER_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // NetworkChangeNotifier. | 130 // NetworkChangeNotifier. |
131 void SetDnsClient(std::unique_ptr<DnsClient> dns_client); | 131 void SetDnsClient(std::unique_ptr<DnsClient> dns_client); |
132 | 132 |
133 // HostResolver methods: | 133 // HostResolver methods: |
134 int Resolve(const RequestInfo& info, | 134 int Resolve(const RequestInfo& info, |
135 RequestPriority priority, | 135 RequestPriority priority, |
136 AddressList* addresses, | 136 AddressList* addresses, |
137 const CompletionCallback& callback, | 137 const CompletionCallback& callback, |
138 RequestHandle* out_req, | 138 RequestHandle* out_req, |
139 const BoundNetLog& source_net_log) override; | 139 const BoundNetLog& source_net_log) override; |
140 void ChangeRequestPriority(RequestHandle req, | |
141 RequestPriority priority) override; | |
142 void CancelRequest(RequestHandle req) override; | |
140 int ResolveFromCache(const RequestInfo& info, | 143 int ResolveFromCache(const RequestInfo& info, |
141 AddressList* addresses, | 144 AddressList* addresses, |
142 const BoundNetLog& source_net_log) override; | 145 const BoundNetLog& source_net_log) override; |
143 void ChangeRequestPriority(RequestHandle req, | 146 int ResolveStaleFromCache(const RequestInfo& info, |
144 RequestPriority priority) override; | 147 AddressList* addresses, |
145 void CancelRequest(RequestHandle req) override; | 148 HostCache::EntryStaleness* stale_info, |
149 const BoundNetLog& source_net_log) override; | |
146 void SetDnsClientEnabled(bool enabled) override; | 150 void SetDnsClientEnabled(bool enabled) override; |
147 HostCache* GetHostCache() override; | 151 HostCache* GetHostCache() override; |
148 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; | 152 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; |
149 | 153 |
150 void set_proc_params_for_test(const ProcTaskParams& proc_params) { | 154 void set_proc_params_for_test(const ProcTaskParams& proc_params) { |
151 proc_params_ = proc_params; | 155 proc_params_ = proc_params; |
152 } | 156 } |
153 | 157 |
154 private: | 158 private: |
155 friend class HostResolverImplTest; | 159 friend class HostResolverImplTest; |
156 class Job; | 160 class Job; |
157 class ProcTask; | 161 class ProcTask; |
158 class LoopbackProbeJob; | 162 class LoopbackProbeJob; |
159 class DnsTask; | 163 class DnsTask; |
160 class Request; | 164 class Request; |
161 typedef HostCache::Key Key; | 165 typedef HostCache::Key Key; |
162 typedef std::map<Key, Job*> JobMap; | 166 typedef std::map<Key, Job*> JobMap; |
163 | 167 |
164 // Number of consecutive failures of DnsTask (with successful fallback to | 168 // Number of consecutive failures of DnsTask (with successful fallback to |
165 // ProcTask) before the DnsClient is disabled until the next DNS change. | 169 // ProcTask) before the DnsClient is disabled until the next DNS change. |
166 static const unsigned kMaximumDnsFailures; | 170 static const unsigned kMaximumDnsFailures; |
167 | 171 |
168 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP | 172 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP |
169 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, | 173 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, |
170 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is | 174 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is |
171 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and | 175 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and |
172 // HOSTS and is not localhost. | 176 // HOSTS and is not localhost. |
177 // | |
178 // If |stale_info| is non-null, then stale cache entries can be returned, and | |
179 // |*stale_info| will be filled in with details of the entry's staleness (if | |
180 // an entry, fresh or stale, was returned). | |
Randy Smith (Not in Mondays)
2016/05/17 20:39:35
I think this comment needs to be updated? |allow_
Julia Tuttle
2016/05/20 17:54:42
Done.
| |
173 int ResolveHelper(const Key& key, | 181 int ResolveHelper(const Key& key, |
174 const RequestInfo& info, | 182 const RequestInfo& info, |
175 const IPAddress* ip_address, | 183 const IPAddress* ip_address, |
176 AddressList* addresses, | 184 AddressList* addresses, |
185 bool allow_stale, | |
186 HostCache::EntryStaleness* stale_info, | |
177 const BoundNetLog& request_net_log); | 187 const BoundNetLog& request_net_log); |
178 | 188 |
179 // Tries to resolve |key| as an IP, returns true and sets |net_error| if | 189 // Tries to resolve |key| as an IP, returns true and sets |net_error| if |
180 // succeeds, returns false otherwise. | 190 // succeeds, returns false otherwise. |
181 bool ResolveAsIP(const Key& key, | 191 bool ResolveAsIP(const Key& key, |
182 const RequestInfo& info, | 192 const RequestInfo& info, |
183 const IPAddress* ip_address, | 193 const IPAddress* ip_address, |
184 int* net_error, | 194 int* net_error, |
185 AddressList* addresses); | 195 AddressList* addresses); |
186 | 196 |
187 // If |key| is not found in cache returns false, otherwise returns | 197 // If |key| is not found in cache returns false, otherwise returns |
188 // true, sets |net_error| to the cached error code and fills |addresses| | 198 // true, sets |net_error| to the cached error code and fills |addresses| |
189 // if it is a positive entry. | 199 // if it is a positive entry. |
200 // | |
201 // If |stale_info| is non-null, then stale cache entries can be returned, and | |
202 // |*stale_info| will be filled in with details of the entry's staleness (if | |
203 // an entry, fresh or stale, was returned). | |
190 bool ServeFromCache(const Key& key, | 204 bool ServeFromCache(const Key& key, |
191 const RequestInfo& info, | 205 const RequestInfo& info, |
192 int* net_error, | 206 int* net_error, |
193 AddressList* addresses); | 207 AddressList* addresses, |
208 bool allow_stale, | |
209 HostCache::EntryStaleness* stale_info); | |
194 | 210 |
195 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the | 211 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the |
196 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. | 212 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. |
197 bool ServeFromHosts(const Key& key, | 213 bool ServeFromHosts(const Key& key, |
198 const RequestInfo& info, | 214 const RequestInfo& info, |
199 AddressList* addresses); | 215 AddressList* addresses); |
200 | 216 |
201 // If |key| is for a localhost name (RFC 6761), returns true and fills | 217 // If |key| is for a localhost name (RFC 6761), returns true and fills |
202 // |addresses| with the loopback IP. Otherwise returns false. | 218 // |addresses| with the loopback IP. Otherwise returns false. |
203 bool ServeLocalhost(const Key& key, | 219 bool ServeLocalhost(const Key& key, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 // This function is only exposed so it can be unit-tested. | 342 // This function is only exposed so it can be unit-tested. |
327 // TODO(tfarina): It would be better to change the tests so this function | 343 // TODO(tfarina): It would be better to change the tests so this function |
328 // gets exercised indirectly through HostResolverImpl. | 344 // gets exercised indirectly through HostResolverImpl. |
329 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, | 345 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, |
330 uint16_t port, | 346 uint16_t port, |
331 AddressList* address_list); | 347 AddressList* address_list); |
332 | 348 |
333 } // namespace net | 349 } // namespace net |
334 | 350 |
335 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 351 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |