Commit c5c07de2 authored by rch's avatar rch Committed by Commit bot

Change ClientSocketPoolManager::InitSocketHandleForHttpRequest and friends

to not take a request_url, since this is confusing for Alternate-Protocol
and Alt-Svc requests. Instead, take an enum which describes the type of
socket to be requested (FTP, SSL, or normal) and endpoint to which the
socket is to be connected.

Review URL: https://codereview.chromium.org/1051023003

Cr-Commit-Position: refs/heads/master@{#324196}
parent 4232e29e
......@@ -628,7 +628,6 @@ int HttpStreamFactoryImpl::Job::DoStart() {
// https://<alternative host>:<alternative port>/...
// so the proxy resolution works with the actual destination, and so
// that the correct socket pool is used.
// TODO(rch): change the socket pool API to not require a full URL.
if (alternative_service_.protocol >= NPN_SPDY_MINIMUM_VERSION &&
alternative_service_.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
// TODO(rch): Figure out how to make QUIC iteract with PAC
......@@ -870,7 +869,7 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() {
if (IsPreconnecting()) {
DCHECK(!stream_factory_->for_websockets_);
return PreconnectSocketsForHttpRequest(
alternative_service_url_, request_info_.extra_headers,
GetSocketGroup(), server_, request_info_.extra_headers,
request_info_.load_flags, priority_, session_, proxy_info_,
ShouldForceSpdySSL(), want_spdy_over_npn, server_ssl_config_,
proxy_ssl_config_, request_info_.privacy_mode, net_log_, num_streams_);
......@@ -887,15 +886,15 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() {
SSLConfig websocket_server_ssl_config = server_ssl_config_;
websocket_server_ssl_config.next_protos.clear();
return InitSocketHandleForWebSocketRequest(
origin_url_, request_info_.extra_headers, request_info_.load_flags,
priority_, session_, proxy_info_, ShouldForceSpdySSL(),
want_spdy_over_npn, websocket_server_ssl_config, proxy_ssl_config_,
request_info_.privacy_mode, net_log_,
GetSocketGroup(), server_, request_info_.extra_headers,
request_info_.load_flags, priority_, session_, proxy_info_,
ShouldForceSpdySSL(), want_spdy_over_npn, websocket_server_ssl_config,
proxy_ssl_config_, request_info_.privacy_mode, net_log_,
connection_.get(), resolution_callback, io_callback_);
}
return InitSocketHandleForHttpRequest(
alternative_service_url_, request_info_.extra_headers,
GetSocketGroup(), server_, request_info_.extra_headers,
request_info_.load_flags, priority_, session_, proxy_info_,
ShouldForceSpdySSL(), want_spdy_over_npn, server_ssl_config_,
proxy_ssl_config_, request_info_.privacy_mode, net_log_,
......@@ -1490,4 +1489,13 @@ void HttpStreamFactoryImpl::Job::MaybeMarkAlternativeServiceBroken() {
}
}
ClientSocketPoolManager::SocketGroupType
HttpStreamFactoryImpl::Job::GetSocketGroup() const {
if (ShouldForceSpdySSL())
return ClientSocketPoolManager::SSL_GROUP;
return ClientSocketPoolManager::GroupTypeFromScheme(
alternative_service_url_.scheme());
}
} // namespace net
......@@ -18,6 +18,7 @@
#include "net/proxy/proxy_service.h"
#include "net/quic/quic_stream_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_manager.h"
#include "net/socket/ssl_client_socket.h"
#include "net/spdy/spdy_session_key.h"
#include "net/ssl/ssl_config_service.h"
......@@ -235,6 +236,8 @@ class HttpStreamFactoryImpl::Job {
void MaybeMarkAlternativeServiceBroken();
ClientSocketPoolManager::SocketGroupType GetSocketGroup() const;
// Record histograms of latency until Connect() completes.
static void LogHttpConnectedMetrics(const ClientSocketHandle& handle);
......
......@@ -66,7 +66,8 @@ static_assert(arraysize(g_max_sockets_per_proxy_server) ==
// The meat of the implementation for the InitSocketHandleForHttpRequest,
// InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods.
int InitSocketPoolHelper(const GURL& request_url,
int InitSocketPoolHelper(ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......@@ -88,10 +89,8 @@ int InitSocketPoolHelper(const GURL& request_url,
scoped_refptr<SOCKSSocketParams> socks_params;
scoped_ptr<HostPortPair> proxy_host_port;
bool using_ssl = request_url.SchemeIs("https") ||
request_url.SchemeIs("wss") || force_spdy_over_ssl;
HostPortPair origin_host_port = HostPortPair::FromURL(request_url);
bool using_ssl = group_type == ClientSocketPoolManager::SSL_GROUP;
HostPortPair origin_host_port = endpoint;
if (!using_ssl && session->params().testing_fixed_http_port != 0) {
origin_host_port.set_port(session->params().testing_fixed_http_port);
......@@ -112,7 +111,7 @@ int InitSocketPoolHelper(const GURL& request_url,
// Determine the host and port to connect to.
std::string connection_group = origin_host_port.ToString();
DCHECK(!connection_group.empty());
if (request_url.SchemeIs("ftp")) {
if (group_type == ClientSocketPoolManager::FTP_GROUP) {
// Combining FTP with forced SPDY over SSL would be a "path to madness".
// Make sure we never do that.
DCHECK(!using_ssl);
......@@ -328,6 +327,18 @@ int InitSocketPoolHelper(const GURL& request_url,
} // namespace
// static
ClientSocketPoolManager::SocketGroupType
ClientSocketPoolManager::GroupTypeFromScheme(const std::string& scheme) {
if (scheme == "ftp")
return FTP_GROUP;
if (scheme == "https" || scheme == "wss")
return SSL_GROUP;
return NORMAL_GROUP;
}
ClientSocketPoolManager::ClientSocketPoolManager() {}
ClientSocketPoolManager::~ClientSocketPoolManager() {}
......@@ -394,7 +405,8 @@ void ClientSocketPoolManager::set_max_sockets_per_proxy_server(
}
int InitSocketHandleForHttpRequest(
const GURL& request_url,
ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......@@ -411,15 +423,16 @@ int InitSocketHandleForHttpRequest(
const CompletionCallback& callback) {
DCHECK(socket_handle);
return InitSocketPoolHelper(
request_url, request_extra_headers, request_load_flags, request_priority,
session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn,
ssl_config_for_origin, ssl_config_for_proxy, false, privacy_mode, net_log,
0, socket_handle, HttpNetworkSession::NORMAL_SOCKET_POOL,
resolution_callback, callback);
group_type, endpoint, request_extra_headers, request_load_flags,
request_priority, session, proxy_info, force_spdy_over_ssl,
want_spdy_over_npn, ssl_config_for_origin, ssl_config_for_proxy, false,
privacy_mode, net_log, 0, socket_handle,
HttpNetworkSession::NORMAL_SOCKET_POOL, resolution_callback, callback);
}
int InitSocketHandleForWebSocketRequest(
const GURL& request_url,
ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......@@ -436,11 +449,11 @@ int InitSocketHandleForWebSocketRequest(
const CompletionCallback& callback) {
DCHECK(socket_handle);
return InitSocketPoolHelper(
request_url, request_extra_headers, request_load_flags, request_priority,
session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn,
ssl_config_for_origin, ssl_config_for_proxy, true, privacy_mode, net_log,
0, socket_handle, HttpNetworkSession::WEBSOCKET_SOCKET_POOL,
resolution_callback, callback);
group_type, endpoint, request_extra_headers, request_load_flags,
request_priority, session, proxy_info, force_spdy_over_ssl,
want_spdy_over_npn, ssl_config_for_origin, ssl_config_for_proxy, true,
privacy_mode, net_log, 0, socket_handle,
HttpNetworkSession::WEBSOCKET_SOCKET_POOL, resolution_callback, callback);
}
int InitSocketHandleForRawConnect(
......@@ -454,47 +467,42 @@ int InitSocketHandleForRawConnect(
ClientSocketHandle* socket_handle,
const CompletionCallback& callback) {
DCHECK(socket_handle);
// Synthesize an HttpRequestInfo.
GURL request_url = GURL("http://" + host_port_pair.ToString());
HttpRequestHeaders request_extra_headers;
int request_load_flags = 0;
RequestPriority request_priority = MEDIUM;
return InitSocketPoolHelper(
request_url, request_extra_headers, request_load_flags, request_priority,
session, proxy_info, false, false, ssl_config_for_origin,
ssl_config_for_proxy, true, privacy_mode, net_log, 0, socket_handle,
ClientSocketPoolManager::NORMAL_GROUP, host_port_pair,
request_extra_headers, request_load_flags, request_priority, session,
proxy_info, false, false, ssl_config_for_origin, ssl_config_for_proxy,
true, privacy_mode, net_log, 0, socket_handle,
HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(),
callback);
}
int InitSocketHandleForTlsConnect(
const HostPortPair& host_port_pair,
HttpNetworkSession* session,
const ProxyInfo& proxy_info,
const SSLConfig& ssl_config_for_origin,
const SSLConfig& ssl_config_for_proxy,
PrivacyMode privacy_mode,
const BoundNetLog& net_log,
ClientSocketHandle* socket_handle,
const CompletionCallback& callback) {
int InitSocketHandleForTlsConnect(const HostPortPair& endpoint,
HttpNetworkSession* session,
const ProxyInfo& proxy_info,
const SSLConfig& ssl_config_for_origin,
const SSLConfig& ssl_config_for_proxy,
PrivacyMode privacy_mode,
const BoundNetLog& net_log,
ClientSocketHandle* socket_handle,
const CompletionCallback& callback) {
DCHECK(socket_handle);
// Synthesize an HttpRequestInfo.
GURL request_url = GURL("https://" + host_port_pair.ToString());
HttpRequestHeaders request_extra_headers;
int request_load_flags = 0;
RequestPriority request_priority = MEDIUM;
return InitSocketPoolHelper(
request_url, request_extra_headers, request_load_flags, request_priority,
session, proxy_info, false, false, ssl_config_for_origin,
ssl_config_for_proxy, true, privacy_mode, net_log, 0, socket_handle,
HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(),
callback);
ClientSocketPoolManager::SSL_GROUP, endpoint, request_extra_headers,
request_load_flags, request_priority, session, proxy_info, false, false,
ssl_config_for_origin, ssl_config_for_proxy, true, privacy_mode, net_log,
0, socket_handle, HttpNetworkSession::NORMAL_SOCKET_POOL,
OnHostResolutionCallback(), callback);
}
int PreconnectSocketsForHttpRequest(
const GURL& request_url,
ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......@@ -508,11 +516,12 @@ int PreconnectSocketsForHttpRequest(
const BoundNetLog& net_log,
int num_preconnect_streams) {
return InitSocketPoolHelper(
request_url, request_extra_headers, request_load_flags, request_priority,
session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn,
ssl_config_for_origin, ssl_config_for_proxy, false, privacy_mode, net_log,
num_preconnect_streams, NULL, HttpNetworkSession::NORMAL_SOCKET_POOL,
OnHostResolutionCallback(), CompletionCallback());
group_type, endpoint, request_extra_headers, request_load_flags,
request_priority, session, proxy_info, force_spdy_over_ssl,
want_spdy_over_npn, ssl_config_for_origin, ssl_config_for_proxy, false,
privacy_mode, net_log, num_preconnect_streams, NULL,
HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(),
CompletionCallback());
}
} // namespace net
......@@ -44,6 +44,15 @@ enum DefaultMaxValues { kDefaultMaxSocketsPerProxyServer = 32 };
class NET_EXPORT_PRIVATE ClientSocketPoolManager {
public:
enum SocketGroupType {
SSL_GROUP, // For all TLS sockets.
NORMAL_GROUP, // For normal HTTP sockets.
FTP_GROUP // For FTP sockets (over an HTTP proxy).
};
// Returns the correct socket group type for |scheme|.
static SocketGroupType GroupTypeFromScheme(const std::string& scheme);
ClientSocketPoolManager();
virtual ~ClientSocketPoolManager();
......@@ -89,8 +98,14 @@ class NET_EXPORT_PRIVATE ClientSocketPoolManager {
// |resolution_callback| will be invoked after the the hostname is
// resolved. If |resolution_callback| does not return OK, then the
// connection will be aborted with that value.
// If |want_spdy_over_ssl| is true, then after the SSL handshake is complete,
// SPDY must have been negotiated or else it will be considered an error.
// If |force_spdy_over_ssl| is true, then SPDY will be assumed to be supported
// for all SSL connections.
// TODO(rch): remove force_spdy_over_ssl.
int InitSocketHandleForHttpRequest(
const GURL& request_url,
ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......@@ -116,7 +131,8 @@ int InitSocketHandleForHttpRequest(
// connection will be aborted with that value.
// This function uses WEBSOCKET_SOCKET_POOL socket pools.
int InitSocketHandleForWebSocketRequest(
const GURL& request_url,
ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......@@ -165,7 +181,8 @@ NET_EXPORT int InitSocketHandleForTlsConnect(
// Similar to InitSocketHandleForHttpRequest except that it initiates the
// desired number of preconnect streams from the relevant socket pool.
int PreconnectSocketsForHttpRequest(
const GURL& request_url,
ClientSocketPoolManager::SocketGroupType group_type,
const HostPortPair& endpoint,
const HttpRequestHeaders& request_extra_headers,
int request_load_flags,
RequestPriority request_priority,
......
......@@ -17,6 +17,7 @@
#include "net/base/net_util.h"
#include "net/http/http_auth_cache.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_request_info.h"
#include "net/http/http_response_headers.h"
#include "net/http/proxy_connect_redirect_http_stream.h"
#include "net/spdy/spdy_http_utils.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment