| 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_SINGLE_REQUEST_HOST_RESOLVER_H_ | 5 #ifndef NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_ |
| 6 #define NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_ | 6 #define NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "net/base/host_resolver.h" | 9 #include "net/base/host_resolver.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 // This class represents the task of resolving a hostname (or IP address | 13 // This class represents the task of resolving a hostname (or IP address |
| 14 // literal) to an AddressList object. It wraps HostResolver to resolve only a | 14 // literal) to an AddressList object. It wraps HostResolver to resolve only a |
| 15 // single hostname at a time and cancels this request when going out of scope. | 15 // single hostname at a time and cancels this request when going out of scope. |
| 16 class NET_EXPORT SingleRequestHostResolver { | 16 class NET_EXPORT SingleRequestHostResolver { |
| 17 public: | 17 public: |
| 18 // |resolver| must remain valid for the lifetime of |this|. | 18 // |resolver| must remain valid for the lifetime of |this|. |
| 19 explicit SingleRequestHostResolver(HostResolver* resolver); | 19 explicit SingleRequestHostResolver(HostResolver* resolver); |
| 20 | 20 |
| 21 // If a completion callback is pending when the resolver is destroyed, the | 21 // If a completion callback is pending when the resolver is destroyed, the |
| 22 // host resolution is cancelled, and the completion callback will not be | 22 // host resolution is cancelled, and the completion callback will not be |
| 23 // called. | 23 // called. |
| 24 ~SingleRequestHostResolver(); | 24 ~SingleRequestHostResolver(); |
| 25 | 25 |
| 26 // Resolves the given hostname (or IP address literal), filling out the | 26 // Resolves the given hostname (or IP address literal), filling out the |
| 27 // |addresses| object upon success. See HostResolver::Resolve() for details. | 27 // |addresses| object upon success. See HostResolver::Resolve() for details. |
| 28 int Resolve(const HostResolver::RequestInfo& info, | 28 int Resolve(const HostResolver::RequestInfo& info, |
| 29 AddressList* addresses, | 29 AddressList* addresses, |
| 30 OldCompletionCallback* callback, | 30 const CompletionCallback& callback, |
| 31 const BoundNetLog& net_log); | 31 const BoundNetLog& net_log); |
| 32 | 32 |
| 33 // Cancels the in-progress request, if any. This prevents the callback | 33 // Cancels the in-progress request, if any. This prevents the callback |
| 34 // from being invoked. Resolve() can be called again after cancelling. | 34 // from being invoked. Resolve() can be called again after cancelling. |
| 35 void Cancel(); | 35 void Cancel(); |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 // Callback for when the request to |resolver_| completes, so we dispatch | 38 // Callback for when the request to |resolver_| completes, so we dispatch |
| 39 // to the user's callback. | 39 // to the user's callback. |
| 40 void OnResolveCompletion(int result); | 40 void OnResolveCompletion(int result); |
| 41 | 41 |
| 42 // The actual host resolver that will handle the request. | 42 // The actual host resolver that will handle the request. |
| 43 HostResolver* const resolver_; | 43 HostResolver* const resolver_; |
| 44 | 44 |
| 45 // The current request (if any). | 45 // The current request (if any). |
| 46 HostResolver::RequestHandle cur_request_; | 46 HostResolver::RequestHandle cur_request_; |
| 47 OldCompletionCallback* cur_request_callback_; | 47 CompletionCallback cur_request_callback_; |
| 48 | 48 |
| 49 // Completion callback for when request to |resolver_| completes. | 49 // Completion callback for when request to |resolver_| completes. |
| 50 OldCompletionCallbackImpl<SingleRequestHostResolver> callback_; | 50 CompletionCallback callback_; |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(SingleRequestHostResolver); | 52 DISALLOW_COPY_AND_ASSIGN(SingleRequestHostResolver); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 } // namespace net | 55 } // namespace net |
| 56 | 56 |
| 57 #endif // NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_ | 57 #endif // NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_ |
| OLD | NEW |