| 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" |
| 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/time.h" | 16 #include "base/time/time.h" |
| 17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 18 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
| 19 #include "net/base/prioritized_dispatcher.h" | |
| 20 #include "net/dns/host_cache.h" | 19 #include "net/dns/host_cache.h" |
| 21 #include "net/dns/host_resolver.h" | 20 #include "net/dns/host_resolver.h" |
| 22 #include "net/dns/host_resolver_proc.h" | 21 #include "net/dns/host_resolver_proc.h" |
| 23 | 22 |
| 24 namespace net { | 23 namespace net { |
| 25 | 24 |
| 26 class BoundNetLog; | 25 class BoundNetLog; |
| 27 class DnsClient; | 26 class DnsClient; |
| 28 class NetLog; | 27 class NetLog; |
| 29 | 28 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 size_t max_retry_attempts; | 89 size_t max_retry_attempts; |
| 91 | 90 |
| 92 // This is the limit after which we make another attempt to resolve the host | 91 // This is the limit after which we make another attempt to resolve the host |
| 93 // if the worker thread has not responded yet. | 92 // if the worker thread has not responded yet. |
| 94 base::TimeDelta unresponsive_delay; | 93 base::TimeDelta unresponsive_delay; |
| 95 | 94 |
| 96 // Factor to grow |unresponsive_delay| when we re-re-try. | 95 // Factor to grow |unresponsive_delay| when we re-re-try. |
| 97 uint32 retry_factor; | 96 uint32 retry_factor; |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 // Creates a HostResolver that first uses the local cache |cache|, and then | 99 // Creates a HostResolver as specified by |options|. |
| 101 // falls back to |proc_params.resolver_proc|. | |
| 102 // | 100 // |
| 103 // If |cache| is NULL, then no caching is used. Otherwise we take | 101 // If Options.enable_caching is true, a cache is created using |
| 104 // ownership of the |cache| pointer, and will free it during destruction. | 102 // HostCache::CreateDefaultCache(). Otherwise no cache is used. |
| 105 // | 103 // |
| 106 // |job_limits| specifies the maximum number of jobs that the resolver will | 104 // Options.GetDispatcherLimits() determines the maximum number of jobs that |
| 107 // run at once. This upper-bounds the total number of outstanding | 105 // the resolver will run at once. This upper-bounds the total number of |
| 108 // DNS transactions (not counting retransmissions and retries). | 106 // outstanding DNS transactions (not counting retransmissions and retries). |
| 109 // | 107 // |
| 110 // |net_log| must remain valid for the life of the HostResolverImpl. | 108 // |net_log| must remain valid for the life of the HostResolverImpl. |
| 111 HostResolverImpl(scoped_ptr<HostCache> cache, | 109 HostResolverImpl(const Options& options, NetLog* net_log); |
| 112 const PrioritizedDispatcher::Limits& job_limits, | |
| 113 const ProcTaskParams& proc_params, | |
| 114 NetLog* net_log); | |
| 115 | 110 |
| 116 // If any completion callbacks are pending when the resolver is destroyed, | 111 // If any completion callbacks are pending when the resolver is destroyed, |
| 117 // the host resolutions are cancelled, and the completion callbacks will not | 112 // the host resolutions are cancelled, and the completion callbacks will not |
| 118 // be called. | 113 // be called. |
| 119 virtual ~HostResolverImpl(); | 114 virtual ~HostResolverImpl(); |
| 120 | 115 |
| 121 // Configures maximum number of Jobs in the queue. Exposed for testing. | 116 // Configures maximum number of Jobs in the queue. Exposed for testing. |
| 122 // Only allowed when the queue is empty. | 117 // Only allowed when the queue is empty. |
| 123 void SetMaxQueuedJobs(size_t value); | 118 void SetMaxQueuedJobs(size_t value); |
| 124 | 119 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 138 virtual int ResolveFromCache(const RequestInfo& info, | 133 virtual int ResolveFromCache(const RequestInfo& info, |
| 139 AddressList* addresses, | 134 AddressList* addresses, |
| 140 const BoundNetLog& source_net_log) OVERRIDE; | 135 const BoundNetLog& source_net_log) OVERRIDE; |
| 141 virtual void CancelRequest(RequestHandle req) OVERRIDE; | 136 virtual void CancelRequest(RequestHandle req) OVERRIDE; |
| 142 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; | 137 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; |
| 143 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; | 138 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; |
| 144 virtual void SetDnsClientEnabled(bool enabled) OVERRIDE; | 139 virtual void SetDnsClientEnabled(bool enabled) OVERRIDE; |
| 145 virtual HostCache* GetHostCache() OVERRIDE; | 140 virtual HostCache* GetHostCache() OVERRIDE; |
| 146 virtual base::Value* GetDnsConfigAsValue() const OVERRIDE; | 141 virtual base::Value* GetDnsConfigAsValue() const OVERRIDE; |
| 147 | 142 |
| 143 void set_proc_params_for_test(const ProcTaskParams& proc_params) { |
| 144 proc_params_ = proc_params; |
| 145 } |
| 146 |
| 148 private: | 147 private: |
| 149 friend class HostResolverImplTest; | 148 friend class HostResolverImplTest; |
| 150 class Job; | 149 class Job; |
| 151 class ProcTask; | 150 class ProcTask; |
| 152 class LoopbackProbeJob; | 151 class LoopbackProbeJob; |
| 153 class DnsTask; | 152 class DnsTask; |
| 154 class Request; | 153 class Request; |
| 155 typedef HostCache::Key Key; | 154 typedef HostCache::Key Key; |
| 156 typedef std::map<Key, Job*> JobMap; | 155 typedef std::map<Key, Job*> JobMap; |
| 157 typedef ScopedVector<Request> RequestsList; | 156 typedef ScopedVector<Request> RequestsList; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 bool HaveDnsConfig() const; | 229 bool HaveDnsConfig() const; |
| 231 | 230 |
| 232 // Called when a host name is successfully resolved and DnsTask was run on it | 231 // Called when a host name is successfully resolved and DnsTask was run on it |
| 233 // and resulted in |net_error|. | 232 // and resulted in |net_error|. |
| 234 void OnDnsTaskResolve(int net_error); | 233 void OnDnsTaskResolve(int net_error); |
| 235 | 234 |
| 236 // Allows the tests to catch slots leaking out of the dispatcher. One | 235 // Allows the tests to catch slots leaking out of the dispatcher. One |
| 237 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job | 236 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job |
| 238 // slots. | 237 // slots. |
| 239 size_t num_running_dispatcher_jobs_for_tests() const { | 238 size_t num_running_dispatcher_jobs_for_tests() const { |
| 240 return dispatcher_.num_running_jobs(); | 239 return dispatcher_->num_running_jobs(); |
| 241 } | 240 } |
| 242 | 241 |
| 243 // Cache of host resolution results. | 242 // Cache of host resolution results. |
| 244 scoped_ptr<HostCache> cache_; | 243 scoped_ptr<HostCache> cache_; |
| 245 | 244 |
| 246 // Map from HostCache::Key to a Job. | 245 // Map from HostCache::Key to a Job. |
| 247 JobMap jobs_; | 246 JobMap jobs_; |
| 248 | 247 |
| 249 // Starts Jobs according to their priority and the configured limits. | 248 // Starts Jobs according to their priority and the configured limits. |
| 250 PrioritizedDispatcher dispatcher_; | 249 scoped_ptr<PrioritizedDispatcher> dispatcher_; |
| 251 | 250 |
| 252 // Limit on the maximum number of jobs queued in |dispatcher_|. | 251 // Limit on the maximum number of jobs queued in |dispatcher_|. |
| 253 size_t max_queued_jobs_; | 252 size_t max_queued_jobs_; |
| 254 | 253 |
| 255 // Parameters for ProcTask. | 254 // Parameters for ProcTask. |
| 256 ProcTaskParams proc_params_; | 255 ProcTaskParams proc_params_; |
| 257 | 256 |
| 258 NetLog* net_log_; | 257 NetLog* net_log_; |
| 259 | 258 |
| 260 // Address family to use when the request doesn't specify one. | 259 // Address family to use when the request doesn't specify one. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 291 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; | 290 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; |
| 292 | 291 |
| 293 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; | 292 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; |
| 294 | 293 |
| 295 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 294 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 296 }; | 295 }; |
| 297 | 296 |
| 298 } // namespace net | 297 } // namespace net |
| 299 | 298 |
| 300 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 299 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |