summaryrefslogtreecommitdiffstats
path: root/net/dns/dns_client.cc
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 23:32:58 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 23:32:58 +0000
commitad24b1827fe58c4a22c0cddb5791a95f2ab1b21b (patch)
tree7e5e4727d7ab5e3a96bc95ee890aebb1b6c2d608 /net/dns/dns_client.cc
parentd7de57877613a63e36facbd485245918c1131f61 (diff)
downloadchromium_src-ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b.zip
chromium_src-ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b.tar.gz
chromium_src-ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b.tar.bz2
Isolates generic DnsClient from AsyncHostResolver.
DnsClient provides a generic DNS client that allows fetching resource records. DnsClient is very lightweight and does not support aggregation, queuing or prioritization of requests. This is the first CL in a series to merge AsyncHostResolver into HostResolverImpl. Also introduces general-purpose BigEndianReader/Writer. BUG=90881 TEST=./net_unittests Review URL: http://codereview.chromium.org/8762001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/dns_client.cc')
-rw-r--r--net/dns/dns_client.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/net/dns/dns_client.cc b/net/dns/dns_client.cc
new file mode 100644
index 0000000..de60cc3
--- /dev/null
+++ b/net/dns/dns_client.cc
@@ -0,0 +1,91 @@
+// 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.
+
+#include "net/dns/dns_client.h"
+
+#include "base/bind.h"
+#include "base/string_piece.h"
+#include "net/base/net_errors.h"
+#include "net/dns/dns_response.h"
+#include "net/dns/dns_session.h"
+#include "net/dns/dns_transaction.h"
+#include "net/socket/client_socket_factory.h"
+
+namespace net {
+
+DnsClient::Request::Request(const base::StringPiece& qname,
+ uint16 qtype,
+ const RequestCallback& callback)
+ : qname_(qname.data(), qname.size()),
+ qtype_(qtype),
+ callback_(callback) {
+}
+
+DnsClient::Request::~Request() {}
+
+// Implementation of DnsClient that uses DnsTransaction to serve requests.
+class DnsClientImpl : public DnsClient {
+ public:
+ class RequestImpl : public Request {
+ public:
+ RequestImpl(const base::StringPiece& qname,
+ uint16 qtype,
+ const RequestCallback& callback,
+ DnsSession* session,
+ const BoundNetLog& net_log)
+ : Request(qname, qtype, callback),
+ session_(session),
+ net_log_(net_log) {
+ }
+
+ virtual int Start() OVERRIDE {
+ transaction_.reset(new DnsTransaction(
+ session_,
+ qname(),
+ qtype(),
+ base::Bind(&RequestImpl::OnComplete, base::Unretained(this)),
+ net_log_));
+ return transaction_->Start();
+ }
+
+ void OnComplete(DnsTransaction* transaction, int rv) {
+ DCHECK_EQ(transaction_.get(), transaction);
+ // TODO(szym):
+ // - handle retransmissions here instead of DnsTransaction
+ // - handle rcode and flags here instead of DnsTransaction
+ // - update RTT in DnsSession
+ // - perform suffix search
+ // - handle DNS over TCP
+ DoCallback(rv, (rv == OK) ? transaction->response() : NULL);
+ }
+
+ private:
+ scoped_refptr<DnsSession> session_;
+ BoundNetLog net_log_;
+ scoped_ptr<DnsTransaction> transaction_;
+ };
+
+ explicit DnsClientImpl(DnsSession* session) {
+ session_ = session;
+ }
+
+ virtual Request* CreateRequest(
+ const base::StringPiece& qname,
+ uint16 qtype,
+ const RequestCallback& callback,
+ const BoundNetLog& source_net_log) OVERRIDE {
+ return new RequestImpl(qname, qtype, callback, session_, source_net_log);
+ }
+
+ private:
+ scoped_refptr<DnsSession> session_;
+};
+
+// static
+DnsClient* DnsClient::CreateClient(DnsSession* session) {
+ return new DnsClientImpl(session);
+}
+
+} // namespace net
+