Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / socket / client_socket_pool_manager.h
blobd8d22a1b3eb3d95a7cf0f0d8d01aab78beffe342
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.
4 //
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"
17 class GURL;
19 namespace base {
20 class Value;
23 namespace net {
25 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)>
26 OnHostResolutionCallback;
28 class BoundNetLog;
29 class ClientSocketHandle;
30 class HostPortPair;
31 class HttpNetworkSession;
32 class HttpProxyClientSocketPool;
33 class HttpRequestHeaders;
34 class ProxyInfo;
35 class TransportClientSocketPool;
36 class SOCKSClientSocketPool;
37 class SSLClientSocketPool;
39 struct SSLConfig;
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 {
46 public:
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,
62 int socket_count);
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,
68 int socket_count);
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,
74 int socket_count);
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.
87 virtual scoped_ptr<base::Value> SocketPoolInfoToValue() const = 0;
90 // A helper method that uses the passed in proxy information to initialize a
91 // ClientSocketHandle with the relevant socket pool. Use this method for
92 // HTTP/HTTPS requests. |ssl_config_for_origin| is only used if the request
93 // uses SSL and |ssl_config_for_proxy| is used if the proxy server is HTTPS.
94 // |resolution_callback| will be invoked after the the hostname is
95 // resolved. If |resolution_callback| does not return OK, then the
96 // connection will be aborted with that value.
97 // If |expect_spdy| is true, then after the SSL handshake is complete,
98 // SPDY must have been negotiated or else it will be considered an error.
99 int InitSocketHandleForHttpRequest(
100 ClientSocketPoolManager::SocketGroupType group_type,
101 const HostPortPair& endpoint,
102 const HttpRequestHeaders& request_extra_headers,
103 int request_load_flags,
104 RequestPriority request_priority,
105 HttpNetworkSession* session,
106 const ProxyInfo& proxy_info,
107 bool expect_spdy,
108 const SSLConfig& ssl_config_for_origin,
109 const SSLConfig& ssl_config_for_proxy,
110 PrivacyMode privacy_mode,
111 const BoundNetLog& net_log,
112 ClientSocketHandle* socket_handle,
113 const OnHostResolutionCallback& resolution_callback,
114 const CompletionCallback& callback);
116 // A helper method that uses the passed in proxy information to initialize a
117 // ClientSocketHandle with the relevant socket pool. Use this method for
118 // HTTP/HTTPS requests for WebSocket handshake.
119 // |ssl_config_for_origin| is only used if the request
120 // uses SSL and |ssl_config_for_proxy| is used if the proxy server is HTTPS.
121 // |resolution_callback| will be invoked after the the hostname is
122 // resolved. If |resolution_callback| does not return OK, then the
123 // connection will be aborted with that value.
124 // This function uses WEBSOCKET_SOCKET_POOL socket pools.
125 int InitSocketHandleForWebSocketRequest(
126 ClientSocketPoolManager::SocketGroupType group_type,
127 const HostPortPair& endpoint,
128 const HttpRequestHeaders& request_extra_headers,
129 int request_load_flags,
130 RequestPriority request_priority,
131 HttpNetworkSession* session,
132 const ProxyInfo& proxy_info,
133 bool expect_spdy,
134 const SSLConfig& ssl_config_for_origin,
135 const SSLConfig& ssl_config_for_proxy,
136 PrivacyMode privacy_mode,
137 const BoundNetLog& net_log,
138 ClientSocketHandle* socket_handle,
139 const OnHostResolutionCallback& resolution_callback,
140 const CompletionCallback& callback);
142 // A helper method that uses the passed in proxy information to initialize a
143 // ClientSocketHandle with the relevant socket pool. Use this method for
144 // a raw socket connection to a host-port pair (that needs to tunnel through
145 // the proxies).
146 NET_EXPORT int InitSocketHandleForRawConnect(
147 const HostPortPair& host_port_pair,
148 HttpNetworkSession* session,
149 const ProxyInfo& proxy_info,
150 const SSLConfig& ssl_config_for_origin,
151 const SSLConfig& ssl_config_for_proxy,
152 PrivacyMode privacy_mode,
153 const BoundNetLog& net_log,
154 ClientSocketHandle* socket_handle,
155 const CompletionCallback& callback);
157 // A helper method that uses the passed in proxy information to initialize a
158 // ClientSocketHandle with the relevant socket pool. Use this method for
159 // a raw socket connection with TLS negotiation to a host-port pair (that needs
160 // to tunnel through the proxies).
161 NET_EXPORT int InitSocketHandleForTlsConnect(
162 const HostPortPair& host_port_pair,
163 HttpNetworkSession* session,
164 const ProxyInfo& proxy_info,
165 const SSLConfig& ssl_config_for_origin,
166 const SSLConfig& ssl_config_for_proxy,
167 PrivacyMode privacy_mode,
168 const BoundNetLog& net_log,
169 ClientSocketHandle* socket_handle,
170 const CompletionCallback& callback);
172 // Similar to InitSocketHandleForHttpRequest except that it initiates the
173 // desired number of preconnect streams from the relevant socket pool.
174 int PreconnectSocketsForHttpRequest(
175 ClientSocketPoolManager::SocketGroupType group_type,
176 const HostPortPair& endpoint,
177 const HttpRequestHeaders& request_extra_headers,
178 int request_load_flags,
179 RequestPriority request_priority,
180 HttpNetworkSession* session,
181 const ProxyInfo& proxy_info,
182 bool expect_spdy,
183 const SSLConfig& ssl_config_for_origin,
184 const SSLConfig& ssl_config_for_proxy,
185 PrivacyMode privacy_mode,
186 const BoundNetLog& net_log,
187 int num_preconnect_streams);
189 } // namespace net
191 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_