Chromium Code Reviews| Index: net/dns/dns_client.cc |
| diff --git a/net/dns/dns_client.cc b/net/dns/dns_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b5869fe4637fa1b26f149b2b8d04324a21e95845 |
| --- /dev/null |
| +++ b/net/dns/dns_client.cc |
| @@ -0,0 +1,92 @@ |
| +// 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()), |
|
mmenke
2011/12/02 00:53:55
nit: Indent 4 spaces.
szym
2011/12/05 23:06:28
Done.
|
| + 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 { |
|
mmenke
2011/12/02 00:53:55
Think you should either not make this an inner cla
|
| + 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) { |
| + } |
| + |
| + 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); |
| +} |
| + |
| + |
|
mmenke
2011/12/02 00:53:55
nit: Only one blank line needed
|
| +} // namespace net |
| + |