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 { | |
| 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. | |
| 
 
szym
2012/09/26 11:16:12
Add remark here or above class SocketLease explain
 
Deprecated (see juliatuttle)
2012/09/26 20:44:50
Done.
 
 | |
| 67 scoped_ptr<SocketLease> AllocateSocket(unsigned server_index, | |
| 68 const NetLog::Source& source); | |
| 69 | |
| 46 private: | 70 private: | 
| 47 friend class base::RefCounted<DnsSession>; | 71 friend class base::RefCounted<DnsSession>; | 
| 48 ~DnsSession(); | 72 | 
| 73 // Release a socket. | |
| 74 void FreeSocket(unsigned server_index, | |
| 75 scoped_ptr<DatagramClientSocket> socket); | |
| 49 | 76 | 
| 50 const DnsConfig config_; | 77 const DnsConfig config_; | 
| 51 ClientSocketFactory* socket_factory_; | 78 scoped_ptr<DnsSocketPool> socket_pool_; | 
| 52 RandCallback rand_callback_; | 79 RandCallback rand_callback_; | 
| 53 NetLog* net_log_; | 80 NetLog* net_log_; | 
| 54 | 81 | 
| 55 // Current index into |config_.nameservers| to begin resolution with. | 82 // Current index into |config_.nameservers| to begin resolution with. | 
| 56 int server_index_; | 83 int server_index_; | 
| 57 | 84 | 
| 58 // TODO(szym): Add current RTT estimate. | 85 // TODO(szym): Add current RTT estimate. | 
| 59 // TODO(szym): Add TCP connection pool to support DNS over TCP. | 86 // TODO(szym): Add TCP connection pool to support DNS over TCP. | 
| 60 // TODO(szym): Add UDP port pool to avoid NAT table overload. | |
| 61 | 87 | 
| 62 DISALLOW_COPY_AND_ASSIGN(DnsSession); | 88 DISALLOW_COPY_AND_ASSIGN(DnsSession); | 
| 63 }; | 89 }; | 
| 64 | 90 | 
| 65 } // namespace net | 91 } // namespace net | 
| 66 | 92 | 
| 67 #endif // NET_DNS_DNS_SESSION_H_ | 93 #endif // NET_DNS_DNS_SESSION_H_ | 
| OLD | NEW |