| 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_BASE_HOST_RESOLVER_IMPL_H_ | 5 #ifndef NET_BASE_HOST_RESOLVER_IMPL_H_ |
| 6 #define NET_BASE_HOST_RESOLVER_IMPL_H_ | 6 #define NET_BASE_HOST_RESOLVER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "net/base/capturing_net_log.h" | 17 #include "net/base/capturing_net_log.h" |
| 18 #include "net/base/host_cache.h" | 18 #include "net/base/host_cache.h" |
| 19 #include "net/base/host_resolver.h" | 19 #include "net/base/host_resolver.h" |
| 20 #include "net/base/host_resolver_proc.h" | 20 #include "net/base/host_resolver_proc.h" |
| 21 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
| 22 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 23 #include "net/base/prioritized_dispatcher.h" | 23 #include "net/base/prioritized_dispatcher.h" |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class BoundNetLog; | 27 class BoundNetLog; |
| 28 class DnsClient; | 28 class DnsClient; |
| 29 struct DnsConfig; | |
| 30 class DnsConfigService; | |
| 31 class NetLog; | 29 class NetLog; |
| 32 | 30 |
| 33 // For each hostname that is requested, HostResolver creates a | 31 // For each hostname that is requested, HostResolver creates a |
| 34 // HostResolverImpl::Job. When this job gets dispatched it creates a ProcTask | 32 // HostResolverImpl::Job. When this job gets dispatched it creates a ProcTask |
| 35 // which runs the given HostResolverProc on a WorkerPool thread. If requests for | 33 // which runs the given HostResolverProc on a WorkerPool thread. If requests for |
| 36 // that same host are made during the job's lifetime, they are attached to the | 34 // that same host are made during the job's lifetime, they are attached to the |
| 37 // existing job rather than creating a new one. This avoids doing parallel | 35 // existing job rather than creating a new one. This avoids doing parallel |
| 38 // resolves for the same host. | 36 // resolves for the same host. |
| 39 // | 37 // |
| 40 // The way these classes fit together is illustrated by: | 38 // The way these classes fit together is illustrated by: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 // from one thread! | 53 // from one thread! |
| 56 // | 54 // |
| 57 // The HostResolverImpl enforces limits on the maximum number of concurrent | 55 // The HostResolverImpl enforces limits on the maximum number of concurrent |
| 58 // threads using PrioritizedDispatcher::Limits. | 56 // threads using PrioritizedDispatcher::Limits. |
| 59 // | 57 // |
| 60 // Jobs are ordered in the queue based on their priority and order of arrival. | 58 // Jobs are ordered in the queue based on their priority and order of arrival. |
| 61 class NET_EXPORT HostResolverImpl | 59 class NET_EXPORT HostResolverImpl |
| 62 : public HostResolver, | 60 : public HostResolver, |
| 63 NON_EXPORTED_BASE(public base::NonThreadSafe), | 61 NON_EXPORTED_BASE(public base::NonThreadSafe), |
| 64 public NetworkChangeNotifier::IPAddressObserver, | 62 public NetworkChangeNotifier::IPAddressObserver, |
| 63 public NetworkChangeNotifier::DNSObserver, |
| 65 public base::SupportsWeakPtr<HostResolverImpl> { | 64 public base::SupportsWeakPtr<HostResolverImpl> { |
| 66 public: | 65 public: |
| 67 // Parameters for ProcTask which resolves hostnames using HostResolveProc. | 66 // Parameters for ProcTask which resolves hostnames using HostResolveProc. |
| 68 // | 67 // |
| 69 // |resolver_proc| is used to perform the actual resolves; it must be | 68 // |resolver_proc| is used to perform the actual resolves; it must be |
| 70 // thread-safe since it is run from multiple worker threads. If | 69 // thread-safe since it is run from multiple worker threads. If |
| 71 // |resolver_proc| is NULL then the default host resolver procedure is | 70 // |resolver_proc| is NULL then the default host resolver procedure is |
| 72 // used (which is SystemHostResolverProc except if overridden). | 71 // used (which is SystemHostResolverProc except if overridden). |
| 73 // | 72 // |
| 74 // For each attempt, we could start another attempt if host is not resolved | 73 // For each attempt, we could start another attempt if host is not resolved |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // |dns_config_service| will be used to detect changes to DNS configuration | 112 // |dns_config_service| will be used to detect changes to DNS configuration |
| 114 // and obtain DnsConfig for DnsClient. | 113 // and obtain DnsConfig for DnsClient. |
| 115 // | 114 // |
| 116 // |dns_client|, if set, will be used to resolve requests. | 115 // |dns_client|, if set, will be used to resolve requests. |
| 117 // | 116 // |
| 118 // |net_log| must remain valid for the life of the HostResolverImpl. | 117 // |net_log| must remain valid for the life of the HostResolverImpl. |
| 119 // TODO(szym): change to scoped_ptr<HostCache>. | 118 // TODO(szym): change to scoped_ptr<HostCache>. |
| 120 HostResolverImpl(HostCache* cache, | 119 HostResolverImpl(HostCache* cache, |
| 121 const PrioritizedDispatcher::Limits& job_limits, | 120 const PrioritizedDispatcher::Limits& job_limits, |
| 122 const ProcTaskParams& proc_params, | 121 const ProcTaskParams& proc_params, |
| 123 scoped_ptr<DnsConfigService> dns_config_service, | |
| 124 scoped_ptr<DnsClient> dns_client, | 122 scoped_ptr<DnsClient> dns_client, |
| 125 NetLog* net_log); | 123 NetLog* net_log); |
| 126 | 124 |
| 127 // If any completion callbacks are pending when the resolver is destroyed, | 125 // If any completion callbacks are pending when the resolver is destroyed, |
| 128 // the host resolutions are cancelled, and the completion callbacks will not | 126 // the host resolutions are cancelled, and the completion callbacks will not |
| 129 // be called. | 127 // be called. |
| 130 virtual ~HostResolverImpl(); | 128 virtual ~HostResolverImpl(); |
| 131 | 129 |
| 132 // Configures maximum number of Jobs in the queue. Exposed for testing. | 130 // Configures maximum number of Jobs in the queue. Exposed for testing. |
| 133 // Only allowed when the queue is empty. | 131 // Only allowed when the queue is empty. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // Might start new jobs. | 212 // Might start new jobs. |
| 215 void AbortAllInProgressJobs(); | 213 void AbortAllInProgressJobs(); |
| 216 | 214 |
| 217 // Attempts to serve each Job in |jobs_| from the HOSTS file if we have | 215 // Attempts to serve each Job in |jobs_| from the HOSTS file if we have |
| 218 // a DnsClient with a valid DnsConfig. | 216 // a DnsClient with a valid DnsConfig. |
| 219 void TryServingAllJobsFromHosts(); | 217 void TryServingAllJobsFromHosts(); |
| 220 | 218 |
| 221 // NetworkChangeNotifier::IPAddressObserver: | 219 // NetworkChangeNotifier::IPAddressObserver: |
| 222 virtual void OnIPAddressChanged() OVERRIDE; | 220 virtual void OnIPAddressChanged() OVERRIDE; |
| 223 | 221 |
| 224 // DnsConfigService callback: | 222 // NetworkChangeNotifier::DNSObserver: |
| 225 void OnDnsConfigChanged(const DnsConfig& dns_config); | 223 virtual void OnDNSChanged() OVERRIDE; |
| 226 | 224 |
| 227 // True if have a DnsClient with a valid DnsConfig. | 225 // True if have a DnsClient with a valid DnsConfig. |
| 228 bool HaveDnsConfig() const; | 226 bool HaveDnsConfig() const; |
| 229 | 227 |
| 230 // Allows the tests to catch slots leaking out of the dispatcher. | 228 // Allows the tests to catch slots leaking out of the dispatcher. |
| 231 size_t num_running_jobs_for_tests() const { | 229 size_t num_running_jobs_for_tests() const { |
| 232 return dispatcher_.num_running_jobs(); | 230 return dispatcher_.num_running_jobs(); |
| 233 } | 231 } |
| 234 | 232 |
| 235 // Cache of host resolution results. | 233 // Cache of host resolution results. |
| 236 scoped_ptr<HostCache> cache_; | 234 scoped_ptr<HostCache> cache_; |
| 237 | 235 |
| 238 // Map from HostCache::Key to a Job. | 236 // Map from HostCache::Key to a Job. |
| 239 JobMap jobs_; | 237 JobMap jobs_; |
| 240 | 238 |
| 241 // Starts Jobs according to their priority and the configured limits. | 239 // Starts Jobs according to their priority and the configured limits. |
| 242 PrioritizedDispatcher dispatcher_; | 240 PrioritizedDispatcher dispatcher_; |
| 243 | 241 |
| 244 // Limit on the maximum number of jobs queued in |dispatcher_|. | 242 // Limit on the maximum number of jobs queued in |dispatcher_|. |
| 245 size_t max_queued_jobs_; | 243 size_t max_queued_jobs_; |
| 246 | 244 |
| 247 // Parameters for ProcTask. | 245 // Parameters for ProcTask. |
| 248 ProcTaskParams proc_params_; | 246 ProcTaskParams proc_params_; |
| 249 | 247 |
| 250 // Address family to use when the request doesn't specify one. | 248 // Address family to use when the request doesn't specify one. |
| 251 AddressFamily default_address_family_; | 249 AddressFamily default_address_family_; |
| 252 | 250 |
| 253 scoped_ptr<DnsConfigService> dns_config_service_; | |
| 254 | |
| 255 // If present, used by DnsTask and ServeFromHosts to resolve requests. | 251 // If present, used by DnsTask and ServeFromHosts to resolve requests. |
| 256 scoped_ptr<DnsClient> dns_client_; | 252 scoped_ptr<DnsClient> dns_client_; |
| 257 | 253 |
| 258 // True if received valid config from |dns_config_service_|. Temporary, used | 254 // True if received valid config from |dns_config_service_|. Temporary, used |
| 259 // to measure performance of DnsConfigService: http://crbug.com/125599 | 255 // to measure performance of DnsConfigService: http://crbug.com/125599 |
| 260 bool received_dns_config_; | 256 bool received_dns_config_; |
| 261 | 257 |
| 262 // Indicate if probing is done after each network change event to set address | 258 // Indicate if probing is done after each network change event to set address |
| 263 // family. When false, explicit setting of address family is used. | 259 // family. When false, explicit setting of address family is used. |
| 264 bool ipv6_probe_monitoring_; | 260 bool ipv6_probe_monitoring_; |
| 265 | 261 |
| 266 // The last un-cancelled IPv6ProbeJob (if any). | 262 // The last un-cancelled IPv6ProbeJob (if any). |
| 267 scoped_refptr<IPv6ProbeJob> ipv6_probe_job_; | 263 scoped_refptr<IPv6ProbeJob> ipv6_probe_job_; |
| 268 | 264 |
| 269 // Any resolver flags that should be added to a request by default. | 265 // Any resolver flags that should be added to a request by default. |
| 270 HostResolverFlags additional_resolver_flags_; | 266 HostResolverFlags additional_resolver_flags_; |
| 271 | 267 |
| 272 NetLog* net_log_; | 268 NetLog* net_log_; |
| 273 | 269 |
| 274 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 270 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 275 }; | 271 }; |
| 276 | 272 |
| 277 } // namespace net | 273 } // namespace net |
| 278 | 274 |
| 279 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ | 275 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |