| 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 #include "net/socket/client_socket_pool_manager.h" | 5 #include "net/socket/client_socket_pool_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/http/http_proxy_client_socket_pool.h" | 12 #include "net/http/http_proxy_client_socket_pool.h" |
| 13 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
| 14 #include "net/http/http_stream_factory.h" | 14 #include "net/http/http_stream_factory.h" |
| 15 #include "net/proxy/proxy_info.h" | 15 #include "net/proxy/proxy_info.h" |
| 16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/client_socket_pool.h" |
| 17 #include "net/socket/socks_client_socket_pool.h" | 18 #include "net/socket/socks_client_socket_pool.h" |
| 18 #include "net/socket/ssl_client_socket_pool.h" | 19 #include "net/socket/ssl_client_socket_pool.h" |
| 19 #include "net/socket/transport_client_socket_pool.h" | 20 #include "net/socket/transport_client_socket_pool.h" |
| 20 #include "net/ssl/ssl_config.h" | 21 #include "net/ssl/ssl_config.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Limit of sockets of each socket pool. | 27 // Limit of sockets of each socket pool. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 break; | 142 break; |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 // Place sockets with and without deprecated ciphers into separate | 145 // Place sockets with and without deprecated ciphers into separate |
| 145 // connection groups. | 146 // connection groups. |
| 146 if (ssl_config_for_origin.deprecated_cipher_suites_enabled) | 147 if (ssl_config_for_origin.deprecated_cipher_suites_enabled) |
| 147 prefix += "deprecatedciphers/"; | 148 prefix += "deprecatedciphers/"; |
| 148 connection_group = prefix + connection_group; | 149 connection_group = prefix + connection_group; |
| 149 } | 150 } |
| 150 | 151 |
| 151 bool ignore_limits = (request_load_flags & LOAD_IGNORE_LIMITS) != 0; | 152 ClientSocketPool::RespectLimits respect_limits = |
| 153 ClientSocketPool::RespectLimits::ENABLED; |
| 154 if ((request_load_flags & LOAD_IGNORE_LIMITS) != 0) |
| 155 respect_limits = ClientSocketPool::RespectLimits::DISABLED; |
| 152 if (!proxy_info.is_direct()) { | 156 if (!proxy_info.is_direct()) { |
| 153 ProxyServer proxy_server = proxy_info.proxy_server(); | 157 ProxyServer proxy_server = proxy_info.proxy_server(); |
| 154 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); | 158 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); |
| 155 scoped_refptr<TransportSocketParams> proxy_tcp_params( | 159 scoped_refptr<TransportSocketParams> proxy_tcp_params( |
| 156 new TransportSocketParams( | 160 new TransportSocketParams( |
| 157 *proxy_host_port, | 161 *proxy_host_port, |
| 158 disable_resolver_cache, | 162 disable_resolver_cache, |
| 159 ignore_limits, | |
| 160 resolution_callback, | 163 resolution_callback, |
| 161 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 164 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
| 162 | 165 |
| 163 if (proxy_info.is_http() || proxy_info.is_https()) { | 166 if (proxy_info.is_http() || proxy_info.is_https()) { |
| 164 std::string user_agent; | 167 std::string user_agent; |
| 165 request_extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, | 168 request_extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, |
| 166 &user_agent); | 169 &user_agent); |
| 167 scoped_refptr<SSLSocketParams> ssl_params; | 170 scoped_refptr<SSLSocketParams> ssl_params; |
| 168 if (proxy_info.is_https()) { | 171 if (proxy_info.is_https()) { |
| 169 // Combine connect and write for SSL sockets in TCP FastOpen | 172 // Combine connect and write for SSL sockets in TCP FastOpen |
| 170 // field trial. | 173 // field trial. |
| 171 TransportSocketParams::CombineConnectAndWritePolicy | 174 TransportSocketParams::CombineConnectAndWritePolicy |
| 172 combine_connect_and_write = | 175 combine_connect_and_write = |
| 173 session->params().enable_tcp_fast_open_for_ssl ? | 176 session->params().enable_tcp_fast_open_for_ssl ? |
| 174 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DESIRED : | 177 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DESIRED : |
| 175 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT; | 178 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT; |
| 176 proxy_tcp_params = new TransportSocketParams(*proxy_host_port, | 179 proxy_tcp_params = new TransportSocketParams(*proxy_host_port, |
| 177 disable_resolver_cache, | 180 disable_resolver_cache, |
| 178 ignore_limits, | |
| 179 resolution_callback, | 181 resolution_callback, |
| 180 combine_connect_and_write); | 182 combine_connect_and_write); |
| 181 // Set ssl_params, and unset proxy_tcp_params | 183 // Set ssl_params, and unset proxy_tcp_params |
| 182 ssl_params = | 184 ssl_params = |
| 183 new SSLSocketParams(proxy_tcp_params, NULL, NULL, | 185 new SSLSocketParams(proxy_tcp_params, NULL, NULL, |
| 184 *proxy_host_port.get(), ssl_config_for_proxy, | 186 *proxy_host_port.get(), ssl_config_for_proxy, |
| 185 PRIVACY_MODE_DISABLED, load_flags, expect_spdy); | 187 PRIVACY_MODE_DISABLED, load_flags, expect_spdy); |
| 186 proxy_tcp_params = NULL; | 188 proxy_tcp_params = NULL; |
| 187 } | 189 } |
| 188 | 190 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (proxy_info.is_direct()) { | 224 if (proxy_info.is_direct()) { |
| 223 // Setup TCP params if non-proxied SSL connection. | 225 // Setup TCP params if non-proxied SSL connection. |
| 224 // Combine connect and write for SSL sockets in TCP FastOpen field trial. | 226 // Combine connect and write for SSL sockets in TCP FastOpen field trial. |
| 225 TransportSocketParams::CombineConnectAndWritePolicy | 227 TransportSocketParams::CombineConnectAndWritePolicy |
| 226 combine_connect_and_write = | 228 combine_connect_and_write = |
| 227 session->params().enable_tcp_fast_open_for_ssl ? | 229 session->params().enable_tcp_fast_open_for_ssl ? |
| 228 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DESIRED : | 230 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DESIRED : |
| 229 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT; | 231 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT; |
| 230 ssl_tcp_params = new TransportSocketParams(origin_host_port, | 232 ssl_tcp_params = new TransportSocketParams(origin_host_port, |
| 231 disable_resolver_cache, | 233 disable_resolver_cache, |
| 232 ignore_limits, | |
| 233 resolution_callback, | 234 resolution_callback, |
| 234 combine_connect_and_write); | 235 combine_connect_and_write); |
| 235 } | 236 } |
| 236 scoped_refptr<SSLSocketParams> ssl_params = new SSLSocketParams( | 237 scoped_refptr<SSLSocketParams> ssl_params = new SSLSocketParams( |
| 237 ssl_tcp_params, socks_params, http_proxy_params, origin_host_port, | 238 ssl_tcp_params, socks_params, http_proxy_params, origin_host_port, |
| 238 ssl_config_for_origin, privacy_mode, load_flags, expect_spdy); | 239 ssl_config_for_origin, privacy_mode, load_flags, expect_spdy); |
| 239 SSLClientSocketPool* ssl_pool = NULL; | 240 SSLClientSocketPool* ssl_pool = NULL; |
| 240 if (proxy_info.is_direct()) { | 241 if (proxy_info.is_direct()) { |
| 241 ssl_pool = session->GetSSLSocketPool(socket_pool_type); | 242 ssl_pool = session->GetSSLSocketPool(socket_pool_type); |
| 242 } else { | 243 } else { |
| 243 ssl_pool = session->GetSocketPoolForSSLWithProxy(socket_pool_type, | 244 ssl_pool = session->GetSocketPoolForSSLWithProxy(socket_pool_type, |
| 244 *proxy_host_port); | 245 *proxy_host_port); |
| 245 } | 246 } |
| 246 | 247 |
| 247 if (num_preconnect_streams) { | 248 if (num_preconnect_streams) { |
| 248 RequestSocketsForPool(ssl_pool, connection_group, ssl_params, | 249 RequestSocketsForPool(ssl_pool, connection_group, ssl_params, |
| 249 num_preconnect_streams, net_log); | 250 num_preconnect_streams, net_log); |
| 250 return OK; | 251 return OK; |
| 251 } | 252 } |
| 252 | 253 |
| 253 return socket_handle->Init(connection_group, ssl_params, | 254 return socket_handle->Init(connection_group, ssl_params, request_priority, |
| 254 request_priority, callback, ssl_pool, | 255 respect_limits, callback, ssl_pool, net_log); |
| 255 net_log); | |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Finally, get the connection started. | 258 // Finally, get the connection started. |
| 259 | 259 |
| 260 if (proxy_info.is_http() || proxy_info.is_https()) { | 260 if (proxy_info.is_http() || proxy_info.is_https()) { |
| 261 HttpProxyClientSocketPool* pool = | 261 HttpProxyClientSocketPool* pool = |
| 262 session->GetSocketPoolForHTTPProxy(socket_pool_type, *proxy_host_port); | 262 session->GetSocketPoolForHTTPProxy(socket_pool_type, *proxy_host_port); |
| 263 if (num_preconnect_streams) { | 263 if (num_preconnect_streams) { |
| 264 RequestSocketsForPool(pool, connection_group, http_proxy_params, | 264 RequestSocketsForPool(pool, connection_group, http_proxy_params, |
| 265 num_preconnect_streams, net_log); | 265 num_preconnect_streams, net_log); |
| 266 return OK; | 266 return OK; |
| 267 } | 267 } |
| 268 | 268 |
| 269 return socket_handle->Init(connection_group, http_proxy_params, | 269 return socket_handle->Init(connection_group, http_proxy_params, |
| 270 request_priority, callback, | 270 request_priority, respect_limits, callback, pool, |
| 271 pool, net_log); | 271 net_log); |
| 272 } | 272 } |
| 273 | 273 |
| 274 if (proxy_info.is_socks()) { | 274 if (proxy_info.is_socks()) { |
| 275 SOCKSClientSocketPool* pool = | 275 SOCKSClientSocketPool* pool = |
| 276 session->GetSocketPoolForSOCKSProxy(socket_pool_type, *proxy_host_port); | 276 session->GetSocketPoolForSOCKSProxy(socket_pool_type, *proxy_host_port); |
| 277 if (num_preconnect_streams) { | 277 if (num_preconnect_streams) { |
| 278 RequestSocketsForPool(pool, connection_group, socks_params, | 278 RequestSocketsForPool(pool, connection_group, socks_params, |
| 279 num_preconnect_streams, net_log); | 279 num_preconnect_streams, net_log); |
| 280 return OK; | 280 return OK; |
| 281 } | 281 } |
| 282 | 282 |
| 283 return socket_handle->Init(connection_group, socks_params, | 283 return socket_handle->Init(connection_group, socks_params, request_priority, |
| 284 request_priority, callback, pool, | 284 respect_limits, callback, pool, net_log); |
| 285 net_log); | |
| 286 } | 285 } |
| 287 | 286 |
| 288 DCHECK(proxy_info.is_direct()); | 287 DCHECK(proxy_info.is_direct()); |
| 289 scoped_refptr<TransportSocketParams> tcp_params = | 288 scoped_refptr<TransportSocketParams> tcp_params = |
| 290 new TransportSocketParams( | 289 new TransportSocketParams( |
| 291 origin_host_port, | 290 origin_host_port, |
| 292 disable_resolver_cache, | 291 disable_resolver_cache, |
| 293 ignore_limits, | |
| 294 resolution_callback, | 292 resolution_callback, |
| 295 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT); | 293 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT); |
| 296 TransportClientSocketPool* pool = | 294 TransportClientSocketPool* pool = |
| 297 session->GetTransportSocketPool(socket_pool_type); | 295 session->GetTransportSocketPool(socket_pool_type); |
| 298 if (num_preconnect_streams) { | 296 if (num_preconnect_streams) { |
| 299 RequestSocketsForPool(pool, connection_group, tcp_params, | 297 RequestSocketsForPool(pool, connection_group, tcp_params, |
| 300 num_preconnect_streams, net_log); | 298 num_preconnect_streams, net_log); |
| 301 return OK; | 299 return OK; |
| 302 } | 300 } |
| 303 | 301 |
| 304 return socket_handle->Init(connection_group, tcp_params, | 302 return socket_handle->Init(connection_group, tcp_params, request_priority, |
| 305 request_priority, callback, | 303 respect_limits, callback, pool, net_log); |
| 306 pool, net_log); | |
| 307 } | 304 } |
| 308 | 305 |
| 309 } // namespace | 306 } // namespace |
| 310 | 307 |
| 311 ClientSocketPoolManager::ClientSocketPoolManager() {} | 308 ClientSocketPoolManager::ClientSocketPoolManager() {} |
| 312 ClientSocketPoolManager::~ClientSocketPoolManager() {} | 309 ClientSocketPoolManager::~ClientSocketPoolManager() {} |
| 313 | 310 |
| 314 // static | 311 // static |
| 315 int ClientSocketPoolManager::max_sockets_per_pool( | 312 int ClientSocketPoolManager::max_sockets_per_pool( |
| 316 HttpNetworkSession::SocketPoolType pool_type) { | 313 HttpNetworkSession::SocketPoolType pool_type) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 int num_preconnect_streams) { | 481 int num_preconnect_streams) { |
| 485 return InitSocketPoolHelper( | 482 return InitSocketPoolHelper( |
| 486 group_type, endpoint, request_extra_headers, request_load_flags, | 483 group_type, endpoint, request_extra_headers, request_load_flags, |
| 487 request_priority, session, proxy_info, expect_spdy, ssl_config_for_origin, | 484 request_priority, session, proxy_info, expect_spdy, ssl_config_for_origin, |
| 488 ssl_config_for_proxy, /*force_tunnel=*/false, privacy_mode, net_log, | 485 ssl_config_for_proxy, /*force_tunnel=*/false, privacy_mode, net_log, |
| 489 num_preconnect_streams, NULL, HttpNetworkSession::NORMAL_SOCKET_POOL, | 486 num_preconnect_streams, NULL, HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 490 OnHostResolutionCallback(), CompletionCallback()); | 487 OnHostResolutionCallback(), CompletionCallback()); |
| 491 } | 488 } |
| 492 | 489 |
| 493 } // namespace net | 490 } // namespace net |
| OLD | NEW |