diff options
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 40 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_unittest.cc | 9 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 97 | ||||
-rw-r--r-- | net/spdy/spdy_session.h | 14 | ||||
-rw-r--r-- | net/spdy/spdy_session_unittest.cc | 8 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 8 |
6 files changed, 53 insertions, 123 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 196c6ea..91e0062 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -6240,13 +6240,32 @@ TEST_F(HttpNetworkTransactionTest, EXPECT_EQ("hello world", response_data); // Set up an initial SpdySession in the pool to reuse. - HostPortProxyPair pair(HostPortPair("www.google.com", 443), - ProxyServer::Direct()); + HostPortPair host_port_pair("www.google.com", 443); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); scoped_refptr<SpdySession> spdy_session = session->spdy_session_pool()->Get(pair, session, BoundNetLog()); scoped_refptr<TCPSocketParams> tcp_params = new TCPSocketParams("www.google.com", 443, MEDIUM, GURL(), false); - spdy_session->Connect("www.google.com:443", tcp_params, MEDIUM); + + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); + EXPECT_EQ(ERR_IO_PENDING, + connection->Init(host_port_pair.ToString(),tcp_params, LOWEST, + &callback, session->tcp_socket_pool(), + BoundNetLog())); + EXPECT_EQ(OK, callback.WaitForResult()); + + SSLConfig ssl_config; + session->ssl_config_service()->GetSSLConfig(&ssl_config); + ClientSocket* socket = connection->release_socket(); + socket = session->socket_factory()->CreateSSLClientSocket( + socket, "" /* request_->url.HostNoBrackets() */ , ssl_config); + connection->set_socket(socket); + EXPECT_EQ(ERR_IO_PENDING, socket->Connect(&callback)); + EXPECT_EQ(OK, callback.WaitForResult()); + + EXPECT_EQ(OK, spdy_session->InitializeWithSocket(connection.release(), + true, OK)); + trans.reset(new HttpNetworkTransaction(session)); rv = trans->Start(&request, &callback, BoundNetLog()); @@ -7396,13 +7415,21 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); // Set up an initial SpdySession in the pool to reuse. - HostPortProxyPair pair(HostPortPair("www.google.com", 443), - ProxyServer::Direct()); + HostPortPair host_port_pair("www.google.com", 443); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); scoped_refptr<SpdySession> spdy_session = session->spdy_session_pool()->Get(pair, session, BoundNetLog()); scoped_refptr<TCPSocketParams> tcp_params = new TCPSocketParams("www.google.com", 443, MEDIUM, GURL(), false); - spdy_session->Connect("www.google.com:443", tcp_params, MEDIUM); + TestCompletionCallback callback; + + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); + EXPECT_EQ(ERR_IO_PENDING, + connection->Init(host_port_pair.ToString(), tcp_params, LOWEST, + &callback, session->tcp_socket_pool(), + BoundNetLog())); + EXPECT_EQ(OK, callback.WaitForResult()); + spdy_session->InitializeWithSocket(connection.release(), false, OK); HttpRequestInfo request; request.method = "GET"; @@ -7414,7 +7441,6 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); - TestCompletionCallback callback; int rv = trans->Start(&request, &callback, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(OK, callback.WaitForResult()); diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index fbc2a8b..c3a6fdc 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -34,7 +34,14 @@ class SpdyHttpStreamTest : public testing::Test { tcp_params_ = new TCPSocketParams(host_port_pair.host(), host_port_pair.port(), MEDIUM, GURL(), false); - return session_->Connect(host_port_pair.host(), tcp_params_, MEDIUM); + TestCompletionCallback callback; + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); + EXPECT_EQ(ERR_IO_PENDING, + connection->Init(host_port_pair.ToString(), tcp_params_, MEDIUM, + &callback, http_session_->tcp_socket_pool(), + BoundNetLog())); + EXPECT_EQ(OK, callback.WaitForResult()); + return session_->InitializeWithSocket(connection.release(), false, OK); } SpdySessionDependencies session_deps_; scoped_refptr<OrderedSocketData> data_; diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 0f72b6e..304562b 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -17,13 +17,9 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "net/base/connection_type_histograms.h" -#include "net/base/load_flags.h" #include "net/base/net_log.h" #include "net/base/net_util.h" #include "net/http/http_network_session.h" -#include "net/socket/client_socket.h" -#include "net/socket/client_socket_factory.h" -#include "net/socket/ssl_client_socket.h" #include "net/spdy/spdy_frame_builder.h" #include "net/spdy/spdy_protocol.h" #include "net/spdy/spdy_settings_storage.h" @@ -223,10 +219,6 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, HttpNetworkSession* session, NetLog* net_log) : ALLOW_THIS_IN_INITIALIZER_LIST( - connect_callback_(this, &SpdySession::OnTCPConnect)), - ALLOW_THIS_IN_INITIALIZER_LIST( - ssl_connect_callback_(this, &SpdySession::OnSSLConnect)), - ALLOW_THIS_IN_INITIALIZER_LIST( read_callback_(this, &SpdySession::OnReadComplete)), ALLOW_THIS_IN_INITIALIZER_LIST( write_callback_(this, &SpdySession::OnWriteComplete)), @@ -262,8 +254,6 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, spdy_framer_.set_visitor(this); - session_->ssl_config_service()->GetSSLConfig(&ssl_config_); - SendSettings(); } @@ -310,34 +300,6 @@ net::Error SpdySession::InitializeWithSocket( return error; } -net::Error SpdySession::Connect( - const std::string& group_name, - const scoped_refptr<TCPSocketParams>& destination, - RequestPriority priority) { - DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES); - - // If the connect process is started, let the caller continue. - if (state_ > IDLE) - return net::OK; - - state_ = CONNECTING; - - static StatsCounter spdy_sessions("spdy.sessions"); - spdy_sessions.Increment(); - - int rv = connection_->Init(group_name, destination, priority, - &connect_callback_, session_->tcp_socket_pool(), - net_log_); - DCHECK(rv <= 0); - - // If the connect is pending, we still return ok. The APIs enqueue - // work until after the connect completes asynchronously later. - if (rv == net::ERR_IO_PENDING) - return net::OK; - OnTCPConnect(rv); - return static_cast<net::Error>(rv); -} - int SpdySession::GetPushStream( const GURL& url, scoped_refptr<SpdyStream>* stream, @@ -591,65 +553,6 @@ LoadState SpdySession::GetLoadState() const { return LOAD_STATE_IDLE; } -void SpdySession::OnTCPConnect(int result) { - // We shouldn't be coming through this path if we didn't just open a fresh - // socket (or have an error trying to do so). - DCHECK(!connection_->socket() || !connection_->is_reused()); - - if (result != net::OK) { - DCHECK_LT(result, 0); - CloseSessionOnError(static_cast<net::Error>(result), true); - return; - } else { - UpdateConnectionTypeHistograms(CONNECTION_SPDY); - } - - AdjustSocketBufferSizes(connection_->socket()); - - if (use_ssl_) { - // Add a SSL socket on top of our existing transport socket. - ClientSocket* socket = connection_->release_socket(); - // TODO(mbelshe): Fix the hostname. This is BROKEN without having - // a real hostname. - socket = session_->socket_factory()->CreateSSLClientSocket( - socket, "" /* request_->url.HostNoBrackets() */ , ssl_config_); - connection_->set_socket(socket); - is_secure_ = true; - int status = connection_->socket()->Connect(&ssl_connect_callback_); - if (status != ERR_IO_PENDING) - OnSSLConnect(status); - } else { - DCHECK_EQ(state_, CONNECTING); - state_ = CONNECTED; - - // Make sure we get any pending data sent. - WriteSocketLater(); - // Start reading - ReadSocket(); - } -} - -void SpdySession::OnSSLConnect(int result) { - // TODO(mbelshe): We need to replicate the functionality of - // HttpNetworkTransaction::DoSSLConnectComplete here, where it calls - // HandleCertificateError() and such. - if (IsCertificateError(result)) - result = OK; // TODO(mbelshe): pretend we're happy anyway. - - if (result == OK) { - DCHECK_EQ(state_, CONNECTING); - state_ = CONNECTED; - - // After we've connected, send any data to the server, and then issue - // our read. - WriteSocketLater(); - ReadSocket(); - } else { - DCHECK_LT(result, 0); // It should be an error, not a byte count. - CloseSessionOnError(static_cast<net::Error>(result), true); - } -} - void SpdySession::OnReadComplete(int bytes_read) { // Parse a frame. For now this code requires that the frame fit into our // buffer (32KB). diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h index 76f105c..e98a478 100644 --- a/net/spdy/spdy_session.h +++ b/net/spdy/spdy_session.h @@ -63,14 +63,6 @@ class SpdySession : public base::RefCounted<SpdySession>, return host_port_proxy_pair_; } - // Connect the Spdy Socket. - // Returns net::Error::OK on success. - // Note that this call does not wait for the connect to complete. Callers can - // immediately start using the SpdySession while it connects. - net::Error Connect(const std::string& group_name, - const scoped_refptr<TCPSocketParams>& destination, - RequestPriority priority); - // Get a pushed stream for a given |url|. // If the server initiates a stream, it might already exist for a given path. // The server might also not have initiated the stream yet, but indicated it @@ -237,8 +229,6 @@ class SpdySession : public base::RefCounted<SpdySession>, void OnWindowUpdate(const spdy::SpdyWindowUpdateControlFrame& frame); // IO Callbacks - void OnTCPConnect(int result); - void OnSSLConnect(int result); void OnReadComplete(int result); void OnWriteComplete(int result); @@ -290,16 +280,12 @@ class SpdySession : public base::RefCounted<SpdySession>, void CloseAllStreams(net::Error status); // Callbacks for the Spdy session. - CompletionCallbackImpl<SpdySession> connect_callback_; - CompletionCallbackImpl<SpdySession> ssl_connect_callback_; CompletionCallbackImpl<SpdySession> read_callback_; CompletionCallbackImpl<SpdySession> write_callback_; // The domain this session is connected to. const HostPortProxyPair host_port_proxy_pair_; - SSLConfig ssl_config_; - scoped_refptr<HttpNetworkSession> session_; // The socket handle for this session. diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index f53d022..faa8433 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -91,8 +91,12 @@ TEST_F(SpdySessionTest, GoAway) { scoped_refptr<TCPSocketParams> tcp_params = new TCPSocketParams(kTestHost, kTestPort, MEDIUM, GURL(), false); - int rv = session->Connect(kTestHost, tcp_params, MEDIUM); - ASSERT_EQ(OK, rv); + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); + EXPECT_EQ(OK, + connection->Init(test_host_port_pair.ToString(), tcp_params, MEDIUM, + NULL, http_session->tcp_socket_pool(), + BoundNetLog())); + EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunAllPending(); diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 392fb3b..54ea82d 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -192,8 +192,12 @@ TEST_F(SpdyStreamTest, SendDataAfterOpen) { HostPortPair host_port_pair("www.google.com", 80); scoped_refptr<TCPSocketParams> tcp_params = new TCPSocketParams(host_port_pair, LOWEST, GURL(), false); - EXPECT_EQ(OK, session->Connect("spdy.www.google.com", tcp_params, - LOWEST)); + + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); + EXPECT_EQ(OK, + connection->Init(host_port_pair.ToString(), tcp_params, LOWEST, + NULL, session_->tcp_socket_pool(), BoundNetLog())); + session->InitializeWithSocket(connection.release(), false, OK); scoped_refptr<SpdyStream> stream; ASSERT_EQ( |