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
3 // found in the LICENSE file.
5 // ClientSocketPoolManager manages access to all ClientSocketPools. It's a
6 // simple container for all of them. Most importantly, it handles the lifetime
7 // and destruction order properly.
9 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_
10 #define NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_
12 #include "net/base/completion_callback.h"
13 #include "net/base/net_export.h"
14 #include "net/base/request_priority.h"
15 #include "net/http/http_network_session.h"
25 typedef base::Callback
<int(const AddressList
&, const BoundNetLog
& net_log
)>
26 OnHostResolutionCallback
;
29 class ClientSocketHandle
;
31 class HttpNetworkSession
;
32 class HttpProxyClientSocketPool
;
33 class HttpRequestHeaders
;
35 class TransportClientSocketPool
;
36 class SOCKSClientSocketPool
;
37 class SSLClientSocketPool
;
41 // This should rather be a simple constant but Windows shared libs doesn't
42 // really offer much flexiblity in exporting contants.
43 enum DefaultMaxValues
{ kDefaultMaxSocketsPerProxyServer
= 32 };
45 class NET_EXPORT_PRIVATE ClientSocketPoolManager
{
47 enum SocketGroupType
{
48 SSL_GROUP
, // For all TLS sockets.
49 NORMAL_GROUP
, // For normal HTTP sockets.
50 FTP_GROUP
// For FTP sockets (over an HTTP proxy).
53 ClientSocketPoolManager();
54 virtual ~ClientSocketPoolManager();
56 // The setter methods below affect only newly created socket pools after the
57 // methods are called. Normally they should be called at program startup
58 // before any ClientSocketPoolManagerImpl is created.
59 static int max_sockets_per_pool(HttpNetworkSession::SocketPoolType pool_type
);
60 static void set_max_sockets_per_pool(
61 HttpNetworkSession::SocketPoolType pool_type
,
64 static int max_sockets_per_group(
65 HttpNetworkSession::SocketPoolType pool_type
);
66 static void set_max_sockets_per_group(
67 HttpNetworkSession::SocketPoolType pool_type
,
70 static int max_sockets_per_proxy_server(
71 HttpNetworkSession::SocketPoolType pool_type
);
72 static void set_max_sockets_per_proxy_server(
73 HttpNetworkSession::SocketPoolType pool_type
,
76 virtual void FlushSocketPoolsWithError(int error
) = 0;
77 virtual void CloseIdleSockets() = 0;
78 virtual TransportClientSocketPool
* GetTransportSocketPool() = 0;
79 virtual SSLClientSocketPool
* GetSSLSocketPool() = 0;
80 virtual SOCKSClientSocketPool
* GetSocketPoolForSOCKSProxy(
81 const HostPortPair
& socks_proxy
) = 0;
82 virtual HttpProxyClientSocketPool
* GetSocketPoolForHTTPProxy(
83 const HostPortPair
& http_proxy
) = 0;
84 virtual SSLClientSocketPool
* GetSocketPoolForSSLWithProxy(
85 const HostPortPair
& proxy_server
) = 0;
86 // Creates a Value summary of the state of the socket pools. The caller is
87 // responsible for deleting the returned value.
88 virtual base::Value
* SocketPoolInfoToValue() const = 0;
91 // A helper method that uses the passed in proxy information to initialize a
92 // ClientSocketHandle with the relevant socket pool. Use this method for
93 // HTTP/HTTPS requests. |ssl_config_for_origin| is only used if the request
94 // uses SSL and |ssl_config_for_proxy| is used if the proxy server is HTTPS.
95 // |resolution_callback| will be invoked after the the hostname is
96 // resolved. If |resolution_callback| does not return OK, then the
97 // connection will be aborted with that value.
98 // If |want_spdy_over_ssl| is true, then after the SSL handshake is complete,
99 // SPDY must have been negotiated or else it will be considered an error.
100 int InitSocketHandleForHttpRequest(
101 ClientSocketPoolManager::SocketGroupType group_type
,
102 const HostPortPair
& endpoint
,
103 const HttpRequestHeaders
& request_extra_headers
,
104 int request_load_flags
,
105 RequestPriority request_priority
,
106 HttpNetworkSession
* session
,
107 const ProxyInfo
& proxy_info
,
108 bool want_spdy_over_npn
,
109 const SSLConfig
& ssl_config_for_origin
,
110 const SSLConfig
& ssl_config_for_proxy
,
111 PrivacyMode privacy_mode
,
112 const BoundNetLog
& net_log
,
113 ClientSocketHandle
* socket_handle
,
114 const OnHostResolutionCallback
& resolution_callback
,
115 const CompletionCallback
& callback
);
117 // A helper method that uses the passed in proxy information to initialize a
118 // ClientSocketHandle with the relevant socket pool. Use this method for
119 // HTTP/HTTPS requests for WebSocket handshake.
120 // |ssl_config_for_origin| is only used if the request
121 // uses SSL and |ssl_config_for_proxy| is used if the proxy server is HTTPS.
122 // |resolution_callback| will be invoked after the the hostname is
123 // resolved. If |resolution_callback| does not return OK, then the
124 // connection will be aborted with that value.
125 // This function uses WEBSOCKET_SOCKET_POOL socket pools.
126 int InitSocketHandleForWebSocketRequest(
127 ClientSocketPoolManager::SocketGroupType group_type
,
128 const HostPortPair
& endpoint
,
129 const HttpRequestHeaders
& request_extra_headers
,
130 int request_load_flags
,
131 RequestPriority request_priority
,
132 HttpNetworkSession
* session
,
133 const ProxyInfo
& proxy_info
,
134 bool want_spdy_over_npn
,
135 const SSLConfig
& ssl_config_for_origin
,
136 const SSLConfig
& ssl_config_for_proxy
,
137 PrivacyMode privacy_mode
,
138 const BoundNetLog
& net_log
,
139 ClientSocketHandle
* socket_handle
,
140 const OnHostResolutionCallback
& resolution_callback
,
141 const CompletionCallback
& callback
);
143 // A helper method that uses the passed in proxy information to initialize a
144 // ClientSocketHandle with the relevant socket pool. Use this method for
145 // a raw socket connection to a host-port pair (that needs to tunnel through
147 NET_EXPORT
int InitSocketHandleForRawConnect(
148 const HostPortPair
& host_port_pair
,
149 HttpNetworkSession
* session
,
150 const ProxyInfo
& proxy_info
,
151 const SSLConfig
& ssl_config_for_origin
,
152 const SSLConfig
& ssl_config_for_proxy
,
153 PrivacyMode privacy_mode
,
154 const BoundNetLog
& net_log
,
155 ClientSocketHandle
* socket_handle
,
156 const CompletionCallback
& callback
);
158 // A helper method that uses the passed in proxy information to initialize a
159 // ClientSocketHandle with the relevant socket pool. Use this method for
160 // a raw socket connection with TLS negotiation to a host-port pair (that needs
161 // to tunnel through the proxies).
162 NET_EXPORT
int InitSocketHandleForTlsConnect(
163 const HostPortPair
& host_port_pair
,
164 HttpNetworkSession
* session
,
165 const ProxyInfo
& proxy_info
,
166 const SSLConfig
& ssl_config_for_origin
,
167 const SSLConfig
& ssl_config_for_proxy
,
168 PrivacyMode privacy_mode
,
169 const BoundNetLog
& net_log
,
170 ClientSocketHandle
* socket_handle
,
171 const CompletionCallback
& callback
);
173 // Similar to InitSocketHandleForHttpRequest except that it initiates the
174 // desired number of preconnect streams from the relevant socket pool.
175 int PreconnectSocketsForHttpRequest(
176 ClientSocketPoolManager::SocketGroupType group_type
,
177 const HostPortPair
& endpoint
,
178 const HttpRequestHeaders
& request_extra_headers
,
179 int request_load_flags
,
180 RequestPriority request_priority
,
181 HttpNetworkSession
* session
,
182 const ProxyInfo
& proxy_info
,
183 bool want_spdy_over_npn
,
184 const SSLConfig
& ssl_config_for_origin
,
185 const SSLConfig
& ssl_config_for_proxy
,
186 PrivacyMode privacy_mode
,
187 const BoundNetLog
& net_log
,
188 int num_preconnect_streams
);
192 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_