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