Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DNS_DNS_SESSION_H_ | 5 #ifndef NET_DNS_DNS_SESSION_H_ |
| 6 #define NET_DNS_DNS_SESSION_H_ | 6 #define NET_DNS_DNS_SESSION_H_ |
| 7 | 7 |
| 8 #include <vector> | |
| 9 | |
| 8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/time.h" | 12 #include "base/time.h" |
| 10 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 11 #include "net/base/rand_callback.h" | 14 #include "net/base/rand_callback.h" |
| 12 #include "net/dns/dns_config_service.h" | 15 #include "net/dns/dns_config_service.h" |
| 16 #include "net/dns/dns_socket_pool.h" | |
| 17 #include "net/udp/datagram_client_socket.h" | |
| 13 | 18 |
| 14 namespace net { | 19 namespace net { |
| 15 | 20 |
| 16 class ClientSocketFactory; | 21 class ClientSocketFactory; |
| 17 class NetLog; | 22 class NetLog; |
| 18 | 23 |
| 19 // Session parameters and state shared between DNS transactions. | 24 // Session parameters and state shared between DNS transactions. |
| 20 // Ref-counted so that DnsClient::Request can keep working in absence of | 25 // Ref-counted so that DnsClient::Request can keep working in absence of |
| 21 // DnsClient. A DnsSession must be recreated when DnsConfig changes. | 26 // DnsClient. A DnsSession must be recreated when DnsConfig changes. |
| 22 class NET_EXPORT_PRIVATE DnsSession | 27 class NET_EXPORT_PRIVATE DnsSession |
| 23 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) { | 28 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) { |
| 24 public: | 29 public: |
| 25 typedef base::Callback<int()> RandCallback; | 30 typedef base::Callback<int()> RandCallback; |
| 26 | 31 |
| 32 class SocketLease { | |
|
szym
2012/12/13 21:45:24
NET_EXPORT_PRIVATE got lost in the rebase?
| |
| 33 public: | |
| 34 SocketLease(scoped_refptr<DnsSession> session, | |
| 35 unsigned server_index, | |
| 36 scoped_ptr<DatagramClientSocket> socket); | |
| 37 ~SocketLease(); | |
| 38 | |
| 39 DatagramClientSocket* socket() { return socket_.get(); } | |
| 40 | |
| 41 private: | |
| 42 scoped_refptr<DnsSession> session_; | |
| 43 unsigned server_index_; | |
| 44 scoped_ptr<DatagramClientSocket> socket_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(SocketLease); | |
| 47 }; | |
| 48 | |
| 27 DnsSession(const DnsConfig& config, | 49 DnsSession(const DnsConfig& config, |
| 28 ClientSocketFactory* factory, | 50 scoped_ptr<DnsSocketPool> socket_pool, |
| 29 const RandIntCallback& rand_int_callback, | 51 const RandIntCallback& rand_int_callback, |
| 30 NetLog* net_log); | 52 NetLog* net_log); |
| 31 | 53 |
| 32 const DnsConfig& config() const { return config_; } | 54 const DnsConfig& config() const { return config_; } |
| 33 NetLog* net_log() const { return net_log_; } | 55 NetLog* net_log() const { return net_log_; } |
| 34 | 56 |
| 35 ClientSocketFactory* socket_factory() { return socket_factory_; } | |
| 36 | |
| 37 // Return the next random query ID. | 57 // Return the next random query ID. |
| 38 int NextQueryId() const; | 58 int NextQueryId() const; |
| 39 | 59 |
| 40 // Return the index of the first configured server to use on first attempt. | 60 // Return the index of the first configured server to use on first attempt. |
| 41 int NextFirstServerIndex(); | 61 int NextFirstServerIndex(); |
| 42 | 62 |
| 43 // Return the timeout for the next query. | 63 // Return the timeout for the next query. |
| 44 base::TimeDelta NextTimeout(int attempt); | 64 base::TimeDelta NextTimeout(int attempt); |
| 45 | 65 |
| 66 // Allocate a socket, already connected to the server address. | |
| 67 // When the SocketLease is destroyed, the socket will be freed. | |
| 68 scoped_ptr<SocketLease> AllocateSocket(unsigned server_index, | |
| 69 const NetLog::Source& source); | |
| 70 | |
| 46 private: | 71 private: |
| 47 friend class base::RefCounted<DnsSession>; | 72 friend class base::RefCounted<DnsSession>; |
| 48 ~DnsSession(); | 73 ~DnsSession(); |
| 49 | 74 |
| 75 // Release a socket. | |
| 76 void FreeSocket(unsigned server_index, | |
| 77 scoped_ptr<DatagramClientSocket> socket); | |
| 78 | |
| 50 const DnsConfig config_; | 79 const DnsConfig config_; |
| 51 ClientSocketFactory* socket_factory_; | 80 scoped_ptr<DnsSocketPool> socket_pool_; |
| 52 RandCallback rand_callback_; | 81 RandCallback rand_callback_; |
| 53 NetLog* net_log_; | 82 NetLog* net_log_; |
| 54 | 83 |
| 55 // Current index into |config_.nameservers| to begin resolution with. | 84 // Current index into |config_.nameservers| to begin resolution with. |
| 56 int server_index_; | 85 int server_index_; |
| 57 | 86 |
| 58 // TODO(szym): Add current RTT estimate. | 87 // TODO(szym): Add current RTT estimate. |
| 59 // TODO(szym): Add TCP connection pool to support DNS over TCP. | 88 // TODO(szym): Add TCP connection pool to support DNS over TCP. |
| 60 // TODO(szym): Add UDP port pool to avoid NAT table overload. | |
| 61 | 89 |
| 62 DISALLOW_COPY_AND_ASSIGN(DnsSession); | 90 DISALLOW_COPY_AND_ASSIGN(DnsSession); |
| 63 }; | 91 }; |
| 64 | 92 |
| 65 } // namespace net | 93 } // namespace net |
| 66 | 94 |
| 67 #endif // NET_DNS_DNS_SESSION_H_ | 95 #endif // NET_DNS_DNS_SESSION_H_ |
| OLD | NEW |