OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef NET_BASE_HOST_RESOLVER_H_ |
6 #define NET_BASE_HOST_RESOLVER_H_ | 6 #define NET_BASE_HOST_RESOLVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // Does additional cleanup prior to destruction. | 192 // Does additional cleanup prior to destruction. |
193 virtual void Shutdown() {} | 193 virtual void Shutdown() {} |
194 | 194 |
195 protected: | 195 protected: |
196 HostResolver(); | 196 HostResolver(); |
197 | 197 |
198 private: | 198 private: |
199 DISALLOW_COPY_AND_ASSIGN(HostResolver); | 199 DISALLOW_COPY_AND_ASSIGN(HostResolver); |
200 }; | 200 }; |
201 | 201 |
202 // This class represents the task of resolving a hostname (or IP address | |
203 // literal) to an AddressList object. It wraps HostResolver to resolve only a | |
204 // single hostname at a time and cancels this request when going out of scope. | |
205 class NET_API SingleRequestHostResolver { | |
206 public: | |
207 // |resolver| must remain valid for the lifetime of |this|. | |
208 explicit SingleRequestHostResolver(HostResolver* resolver); | |
209 | |
210 // If a completion callback is pending when the resolver is destroyed, the | |
211 // host resolution is cancelled, and the completion callback will not be | |
212 // called. | |
213 ~SingleRequestHostResolver(); | |
214 | |
215 // Resolves the given hostname (or IP address literal), filling out the | |
216 // |addresses| object upon success. See HostResolver::Resolve() for details. | |
217 int Resolve(const HostResolver::RequestInfo& info, | |
218 AddressList* addresses, | |
219 CompletionCallback* callback, | |
220 const BoundNetLog& net_log); | |
221 | |
222 // Cancels the in-progress request, if any. This prevents the callback | |
223 // from being invoked. Resolve() can be called again after cancelling. | |
224 void Cancel(); | |
225 | |
226 private: | |
227 // Callback for when the request to |resolver_| completes, so we dispatch | |
228 // to the user's callback. | |
229 void OnResolveCompletion(int result); | |
230 | |
231 // The actual host resolver that will handle the request. | |
232 HostResolver* const resolver_; | |
233 | |
234 // The current request (if any). | |
235 HostResolver::RequestHandle cur_request_; | |
236 CompletionCallback* cur_request_callback_; | |
237 | |
238 // Completion callback for when request to |resolver_| completes. | |
239 CompletionCallbackImpl<SingleRequestHostResolver> callback_; | |
240 | |
241 DISALLOW_COPY_AND_ASSIGN(SingleRequestHostResolver); | |
242 }; | |
243 | |
244 // Creates a HostResolver implementation that queries the underlying system. | 202 // Creates a HostResolver implementation that queries the underlying system. |
245 // (Except if a unit-test has changed the global HostResolverProc using | 203 // (Except if a unit-test has changed the global HostResolverProc using |
246 // ScopedHostResolverProc to intercept requests to the system). | 204 // ScopedHostResolverProc to intercept requests to the system). |
247 // |max_concurrent_resolves| is how many resolve requests will be allowed to | 205 // |max_concurrent_resolves| is how many resolve requests will be allowed to |
248 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a | 206 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a |
249 // default value. | 207 // default value. |
250 // |max_retry_attempts| is the maximum number of times we will retry for host | 208 // |max_retry_attempts| is the maximum number of times we will retry for host |
251 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default | 209 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default |
252 // value. | 210 // value. |
253 NET_API HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, | 211 NET_API HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, |
254 size_t max_retry_attempts, | 212 size_t max_retry_attempts, |
255 NetLog* net_log); | 213 NetLog* net_log); |
256 | 214 |
257 } // namespace net | 215 } // namespace net |
258 | 216 |
259 #endif // NET_BASE_HOST_RESOLVER_H_ | 217 #endif // NET_BASE_HOST_RESOLVER_H_ |
OLD | NEW |