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