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/net_util.h" |
18 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
19 #include "net/dns/host_cache.h" | 20 #include "net/dns/host_cache.h" |
20 #include "net/dns/host_resolver.h" | 21 #include "net/dns/host_resolver.h" |
21 #include "net/dns/host_resolver_proc.h" | 22 #include "net/dns/host_resolver_proc.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
25 class BoundNetLog; | 26 class BoundNetLog; |
26 class DnsClient; | 27 class DnsClient; |
27 class NetLog; | 28 class NetLog; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Number of consecutive failures of DnsTask (with successful fallback to | 159 // Number of consecutive failures of DnsTask (with successful fallback to |
159 // ProcTask) before the DnsClient is disabled until the next DNS change. | 160 // ProcTask) before the DnsClient is disabled until the next DNS change. |
160 static const unsigned kMaximumDnsFailures; | 161 static const unsigned kMaximumDnsFailures; |
161 | 162 |
162 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP | 163 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP |
163 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, | 164 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, |
164 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is | 165 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is |
165 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and HOSTS. | 166 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and HOSTS. |
166 int ResolveHelper(const Key& key, | 167 int ResolveHelper(const Key& key, |
167 const RequestInfo& info, | 168 const RequestInfo& info, |
| 169 const IPAddressNumber* ip_address, |
168 AddressList* addresses, | 170 AddressList* addresses, |
169 const BoundNetLog& request_net_log); | 171 const BoundNetLog& request_net_log); |
170 | 172 |
171 // Tries to resolve |key| as an IP, returns true and sets |net_error| if | 173 // Tries to resolve |key| as an IP, returns true and sets |net_error| if |
172 // succeeds, returns false otherwise. | 174 // succeeds, returns false otherwise. |
173 bool ResolveAsIP(const Key& key, | 175 bool ResolveAsIP(const Key& key, |
174 const RequestInfo& info, | 176 const RequestInfo& info, |
| 177 const IPAddressNumber* ip_address, |
175 int* net_error, | 178 int* net_error, |
176 AddressList* addresses); | 179 AddressList* addresses); |
177 | 180 |
178 // If |key| is not found in cache returns false, otherwise returns | 181 // If |key| is not found in cache returns false, otherwise returns |
179 // true, sets |net_error| to the cached error code and fills |addresses| | 182 // true, sets |net_error| to the cached error code and fills |addresses| |
180 // if it is a positive entry. | 183 // if it is a positive entry. |
181 bool ServeFromCache(const Key& key, | 184 bool ServeFromCache(const Key& key, |
182 const RequestInfo& info, | 185 const RequestInfo& info, |
183 int* net_error, | 186 int* net_error, |
184 AddressList* addresses); | 187 AddressList* addresses); |
185 | 188 |
186 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the | 189 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the |
187 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. | 190 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. |
188 bool ServeFromHosts(const Key& key, | 191 bool ServeFromHosts(const Key& key, |
189 const RequestInfo& info, | 192 const RequestInfo& info, |
190 AddressList* addresses); | 193 AddressList* addresses); |
191 | 194 |
192 // Callback from HaveOnlyLoopbackAddresses probe. | 195 // Callback from HaveOnlyLoopbackAddresses probe. |
193 void SetHaveOnlyLoopbackAddresses(bool result); | 196 void SetHaveOnlyLoopbackAddresses(bool result); |
194 | 197 |
195 // Returns the (hostname, address_family) key to use for |info|, choosing an | 198 // Returns the (hostname, address_family) key to use for |info|, choosing an |
196 // "effective" address family by inheriting the resolver's default address | 199 // "effective" address family by inheriting the resolver's default address |
197 // family when the request leaves it unspecified. | 200 // family when the request leaves it unspecified. |
198 Key GetEffectiveKeyForRequest(const RequestInfo& info, | 201 Key GetEffectiveKeyForRequest(const RequestInfo& info, |
| 202 const IPAddressNumber* ip_number, |
199 const BoundNetLog& net_log) const; | 203 const BoundNetLog& net_log) const; |
200 | 204 |
201 // Records the result in cache if cache is present. | 205 // Records the result in cache if cache is present. |
202 void CacheResult(const Key& key, | 206 void CacheResult(const Key& key, |
203 const HostCache::Entry& entry, | 207 const HostCache::Entry& entry, |
204 base::TimeDelta ttl); | 208 base::TimeDelta ttl); |
205 | 209 |
206 // Removes |job| from |jobs_|, only if it exists. | 210 // Removes |job| from |jobs_|, only if it exists. |
207 void RemoveJob(Job* job); | 211 void RemoveJob(Job* job); |
208 | 212 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; | 294 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; |
291 | 295 |
292 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; | 296 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; |
293 | 297 |
294 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 298 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
295 }; | 299 }; |
296 | 300 |
297 } // namespace net | 301 } // namespace net |
298 | 302 |
299 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 303 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |