From ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b Mon Sep 17 00:00:00 2001 From: "szym@chromium.org" Date: Tue, 6 Dec 2011 23:32:58 +0000 Subject: 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 --- net/dns/dns_session.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 net/dns/dns_session.h (limited to 'net/dns/dns_session.h') diff --git a/net/dns/dns_session.h b/net/dns/dns_session.h new file mode 100644 index 0000000..df986ea --- /dev/null +++ b/net/dns/dns_session.h @@ -0,0 +1,70 @@ +// 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. + +#ifndef NET_DNS_DNS_SESSION_H_ +#define NET_DNS_DNS_SESSION_H_ +#pragma once + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/time.h" +#include "net/base/net_export.h" +#include "net/base/rand_callback.h" +#include "net/dns/dns_config_service.h" + +namespace net { + +class ClientSocketFactory; +class NetLog; + +// Session parameters and state shared between DNS transactions. +// Ref-counted so that DnsClient::Request can keep working in absence of +// DnsClient. A DnsSession must be recreated when DnsConfig changes. +class NET_EXPORT_PRIVATE DnsSession + : NON_EXPORTED_BASE(public base::RefCounted) { + public: + typedef base::Callback RandCallback; + + DnsSession(const DnsConfig& config, + ClientSocketFactory* factory, + const RandIntCallback& rand_int_callback, + NetLog* net_log); + + ClientSocketFactory* socket_factory() const { return socket_factory_.get(); } + const DnsConfig& config() const { return config_; } + NetLog* net_log() const { return net_log_; } + + // Return the next random query ID. + int NextId() const; + + // Return the next server address. + const IPEndPoint& NextServer(); + + // Return the timeout for the next transaction. + base::TimeDelta NextTimeout(int attempt); + + private: + friend class base::RefCounted; + ~DnsSession(); + + const DnsConfig config_; + scoped_ptr socket_factory_; + RandCallback rand_callback_; + NetLog* net_log_; + + // Current index into |config_.nameservers|. + int server_index_; + + // TODO(szym): add current RTT estimate + // TODO(szym): add flag to indicate DNSSEC is supported + // TODO(szym): add TCP connection pool to support DNS over TCP + // TODO(szym): add UDP socket pool ? + + DISALLOW_COPY_AND_ASSIGN(DnsSession); +}; + +} // namespace net + +#endif // NET_DNS_DNS_SESSION_H_ + -- cgit v1.1