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_H_ | 5 #ifndef NET_DNS_HOST_RESOLVER_H_ |
6 #define NET_DNS_HOST_RESOLVER_H_ | 6 #define NET_DNS_HOST_RESOLVER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "net/base/address_family.h" | 15 #include "net/base/address_family.h" |
16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
17 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
18 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
19 #include "net/base/prioritized_dispatcher.h" | 19 #include "net/base/prioritized_dispatcher.h" |
20 #include "net/base/request_priority.h" | 20 #include "net/base/request_priority.h" |
| 21 #include "net/dns/host_cache.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class Value; | 24 class Value; |
24 } | 25 } |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 | 28 |
28 class AddressList; | 29 class AddressList; |
29 class BoundNetLog; | 30 class BoundNetLog; |
30 class HostCache; | |
31 class HostResolverProc; | 31 class HostResolverProc; |
32 class NetLog; | 32 class NetLog; |
33 | 33 |
34 // This class represents the task of resolving hostnames (or IP address | 34 // This class represents the task of resolving hostnames (or IP address |
35 // literal) to an AddressList object. | 35 // literal) to an AddressList object. |
36 // | 36 // |
37 // HostResolver can handle multiple requests at a time, so when cancelling a | 37 // HostResolver can handle multiple requests at a time, so when cancelling a |
38 // request the RequestHandle that was returned by Resolve() needs to be | 38 // request the RequestHandle that was returned by Resolve() needs to be |
39 // given. A simpler alternative for consumers that only have 1 outstanding | 39 // given. A simpler alternative for consumers that only have 1 outstanding |
40 // request at a time is to create a SingleRequestHostResolver wrapper around | 40 // request at a time is to create a SingleRequestHostResolver wrapper around |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // completed. | 148 // completed. |
149 // | 149 // |
150 // Profiling information for the request is saved to |net_log| if non-NULL. | 150 // Profiling information for the request is saved to |net_log| if non-NULL. |
151 virtual int Resolve(const RequestInfo& info, | 151 virtual int Resolve(const RequestInfo& info, |
152 RequestPriority priority, | 152 RequestPriority priority, |
153 AddressList* addresses, | 153 AddressList* addresses, |
154 const CompletionCallback& callback, | 154 const CompletionCallback& callback, |
155 RequestHandle* out_req, | 155 RequestHandle* out_req, |
156 const BoundNetLog& net_log) = 0; | 156 const BoundNetLog& net_log) = 0; |
157 | 157 |
158 // Resolves the given hostname (or IP address literal) out of cache or HOSTS | |
159 // file (if enabled) only. This is guaranteed to complete synchronously. | |
160 // This acts like |Resolve()| if the hostname is IP literal, or cached value | |
161 // or HOSTS entry exists. Otherwise, ERR_DNS_CACHE_MISS is returned. | |
162 virtual int ResolveFromCache(const RequestInfo& info, | |
163 AddressList* addresses, | |
164 const BoundNetLog& net_log) = 0; | |
165 | |
166 // Changes the priority of the specified request. |req| is the handle returned | 158 // Changes the priority of the specified request. |req| is the handle returned |
167 // by Resolve(). ChangeRequestPriority must NOT be called after the request's | 159 // by Resolve(). ChangeRequestPriority must NOT be called after the request's |
168 // completion callback has already run or the request was canceled. | 160 // completion callback has already run or the request was canceled. |
169 virtual void ChangeRequestPriority(RequestHandle req, | 161 virtual void ChangeRequestPriority(RequestHandle req, |
170 RequestPriority priority); | 162 RequestPriority priority); |
171 | 163 |
172 // Cancels the specified request. |req| is the handle returned by Resolve(). | 164 // Cancels the specified request. |req| is the handle returned by Resolve(). |
173 // After a request is canceled, its completion callback will not be called. | 165 // After a request is canceled, its completion callback will not be called. |
174 // CancelRequest must NOT be called after the request's completion callback | 166 // CancelRequest must NOT be called after the request's completion callback |
175 // has already run or the request was canceled. | 167 // has already run or the request was canceled. |
176 virtual void CancelRequest(RequestHandle req) = 0; | 168 virtual void CancelRequest(RequestHandle req) = 0; |
177 | 169 |
| 170 // Resolves the given hostname (or IP address literal) out of cache or HOSTS |
| 171 // file (if enabled) only. This is guaranteed to complete synchronously. |
| 172 // This acts like |Resolve()| if the hostname is IP literal, or cached value |
| 173 // or HOSTS entry exists. Otherwise, ERR_DNS_CACHE_MISS is returned. |
| 174 virtual int ResolveFromCache(const RequestInfo& info, |
| 175 AddressList* addresses, |
| 176 const BoundNetLog& net_log) = 0; |
| 177 |
| 178 // Like |ResolveFromCache()|, but can return a stale result if the |
| 179 // implementation supports it. Fills in |*stale_info| if a response is |
| 180 // returned to indicate how stale (or not) it is. |
| 181 virtual int ResolveStaleFromCache(const RequestInfo& info, |
| 182 AddressList* addresses, |
| 183 HostCache::EntryStaleness* stale_info, |
| 184 const BoundNetLog& net_log); |
| 185 |
| 186 // Uses |ResolveStaleFromCache| and |Resolve| to get fresh data (either from |
| 187 // the cache or from the network) but also return stale data if any is |
| 188 // available. |
| 189 // |
| 190 // If a fresh result is available in cache, populates |addresses| and returns |
| 191 // it synchronously. |
| 192 // |
| 193 // Otherwise, starts a network request, returns ERR_IO_PENDING, and: |
| 194 // |
| 195 // If a stale result is available in cache, returns it through |
| 196 // |*stale_error|, |*stale_addresses|, and |*stale_info|. |
| 197 // |
| 198 // If no result is available in cache, sets |*stale_error| to |
| 199 // ERR_DNS_CACHE_MISS. |
| 200 // |
| 201 // In either asynchronous case: |
| 202 // |
| 203 // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to |
| 204 // the async request. This handle is not valid after the request has |
| 205 // completed. |
| 206 int ResolveStale(const RequestInfo& info, |
| 207 RequestPriority priority, |
| 208 AddressList* addresses, |
| 209 const CompletionCallback& callback, |
| 210 RequestHandle* out_req, |
| 211 int* stale_error, |
| 212 AddressList* stale_addresses, |
| 213 HostCache::EntryStaleness* stale_info, |
| 214 const BoundNetLog& net_log); |
| 215 |
178 // Enable or disable the built-in asynchronous DnsClient. | 216 // Enable or disable the built-in asynchronous DnsClient. |
179 virtual void SetDnsClientEnabled(bool enabled); | 217 virtual void SetDnsClientEnabled(bool enabled); |
180 | 218 |
181 // Returns the HostResolverCache |this| uses, or NULL if there isn't one. | 219 // Returns the HostResolverCache |this| uses, or NULL if there isn't one. |
182 // Used primarily to clear the cache and for getting debug information. | 220 // Used primarily to clear the cache and for getting debug information. |
183 virtual HostCache* GetHostCache(); | 221 virtual HostCache* GetHostCache(); |
184 | 222 |
185 // Returns the current DNS configuration |this| is using, as a Value, or | 223 // Returns the current DNS configuration |this| is using, as a Value, or |
186 // nullptr if it's configured to always use the system host resolver. | 224 // nullptr if it's configured to always use the system host resolver. |
187 virtual std::unique_ptr<base::Value> GetDnsConfigAsValue() const; | 225 virtual std::unique_ptr<base::Value> GetDnsConfigAsValue() const; |
(...skipping 11 matching lines...) Expand all Loading... |
199 protected: | 237 protected: |
200 HostResolver(); | 238 HostResolver(); |
201 | 239 |
202 private: | 240 private: |
203 DISALLOW_COPY_AND_ASSIGN(HostResolver); | 241 DISALLOW_COPY_AND_ASSIGN(HostResolver); |
204 }; | 242 }; |
205 | 243 |
206 } // namespace net | 244 } // namespace net |
207 | 245 |
208 #endif // NET_DNS_HOST_RESOLVER_H_ | 246 #endif // NET_DNS_HOST_RESOLVER_H_ |
OLD | NEW |