| 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 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| 6 #define NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/template_util.h" | 15 #include "base/template_util.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/host_resolver.h" | 17 #include "net/base/host_resolver.h" |
| 18 #include "net/base/load_states.h" | 18 #include "net/base/load_states.h" |
| 19 #include "net/base/request_priority.h" | 19 #include "net/base/request_priority.h" |
| 20 | 20 |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 class ClientSocket; | |
| 26 class ClientSocketHandle; | 25 class ClientSocketHandle; |
| 27 class ClientSocketPoolHistograms; | 26 class ClientSocketPoolHistograms; |
| 27 class StreamSocket; |
| 28 | 28 |
| 29 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 29 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
| 30 // It also maintains a list of idle persistent sockets. | 30 // It also maintains a list of idle persistent sockets. |
| 31 // | 31 // |
| 32 class ClientSocketPool { | 32 class ClientSocketPool { |
| 33 public: | 33 public: |
| 34 // Requests a connected socket for a group_name. | 34 // Requests a connected socket for a group_name. |
| 35 // | 35 // |
| 36 // There are five possible results from calling this function: | 36 // There are five possible results from calling this function: |
| 37 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 37 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
| 38 // 2) RequestSocket returns OK with a newly connected socket. | 38 // 2) RequestSocket returns OK with a newly connected socket. |
| 39 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a | 39 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a |
| 40 // wait list until a socket is available to reuse or a new socket finishes | 40 // wait list until a socket is available to reuse or a new socket finishes |
| 41 // connecting. |priority| will determine the placement into the wait list. | 41 // connecting. |priority| will determine the placement into the wait list. |
| 42 // 4) An error occurred early on, so RequestSocket returns an error code. | 42 // 4) An error occurred early on, so RequestSocket returns an error code. |
| 43 // 5) A recoverable error occurred while setting up the socket. An error | 43 // 5) A recoverable error occurred while setting up the socket. An error |
| 44 // code is returned, but the |handle| is initialized with the new socket. | 44 // code is returned, but the |handle| is initialized with the new socket. |
| 45 // The caller must recover from the error before using the connection, or | 45 // The caller must recover from the error before using the connection, or |
| 46 // Disconnect the socket before releasing or resetting the |handle|. | 46 // Disconnect the socket before releasing or resetting the |handle|. |
| 47 // The current recoverable errors are: the errors accepted by | 47 // The current recoverable errors are: the errors accepted by |
| 48 // IsCertificateError(err) and PROXY_AUTH_REQUESTED, or | 48 // IsCertificateError(err) and PROXY_AUTH_REQUESTED, or |
| 49 // HTTPS_PROXY_TUNNEL_RESPONSE when reported by HttpProxyClientSocketPool. | 49 // HTTPS_PROXY_TUNNEL_RESPONSE when reported by HttpProxyClientSocketPool. |
| 50 // | 50 // |
| 51 // If this function returns OK, then |handle| is initialized upon return. | 51 // If this function returns OK, then |handle| is initialized upon return. |
| 52 // The |handle|'s is_initialized method will return true in this case. If a | 52 // The |handle|'s is_initialized method will return true in this case. If a |
| 53 // ClientSocket was reused, then ClientSocketPool will call | 53 // StreamSocket was reused, then ClientSocketPool will call |
| 54 // |handle|->set_reused(true). In either case, the socket will have been | 54 // |handle|->set_reused(true). In either case, the socket will have been |
| 55 // allocated and will be connected. A client might want to know whether or | 55 // allocated and will be connected. A client might want to know whether or |
| 56 // not the socket is reused in order to request a new socket if he encounters | 56 // not the socket is reused in order to request a new socket if he encounters |
| 57 // an error with the reused socket. | 57 // an error with the reused socket. |
| 58 // | 58 // |
| 59 // If ERR_IO_PENDING is returned, then the callback will be used to notify the | 59 // If ERR_IO_PENDING is returned, then the callback will be used to notify the |
| 60 // client of completion. | 60 // client of completion. |
| 61 // | 61 // |
| 62 // Profiling information for the request is saved to |net_log| if non-NULL. | 62 // Profiling information for the request is saved to |net_log| if non-NULL. |
| 63 virtual int RequestSocket(const std::string& group_name, | 63 virtual int RequestSocket(const std::string& group_name, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 // same handle parameter must be passed to this method as was passed to the | 86 // same handle parameter must be passed to this method as was passed to the |
| 87 // RequestSocket call being cancelled. The associated CompletionCallback is | 87 // RequestSocket call being cancelled. The associated CompletionCallback is |
| 88 // not run. However, for performance, we will let one ConnectJob complete | 88 // not run. However, for performance, we will let one ConnectJob complete |
| 89 // and go idle. | 89 // and go idle. |
| 90 virtual void CancelRequest(const std::string& group_name, | 90 virtual void CancelRequest(const std::string& group_name, |
| 91 ClientSocketHandle* handle) = 0; | 91 ClientSocketHandle* handle) = 0; |
| 92 | 92 |
| 93 // Called to release a socket once the socket is no longer needed. If the | 93 // Called to release a socket once the socket is no longer needed. If the |
| 94 // socket still has an established connection, then it will be added to the | 94 // socket still has an established connection, then it will be added to the |
| 95 // set of idle sockets to be used to satisfy future RequestSocket calls. | 95 // set of idle sockets to be used to satisfy future RequestSocket calls. |
| 96 // Otherwise, the ClientSocket is destroyed. |id| is used to differentiate | 96 // Otherwise, the StreamSocket is destroyed. |id| is used to differentiate |
| 97 // between updated versions of the same pool instance. The pool's id will | 97 // between updated versions of the same pool instance. The pool's id will |
| 98 // change when it flushes, so it can use this |id| to discard sockets with | 98 // change when it flushes, so it can use this |id| to discard sockets with |
| 99 // mismatched ids. | 99 // mismatched ids. |
| 100 virtual void ReleaseSocket(const std::string& group_name, | 100 virtual void ReleaseSocket(const std::string& group_name, |
| 101 ClientSocket* socket, | 101 StreamSocket* socket, |
| 102 int id) = 0; | 102 int id) = 0; |
| 103 | 103 |
| 104 // This flushes all state from the ClientSocketPool. This means that all | 104 // This flushes all state from the ClientSocketPool. This means that all |
| 105 // idle and connecting sockets are discarded. Active sockets being | 105 // idle and connecting sockets are discarded. Active sockets being |
| 106 // held by ClientSocketPool clients will be discarded when released back to | 106 // held by ClientSocketPool clients will be discarded when released back to |
| 107 // the pool. Does not flush any pools wrapped by |this|. | 107 // the pool. Does not flush any pools wrapped by |this|. |
| 108 virtual void Flush() = 0; | 108 virtual void Flush() = 0; |
| 109 | 109 |
| 110 // Called to close any idle connections held by the connection manager. | 110 // Called to close any idle connections held by the connection manager. |
| 111 virtual void CloseIdleSockets() = 0; | 111 virtual void CloseIdleSockets() = 0; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const scoped_refptr<SocketParams>& params, | 183 const scoped_refptr<SocketParams>& params, |
| 184 int num_sockets, | 184 int num_sockets, |
| 185 const BoundNetLog& net_log) { | 185 const BoundNetLog& net_log) { |
| 186 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); | 186 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); |
| 187 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 187 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
| 188 } | 188 } |
| 189 | 189 |
| 190 } // namespace net | 190 } // namespace net |
| 191 | 191 |
| 192 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 192 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |