Chromium Code Reviews| 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/ssl_client_socket_pool.h" | 5 #include "net/socket/ssl_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" | |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/http/http_proxy_client_socket.h" | 17 #include "net/http/http_proxy_client_socket.h" |
| 17 #include "net/http/http_proxy_client_socket_pool.h" | 18 #include "net/http/http_proxy_client_socket_pool.h" |
| 18 #include "net/socket/client_socket_factory.h" | 19 #include "net/socket/client_socket_factory.h" |
| 19 #include "net/socket/client_socket_handle.h" | 20 #include "net/socket/client_socket_handle.h" |
| 20 #include "net/socket/socks_client_socket_pool.h" | 21 #include "net/socket/socks_client_socket_pool.h" |
| 21 #include "net/socket/ssl_client_socket.h" | 22 #include "net/socket/ssl_client_socket.h" |
| 22 #include "net/socket/transport_client_socket_pool.h" | 23 #include "net/socket/transport_client_socket_pool.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 pending_sockets_and_callbacks_.begin(); | 103 pending_sockets_and_callbacks_.begin(); |
| 103 it != pending_sockets_and_callbacks_.end(); | 104 it != pending_sockets_and_callbacks_.end(); |
| 104 ++it) { | 105 ++it) { |
| 105 if (it->socket == ssl_socket) { | 106 if (it->socket == ssl_socket) { |
| 106 pending_sockets_and_callbacks_.erase(it); | 107 pending_sockets_and_callbacks_.erase(it); |
| 107 return; | 108 return; |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 113 SSLConnectJobMessenger::SSLConnectJobMessenger() : weak_factory_(this) { | |
| 114 } | |
| 115 | |
| 112 bool SSLConnectJobMessenger::CanProceed(SSLClientSocket* ssl_socket) { | 116 bool SSLConnectJobMessenger::CanProceed(SSLClientSocket* ssl_socket) { |
| 113 // If the session is in the session cache, or there are no connecting | 117 // If the session is in the session cache, or there are no connecting |
| 114 // sockets, allow the connection to proceed. | 118 // sockets, allow the connection to proceed. |
| 115 return ssl_socket->InSessionCache() || connecting_sockets_.empty(); | 119 return ssl_socket->InSessionCache() || connecting_sockets_.empty(); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void SSLConnectJobMessenger::MonitorConnectionResult( | 122 void SSLConnectJobMessenger::MonitorConnectionResult( |
| 119 SSLClientSocket* ssl_socket) { | 123 SSLClientSocket* ssl_socket) { |
| 120 connecting_sockets_.push_back(ssl_socket); | 124 connecting_sockets_.push_back(ssl_socket); |
| 121 // TODO(mshelley): Both of these callbacks will use WeakPtr in future CL. | |
| 122 ssl_socket->SetHandshakeCompletionCallback(base::Bind( | 125 ssl_socket->SetHandshakeCompletionCallback(base::Bind( |
| 123 &SSLConnectJobMessenger::OnJobCompleted, base::Unretained(this))); | 126 &SSLConnectJobMessenger::OnJobCompleted, weak_factory_.GetWeakPtr())); |
| 124 } | 127 } |
| 125 | 128 |
| 126 void SSLConnectJobMessenger::AddPendingSocket(SSLClientSocket* ssl_socket, | 129 void SSLConnectJobMessenger::AddPendingSocket(SSLClientSocket* ssl_socket, |
| 127 const base::Closure& callback) { | 130 const base::Closure& callback) { |
| 128 DCHECK(!connecting_sockets_.empty()); | 131 DCHECK(!connecting_sockets_.empty()); |
| 129 pending_sockets_and_callbacks_.push_back( | 132 pending_sockets_and_callbacks_.push_back( |
| 130 SocketAndCallback(ssl_socket, callback)); | 133 SocketAndCallback(ssl_socket, callback)); |
| 131 } | 134 } |
| 132 | 135 |
| 133 void SSLConnectJobMessenger::OnJobCompleted() { | 136 void SSLConnectJobMessenger::OnJobCompleted() { |
| 134 connecting_sockets_.clear(); | 137 connecting_sockets_.clear(); |
| 135 SSLPendingSocketsAndCallbacks temp_list; | 138 SSLPendingSocketsAndCallbacks temp_list; |
| 136 temp_list.swap(pending_sockets_and_callbacks_); | 139 temp_list.swap(pending_sockets_and_callbacks_); |
| 137 RunAllCallbacks(temp_list); | 140 RunAllCallbacks(temp_list); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void SSLConnectJobMessenger::RunAllCallbacks( | 143 void SSLConnectJobMessenger::RunAllCallbacks( |
| 141 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) { | 144 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) { |
| 145 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
| 146 base::ThreadTaskRunnerHandle::Get(); | |
| 142 for (std::vector<SocketAndCallback>::const_iterator it = | 147 for (std::vector<SocketAndCallback>::const_iterator it = |
| 143 pending_sockets_and_callbacks.begin(); | 148 pending_sockets_and_callbacks.begin(); |
| 144 it != pending_sockets_and_callbacks.end(); | 149 it != pending_sockets_and_callbacks.end(); |
| 145 ++it) { | 150 ++it) { |
| 146 it->callback.Run(); | 151 task_runner->PostTask(FROM_HERE, it->callback); |
|
wtc
2014/08/05 00:44:57
1. I think running the callbacks directly is safe
Ryan Sleevi
2014/08/06 02:15:50
I don't think this is entirely true. Any one of th
| |
| 147 } | 152 } |
| 148 } | 153 } |
| 149 | 154 |
| 150 // Timeout for the SSL handshake portion of the connect. | 155 // Timeout for the SSL handshake portion of the connect. |
| 151 static const int kSSLHandshakeTimeoutInSeconds = 30; | 156 static const int kSSLHandshakeTimeoutInSeconds = 30; |
| 152 | 157 |
| 153 SSLConnectJob::SSLConnectJob(const std::string& group_name, | 158 SSLConnectJob::SSLConnectJob(const std::string& group_name, |
| 154 RequestPriority priority, | 159 RequestPriority priority, |
| 155 const scoped_refptr<SSLSocketParams>& params, | 160 const scoped_refptr<SSLSocketParams>& params, |
| 156 const base::TimeDelta& timeout_duration, | 161 const base::TimeDelta& timeout_duration, |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 if (base_.CloseOneIdleSocket()) | 816 if (base_.CloseOneIdleSocket()) |
| 812 return true; | 817 return true; |
| 813 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 818 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 814 } | 819 } |
| 815 | 820 |
| 816 void SSLClientSocketPool::OnSSLConfigChanged() { | 821 void SSLClientSocketPool::OnSSLConfigChanged() { |
| 817 FlushWithError(ERR_NETWORK_CHANGED); | 822 FlushWithError(ERR_NETWORK_CHANGED); |
| 818 } | 823 } |
| 819 | 824 |
| 820 } // namespace net | 825 } // namespace net |
| OLD | NEW |