Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2008)

Unified Diff: net/socket/ssl_client_socket_pool.cc

Issue 328903004: SSL Connect Job Waiting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add separate state for ProcessPendingJobs Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/socket/ssl_client_socket_pool.cc
diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc
index 2c704658820bc06a8404679c2f796be269657387..da633b2bc41f408703fad71d42221adcfc6ec155 100644
--- a/net/socket/ssl_client_socket_pool.cc
+++ b/net/socket/ssl_client_socket_pool.cc
@@ -107,6 +107,7 @@ SSLConnectJob::SSLConnectJob(const std::string& group_name,
ClientSocketFactory* client_socket_factory,
HostResolver* host_resolver,
const SSLClientSocketContext& context,
+ PendingJobList* pending_jobs_list,
Delegate* delegate,
NetLog* net_log)
: ConnectJob(group_name,
@@ -127,11 +128,16 @@ SSLConnectJob::SSLConnectJob(const std::string& group_name,
(params->privacy_mode() == PRIVACY_MODE_ENABLED
? "pm/" + context.ssl_session_cache_shard
: context.ssl_session_cache_shard)),
- callback_(base::Bind(&SSLConnectJob::OnIOComplete,
- base::Unretained(this))) {}
+ io_callback_(
+ base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))),
+ pending_jobs_(pending_jobs_list) {
+}
SSLConnectJob::~SSLConnectJob() {}
+// static
+bool SSLConnectJob::enable_job_waiting_ = false;
+
LoadState SSLConnectJob::GetLoadState() const {
switch (next_state_) {
case STATE_TUNNEL_CONNECT_COMPLETE:
@@ -144,6 +150,8 @@ LoadState SSLConnectJob::GetLoadState() const {
case STATE_SOCKS_CONNECT_COMPLETE:
case STATE_TUNNEL_CONNECT:
return transport_socket_handle_->GetLoadState();
+ case STATE_CREATE_SSL_SOCKET:
+ case STATE_CHECK_FOR_RESUME:
case STATE_SSL_CONNECT:
case STATE_SSL_CONNECT_COMPLETE:
return LOAD_STATE_SSL_HANDSHAKE;
@@ -165,6 +173,10 @@ void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) {
handle->set_is_ssl_error(true);
}
+void SSLConnectJob::EnableJobWaiting(bool enable) {
+ enable_job_waiting_ = enable;
+}
+
void SSLConnectJob::OnIOComplete(int result) {
int rv = DoLoop(result);
if (rv != ERR_IO_PENDING)
@@ -200,6 +212,12 @@ int SSLConnectJob::DoLoop(int result) {
case STATE_TUNNEL_CONNECT_COMPLETE:
rv = DoTunnelConnectComplete(rv);
break;
+ case STATE_CREATE_SSL_SOCKET:
+ rv = DoCreateSSLSocket();
+ break;
+ case STATE_CHECK_FOR_RESUME:
+ rv = DoCheckForResume();
+ break;
case STATE_SSL_CONNECT:
DCHECK_EQ(OK, rv);
rv = DoSSLConnect();
@@ -207,6 +225,9 @@ int SSLConnectJob::DoLoop(int result) {
case STATE_SSL_CONNECT_COMPLETE:
rv = DoSSLConnectComplete(rv);
break;
+ case STATE_PROCESS_PENDING_JOBS:
+ rv = DoProcessPendingJobs(rv);
+ break;
default:
NOTREACHED() << "bad state";
rv = ERR_FAILED;
@@ -227,14 +248,16 @@ int SSLConnectJob::DoTransportConnect() {
return transport_socket_handle_->Init(group_name(),
direct_params,
priority(),
- callback_,
+ io_callback_,
transport_pool_,
net_log());
}
int SSLConnectJob::DoTransportConnectComplete(int result) {
- if (result == OK)
- next_state_ = STATE_SSL_CONNECT;
+ if (result != OK)
+ return result;
+
+ next_state_ = STATE_CREATE_SSL_SOCKET;
return result;
}
@@ -248,14 +271,16 @@ int SSLConnectJob::DoSOCKSConnect() {
return transport_socket_handle_->Init(group_name(),
socks_proxy_params,
priority(),
- callback_,
+ io_callback_,
socks_pool_,
net_log());
}
int SSLConnectJob::DoSOCKSConnectComplete(int result) {
- if (result == OK)
- next_state_ = STATE_SSL_CONNECT;
+ if (result != OK)
+ return result;
+
+ next_state_ = STATE_CREATE_SSL_SOCKET;
return result;
}
@@ -270,7 +295,7 @@ int SSLConnectJob::DoTunnelConnect() {
return transport_socket_handle_->Init(group_name(),
http_proxy_params,
priority(),
- callback_,
+ io_callback_,
http_proxy_pool_,
net_log());
}
@@ -291,12 +316,15 @@ int SSLConnectJob::DoTunnelConnectComplete(int result) {
if (result < 0)
return result;
- next_state_ = STATE_SSL_CONNECT;
+ next_state_ = STATE_CREATE_SSL_SOCKET;
return result;
}
-int SSLConnectJob::DoSSLConnect() {
- next_state_ = STATE_SSL_CONNECT_COMPLETE;
+int SSLConnectJob::DoCreateSSLSocket() {
+ if (enable_job_waiting_)
+ next_state_ = STATE_CHECK_FOR_RESUME;
+ else
+ next_state_ = STATE_SSL_CONNECT;
// Reset the timeout to just the time allowed for the SSL handshake.
ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds));
@@ -307,26 +335,58 @@ int SSLConnectJob::DoSSLConnect() {
if (!transport_socket_handle_->is_reused() &&
!socket_connect_timing.connect_start.is_null()) {
// Overwriting |connect_start| serves two purposes - it adjusts timing so
- // |connect_start| doesn't include dns times, and it adjusts the time so
+ // |connect_start| doesn't include DNS times, and it adjusts the time so
// as not to include time spent waiting for an idle socket.
connect_timing_.connect_start = socket_connect_timing.connect_start;
connect_timing_.dns_start = socket_connect_timing.dns_start;
connect_timing_.dns_end = socket_connect_timing.dns_end;
}
- connect_timing_.ssl_start = base::TimeTicks::Now();
-
ssl_socket_ = client_socket_factory_->CreateSSLClientSocket(
transport_socket_handle_.Pass(),
params_->host_and_port(),
params_->ssl_config(),
context_);
- return ssl_socket_->Connect(callback_);
+ return OK;
+}
+
+int SSLConnectJob::DoCheckForResume() {
+ // If the group's session is in the cache, continue with the session
+ // resumption SSL handshake.
wtc 2014/06/26 17:48:17 Move this comment to line 358.
+ next_state_ = STATE_SSL_CONNECT;
+
+ if (ssl_socket_->InSessionCache())
+ return OK;
+
+ // If there are pending jobs, wait.
+ if (!pending_jobs_->empty()) {
+ pending_jobs_->push_back(this);
+ return ERR_IO_PENDING;
+ }
+
+ // If there are no pending jobs, continue the full SSL handshake
+ // because a resumption handshake is not possible.
+ //
+ // Add |this| to pending jobs to ensure that future jobs
+ // will know that there is a job in progress.
+ pending_jobs_->push_back(this);
+ return OK;
wtc 2014/06/26 17:48:17 Nit: it is possible to rewrite lines 361-373 to el
+}
+
+int SSLConnectJob::DoSSLConnect() {
+ next_state_ = STATE_SSL_CONNECT_COMPLETE;
+
+ connect_timing_.ssl_start = base::TimeTicks::Now();
+
+ return ssl_socket_->Connect(io_callback_);
}
int SSLConnectJob::DoSSLConnectComplete(int result) {
connect_timing_.ssl_end = base::TimeTicks::Now();
+ if (enable_job_waiting_)
+ next_state_ = STATE_PROCESS_PENDING_JOBS;
+
SSLClientSocket::NextProtoStatus status =
SSLClientSocket::kNextProtoUnsupported;
std::string proto;
@@ -351,8 +411,9 @@ int SSLConnectJob::DoSSLConnectComplete(int result) {
ssl_socket_->set_was_spdy_negotiated(true);
}
}
- if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated())
+ if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) {
return ERR_NPN_NEGOTIATION_FAILED;
+ }
// Spdy might be turned on by default, or it might be over npn.
bool using_spdy = params_->force_spdy_over_ssl() ||
@@ -411,9 +472,9 @@ int SSLConnectJob::DoSSLConnectComplete(int result) {
}
const std::string& host = params_->host_and_port().host();
- bool is_google = host == "google.com" ||
- (host.size() > 11 &&
- host.rfind(".google.com") == host.size() - 11);
+ bool is_google =
+ host == "google.com" ||
+ (host.size() > 11 && host.rfind(".google.com") == host.size() - 11);
if (is_google) {
UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2",
connect_duration,
@@ -449,6 +510,47 @@ int SSLConnectJob::DoSSLConnectComplete(int result) {
return result;
}
+int SSLConnectJob::DoProcessPendingJobs(int result) {
+ ProcessPendingJobs(result);
+ return result;
+}
+
+void SSLConnectJob::ProcessPendingJobs(int result) {
wtc 2014/06/26 17:48:17 Nit: I would get rid of the ProcessPendingJobs fun
+ // If there is a pending list
+ if (!pending_jobs_->empty()) {
+ // The first element of the vector will always be the leading job.
+ PendingJobList::iterator it = pending_jobs_->begin();
+
+ if (result == OK) {
+ // If the connection was successful, tell all pending jobs to proceed.
+ PendingJobList pending_jobs(it + 1, pending_jobs_->end());
+ pending_jobs_->clear();
+ for (PendingJobList::iterator job = pending_jobs.begin();
wtc 2014/06/26 17:48:17 Nit: this can be a const_iterator.
+ job != pending_jobs.end();
+ ++job) {
+ (*job)->ResumeSSLConnection();
+ }
+
+ } else {
+ // If the connection failed, tell one (if any) of the remaining jobs
+ // to proceed as the new leader.
+ it = pending_jobs_->erase(it);
+ if (it != pending_jobs_->end())
+ (*it)->ResumeSSLConnection();
+ }
+ }
+}
+
+void SSLConnectJob::ResumeSSLConnection() {
+ DCHECK_EQ(next_state_, STATE_SSL_CONNECT);
+ next_state_ = STATE_SSL_CONNECT;
wtc 2014/06/26 17:48:17 Delete this line.
+ OnIOComplete(OK);
+}
+
+bool SSLConnectJob::GetEnableJobWaiting() {
wtc 2014/06/26 17:48:17 Move this to line 178, to follow the definition of
+ return enable_job_waiting_;
+}
+
SSLConnectJob::State SSLConnectJob::GetInitialState(
SSLSocketParams::ConnectionType connection_type) {
switch (connection_type) {
@@ -482,7 +584,8 @@ SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
client_socket_factory_(client_socket_factory),
host_resolver_(host_resolver),
context_(context),
- net_log_(net_log) {
+ net_log_(net_log),
+ pending_jobs_map_(new PendingJobMap()) {
base::TimeDelta max_transport_timeout = base::TimeDelta();
base::TimeDelta pool_timeout;
if (transport_pool_)
@@ -520,21 +623,24 @@ SSLClientSocketPool::SSLClientSocketPool(
: transport_pool_(transport_pool),
socks_pool_(socks_pool),
http_proxy_pool_(http_proxy_pool),
- base_(this, max_sockets, max_sockets_per_group, histograms,
+ base_(this,
+ max_sockets,
+ max_sockets_per_group,
+ histograms,
ClientSocketPool::unused_idle_socket_timeout(),
ClientSocketPool::used_idle_socket_timeout(),
- new SSLConnectJobFactory(transport_pool,
- socks_pool,
- http_proxy_pool,
- client_socket_factory,
- host_resolver,
- SSLClientSocketContext(
- cert_verifier,
- server_bound_cert_service,
- transport_security_state,
- cert_transparency_verifier,
- ssl_session_cache_shard),
- net_log)),
+ new SSLConnectJobFactory(
+ transport_pool,
+ socks_pool,
+ http_proxy_pool,
+ client_socket_factory,
+ host_resolver,
+ SSLClientSocketContext(cert_verifier,
+ server_bound_cert_service,
+ transport_security_state,
+ cert_transparency_verifier,
+ ssl_session_cache_shard),
+ net_log)),
ssl_config_service_(ssl_config_service) {
if (ssl_config_service_.get())
ssl_config_service_->AddObserver(this);
@@ -556,11 +662,35 @@ SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
const std::string& group_name,
const PoolBase::Request& request,
ConnectJob::Delegate* delegate) const {
- return scoped_ptr<ConnectJob>(
- new SSLConnectJob(group_name, request.priority(), request.params(),
- ConnectionTimeout(), transport_pool_, socks_pool_,
- http_proxy_pool_, client_socket_factory_,
- host_resolver_, context_, delegate, net_log_));
+ SSLConnectJob::PendingJobList* pending_job_list;
+ if (SSLConnectJob::GetEnableJobWaiting()) {
+ PendingJobMap::const_iterator it = pending_jobs_map_->find(group_name);
+ if (it == pending_jobs_map_->end()) {
+ std::pair<PendingJobMap::iterator, bool> iter =
wtc 2014/06/26 17:48:17 Nit: it is a little confusing to have variables na
+ pending_jobs_map_->insert(PendingJobMap::value_type(
wtc 2014/06/26 17:48:17 Nit: it seems that this line is indented with thre
+ group_name, new SSLConnectJob::PendingJobList()));
+
+ it = iter.first;
+ }
+
+ pending_job_list = it->second;
+ } else {
+ pending_job_list = NULL;
+ }
+
+ return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name,
+ request.priority(),
+ request.params(),
+ ConnectionTimeout(),
+ transport_pool_,
+ socks_pool_,
+ http_proxy_pool_,
+ client_socket_factory_,
+ host_resolver_,
+ context_,
+ pending_job_list,
+ delegate,
+ net_log_));
}
base::TimeDelta

Powered by Google App Engine
This is Rietveld 408576698