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 #include "net/dns/dns_client.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/string_piece.h" |
| 9 #include "net/base/net_errors.h" |
| 10 #include "net/dns/dns_response.h" |
| 11 #include "net/dns/dns_session.h" |
| 12 #include "net/dns/dns_transaction.h" |
| 13 #include "net/socket/client_socket_factory.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 DnsClient::Request::Request(const base::StringPiece& qname, |
| 18 uint16 qtype, |
| 19 const RequestCallback& callback) |
| 20 : qname_(qname.data(), qname.size()), |
| 21 qtype_(qtype), |
| 22 callback_(callback) { |
| 23 } |
| 24 |
| 25 DnsClient::Request::~Request() {} |
| 26 |
| 27 // Implementation of DnsClient that uses DnsTransaction to serve requests. |
| 28 class DnsClientImpl : public DnsClient { |
| 29 public: |
| 30 class RequestImpl : public Request { |
| 31 public: |
| 32 RequestImpl(const base::StringPiece& qname, |
| 33 uint16 qtype, |
| 34 const RequestCallback& callback, |
| 35 DnsSession* session, |
| 36 const BoundNetLog& net_log) |
| 37 : Request(qname, qtype, callback), |
| 38 session_(session), |
| 39 net_log_(net_log) { |
| 40 } |
| 41 |
| 42 virtual int Start() OVERRIDE { |
| 43 transaction_.reset(new DnsTransaction( |
| 44 session_, |
| 45 qname(), |
| 46 qtype(), |
| 47 base::Bind(&RequestImpl::OnComplete, base::Unretained(this)), |
| 48 net_log_)); |
| 49 return transaction_->Start(); |
| 50 } |
| 51 |
| 52 void OnComplete(DnsTransaction* transaction, int rv) { |
| 53 DCHECK_EQ(transaction_.get(), transaction); |
| 54 // TODO(szym): |
| 55 // - handle retransmissions here instead of DnsTransaction |
| 56 // - handle rcode and flags here instead of DnsTransaction |
| 57 // - update RTT in DnsSession |
| 58 // - perform suffix search |
| 59 // - handle DNS over TCP |
| 60 DoCallback(rv, (rv == OK) ? transaction->response() : NULL); |
| 61 } |
| 62 |
| 63 private: |
| 64 scoped_refptr<DnsSession> session_; |
| 65 BoundNetLog net_log_; |
| 66 scoped_ptr<DnsTransaction> transaction_; |
| 67 }; |
| 68 |
| 69 explicit DnsClientImpl(DnsSession* session) { |
| 70 session_ = session; |
| 71 } |
| 72 |
| 73 virtual Request* CreateRequest( |
| 74 const base::StringPiece& qname, |
| 75 uint16 qtype, |
| 76 const RequestCallback& callback, |
| 77 const BoundNetLog& source_net_log) OVERRIDE { |
| 78 return new RequestImpl(qname, qtype, callback, session_, source_net_log); |
| 79 } |
| 80 |
| 81 private: |
| 82 scoped_refptr<DnsSession> session_; |
| 83 }; |
| 84 |
| 85 // static |
| 86 DnsClient* DnsClient::CreateClient(DnsSession* session) { |
| 87 return new DnsClientImpl(session); |
| 88 } |
| 89 |
| 90 } // namespace net |
| 91 |
OLD | NEW |