summaryrefslogtreecommitdiffstats
path: root/net/base/single_request_host_resolver.h
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-06 18:25:19 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-06 18:25:19 +0000
commitb11279e2abfc427e30f0ccaa8e265f5ebbb63b3c (patch)
tree88a3814a2a1c9e8ad675f6c27875bc04f8942038 /net/base/single_request_host_resolver.h
parent182d4f35a1b22d141ea12a7ba286440e5797bd36 (diff)
downloadchromium_src-b11279e2abfc427e30f0ccaa8e265f5ebbb63b3c.zip
chromium_src-b11279e2abfc427e30f0ccaa8e265f5ebbb63b3c.tar.gz
chromium_src-b11279e2abfc427e30f0ccaa8e265f5ebbb63b3c.tar.bz2
Add unit-tests for SingleRequestHostResolver.
To facilitate this, moved it out of host_resolver.cc to its own set of files. BUG=84261 Review URL: http://codereview.chromium.org/6993015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/single_request_host_resolver.h')
-rw-r--r--net/base/single_request_host_resolver.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/net/base/single_request_host_resolver.h b/net/base/single_request_host_resolver.h
new file mode 100644
index 0000000..6b9ec9b
--- /dev/null
+++ b/net/base/single_request_host_resolver.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_
+#define NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_
+#pragma once
+
+#include "net/base/host_resolver.h"
+
+namespace net {
+
+// This class represents the task of resolving a hostname (or IP address
+// literal) to an AddressList object. It wraps HostResolver to resolve only a
+// single hostname at a time and cancels this request when going out of scope.
+class NET_API SingleRequestHostResolver {
+ public:
+ // |resolver| must remain valid for the lifetime of |this|.
+ explicit SingleRequestHostResolver(HostResolver* resolver);
+
+ // If a completion callback is pending when the resolver is destroyed, the
+ // host resolution is cancelled, and the completion callback will not be
+ // called.
+ ~SingleRequestHostResolver();
+
+ // Resolves the given hostname (or IP address literal), filling out the
+ // |addresses| object upon success. See HostResolver::Resolve() for details.
+ int Resolve(const HostResolver::RequestInfo& info,
+ AddressList* addresses,
+ CompletionCallback* callback,
+ const BoundNetLog& net_log);
+
+ // Cancels the in-progress request, if any. This prevents the callback
+ // from being invoked. Resolve() can be called again after cancelling.
+ void Cancel();
+
+ private:
+ // Callback for when the request to |resolver_| completes, so we dispatch
+ // to the user's callback.
+ void OnResolveCompletion(int result);
+
+ // The actual host resolver that will handle the request.
+ HostResolver* const resolver_;
+
+ // The current request (if any).
+ HostResolver::RequestHandle cur_request_;
+ CompletionCallback* cur_request_callback_;
+
+ // Completion callback for when request to |resolver_| completes.
+ CompletionCallbackImpl<SingleRequestHostResolver> callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(SingleRequestHostResolver);
+};
+
+} // namespace net
+
+#endif // NET_BASE_SINGLE_REQUEST_HOST_RESOLVER_H_