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 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/power_monitor/power_observer.h" |
16 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
17 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
20 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
22 #include "net/dns/host_cache.h" | 23 #include "net/dns/host_cache.h" |
23 #include "net/dns/host_resolver.h" | 24 #include "net/dns/host_resolver.h" |
24 #include "net/dns/host_resolver_proc.h" | 25 #include "net/dns/host_resolver_proc.h" |
25 | 26 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // | 58 // |
58 // The HostResolverImpl enforces limits on the maximum number of concurrent | 59 // The HostResolverImpl enforces limits on the maximum number of concurrent |
59 // threads using PrioritizedDispatcher::Limits. | 60 // threads using PrioritizedDispatcher::Limits. |
60 // | 61 // |
61 // Jobs are ordered in the queue based on their priority and order of arrival. | 62 // Jobs are ordered in the queue based on their priority and order of arrival. |
62 class NET_EXPORT HostResolverImpl | 63 class NET_EXPORT HostResolverImpl |
63 : public HostResolver, | 64 : public HostResolver, |
64 NON_EXPORTED_BASE(public base::NonThreadSafe), | 65 NON_EXPORTED_BASE(public base::NonThreadSafe), |
65 public NetworkChangeNotifier::IPAddressObserver, | 66 public NetworkChangeNotifier::IPAddressObserver, |
66 public NetworkChangeNotifier::ConnectionTypeObserver, | 67 public NetworkChangeNotifier::ConnectionTypeObserver, |
67 public NetworkChangeNotifier::DNSObserver { | 68 public NetworkChangeNotifier::DNSObserver, |
| 69 public base::PowerObserver { |
68 public: | 70 public: |
69 // Parameters for ProcTask which resolves hostnames using HostResolveProc. | 71 // Parameters for ProcTask which resolves hostnames using HostResolveProc. |
70 // | 72 // |
71 // |resolver_proc| is used to perform the actual resolves; it must be | 73 // |resolver_proc| is used to perform the actual resolves; it must be |
72 // thread-safe since it may be run from multiple worker threads. If | 74 // thread-safe since it may be run from multiple worker threads. If |
73 // |resolver_proc| is NULL then the default host resolver procedure is | 75 // |resolver_proc| is NULL then the default host resolver procedure is |
74 // used (which is SystemHostResolverProc except if overridden). | 76 // used (which is SystemHostResolverProc except if overridden). |
75 // | 77 // |
76 // For each attempt, we could start another attempt if host is not resolved | 78 // For each attempt, we could start another attempt if host is not resolved |
77 // within |unresponsive_delay| time. We keep attempting to resolve the host | 79 // within |unresponsive_delay| time. We keep attempting to resolve the host |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 void OnIPAddressChanged() override; | 285 void OnIPAddressChanged() override; |
284 | 286 |
285 // NetworkChangeNotifier::ConnectionTypeObserver: | 287 // NetworkChangeNotifier::ConnectionTypeObserver: |
286 void OnConnectionTypeChanged( | 288 void OnConnectionTypeChanged( |
287 NetworkChangeNotifier::ConnectionType type) override; | 289 NetworkChangeNotifier::ConnectionType type) override; |
288 | 290 |
289 // NetworkChangeNotifier::DNSObserver: | 291 // NetworkChangeNotifier::DNSObserver: |
290 void OnDNSChanged() override; | 292 void OnDNSChanged() override; |
291 void OnInitialDNSConfigRead() override; | 293 void OnInitialDNSConfigRead() override; |
292 | 294 |
| 295 // base::PowerObserver: |
| 296 void OnSuspend() override; |
| 297 |
293 void UpdateDNSConfig(bool config_changed); | 298 void UpdateDNSConfig(bool config_changed); |
294 | 299 |
295 // True if have a DnsClient with a valid DnsConfig. | 300 // True if have a DnsClient with a valid DnsConfig. |
296 bool HaveDnsConfig() const; | 301 bool HaveDnsConfig() const; |
297 | 302 |
298 // Called when a host name is successfully resolved and DnsTask was run on it | 303 // Called when a host name is successfully resolved and DnsTask was run on it |
299 // and resulted in |net_error|. | 304 // and resulted in |net_error|. |
300 void OnDnsTaskResolve(int net_error); | 305 void OnDnsTaskResolve(int net_error); |
301 | 306 |
302 void OnCacheEntryEvicted(const HostCache::Key& key, | 307 void OnCacheEntryEvicted(const HostCache::Key& key, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // This function is only exposed so it can be unit-tested. | 395 // This function is only exposed so it can be unit-tested. |
391 // TODO(tfarina): It would be better to change the tests so this function | 396 // TODO(tfarina): It would be better to change the tests so this function |
392 // gets exercised indirectly through HostResolverImpl. | 397 // gets exercised indirectly through HostResolverImpl. |
393 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, | 398 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, |
394 uint16_t port, | 399 uint16_t port, |
395 AddressList* address_list); | 400 AddressList* address_list); |
396 | 401 |
397 } // namespace net | 402 } // namespace net |
398 | 403 |
399 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 404 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |