| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A ClientSocketPoolBase is used to restrict the number of sockets open at | 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at |
| 6 // a time. It also maintains a list of idle persistent sockets for reuse. | 6 // a time. It also maintains a list of idle persistent sockets for reuse. |
| 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle | 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle |
| 8 // the core logic of (1) restricting the number of active (connected or | 8 // the core logic of (1) restricting the number of active (connected or |
| 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) | 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) |
| 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) | 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include "base/basictypes.h" | 32 #include "base/basictypes.h" |
| 33 #include "base/memory/ref_counted.h" | 33 #include "base/memory/ref_counted.h" |
| 34 #include "base/memory/scoped_ptr.h" | 34 #include "base/memory/scoped_ptr.h" |
| 35 #include "base/task.h" | 35 #include "base/task.h" |
| 36 #include "base/time.h" | 36 #include "base/time.h" |
| 37 #include "base/timer.h" | 37 #include "base/timer.h" |
| 38 #include "net/base/address_list.h" | 38 #include "net/base/address_list.h" |
| 39 #include "net/base/completion_callback.h" | 39 #include "net/base/completion_callback.h" |
| 40 #include "net/base/load_states.h" | 40 #include "net/base/load_states.h" |
| 41 #include "net/base/net_api.h" | |
| 42 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 42 #include "net/base/net_export.h" |
| 43 #include "net/base/net_log.h" | 43 #include "net/base/net_log.h" |
| 44 #include "net/base/network_change_notifier.h" | 44 #include "net/base/network_change_notifier.h" |
| 45 #include "net/base/request_priority.h" | 45 #include "net/base/request_priority.h" |
| 46 #include "net/socket/client_socket_pool.h" | 46 #include "net/socket/client_socket_pool.h" |
| 47 #include "net/socket/stream_socket.h" | 47 #include "net/socket/stream_socket.h" |
| 48 | 48 |
| 49 namespace net { | 49 namespace net { |
| 50 | 50 |
| 51 class ClientSocketHandle; | 51 class ClientSocketHandle; |
| 52 | 52 |
| 53 // Returns the client socket reuse policy. | 53 // Returns the client socket reuse policy. |
| 54 NET_TEST int GetSocketReusePolicy(); | 54 NET_EXPORT_PRIVATE int GetSocketReusePolicy(); |
| 55 | 55 |
| 56 // Sets the client socket reuse policy. | 56 // Sets the client socket reuse policy. |
| 57 // NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value. | 57 // NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value. |
| 58 NET_API void SetSocketReusePolicy(int policy); | 58 NET_EXPORT void SetSocketReusePolicy(int policy); |
| 59 | 59 |
| 60 // ConnectJob provides an abstract interface for "connecting" a socket. | 60 // ConnectJob provides an abstract interface for "connecting" a socket. |
| 61 // The connection may involve host resolution, tcp connection, ssl connection, | 61 // The connection may involve host resolution, tcp connection, ssl connection, |
| 62 // etc. | 62 // etc. |
| 63 class NET_TEST ConnectJob { | 63 class NET_EXPORT_PRIVATE ConnectJob { |
| 64 public: | 64 public: |
| 65 class NET_TEST Delegate { | 65 class NET_EXPORT_PRIVATE Delegate { |
| 66 public: | 66 public: |
| 67 Delegate() {} | 67 Delegate() {} |
| 68 virtual ~Delegate() {} | 68 virtual ~Delegate() {} |
| 69 | 69 |
| 70 // Alerts the delegate that the connection completed. | 70 // Alerts the delegate that the connection completed. |
| 71 virtual void OnConnectJobComplete(int result, ConnectJob* job) = 0; | 71 virtual void OnConnectJobComplete(int result, ConnectJob* job) = 0; |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(Delegate); | 74 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 75 }; | 75 }; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 DISALLOW_COPY_AND_ASSIGN(ConnectJob); | 155 DISALLOW_COPY_AND_ASSIGN(ConnectJob); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 namespace internal { | 158 namespace internal { |
| 159 | 159 |
| 160 // ClientSocketPoolBaseHelper is an internal class that implements almost all | 160 // ClientSocketPoolBaseHelper is an internal class that implements almost all |
| 161 // the functionality from ClientSocketPoolBase without using templates. | 161 // the functionality from ClientSocketPoolBase without using templates. |
| 162 // ClientSocketPoolBase adds templated definitions built on top of | 162 // ClientSocketPoolBase adds templated definitions built on top of |
| 163 // ClientSocketPoolBaseHelper. This class is not for external use, please use | 163 // ClientSocketPoolBaseHelper. This class is not for external use, please use |
| 164 // ClientSocketPoolBase instead. | 164 // ClientSocketPoolBase instead. |
| 165 class NET_TEST ClientSocketPoolBaseHelper | 165 class NET_EXPORT_PRIVATE ClientSocketPoolBaseHelper |
| 166 : public ConnectJob::Delegate, | 166 : public ConnectJob::Delegate, |
| 167 public NetworkChangeNotifier::IPAddressObserver { | 167 public NetworkChangeNotifier::IPAddressObserver { |
| 168 public: | 168 public: |
| 169 typedef uint32 Flags; | 169 typedef uint32 Flags; |
| 170 | 170 |
| 171 // Used to specify specific behavior for the ClientSocketPool. | 171 // Used to specify specific behavior for the ClientSocketPool. |
| 172 enum Flag { | 172 enum Flag { |
| 173 NORMAL = 0, // Normal behavior. | 173 NORMAL = 0, // Normal behavior. |
| 174 NO_IDLE_SOCKETS = 0x1, // Do not return an idle socket. Create a new one. | 174 NO_IDLE_SOCKETS = 0x1, // Do not return an idle socket. Create a new one. |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 enum ClientSocketReusePolicy { | 177 enum ClientSocketReusePolicy { |
| 178 // Socket with largest amount of bytes transferred. | 178 // Socket with largest amount of bytes transferred. |
| 179 USE_WARMEST_SOCKET = 0, | 179 USE_WARMEST_SOCKET = 0, |
| 180 | 180 |
| 181 // Socket which scores highest on large bytes transferred and low idle time. | 181 // Socket which scores highest on large bytes transferred and low idle time. |
| 182 USE_WARM_SOCKET = 1, | 182 USE_WARM_SOCKET = 1, |
| 183 | 183 |
| 184 // Socket which was most recently used. | 184 // Socket which was most recently used. |
| 185 USE_LAST_ACCESSED_SOCKET = 2, | 185 USE_LAST_ACCESSED_SOCKET = 2, |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 class NET_TEST Request { | 188 class NET_EXPORT_PRIVATE Request { |
| 189 public: | 189 public: |
| 190 Request(ClientSocketHandle* handle, | 190 Request(ClientSocketHandle* handle, |
| 191 CompletionCallback* callback, | 191 CompletionCallback* callback, |
| 192 RequestPriority priority, | 192 RequestPriority priority, |
| 193 bool ignore_limits, | 193 bool ignore_limits, |
| 194 Flags flags, | 194 Flags flags, |
| 195 const BoundNetLog& net_log); | 195 const BoundNetLog& net_log); |
| 196 | 196 |
| 197 virtual ~Request(); | 197 virtual ~Request(); |
| 198 | 198 |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 // Histograms for the pool | 764 // Histograms for the pool |
| 765 ClientSocketPoolHistograms* const histograms_; | 765 ClientSocketPoolHistograms* const histograms_; |
| 766 internal::ClientSocketPoolBaseHelper helper_; | 766 internal::ClientSocketPoolBaseHelper helper_; |
| 767 | 767 |
| 768 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 768 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 769 }; | 769 }; |
| 770 | 770 |
| 771 } // namespace net | 771 } // namespace net |
| 772 | 772 |
| 773 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 773 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |