| 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_SOCKET_POOL_H_ | 5 #ifndef NET_DNS_DNS_SOCKET_POOL_H_ |
| 6 #define NET_DNS_DNS_SOCKET_POOL_H_ | 6 #define NET_DNS_DNS_SOCKET_POOL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/base/rand_callback.h" | 13 #include "net/base/rand_callback.h" |
| 14 #include "net/log/net_log.h" | |
| 15 | 14 |
| 16 namespace net { | 15 namespace net { |
| 17 | 16 |
| 18 class ClientSocketFactory; | 17 class ClientSocketFactory; |
| 19 class DatagramClientSocket; | 18 class DatagramClientSocket; |
| 20 class IPEndPoint; | 19 class IPEndPoint; |
| 21 class NetLog; | 20 class NetLog; |
| 21 struct NetLogSource; |
| 22 class StreamSocket; | 22 class StreamSocket; |
| 23 | 23 |
| 24 // A DnsSocketPool is an abstraction layer around a ClientSocketFactory that | 24 // A DnsSocketPool is an abstraction layer around a ClientSocketFactory that |
| 25 // allows preallocation, reuse, or other strategies to manage sockets connected | 25 // allows preallocation, reuse, or other strategies to manage sockets connected |
| 26 // to DNS servers. | 26 // to DNS servers. |
| 27 class NET_EXPORT_PRIVATE DnsSocketPool { | 27 class NET_EXPORT_PRIVATE DnsSocketPool { |
| 28 public: | 28 public: |
| 29 virtual ~DnsSocketPool() { } | 29 virtual ~DnsSocketPool() { } |
| 30 | 30 |
| 31 // Creates a DnsSocketPool that implements the default strategy for managing | 31 // Creates a DnsSocketPool that implements the default strategy for managing |
| (...skipping 28 matching lines...) Expand all Loading... |
| 60 unsigned server_index) = 0; | 60 unsigned server_index) = 0; |
| 61 | 61 |
| 62 // Frees a socket allocated by AllocateSocket. |server_index| must be the | 62 // Frees a socket allocated by AllocateSocket. |server_index| must be the |
| 63 // same index passed to AllocateSocket. | 63 // same index passed to AllocateSocket. |
| 64 virtual void FreeSocket(unsigned server_index, | 64 virtual void FreeSocket(unsigned server_index, |
| 65 std::unique_ptr<DatagramClientSocket> socket) = 0; | 65 std::unique_ptr<DatagramClientSocket> socket) = 0; |
| 66 | 66 |
| 67 // Creates a StreamSocket from the factory for a transaction over TCP. These | 67 // Creates a StreamSocket from the factory for a transaction over TCP. These |
| 68 // sockets are not pooled. | 68 // sockets are not pooled. |
| 69 std::unique_ptr<StreamSocket> CreateTCPSocket(unsigned server_index, | 69 std::unique_ptr<StreamSocket> CreateTCPSocket(unsigned server_index, |
| 70 const NetLog::Source& source); | 70 const NetLogSource& source); |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 DnsSocketPool(ClientSocketFactory* socket_factory, | 73 DnsSocketPool(ClientSocketFactory* socket_factory, |
| 74 const RandIntCallback& rand_int_callback); | 74 const RandIntCallback& rand_int_callback); |
| 75 | 75 |
| 76 void InitializeInternal( | 76 void InitializeInternal( |
| 77 const std::vector<IPEndPoint>* nameservers, | 77 const std::vector<IPEndPoint>* nameservers, |
| 78 NetLog* net_log); | 78 NetLog* net_log); |
| 79 | 79 |
| 80 std::unique_ptr<DatagramClientSocket> CreateConnectedSocket( | 80 std::unique_ptr<DatagramClientSocket> CreateConnectedSocket( |
| 81 unsigned server_index); | 81 unsigned server_index); |
| 82 | 82 |
| 83 // Returns a random int in the specified range. | 83 // Returns a random int in the specified range. |
| 84 int GetRandomInt(int min, int max); | 84 int GetRandomInt(int min, int max); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 ClientSocketFactory* socket_factory_; | 87 ClientSocketFactory* socket_factory_; |
| 88 const RandIntCallback& rand_int_callback_; | 88 const RandIntCallback& rand_int_callback_; |
| 89 NetLog* net_log_; | 89 NetLog* net_log_; |
| 90 const std::vector<IPEndPoint>* nameservers_; | 90 const std::vector<IPEndPoint>* nameservers_; |
| 91 bool initialized_; | 91 bool initialized_; |
| 92 | 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(DnsSocketPool); | 93 DISALLOW_COPY_AND_ASSIGN(DnsSocketPool); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // namespace net | 96 } // namespace net |
| 97 | 97 |
| 98 #endif // NET_DNS_DNS_SOCKET_POOL_H_ | 98 #endif // NET_DNS_DNS_SOCKET_POOL_H_ |
| OLD | NEW |