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 <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 friend class HostResolverImplTest; | 150 friend class HostResolverImplTest; |
151 class Job; | 151 class Job; |
152 class ProcTask; | 152 class ProcTask; |
153 class LoopbackProbeJob; | 153 class LoopbackProbeJob; |
154 class DnsTask; | 154 class DnsTask; |
155 class Request; | 155 class Request; |
156 typedef HostCache::Key Key; | 156 typedef HostCache::Key Key; |
157 typedef std::map<Key, Job*> JobMap; | 157 typedef std::map<Key, Job*> JobMap; |
158 typedef ScopedVector<Request> RequestsList; | 158 typedef ScopedVector<Request> RequestsList; |
159 | 159 |
| 160 // Number of consecutive failures of DnsTask (with successful fallback to |
| 161 // ProcTask) before the DnsClient is disabled until the next DNS change. |
| 162 static const unsigned kMaximumDnsFailures; |
| 163 |
160 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP | 164 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP |
161 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, | 165 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, |
162 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is | 166 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is |
163 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and HOSTS. | 167 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and HOSTS. |
164 int ResolveHelper(const Key& key, | 168 int ResolveHelper(const Key& key, |
165 const RequestInfo& info, | 169 const RequestInfo& info, |
166 AddressList* addresses, | 170 AddressList* addresses, |
167 const BoundNetLog& request_net_log); | 171 const BoundNetLog& request_net_log); |
168 | 172 |
169 // Tries to resolve |key| as an IP, returns true and sets |net_error| if | 173 // Tries to resolve |key| as an IP, returns true and sets |net_error| if |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 const HostCache::Entry& entry, | 205 const HostCache::Entry& entry, |
202 base::TimeDelta ttl); | 206 base::TimeDelta ttl); |
203 | 207 |
204 // Removes |job| from |jobs_|, only if it exists. | 208 // Removes |job| from |jobs_|, only if it exists. |
205 void RemoveJob(Job* job); | 209 void RemoveJob(Job* job); |
206 | 210 |
207 // Aborts all in progress jobs with ERR_NETWORK_CHANGED and notifies their | 211 // Aborts all in progress jobs with ERR_NETWORK_CHANGED and notifies their |
208 // requests. Might start new jobs. | 212 // requests. Might start new jobs. |
209 void AbortAllInProgressJobs(); | 213 void AbortAllInProgressJobs(); |
210 | 214 |
| 215 // Aborts all in progress DnsTasks. In-progress jobs will fall back to |
| 216 // ProcTasks. Might start new jobs, if any jobs were taking up two dispatcher |
| 217 // slots. |
| 218 void AbortDnsTasks(); |
| 219 |
211 // Attempts to serve each Job in |jobs_| from the HOSTS file if we have | 220 // Attempts to serve each Job in |jobs_| from the HOSTS file if we have |
212 // a DnsClient with a valid DnsConfig. | 221 // a DnsClient with a valid DnsConfig. |
213 void TryServingAllJobsFromHosts(); | 222 void TryServingAllJobsFromHosts(); |
214 | 223 |
215 // NetworkChangeNotifier::IPAddressObserver: | 224 // NetworkChangeNotifier::IPAddressObserver: |
216 virtual void OnIPAddressChanged() OVERRIDE; | 225 virtual void OnIPAddressChanged() OVERRIDE; |
217 | 226 |
218 // NetworkChangeNotifier::DNSObserver: | 227 // NetworkChangeNotifier::DNSObserver: |
219 virtual void OnDNSChanged() OVERRIDE; | 228 virtual void OnDNSChanged() OVERRIDE; |
220 | 229 |
221 // True if have a DnsClient with a valid DnsConfig. | 230 // True if have a DnsClient with a valid DnsConfig. |
222 bool HaveDnsConfig() const; | 231 bool HaveDnsConfig() const; |
223 | 232 |
224 // Called when a host name is successfully resolved and DnsTask was run on it | 233 // Called when a host name is successfully resolved and DnsTask was run on it |
225 // and resulted in |net_error|. | 234 // and resulted in |net_error|. |
226 void OnDnsTaskResolve(int net_error); | 235 void OnDnsTaskResolve(int net_error); |
227 | 236 |
228 // Allows the tests to catch slots leaking out of the dispatcher. | 237 // Allows the tests to catch slots leaking out of the dispatcher. One |
229 size_t num_running_jobs_for_tests() const { | 238 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job |
| 239 // slots. |
| 240 size_t num_running_dispatcher_jobs_for_tests() const { |
230 return dispatcher_.num_running_jobs(); | 241 return dispatcher_.num_running_jobs(); |
231 } | 242 } |
232 | 243 |
233 // Cache of host resolution results. | 244 // Cache of host resolution results. |
234 scoped_ptr<HostCache> cache_; | 245 scoped_ptr<HostCache> cache_; |
235 | 246 |
236 // Map from HostCache::Key to a Job. | 247 // Map from HostCache::Key to a Job. |
237 JobMap jobs_; | 248 JobMap jobs_; |
238 | 249 |
239 // Starts Jobs according to their priority and the configured limits. | 250 // Starts Jobs according to their priority and the configured limits. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 288 |
278 // Allow fallback to ProcTask if DnsTask fails. | 289 // Allow fallback to ProcTask if DnsTask fails. |
279 bool fallback_to_proctask_; | 290 bool fallback_to_proctask_; |
280 | 291 |
281 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 292 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
282 }; | 293 }; |
283 | 294 |
284 } // namespace net | 295 } // namespace net |
285 | 296 |
286 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 297 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |