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 DnsSession; |
30 class DnsTransactionFactory; | 31 class DnsTransactionFactory; |
31 | 32 |
32 // For each hostname that is requested, HostResolver creates a | 33 // For each hostname that is requested, HostResolver creates a |
33 // HostResolverImpl::Job. When this job gets dispatched it creates a ProcTask | 34 // HostResolverImpl::Job. When this job gets dispatched it creates a ProcTask |
34 // which runs the given HostResolverProc on a WorkerPool thread. If requests for | 35 // 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 | 36 // 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 | 37 // existing job rather than creating a new one. This avoids doing parallel |
37 // resolves for the same host. | 38 // resolves for the same host. |
38 // | 39 // |
39 // The way these classes fit together is illustrated by: | 40 // The way these classes fit together is illustrated by: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool ResolveAsIP(const Key& key, | 178 bool ResolveAsIP(const Key& key, |
178 const RequestInfo& info, | 179 const RequestInfo& info, |
179 int* net_error, | 180 int* net_error, |
180 AddressList* addresses); | 181 AddressList* addresses); |
181 | 182 |
182 // If |key| is not found in cache returns false, otherwise returns | 183 // If |key| is not found in cache returns false, otherwise returns |
183 // true, sets |net_error| to the cached error code and fills |addresses| | 184 // true, sets |net_error| to the cached error code and fills |addresses| |
184 // if it is a positive entry. | 185 // if it is a positive entry. |
185 bool ServeFromCache(const Key& key, | 186 bool ServeFromCache(const Key& key, |
186 const RequestInfo& info, | 187 const RequestInfo& info, |
187 const BoundNetLog& request_net_log, | |
188 int* net_error, | 188 int* net_error, |
189 AddressList* addresses); | 189 AddressList* addresses); |
190 | 190 |
| 191 // If |key| is not found in the HOSTS file or no HOSTS file known, returns |
| 192 // false, otherwise returns true and fills |addresses|. |
| 193 bool ServeFromHosts(const Key& key, |
| 194 const RequestInfo& info, |
| 195 AddressList* addresses); |
| 196 |
191 // Notifies IPv6ProbeJob not to call back, and discard reference to the job. | 197 // Notifies IPv6ProbeJob not to call back, and discard reference to the job. |
192 void DiscardIPv6ProbeJob(); | 198 void DiscardIPv6ProbeJob(); |
193 | 199 |
194 // Callback from IPv6 probe activity. | 200 // Callback from IPv6 probe activity. |
195 void IPv6ProbeSetDefaultAddressFamily(AddressFamily address_family); | 201 void IPv6ProbeSetDefaultAddressFamily(AddressFamily address_family); |
196 | 202 |
197 // Returns the (hostname, address_family) key to use for |info|, choosing an | 203 // Returns the (hostname, address_family) key to use for |info|, choosing an |
198 // "effective" address family by inheriting the resolver's default address | 204 // "effective" address family by inheriting the resolver's default address |
199 // family when the request leaves it unspecified. | 205 // family when the request leaves it unspecified. |
200 Key GetEffectiveKeyForRequest(const RequestInfo& info) const; | 206 Key GetEffectiveKeyForRequest(const RequestInfo& info) const; |
201 | 207 |
202 // Records the result in cache if cache is present. | 208 // Records the result in cache if cache is present. |
203 void CacheResult(const Key& key, | 209 void CacheResult(const Key& key, |
204 int net_error, | 210 int net_error, |
205 const AddressList& addr_list, | 211 const AddressList& addr_list, |
206 base::TimeDelta ttl); | 212 base::TimeDelta ttl); |
207 | 213 |
208 // Removes |job| from |jobs_|, only if it exists. | 214 // Removes |job| from |jobs_|, only if it exists. |
209 void RemoveJob(Job* job); | 215 void RemoveJob(Job* job); |
210 | 216 |
211 // Aborts all in progress jobs and notifies their requests. | 217 // Aborts all in progress jobs and notifies their requests. |
212 // Might start new jobs. | 218 // Might start new jobs. |
213 void AbortAllInProgressJobs(); | 219 void AbortAllInProgressJobs(); |
214 | 220 |
| 221 // Attempts to serve each Job in |jobs_| from the HOSTS file. |
| 222 void TryServingAllJobsFromHosts(); |
| 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(unsigned detail) OVERRIDE; | 228 virtual void OnDNSChanged(unsigned detail) OVERRIDE; |
220 | 229 |
221 // DnsConfigService::Observer: | 230 // DnsConfigService::Observer: |
222 virtual void OnConfigChanged(const DnsConfig& dns_config) OVERRIDE; | 231 virtual void OnConfigChanged(const DnsConfig& dns_config) OVERRIDE; |
223 | 232 |
224 // Cache of host resolution results. | 233 // Cache of host resolution results. |
225 scoped_ptr<HostCache> cache_; | 234 scoped_ptr<HostCache> cache_; |
226 | 235 |
227 // Map from HostCache::Key to a Job. | 236 // Map from HostCache::Key to a Job. |
228 JobMap jobs_; | 237 JobMap jobs_; |
229 | 238 |
230 // Starts Jobs according to their priority and the configured limits. | 239 // Starts Jobs according to their priority and the configured limits. |
231 PrioritizedDispatcher dispatcher_; | 240 PrioritizedDispatcher dispatcher_; |
232 | 241 |
233 // Limit on the maximum number of jobs queued in |dispatcher_|. | 242 // Limit on the maximum number of jobs queued in |dispatcher_|. |
234 size_t max_queued_jobs_; | 243 size_t max_queued_jobs_; |
235 | 244 |
236 // Parameters for ProcTask. | 245 // Parameters for ProcTask. |
237 ProcTaskParams proc_params_; | 246 ProcTaskParams proc_params_; |
238 | 247 |
239 scoped_ptr<DnsTransactionFactory> dns_transaction_factory_; | 248 scoped_ptr<DnsTransactionFactory> dns_transaction_factory_; |
240 | 249 |
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_refptr<DnsSession> dns_session_; |
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 |