diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:32:58 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:32:58 +0000 |
commit | ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b (patch) | |
tree | 7e5e4727d7ab5e3a96bc95ee890aebb1b6c2d608 /net/dns/dns_transaction.h | |
parent | d7de57877613a63e36facbd485245918c1131f61 (diff) | |
download | chromium_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_transaction.h')
-rw-r--r-- | net/dns/dns_transaction.h | 86 |
1 files changed, 22 insertions, 64 deletions
diff --git a/net/dns/dns_transaction.h b/net/dns/dns_transaction.h index c126193..d4078f0 100644 --- a/net/dns/dns_transaction.h +++ b/net/dns/dns_transaction.h @@ -6,12 +6,10 @@ #define NET_DNS_DNS_TRANSACTION_H_ #pragma once -#include <set> #include <string> -#include <utility> #include <vector> -#include "base/gtest_prod_util.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/timer.h" #include "base/threading/non_thread_safe.h" @@ -23,70 +21,39 @@ namespace net { -class ClientSocketFactory; class DatagramClientSocket; class DnsQuery; class DnsResponse; +class DnsSession; -// Performs (with fixed retries) a single asynchronous DNS transaction, +// Performs a single asynchronous DNS transaction over UDP, // which consists of sending out a DNS query, waiting for a response, and -// parsing and returning the IP addresses that it matches. +// returning the response that it matches. class NET_EXPORT_PRIVATE DnsTransaction : NON_EXPORTED_BASE(public base::NonThreadSafe) { public: - typedef std::pair<std::string, uint16> Key; - - // Interface that should be implemented by DnsTransaction consumers and - // passed to the |Start| method to be notified when the transaction has - // completed. - class NET_EXPORT_PRIVATE Delegate { - public: - Delegate(); - virtual ~Delegate(); - - // A consumer of DnsTransaction should override |OnTransactionComplete| - // and call |set_delegate(this)|. The method will be called once the - // resolution has completed, results passed in as arguments. - virtual void OnTransactionComplete( - int result, - const DnsTransaction* transaction, - const IPAddressList& ip_addresses); - - private: - friend class DnsTransaction; - - void Attach(DnsTransaction* transaction); - void Detach(DnsTransaction* transaction); - - std::set<DnsTransaction*> registered_transactions_; + typedef base::Callback<void(DnsTransaction*, int)> ResultCallback; + + // Create new transaction using the parameters and state in |session|. + // Issues query for name |qname| (in DNS format) type |qtype| and class IN. + // Calls |callback| on completion or timeout. + // TODO(szym): change dependency to (IPEndPoint, Socket, DnsQuery, callback) + DnsTransaction(DnsSession* session, + const base::StringPiece& qname, + uint16 qtype, + const ResultCallback& callback, + const BoundNetLog& source_net_log); + ~DnsTransaction(); - DISALLOW_COPY_AND_ASSIGN(Delegate); - }; + const DnsQuery* query() const { return query_.get(); } - // |dns_server| is the address of the DNS server, |dns_name| is the - // hostname (in DNS format) to be resolved, |query_type| is the type of - // the query, either kDNS_A or kDNS_AAAA, |rand_int| is the PRNG used for - // generating DNS query. - DnsTransaction(const IPEndPoint& dns_server, - const std::string& dns_name, - uint16 query_type, - const RandIntCallback& rand_int, - ClientSocketFactory* socket_factory, - const BoundNetLog& source_net_log, - NetLog* net_log); - ~DnsTransaction(); - void SetDelegate(Delegate* delegate); - const Key& key() const { return key_; } + const DnsResponse* response() const { return response_.get(); } // Starts the resolution process. Will return ERR_IO_PENDING and will // notify the caller via |delegate|. Should only be called once. int Start(); private: - FRIEND_TEST_ALL_PREFIXES(DnsTransactionTest, FirstTimeoutTest); - FRIEND_TEST_ALL_PREFIXES(DnsTransactionTest, SecondTimeoutTest); - FRIEND_TEST_ALL_PREFIXES(DnsTransactionTest, ThirdTimeoutTest); - enum State { STATE_CONNECT, STATE_CONNECT_COMPLETE, @@ -114,26 +81,17 @@ class NET_EXPORT_PRIVATE DnsTransaction : void RevokeTimer(); void OnTimeout(); - // This is to be used by unit tests only. - void set_timeouts_ms(const std::vector<base::TimeDelta>& timeouts_ms); - - const IPEndPoint dns_server_; - Key key_; - IPAddressList ip_addresses_; - Delegate* delegate_; - + scoped_refptr<DnsSession> session_; + IPEndPoint dns_server_; scoped_ptr<DnsQuery> query_; + ResultCallback callback_; scoped_ptr<DnsResponse> response_; scoped_ptr<DatagramClientSocket> socket_; // Number of retry attempts so far. - size_t attempts_; - - // Timeouts in milliseconds. - std::vector<base::TimeDelta> timeouts_ms_; + int attempts_; State next_state_; - ClientSocketFactory* socket_factory_; base::OneShotTimer<DnsTransaction> timer_; OldCompletionCallbackImpl<DnsTransaction> io_callback_; |