| 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 #ifndef NET_DNS_DNS_TRANSACTION_H_ | |
| 6 #define NET_DNS_DNS_TRANSACTION_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/timer.h" | |
| 15 #include "base/threading/non_thread_safe.h" | |
| 16 #include "net/base/completion_callback.h" | |
| 17 #include "net/base/ip_endpoint.h" | |
| 18 #include "net/base/net_export.h" | |
| 19 #include "net/base/net_log.h" | |
| 20 #include "net/base/rand_callback.h" | |
| 21 | |
| 22 namespace net { | |
| 23 | |
| 24 class DatagramClientSocket; | |
| 25 class DnsQuery; | |
| 26 class DnsResponse; | |
| 27 class DnsSession; | |
| 28 | |
| 29 // Performs a single asynchronous DNS transaction over UDP, | |
| 30 // which consists of sending out a DNS query, waiting for a response, and | |
| 31 // returning the response that it matches. | |
| 32 class NET_EXPORT_PRIVATE DnsTransaction : | |
| 33 NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
| 34 public: | |
| 35 typedef base::Callback<void(DnsTransaction*, int)> ResultCallback; | |
| 36 | |
| 37 // Create new transaction using the parameters and state in |session|. | |
| 38 // Issues query for name |qname| (in DNS format) type |qtype| and class IN. | |
| 39 // Calls |callback| on completion or timeout. | |
| 40 // TODO(szym): change dependency to (IPEndPoint, Socket, DnsQuery, callback) | |
| 41 DnsTransaction(DnsSession* session, | |
| 42 const base::StringPiece& qname, | |
| 43 uint16 qtype, | |
| 44 const ResultCallback& callback, | |
| 45 const BoundNetLog& source_net_log); | |
| 46 ~DnsTransaction(); | |
| 47 | |
| 48 const DnsQuery* query() const { return query_.get(); } | |
| 49 | |
| 50 const DnsResponse* response() const { return response_.get(); } | |
| 51 | |
| 52 // Starts the resolution process. Will return ERR_IO_PENDING and will | |
| 53 // notify the caller via |delegate|. Should only be called once. | |
| 54 int Start(); | |
| 55 | |
| 56 private: | |
| 57 enum State { | |
| 58 STATE_CONNECT, | |
| 59 STATE_CONNECT_COMPLETE, | |
| 60 STATE_SEND_QUERY, | |
| 61 STATE_SEND_QUERY_COMPLETE, | |
| 62 STATE_READ_RESPONSE, | |
| 63 STATE_READ_RESPONSE_COMPLETE, | |
| 64 STATE_NONE, | |
| 65 }; | |
| 66 | |
| 67 int DoLoop(int result); | |
| 68 void DoCallback(int result); | |
| 69 void OnIOComplete(int result); | |
| 70 | |
| 71 int DoConnect(); | |
| 72 int DoConnectComplete(int result); | |
| 73 int DoSendQuery(); | |
| 74 int DoSendQueryComplete(int result); | |
| 75 int DoReadResponse(); | |
| 76 int DoReadResponseComplete(int result); | |
| 77 | |
| 78 // Fixed number of attempts are made to send a query and read a response, | |
| 79 // and at the start of each, a timer is started with increasing delays. | |
| 80 void StartTimer(base::TimeDelta delay); | |
| 81 void RevokeTimer(); | |
| 82 void OnTimeout(); | |
| 83 | |
| 84 scoped_refptr<DnsSession> session_; | |
| 85 IPEndPoint dns_server_; | |
| 86 scoped_ptr<DnsQuery> query_; | |
| 87 ResultCallback callback_; | |
| 88 scoped_ptr<DnsResponse> response_; | |
| 89 scoped_ptr<DatagramClientSocket> socket_; | |
| 90 | |
| 91 // Number of retry attempts so far. | |
| 92 int attempts_; | |
| 93 | |
| 94 State next_state_; | |
| 95 base::OneShotTimer<DnsTransaction> timer_; | |
| 96 | |
| 97 BoundNetLog net_log_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(DnsTransaction); | |
| 100 }; | |
| 101 | |
| 102 } // namespace net | |
| 103 | |
| 104 #endif // NET_DNS_DNS_TRANSACTION_H_ | |
| OLD | NEW |