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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "net/base/capturing_net_log.h" | 18 #include "net/base/capturing_net_log.h" |
19 #include "net/base/host_cache.h" | 19 #include "net/base/host_cache.h" |
20 #include "net/base/host_resolver.h" | 20 #include "net/base/host_resolver.h" |
21 #include "net/base/host_resolver_proc.h" | 21 #include "net/base/host_resolver_proc.h" |
22 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
23 #include "net/base/net_log.h" | 23 #include "net/base/net_log.h" |
24 #include "net/base/network_change_notifier.h" | 24 #include "net/base/network_change_notifier.h" |
25 #include "net/base/prioritized_dispatcher.h" | 25 #include "net/base/prioritized_dispatcher.h" |
26 #include "net/dns/dns_config_service.h" | 26 #include "net/dns/dns_config_service.h" |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 | 29 |
30 class DnsTransactionFactory; | 30 class DnsClient; |
31 | 31 |
32 // For each hostname that is requested, HostResolver creates a | 32 // For each hostname that is requested, HostResolver creates a |
33 // HostResolverImpl::Job. When this job gets dispatched it creates a ProcTask | 33 // HostResolverImpl::Job. When this job gets dispatched it creates a ProcTask |
34 // which runs the given HostResolverProc on a WorkerPool thread. If requests for | 34 // which runs the given HostResolverProc on a WorkerPool thread. If requests for |
35 // that same host are made during the job's lifetime, they are attached to the | 35 // that same host are made during the job's lifetime, they are attached to the |
36 // existing job rather than creating a new one. This avoids doing parallel | 36 // existing job rather than creating a new one. This avoids doing parallel |
37 // resolves for the same host. | 37 // resolves for the same host. |
38 // | 38 // |
39 // The way these classes fit together is illustrated by: | 39 // The way these classes fit together is illustrated by: |
40 // | 40 // |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool ResolveAsIP(const Key& key, | 177 bool ResolveAsIP(const Key& key, |
178 const RequestInfo& info, | 178 const RequestInfo& info, |
179 int* net_error, | 179 int* net_error, |
180 AddressList* addresses); | 180 AddressList* addresses); |
181 | 181 |
182 // If |key| is not found in cache returns false, otherwise returns | 182 // If |key| is not found in cache returns false, otherwise returns |
183 // true, sets |net_error| to the cached error code and fills |addresses| | 183 // true, sets |net_error| to the cached error code and fills |addresses| |
184 // if it is a positive entry. | 184 // if it is a positive entry. |
185 bool ServeFromCache(const Key& key, | 185 bool ServeFromCache(const Key& key, |
186 const RequestInfo& info, | 186 const RequestInfo& info, |
187 const BoundNetLog& request_net_log, | |
188 int* net_error, | 187 int* net_error, |
189 AddressList* addresses); | 188 AddressList* addresses); |
190 | 189 |
| 190 // If |key| is not found in the HOSTS file or no HOSTS file known, returns |
| 191 // false, otherwise returns true and fills |addresses|. |
| 192 bool ServeFromHosts(const Key& key, |
| 193 const RequestInfo& info, |
| 194 AddressList* addresses); |
| 195 |
191 // Notifies IPv6ProbeJob not to call back, and discard reference to the job. | 196 // Notifies IPv6ProbeJob not to call back, and discard reference to the job. |
192 void DiscardIPv6ProbeJob(); | 197 void DiscardIPv6ProbeJob(); |
193 | 198 |
194 // Callback from IPv6 probe activity. | 199 // Callback from IPv6 probe activity. |
195 void IPv6ProbeSetDefaultAddressFamily(AddressFamily address_family); | 200 void IPv6ProbeSetDefaultAddressFamily(AddressFamily address_family); |
196 | 201 |
197 // Returns the (hostname, address_family) key to use for |info|, choosing an | 202 // Returns the (hostname, address_family) key to use for |info|, choosing an |
198 // "effective" address family by inheriting the resolver's default address | 203 // "effective" address family by inheriting the resolver's default address |
199 // family when the request leaves it unspecified. | 204 // family when the request leaves it unspecified. |
200 Key GetEffectiveKeyForRequest(const RequestInfo& info) const; | 205 Key GetEffectiveKeyForRequest(const RequestInfo& info) const; |
201 | 206 |
202 // Records the result in cache if cache is present. | 207 // Records the result in cache if cache is present. |
203 void CacheResult(const Key& key, | 208 void CacheResult(const Key& key, |
204 int net_error, | 209 int net_error, |
205 const AddressList& addr_list, | 210 const AddressList& addr_list, |
206 base::TimeDelta ttl); | 211 base::TimeDelta ttl); |
207 | 212 |
208 // Removes |job| from |jobs_|, only if it exists. | 213 // Removes |job| from |jobs_|, only if it exists. |
209 void RemoveJob(Job* job); | 214 void RemoveJob(Job* job); |
210 | 215 |
211 // Aborts all in progress jobs and notifies their requests. | 216 // Aborts all in progress jobs and notifies their requests. |
212 // Might start new jobs. | 217 // Might start new jobs. |
213 void AbortAllInProgressJobs(); | 218 void AbortAllInProgressJobs(); |
214 | 219 |
| 220 // Attempts to serve each Job in |jobs_| from the HOSTS file. |
| 221 void TryServingAllJobsFromHosts(); |
| 222 |
215 // NetworkChangeNotifier::IPAddressObserver: | 223 // NetworkChangeNotifier::IPAddressObserver: |
216 virtual void OnIPAddressChanged() OVERRIDE; | 224 virtual void OnIPAddressChanged() OVERRIDE; |
217 | 225 |
218 // NetworkChangeNotifier::DNSObserver: | 226 // NetworkChangeNotifier::DNSObserver: |
219 virtual void OnDNSChanged(unsigned detail) OVERRIDE; | 227 virtual void OnDNSChanged(unsigned detail) OVERRIDE; |
220 | 228 |
221 // DnsConfigService::Observer: | 229 // DnsConfigService::Observer: |
222 virtual void OnConfigChanged(const DnsConfig& dns_config) OVERRIDE; | 230 virtual void OnConfigChanged(const DnsConfig& dns_config) OVERRIDE; |
223 | 231 |
| 232 // True if have fully configured DNS client. |
| 233 bool HaveDnsConfig() const; |
| 234 |
224 // Cache of host resolution results. | 235 // Cache of host resolution results. |
225 scoped_ptr<HostCache> cache_; | 236 scoped_ptr<HostCache> cache_; |
226 | 237 |
227 // Map from HostCache::Key to a Job. | 238 // Map from HostCache::Key to a Job. |
228 JobMap jobs_; | 239 JobMap jobs_; |
229 | 240 |
230 // Starts Jobs according to their priority and the configured limits. | 241 // Starts Jobs according to their priority and the configured limits. |
231 PrioritizedDispatcher dispatcher_; | 242 PrioritizedDispatcher dispatcher_; |
232 | 243 |
233 // Limit on the maximum number of jobs queued in |dispatcher_|. | 244 // Limit on the maximum number of jobs queued in |dispatcher_|. |
234 size_t max_queued_jobs_; | 245 size_t max_queued_jobs_; |
235 | 246 |
236 // Parameters for ProcTask. | 247 // Parameters for ProcTask. |
237 ProcTaskParams proc_params_; | 248 ProcTaskParams proc_params_; |
238 | 249 |
239 scoped_ptr<DnsTransactionFactory> dns_transaction_factory_; | |
240 | |
241 // Address family to use when the request doesn't specify one. | 250 // Address family to use when the request doesn't specify one. |
242 AddressFamily default_address_family_; | 251 AddressFamily default_address_family_; |
243 | 252 |
| 253 scoped_ptr<DnsClient> dns_client_; |
244 scoped_ptr<DnsConfigService> dns_config_service_; | 254 scoped_ptr<DnsConfigService> dns_config_service_; |
245 | 255 |
246 // Indicate if probing is done after each network change event to set address | 256 // Indicate if probing is done after each network change event to set address |
247 // family. | 257 // family. |
248 // When false, explicit setting of address family is used. | 258 // When false, explicit setting of address family is used. |
249 bool ipv6_probe_monitoring_; | 259 bool ipv6_probe_monitoring_; |
250 | 260 |
251 // The last un-cancelled IPv6ProbeJob (if any). | 261 // The last un-cancelled IPv6ProbeJob (if any). |
252 scoped_refptr<IPv6ProbeJob> ipv6_probe_job_; | 262 scoped_refptr<IPv6ProbeJob> ipv6_probe_job_; |
253 | 263 |
254 // Any resolver flags that should be added to a request by default. | 264 // Any resolver flags that should be added to a request by default. |
255 HostResolverFlags additional_resolver_flags_; | 265 HostResolverFlags additional_resolver_flags_; |
256 | 266 |
257 NetLog* net_log_; | 267 NetLog* net_log_; |
258 | 268 |
259 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 269 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
260 }; | 270 }; |
261 | 271 |
262 } // namespace net | 272 } // namespace net |
263 | 273 |
264 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ | 274 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |