diff options
author | mef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 18:01:40 +0000 |
---|---|---|
committer | mef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 18:01:40 +0000 |
commit | e6d017658f1f60b06eebff1b0ac5ba6751b8daa7 (patch) | |
tree | 570100639ba4ce142591694b297b0218d55e54a5 /net/spdy | |
parent | 8fcb7fa663d0ec60859e931c01929baa64ee47e4 (diff) | |
download | chromium_src-e6d017658f1f60b06eebff1b0ac5ba6751b8daa7.zip chromium_src-e6d017658f1f60b06eebff1b0ac5ba6751b8daa7.tar.gz chromium_src-e6d017658f1f60b06eebff1b0ac5ba6751b8daa7.tar.bz2 |
ChannelID-less Connections in Chrome should be more granular.
Added enum PrivacyMode (Enabled/Disabled) to mark connections which should not use ChannelID even if it is globally enabled.
PrivacyMode is enabled if user blocks sending or saving cookies to/from particular server, taking in account third party cookie settings as well. See crbug.com/223191 for design doc.
Segmented client socket pools according to privacy mode setting used for particular connection (added 'pm/' prefix to pool key. Introduced SpdySessionKey structure and added PrivacyMode to the key of SpdySessionPool.
Added propagation of Privacy Mode setting from Web Sockets. Added check of Privacy Mode to predictor and pre-connect logic.
BUG=223191
TEST=unit_tests gtest_filter=ChromeNetworkDelegatePrivacyModeTest*
Review URL: https://chromiumcodereview.appspot.com/13008028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_http_stream_spdy2_unittest.cc | 41 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_spdy3_unittest.cc | 66 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_spdy2_unittest.cc | 16 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_spdy3_unittest.cc | 16 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket_unittest.cc | 7 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 24 | ||||
-rw-r--r-- | net/spdy/spdy_session.h | 26 | ||||
-rw-r--r-- | net/spdy/spdy_session_key.cc | 50 | ||||
-rw-r--r-- | net/spdy/spdy_session_key.h | 58 | ||||
-rw-r--r-- | net/spdy/spdy_session_pool.cc | 138 | ||||
-rw-r--r-- | net/spdy/spdy_session_pool.h | 45 | ||||
-rw-r--r-- | net/spdy/spdy_session_spdy2_unittest.cc | 148 | ||||
-rw-r--r-- | net/spdy/spdy_session_spdy3_unittest.cc | 215 | ||||
-rw-r--r-- | net/spdy/spdy_stream_spdy2_unittest.cc | 5 | ||||
-rw-r--r-- | net/spdy/spdy_stream_spdy3_unittest.cc | 5 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_common.cc | 8 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_common.h | 4 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream_spdy2_unittest.cc | 21 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream_spdy3_unittest.cc | 22 |
19 files changed, 558 insertions, 357 deletions
diff --git a/net/spdy/spdy_http_stream_spdy2_unittest.cc b/net/spdy/spdy_http_stream_spdy2_unittest.cc index 74102f4..27b0419 100644 --- a/net/spdy/spdy_http_stream_spdy2_unittest.cc +++ b/net/spdy/spdy_http_stream_spdy2_unittest.cc @@ -81,14 +81,15 @@ class SpdyHttpStreamSpdy2Test : public testing::Test { int InitSessionDeterministic(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count, HostPortPair& host_port_pair) { - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); deterministic_data_.reset( new DeterministicSocketData(reads, reads_count, writes, writes_count)); session_deps_.deterministic_socket_factory->AddSocketDataProvider( deterministic_data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -110,12 +111,13 @@ class SpdyHttpStreamSpdy2Test : public testing::Test { int InitSession(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count, HostPortPair& host_port_pair) { - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); data_.reset(new OrderedSocketData(reads, reads_count, writes, writes_count)); session_deps_.socket_factory->AddSocketDataProvider(data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -154,7 +156,8 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendRequest) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -179,7 +182,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendRequest) { EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); // This triggers the MockWrite and read 2 @@ -193,7 +196,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendRequest) { // Because we abandoned the stream, we don't expect to find a session in the // pool anymore. - EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); @@ -224,7 +227,8 @@ TEST_F(SpdyHttpStreamSpdy2Test, LoadTimingTwoRequests) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); ASSERT_EQ(OK, InitSessionDeterministic(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -244,7 +248,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, LoadTimingTwoRequests) { CompletionCallback())); EXPECT_EQ(ERR_IO_PENDING, http_stream1->SendRequest(headers1, &response1, callback1.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); HttpRequestInfo request2; request2.method = "GET"; @@ -261,7 +265,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, LoadTimingTwoRequests) { CompletionCallback())); EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers2, &response2, callback2.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // First write. deterministic_data()->RunFor(1); @@ -309,7 +313,8 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -338,7 +343,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) { EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // This results in writing the post body and reading the response headers. callback.WaitForResult(); @@ -350,7 +355,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) { // Because we abandoned the stream, we don't expect to find a session in the // pool anymore. - EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -381,7 +386,8 @@ TEST_F(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); ASSERT_EQ(OK, InitSessionDeterministic(reads, arraysize(reads), writes, arraysize(writes), @@ -410,7 +416,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost) { // complete asynchronously. EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // Complete the initial request write and the first chunk. deterministic_data()->RunFor(2); @@ -478,7 +484,8 @@ TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -513,7 +520,7 @@ TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { // Because we abandoned the stream, we don't expect to find a session in the // pool anymore. - EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } diff --git a/net/spdy/spdy_http_stream_spdy3_unittest.cc b/net/spdy/spdy_http_stream_spdy3_unittest.cc index 9d42941..cfdcb14 100644 --- a/net/spdy/spdy_http_stream_spdy3_unittest.cc +++ b/net/spdy/spdy_http_stream_spdy3_unittest.cc @@ -89,14 +89,15 @@ class SpdyHttpStreamSpdy3Test : public testing::Test { int InitSessionDeterministic(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count, HostPortPair& host_port_pair) { - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); deterministic_data_.reset( new DeterministicSocketData(reads, reads_count, writes, writes_count)); session_deps_.deterministic_socket_factory->AddSocketDataProvider( deterministic_data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -118,12 +119,13 @@ class SpdyHttpStreamSpdy3Test : public testing::Test { int InitSession(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count, HostPortPair& host_port_pair) { - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); data_.reset(new OrderedSocketData(reads, reads_count, writes, writes_count)); session_deps_.socket_factory->AddSocketDataProvider(data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -177,7 +179,8 @@ TEST_F(SpdyHttpStreamSpdy3Test, SendRequest) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -202,7 +205,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, SendRequest) { EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); // This triggers the MockWrite and read 2 @@ -216,7 +219,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, SendRequest) { // Because we abandoned the stream, we don't expect to find a session in the // pool anymore. - EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); @@ -247,7 +250,8 @@ TEST_F(SpdyHttpStreamSpdy3Test, LoadTimingTwoRequests) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); ASSERT_EQ(OK, InitSessionDeterministic(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -267,7 +271,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, LoadTimingTwoRequests) { CompletionCallback())); EXPECT_EQ(ERR_IO_PENDING, http_stream1->SendRequest(headers1, &response1, callback1.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); HttpRequestInfo request2; request2.method = "GET"; @@ -284,7 +288,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, LoadTimingTwoRequests) { CompletionCallback())); EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers2, &response2, callback2.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // First write. deterministic_data()->RunFor(1); @@ -345,7 +349,8 @@ void SpdyHttpStreamSpdy3Test::RunSendChunkedPostTest( reads.push_back(MockRead(SYNCHRONOUS, 0, seq++)); // EOF HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); EXPECT_EQ(OK, InitSession(vector_as_array(&reads), reads.size(), vector_as_array(&writes), writes.size(), host_port_pair)); @@ -376,7 +381,7 @@ void SpdyHttpStreamSpdy3Test::RunSendChunkedPostTest( EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // This results in writing the post body and reading the response headers. callback.WaitForResult(); @@ -388,7 +393,7 @@ void SpdyHttpStreamSpdy3Test::RunSendChunkedPostTest( // Because we abandoned the stream, we don't expect to find a session in the // pool anymore. - EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -428,7 +433,8 @@ TEST_F(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPost) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); ASSERT_EQ(OK, InitSessionDeterministic(reads, arraysize(reads), writes, arraysize(writes), @@ -457,7 +463,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPost) { // complete asynchronously. EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // Complete the initial request write and the first chunk. deterministic_data()->RunFor(2); @@ -530,7 +536,8 @@ TEST_F(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPostWithWindowUpdate) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); DeterministicSocketData data(reads, arraysize(reads), writes, arraysize(writes)); @@ -541,7 +548,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPostWithWindowUpdate) { http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( &session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -584,7 +591,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPostWithWindowUpdate) { // complete asynchronously. EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); // Complete the initial request write and first chunk. data.RunFor(2); @@ -640,7 +647,8 @@ TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -675,7 +683,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) { // Because we abandoned the stream, we don't expect to find a session in the // pool anymore. - EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -803,7 +811,8 @@ void SpdyHttpStreamSpdy3Test::TestSendCredentials( }; HostPortPair host_port_pair(HostPortPair::FromURL(GURL(kUrl1))); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); DeterministicMockClientSocketFactory* socket_factory = session_deps_.deterministic_socket_factory.get(); @@ -817,7 +826,7 @@ void SpdyHttpStreamSpdy3Test::TestSendCredentials( socket_factory->AddSSLSocketDataProvider(&ssl); http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( &session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -867,7 +876,7 @@ void SpdyHttpStreamSpdy3Test::TestSendCredentials( EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); data.RunFor(2); callback.WaitForResult(); @@ -948,9 +957,10 @@ TEST_F(SpdyHttpStreamSpdy3Test, DontSendCredentialsForHttpUrlsEC) { }; HostPortPair host_port_pair(HostPortPair::FromURL(GURL(kUrl1))); - HostPortProxyPair pair(host_port_pair, - ProxyServer::FromURI("proxy.google.com", - ProxyServer::SCHEME_HTTPS)); + SpdySessionKey key(host_port_pair, + ProxyServer::FromURI("proxy.google.com", + ProxyServer::SCHEME_HTTPS), + kPrivacyModeDisabled); DeterministicMockClientSocketFactory* socket_factory = session_deps_.deterministic_socket_factory.get(); @@ -964,7 +974,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, DontSendCredentialsForHttpUrlsEC) { socket_factory->AddSSLSocketDataProvider(&ssl); http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( &session_deps_); - session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); + session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback()); @@ -1010,7 +1020,7 @@ TEST_F(SpdyHttpStreamSpdy3Test, DontSendCredentialsForHttpUrlsEC) { EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, callback.callback())); - EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); data.RunFor(2); EXPECT_EQ(OK, callback.WaitForResult()); diff --git a/net/spdy/spdy_network_transaction_spdy2_unittest.cc b/net/spdy/spdy_network_transaction_spdy2_unittest.cc index 89c5e31..2094d94 100644 --- a/net/spdy/spdy_network_transaction_spdy2_unittest.cc +++ b/net/spdy/spdy_network_transaction_spdy2_unittest.cc @@ -515,12 +515,13 @@ class SpdyNetworkTransactionSpdy2Test const GURL& url = helper.request().url; int port = helper.test_type() == SPDYNPN ? 443 : 80; HostPortPair host_port_pair(url.host(), port); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); BoundNetLog log; const scoped_refptr<HttpNetworkSession>& session = helper.session(); SpdySessionPool* pool(session->spdy_session_pool()); - EXPECT_TRUE(pool->HasSession(pair)); - scoped_refptr<SpdySession> spdy_session(pool->Get(pair, log)); + EXPECT_TRUE(pool->HasSession(key)); + scoped_refptr<SpdySession> spdy_session(pool->Get(key, log)); ASSERT_TRUE(spdy_session.get() != NULL); EXPECT_EQ(0u, spdy_session->num_active_streams()); EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); @@ -4656,12 +4657,13 @@ TEST_P(SpdyNetworkTransactionSpdy2Test, DirectConnectProxyReconnect) { // Check that the SpdySession is still in the SpdySessionPool. HostPortPair host_port_pair("www.google.com", helper.port()); - HostPortProxyPair session_pool_key_direct( - host_port_pair, ProxyServer::Direct()); + SpdySessionKey session_pool_key_direct( + host_port_pair, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_TRUE(spdy_session_pool->HasSession(session_pool_key_direct)); - HostPortProxyPair session_pool_key_proxy( + SpdySessionKey session_pool_key_proxy( host_port_pair, - ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP)); + ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), + kPrivacyModeDisabled); EXPECT_FALSE(spdy_session_pool->HasSession(session_pool_key_proxy)); // Set up data for the proxy connection. diff --git a/net/spdy/spdy_network_transaction_spdy3_unittest.cc b/net/spdy/spdy_network_transaction_spdy3_unittest.cc index 948f16f..bd433c0 100644 --- a/net/spdy/spdy_network_transaction_spdy3_unittest.cc +++ b/net/spdy/spdy_network_transaction_spdy3_unittest.cc @@ -517,12 +517,13 @@ class SpdyNetworkTransactionSpdy3Test const GURL& url = helper.request().url; int port = helper.test_type() == SPDYNPN ? 443 : 80; HostPortPair host_port_pair(url.host(), port); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); BoundNetLog log; const scoped_refptr<HttpNetworkSession>& session = helper.session(); SpdySessionPool* pool(session->spdy_session_pool()); - EXPECT_TRUE(pool->HasSession(pair)); - scoped_refptr<SpdySession> spdy_session(pool->Get(pair, log)); + EXPECT_TRUE(pool->HasSession(key)); + scoped_refptr<SpdySession> spdy_session(pool->Get(key, log)); ASSERT_TRUE(spdy_session.get() != NULL); EXPECT_EQ(0u, spdy_session->num_active_streams()); EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); @@ -5243,12 +5244,13 @@ TEST_P(SpdyNetworkTransactionSpdy3Test, DirectConnectProxyReconnect) { // Check that the SpdySession is still in the SpdySessionPool. HostPortPair host_port_pair("www.google.com", helper.port()); - HostPortProxyPair session_pool_key_direct( - host_port_pair, ProxyServer::Direct()); + SpdySessionKey session_pool_key_direct( + host_port_pair, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_TRUE(spdy_session_pool->HasSession(session_pool_key_direct)); - HostPortProxyPair session_pool_key_proxy( + SpdySessionKey session_pool_key_proxy( host_port_pair, - ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP)); + ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), + kPrivacyModeDisabled); EXPECT_FALSE(spdy_session_pool->HasSession(session_pool_key_proxy)); // Set up data for the proxy connection. diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc index 6e27d47..70426c3 100644 --- a/net/spdy/spdy_proxy_client_socket_unittest.cc +++ b/net/spdy/spdy_proxy_client_socket_unittest.cc @@ -128,7 +128,7 @@ class SpdyProxyClientSocketTest HostPortPair proxy_host_port_; HostPortPair endpoint_host_port_pair_; ProxyServer proxy_; - HostPortProxyPair endpoint_host_port_proxy_pair_; + SpdySessionKey endpoint_spdy_session_key_; scoped_refptr<TransportSocketParams> transport_params_; DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); @@ -153,7 +153,8 @@ SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() proxy_host_port_(kProxyHost, kProxyPort), endpoint_host_port_pair_(kOriginHost, kOriginPort), proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), - endpoint_host_port_proxy_pair_(endpoint_host_port_pair_, proxy_), + endpoint_spdy_session_key_(endpoint_host_port_pair_, proxy_, + kPrivacyModeDisabled), transport_params_(new TransportSocketParams(proxy_host_port_, LOWEST, false, @@ -190,7 +191,7 @@ void SpdyProxyClientSocketTest::Initialize(MockRead* reads, // Creates a new spdy session. spdy_session_ = - session_->spdy_session_pool()->Get(endpoint_host_port_proxy_pair_, + session_->spdy_session_pool()->Get(endpoint_spdy_session_key_, net_log_.bound()); // Perform the TCP connect. diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index b2b02c3..537c2b7 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -308,7 +308,7 @@ void SpdyStreamRequest::Reset() { callback_.Reset(); } -SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, +SpdySession::SpdySession(const SpdySessionKey& spdy_session_key, SpdySessionPool* spdy_session_pool, HttpServerProperties* http_server_properties, bool verify_domain_authentication, @@ -324,7 +324,7 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, const HostPortPair& trusted_spdy_proxy, NetLog* net_log) : weak_factory_(this), - host_port_proxy_pair_(host_port_proxy_pair), + spdy_session_key_(spdy_session_key), spdy_session_pool_(spdy_session_pool), http_server_properties_(http_server_properties), connection_(new ClientSocketHandle), @@ -383,7 +383,7 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, DCHECK(HttpStreamFactory::spdy_enabled()); net_log_.BeginEvent( NetLog::TYPE_SPDY_SESSION, - base::Bind(&NetLogSpdySessionCallback, &host_port_proxy_pair_)); + base::Bind(&NetLogSpdySessionCallback, &host_port_proxy_pair())); next_unclaimed_push_stream_sweep_time_ = time_func_() + base::TimeDelta::FromSeconds(kMinPushedStreamLifetimeSeconds); // TODO(mbelshe): consider randomization of the stream_hi_water_mark. @@ -501,9 +501,8 @@ bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { return !ssl_info.client_cert_sent && (enable_credential_frames_ || !ssl_info.channel_id_sent || ServerBoundCertService::GetDomainForHost(domain) == - ServerBoundCertService::GetDomainForHost( - host_port_proxy_pair_.first.host())) && - ssl_info.cert->VerifyNameMatch(domain); + ServerBoundCertService::GetDomainForHost(host_port_pair().host())) && + ssl_info.cert->VerifyNameMatch(domain); } int SpdySession::GetPushStream( @@ -664,8 +663,8 @@ bool SpdySession::NeedsCredentials() const { return ssl_socket->WasChannelIDSent(); } -void SpdySession::AddPooledAlias(const HostPortProxyPair& alias) { - pooled_aliases_.insert(alias); +void SpdySession::AddPooledAlias(const SpdySessionKey& alias_key) { + pooled_aliases_.insert(alias_key); } int SpdySession::GetProtocolVersion() const { @@ -1333,17 +1332,18 @@ base::Value* SpdySession::GetInfoAsValue() const { dict->SetInteger("source_id", net_log_.source().id); - dict->SetString("host_port_pair", host_port_proxy_pair_.first.ToString()); + dict->SetString("host_port_pair", host_port_pair().ToString()); if (!pooled_aliases_.empty()) { base::ListValue* alias_list = new base::ListValue(); - for (std::set<HostPortProxyPair>::const_iterator it = + for (std::set<SpdySessionKey>::const_iterator it = pooled_aliases_.begin(); it != pooled_aliases_.end(); it++) { - alias_list->Append(new base::StringValue(it->first.ToString())); + alias_list->Append(new base::StringValue( + it->host_port_pair().ToString())); } dict->Set("aliases", alias_list); } - dict->SetString("proxy", host_port_proxy_pair_.second.ToURI()); + dict->SetString("proxy", host_port_proxy_pair().second.ToURI()); dict->SetInteger("active_streams", active_streams_.size()); diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h index ba3a55c..f78825c 100644 --- a/net/spdy/spdy_session.h +++ b/net/spdy/spdy_session.h @@ -189,13 +189,13 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, }; // Create a new SpdySession. - // |host_port_proxy_pair| is the host/port that this session connects to, and - // the proxy configuration settings that it's using. + // |spdy_session_key| is the host/port that this session connects to, privacy + // and proxy configuration settings that it's using. // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must // strictly be greater than |this|. // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log // network events to. - SpdySession(const HostPortProxyPair& host_port_proxy_pair, + SpdySession(const SpdySessionKey& spdy_session_key, SpdySessionPool* spdy_session_pool, HttpServerProperties* http_server_properties, bool verify_domain_authentication, @@ -212,12 +212,14 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, NetLog* net_log); const HostPortPair& host_port_pair() const { - return host_port_proxy_pair_.first; + return spdy_session_key_.host_port_proxy_pair().first; } const HostPortProxyPair& host_port_proxy_pair() const { - return host_port_proxy_pair_; + return spdy_session_key_.host_port_proxy_pair(); + } + const SpdySessionKey& spdy_session_key() const { + return spdy_session_key_; } - // 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 @@ -428,10 +430,10 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, SpdyCredentialState* credential_state() { return &credential_state_; } // Adds |alias| to set of aliases associated with this session. - void AddPooledAlias(const HostPortProxyPair& alias); + void AddPooledAlias(const SpdySessionKey& alias_key); // Returns the set of aliases associated with this session. - const std::set<HostPortProxyPair>& pooled_aliases() const { + const std::set<SpdySessionKey>& pooled_aliases() const { return pooled_aliases_; } @@ -789,12 +791,12 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, // method. base::WeakPtrFactory<SpdySession> weak_factory_; - // The domain this session is connected to. - const HostPortProxyPair host_port_proxy_pair_; + // The key used to identify this session. + const SpdySessionKey spdy_session_key_; - // Set set of HostPortProxyPairs for which this session has serviced + // Set set of SpdySessionKeys for which this session has serviced // requests. - std::set<HostPortProxyPair> pooled_aliases_; + std::set<SpdySessionKey> pooled_aliases_; // |spdy_session_pool_| owns us, therefore its lifetime must exceed ours. We // set this to NULL after we are removed from the pool. diff --git a/net/spdy/spdy_session_key.cc b/net/spdy/spdy_session_key.cc new file mode 100644 index 0000000..3d6cdea --- /dev/null +++ b/net/spdy/spdy_session_key.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/spdy/spdy_session_key.h" + +#include "base/logging.h" + +namespace net { + +SpdySessionKey::SpdySessionKey() : privacy_mode_(kPrivacyModeDisabled) { +} + +SpdySessionKey::SpdySessionKey(const HostPortPair& host_port_pair, + const ProxyServer& proxy_server, + PrivacyMode privacy_mode) + : host_port_proxy_pair_(host_port_pair, proxy_server), + privacy_mode_(privacy_mode) { + DVLOG(1) << "SpdySessionKey(host=" << host_port_pair.ToString() + << ", proxy=" << proxy_server.ToURI() + << ", privacy=" << privacy_mode; +} + +SpdySessionKey::SpdySessionKey(const HostPortProxyPair& host_port_proxy_pair, + PrivacyMode privacy_mode) + : host_port_proxy_pair_(host_port_proxy_pair), + privacy_mode_(privacy_mode) { + DVLOG(1) << "SpdySessionKey(hppp=" << host_port_proxy_pair.first.ToString() + << "," << host_port_proxy_pair.second.ToURI() + << ", privacy=" << privacy_mode; +} + +SpdySessionKey::~SpdySessionKey() {} + +bool SpdySessionKey::operator<(const SpdySessionKey& other) const { + if (privacy_mode_ != other.privacy_mode_) + return privacy_mode_ < other.privacy_mode_; + if (!host_port_proxy_pair_.first.Equals(other.host_port_proxy_pair_.first)) + return host_port_proxy_pair_.first < other.host_port_proxy_pair_.first; + return host_port_proxy_pair_.second < other.host_port_proxy_pair_.second; +} + +bool SpdySessionKey::Equals(const SpdySessionKey& other) const { + return privacy_mode_ == other.privacy_mode_ && + host_port_proxy_pair_.first.Equals(other.host_port_proxy_pair_.first) && + host_port_proxy_pair_.second == other.host_port_proxy_pair_.second; +} + +} // namespace net + diff --git a/net/spdy/spdy_session_key.h b/net/spdy/spdy_session_key.h new file mode 100644 index 0000000..59c832b --- /dev/null +++ b/net/spdy/spdy_session_key.h @@ -0,0 +1,58 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_SPDY_SPDY_SESSION_KEY_H_ +#define NET_SPDY_SPDY_SESSION_KEY_H_ + +#include "net/base/privacy_mode.h" +#include "net/proxy/proxy_server.h" + +namespace net { + +// SpdySessionKey is used as unique index for SpdySessionPool. +class NET_EXPORT_PRIVATE SpdySessionKey { + public: + SpdySessionKey(); + SpdySessionKey(const HostPortPair& host_port_pair, + const ProxyServer& proxy_server, + PrivacyMode privacy_mode); + + // Temporary hack for implicit copy constructor + SpdySessionKey(const HostPortProxyPair& host_port_proxy_pair, + PrivacyMode privacy_mode); + + ~SpdySessionKey(); + + // Comparator function so this can be placed in a std::map. + bool operator<(const SpdySessionKey& other) const; + + // Equality test of contents. (Probably another violation of style guide). + bool Equals(const SpdySessionKey& other) const; + + const HostPortProxyPair& host_port_proxy_pair() const { + return host_port_proxy_pair_; + } + + const HostPortPair& host_port_pair() const { + return host_port_proxy_pair_.first; + } + + const ProxyServer& proxy_server() const { + return host_port_proxy_pair_.second; + } + + PrivacyMode privacy_mode() const { + return privacy_mode_; + } + + private: + HostPortProxyPair host_port_proxy_pair_; + // If enabled, then session cannot be tracked by the server. + PrivacyMode privacy_mode_; +}; + +} // namespace net + +#endif // NET_SPDY_SPDY_SESSION_KEY_H_ + diff --git a/net/spdy/spdy_session_pool.cc b/net/spdy/spdy_session_pool.cc index a0ecc31..64c905f 100644 --- a/net/spdy/spdy_session_pool.cc +++ b/net/spdy/spdy_session_pool.cc @@ -26,11 +26,6 @@ enum SpdySessionGetTypes { SPDY_SESSION_GET_MAX = 4 }; -bool HostPortProxyPairsAreEqual(const HostPortProxyPair& a, - const HostPortProxyPair& b) { - return a.first.Equals(b.first) && a.second == b.second; -} - } // The maximum number of sessions to open to a single domain. @@ -89,26 +84,26 @@ SpdySessionPool::~SpdySessionPool() { } scoped_refptr<SpdySession> SpdySessionPool::Get( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log) { - return GetInternal(host_port_proxy_pair, net_log, false); + return GetInternal(spdy_session_key, net_log, false); } scoped_refptr<SpdySession> SpdySessionPool::GetIfExists( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log) { - return GetInternal(host_port_proxy_pair, net_log, true); + return GetInternal(spdy_session_key, net_log, true); } scoped_refptr<SpdySession> SpdySessionPool::GetInternal( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log, bool only_use_existing_sessions) { scoped_refptr<SpdySession> spdy_session; - SpdySessionList* list = GetSessionList(host_port_proxy_pair); + SpdySessionList* list = GetSessionList(spdy_session_key); if (!list) { // Check if we have a Session through a domain alias. - spdy_session = GetFromAlias(host_port_proxy_pair, net_log, true); + spdy_session = GetFromAlias(spdy_session_key, net_log, true); if (spdy_session) { UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", FOUND_EXISTING_FROM_IP_POOL, @@ -117,14 +112,14 @@ scoped_refptr<SpdySession> SpdySessionPool::GetInternal( NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, spdy_session->net_log().source().ToEventParametersCallback()); // Add this session to the map so that we can find it next time. - list = AddSessionList(host_port_proxy_pair); + list = AddSessionList(spdy_session_key); list->push_back(spdy_session); - spdy_session->AddPooledAlias(host_port_proxy_pair); + spdy_session->AddPooledAlias(spdy_session_key); return spdy_session; } else if (only_use_existing_sessions) { return NULL; } - list = AddSessionList(host_port_proxy_pair); + list = AddSessionList(spdy_session_key); } DCHECK(list); @@ -141,7 +136,7 @@ scoped_refptr<SpdySession> SpdySessionPool::GetInternal( DCHECK(!only_use_existing_sessions); - spdy_session = new SpdySession(host_port_proxy_pair, this, + spdy_session = new SpdySession(spdy_session_key, this, http_server_properties_, verify_domain_authentication_, enable_sending_initial_settings_, @@ -167,7 +162,7 @@ scoped_refptr<SpdySession> SpdySessionPool::GetInternal( } net::Error SpdySessionPool::GetSpdySessionFromSocket( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, ClientSocketHandle* connection, const BoundNetLog& net_log, int certificate_error_code, @@ -177,7 +172,7 @@ net::Error SpdySessionPool::GetSpdySessionFromSocket( IMPORTED_FROM_SOCKET, SPDY_SESSION_GET_MAX); // Create the SPDY session and add it to the pool. - *spdy_session = new SpdySession(host_port_proxy_pair, this, + *spdy_session = new SpdySession(spdy_session_key, this, http_server_properties_, verify_domain_authentication_, enable_sending_initial_settings_, @@ -191,9 +186,9 @@ net::Error SpdySessionPool::GetSpdySessionFromSocket( time_func_, trusted_spdy_proxy_, net_log.net_log()); - SpdySessionList* list = GetSessionList(host_port_proxy_pair); + SpdySessionList* list = GetSessionList(spdy_session_key); if (!list) - list = AddSessionList(host_port_proxy_pair); + list = AddSessionList(spdy_session_key); DCHECK(list->empty()); list->push_back(*spdy_session); @@ -206,10 +201,11 @@ net::Error SpdySessionPool::GetSpdySessionFromSocket( // potentially be pooled with this one. Because GetPeerAddress() reports the // proxy's address instead of the origin server, check to see if this is a // direct connection. - if (enable_ip_pooling_ && host_port_proxy_pair.second.is_direct()) { + if (enable_ip_pooling_ && + spdy_session_key.proxy_server().is_direct()) { IPEndPoint address; if (connection->socket()->GetPeerAddress(&address) == OK) - AddAlias(address, host_port_proxy_pair); + AddAlias(address, spdy_session_key); } // Now we can initialize the session with the SSL socket. @@ -218,25 +214,25 @@ net::Error SpdySessionPool::GetSpdySessionFromSocket( } bool SpdySessionPool::HasSession( - const HostPortProxyPair& host_port_proxy_pair) const { - if (GetSessionList(host_port_proxy_pair)) + const SpdySessionKey& spdy_session_key) const { + if (GetSessionList(spdy_session_key)) return true; // Check if we have a session via an alias. scoped_refptr<SpdySession> spdy_session = - GetFromAlias(host_port_proxy_pair, BoundNetLog(), false); + GetFromAlias(spdy_session_key, BoundNetLog(), false); return spdy_session.get() != NULL; } void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) { - bool ok = RemoveFromSessionList(session, session->host_port_proxy_pair()); + bool ok = RemoveFromSessionList(session, session->spdy_session_key()); DCHECK(ok); session->net_log().AddEvent( NetLog::TYPE_SPDY_SESSION_POOL_REMOVE_SESSION, session->net_log().source().ToEventParametersCallback()); - const std::set<HostPortProxyPair>& aliases = session->pooled_aliases(); - for (std::set<HostPortProxyPair>::const_iterator it = aliases.begin(); + const std::set<SpdySessionKey>& aliases = session->pooled_aliases(); + for (std::set<SpdySessionKey>::const_iterator it = aliases.begin(); it != aliases.end(); ++it) { ok = RemoveFromSessionList(session, *it); DCHECK(ok); @@ -245,13 +241,13 @@ void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) { bool SpdySessionPool::RemoveFromSessionList( const scoped_refptr<SpdySession>& session, - const HostPortProxyPair& pair) { - SpdySessionList* list = GetSessionList(pair); + const SpdySessionKey& spdy_session_key) { + SpdySessionList* list = GetSessionList(spdy_session_key); if (!list) return false; list->remove(session); if (list->empty()) - RemoveSessionList(pair); + RemoveSessionList(spdy_session_key); return true; } @@ -265,9 +261,9 @@ Value* SpdySessionPool::SpdySessionPoolInfoToValue() const { session != sessions->end(); ++session) { // Only add the session if the key in the map matches the main // host_port_proxy_pair (not an alias). - const HostPortProxyPair& key = it->first; - const HostPortProxyPair& pair = session->get()->host_port_proxy_pair(); - if (key.first.Equals(pair.first) && key.second == pair.second) + const SpdySessionKey& key = it->first; + const SpdySessionKey& session_key = session->get()->spdy_session_key(); + if (key.Equals(session_key)) list->Append(session->get()->GetInfoAsValue()); } } @@ -298,17 +294,17 @@ scoped_refptr<SpdySession> SpdySessionPool::GetExistingSession( } scoped_refptr<SpdySession> SpdySessionPool::GetFromAlias( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log, bool record_histograms) const { // We should only be checking aliases when there is no direct session. - DCHECK(!GetSessionList(host_port_proxy_pair)); + DCHECK(!GetSessionList(spdy_session_key)); if (!enable_ip_pooling_) return NULL; AddressList addresses; - if (!LookupAddresses(host_port_proxy_pair, net_log, &addresses)) + if (!LookupAddresses(spdy_session_key, net_log, &addresses)) return NULL; for (AddressList::const_iterator iter = addresses.begin(); iter != addresses.end(); @@ -318,13 +314,15 @@ scoped_refptr<SpdySession> SpdySessionPool::GetFromAlias( continue; // We found an alias. - const HostPortProxyPair& alias_pair = alias_iter->second; + const SpdySessionKey& alias_key = alias_iter->second; - // If the proxy settings match, we can reuse this session. - if (!(alias_pair.second == host_port_proxy_pair.second)) + // If the proxy and privacy settings match, we can reuse this session. + if (!(alias_key.proxy_server() == spdy_session_key.proxy_server()) || + !(alias_key.privacy_mode() == + spdy_session_key.privacy_mode())) continue; - SpdySessionList* list = GetSessionList(alias_pair); + SpdySessionList* list = GetSessionList(alias_key); if (!list) { NOTREACHED(); // It shouldn't be in the aliases table if we can't get it! continue; @@ -334,7 +332,7 @@ scoped_refptr<SpdySession> SpdySessionPool::GetFromAlias( // If the SPDY session is a secure one, we need to verify that the server // is authenticated to serve traffic for |host_port_proxy_pair| too. if (!spdy_session->VerifyDomainAuthentication( - host_port_proxy_pair.first.host())) { + spdy_session_key.host_port_pair().host())) { if (record_histograms) UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 0, 2); continue; @@ -358,74 +356,76 @@ void SpdySessionPool::OnCertTrustChanged(const X509Certificate* cert) { CloseCurrentSessions(ERR_NETWORK_CHANGED); } -const HostPortProxyPair& SpdySessionPool::NormalizeListPair( - const HostPortProxyPair& host_port_proxy_pair) const { +const SpdySessionKey& SpdySessionPool::NormalizeListKey( + const SpdySessionKey& spdy_session_key) const { if (!force_single_domain_) - return host_port_proxy_pair; + return spdy_session_key; - static HostPortProxyPair* single_domain_pair = NULL; - if (!single_domain_pair) { + static SpdySessionKey* single_domain_key = NULL; + if (!single_domain_key) { HostPortPair single_domain = HostPortPair("singledomain.com", 80); - single_domain_pair = new HostPortProxyPair(single_domain, - ProxyServer::Direct()); + single_domain_key = new SpdySessionKey(single_domain, + ProxyServer::Direct(), + kPrivacyModeDisabled); } - return *single_domain_pair; + return *single_domain_key; } SpdySessionPool::SpdySessionList* SpdySessionPool::AddSessionList( - const HostPortProxyPair& host_port_proxy_pair) { - const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); - DCHECK(sessions_.find(pair) == sessions_.end()); + const SpdySessionKey& spdy_session_key) { + const SpdySessionKey& key = NormalizeListKey(spdy_session_key); + DCHECK(sessions_.find(key) == sessions_.end()); SpdySessionPool::SpdySessionList* list = new SpdySessionList(); - sessions_[pair] = list; + sessions_[spdy_session_key] = list; return list; } SpdySessionPool::SpdySessionList* SpdySessionPool::GetSessionList( - const HostPortProxyPair& host_port_proxy_pair) const { - const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); - SpdySessionsMap::const_iterator it = sessions_.find(pair); + const SpdySessionKey& spdy_session_key) const { + const SpdySessionKey& key = NormalizeListKey(spdy_session_key); + SpdySessionsMap::const_iterator it = sessions_.find(key); if (it != sessions_.end()) return it->second; return NULL; } void SpdySessionPool::RemoveSessionList( - const HostPortProxyPair& host_port_proxy_pair) { - const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); - SpdySessionList* list = GetSessionList(pair); + const SpdySessionKey& spdy_session_key) { + const SpdySessionKey& key = NormalizeListKey(spdy_session_key); + SpdySessionList* list = GetSessionList(key); if (list) { delete list; - sessions_.erase(pair); + sessions_.erase(key); } else { DCHECK(false) << "removing orphaned session list"; } - RemoveAliases(host_port_proxy_pair); + RemoveAliases(spdy_session_key); } -bool SpdySessionPool::LookupAddresses(const HostPortProxyPair& pair, +bool SpdySessionPool::LookupAddresses(const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log, AddressList* addresses) const { - net::HostResolver::RequestInfo resolve_info(pair.first); + net::HostResolver::RequestInfo resolve_info( + spdy_session_key.host_port_pair()); int rv = resolver_->ResolveFromCache(resolve_info, addresses, net_log); DCHECK_NE(ERR_IO_PENDING, rv); return rv == OK; } void SpdySessionPool::AddAlias(const IPEndPoint& endpoint, - const HostPortProxyPair& pair) { + const SpdySessionKey& spdy_session_key) { DCHECK(enable_ip_pooling_); - aliases_[endpoint] = pair; + aliases_[endpoint] = spdy_session_key; } -void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { +void SpdySessionPool::RemoveAliases(const SpdySessionKey& spdy_session_key) { // Walk the aliases map, find references to this pair. // TODO(mbelshe): Figure out if this is too expensive. SpdyAliasMap::iterator alias_it = aliases_.begin(); while (alias_it != aliases_.end()) { - if (HostPortProxyPairsAreEqual(alias_it->second, pair)) { + if (alias_it->second.Equals(spdy_session_key)) { aliases_.erase(alias_it); alias_it = aliases_.begin(); // Iterator was invalidated. continue; @@ -491,7 +491,7 @@ void SpdySessionPool::CloseIdleSessions() { continue; } - HostPortProxyPair key = map_it->first; + SpdySessionKey key(map_it->first); session->CloseSessionOnError( net::ERR_ABORTED, true, "Closing idle sessions."); // CloseSessionOnError can invalidate the iterator. diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h index 992e502..f2e6b84 100644 --- a/net/spdy/spdy_session_pool.h +++ b/net/spdy/spdy_session_pool.h @@ -21,6 +21,7 @@ #include "net/proxy/proxy_config.h" #include "net/proxy/proxy_server.h" #include "net/socket/next_proto.h" +#include "net/spdy/spdy_session_key.h" #include "net/ssl/ssl_config_service.h" namespace net { @@ -68,12 +69,12 @@ class NET_EXPORT SpdySessionPool // Either returns an existing SpdySession or creates a new SpdySession for // use. scoped_refptr<SpdySession> Get( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log); // Only returns a SpdySession if it already exists. scoped_refptr<SpdySession> GetIfExists( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log); // Builds a SpdySession from an existing SSL socket. Users should try @@ -87,7 +88,7 @@ class NET_EXPORT SpdySessionPool // Returns OK on success, and the |spdy_session| will be provided. // Returns an error on failure, and |spdy_session| will be NULL. net::Error GetSpdySessionFromSocket( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, ClientSocketHandle* connection, const BoundNetLog& net_log, int certificate_error_code, @@ -99,7 +100,7 @@ class NET_EXPORT SpdySessionPool // using the HostCache, if HasSession() returns true at one point, it does not // imply the SpdySessionPool will still have a matching session in the near // future, since the HostCache's entry may have expired. - bool HasSession(const HostPortProxyPair& host_port_proxy_pair) const; + bool HasSession(const SpdySessionKey& spdy_session_key) const; // Close all SpdySessions, including any new ones created in the process of // closing the current ones. @@ -148,47 +149,49 @@ class NET_EXPORT SpdySessionPool WindowUpdateOverflow); typedef std::list<scoped_refptr<SpdySession> > SpdySessionList; - typedef std::map<HostPortProxyPair, SpdySessionList*> SpdySessionsMap; - typedef std::map<IPEndPoint, HostPortProxyPair> SpdyAliasMap; + typedef std::map<SpdySessionKey, SpdySessionList*> SpdySessionsMap; + typedef std::map<IPEndPoint, SpdySessionKey> SpdyAliasMap; scoped_refptr<SpdySession> GetInternal( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log, bool only_use_existing_sessions); scoped_refptr<SpdySession> GetExistingSession( SpdySessionList* list, const BoundNetLog& net_log) const; scoped_refptr<SpdySession> GetFromAlias( - const HostPortProxyPair& host_port_proxy_pair, + const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log, bool record_histograms) const; // Helper functions for manipulating the lists. - const HostPortProxyPair& NormalizeListPair( - const HostPortProxyPair& host_port_proxy_pair) const; + const SpdySessionKey& NormalizeListKey( + const SpdySessionKey& spdy_session_key) const; SpdySessionList* AddSessionList( - const HostPortProxyPair& host_port_proxy_pair); + const SpdySessionKey& spdy_session_key); SpdySessionList* GetSessionList( - const HostPortProxyPair& host_port_proxy_pair) const; - void RemoveSessionList(const HostPortProxyPair& host_port_proxy_pair); + const SpdySessionKey& spdy_session_key) const; + void RemoveSessionList(const SpdySessionKey& spdy_session_key); - // Does a DNS cache lookup for |pair|, and returns the |addresses| found. + // Does a DNS cache lookup for |spdy_session_key|, and returns + // the |addresses| found. // Returns true if addresses found, false otherwise. - bool LookupAddresses(const HostPortProxyPair& pair, + bool LookupAddresses(const SpdySessionKey& spdy_session_key, const BoundNetLog& net_log, AddressList* addresses) const; - // Add |address| as an IP-equivalent address for |pair|. - void AddAlias(const IPEndPoint& address, const HostPortProxyPair& pair); + // Add |address| as an IP-equivalent address for |spdy_session_key|. + void AddAlias(const IPEndPoint& address, + const SpdySessionKey& spdy_session_key); - // Remove all aliases for |pair| from the aliases table. - void RemoveAliases(const HostPortProxyPair& pair); + // Remove all aliases for |spdy_session_key| from the aliases table. + void RemoveAliases(const SpdySessionKey& spdy_session_key); - // Removes |session| from the session list associated with |pair|. + // Removes |session| from the session list associated with |spdy_session_key|. // Returns true if the session was removed, false otherwise. bool RemoveFromSessionList(const scoped_refptr<SpdySession>& session, - const HostPortProxyPair& pair); + const SpdySessionKey& spdy_session_key); HttpServerProperties* const http_server_properties_; diff --git a/net/spdy/spdy_session_spdy2_unittest.cc b/net/spdy/spdy_session_spdy2_unittest.cc index 988c104..9650df8 100644 --- a/net/spdy/spdy_session_spdy2_unittest.cc +++ b/net/spdy/spdy_session_spdy2_unittest.cc @@ -54,7 +54,8 @@ class SpdySessionSpdy2Test : public PlatformTest { spdy_session_pool_(NULL), test_url_(kTestUrl), test_host_port_pair_(kTestHost, kTestPort), - pair_(test_host_port_pair_, ProxyServer::Direct()) { + key_(test_host_port_pair_, ProxyServer::Direct(), + kPrivacyModeDisabled) { } virtual ~SpdySessionSpdy2Test() { @@ -82,17 +83,17 @@ class SpdySessionSpdy2Test : public PlatformTest { spdy_session_pool_ = http_session_->spdy_session_pool(); } - scoped_refptr<SpdySession> GetSession(const HostPortProxyPair& pair) { - EXPECT_FALSE(spdy_session_pool_->HasSession(pair)); + scoped_refptr<SpdySession> GetSession(const SpdySessionKey& key) { + EXPECT_FALSE(spdy_session_pool_->HasSession(key)); scoped_refptr<SpdySession> session = - spdy_session_pool_->Get(pair, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair)); + spdy_session_pool_->Get(key, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool_->HasSession(key)); return session; } - // Creates an initialized session to |pair_|. + // Creates an initialized session to |key_|. scoped_refptr<SpdySession> CreateInitializedSession() { - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); EXPECT_EQ( OK, InitializeSession( @@ -128,7 +129,7 @@ class SpdySessionSpdy2Test : public PlatformTest { SpdySessionPool* spdy_session_pool_; GURL test_url_; HostPortPair test_host_port_pair_; - HostPortProxyPair pair_; + SpdySessionKey key_; }; TEST_F(SpdySessionSpdy2Test, GoAway) { @@ -189,17 +190,17 @@ TEST_F(SpdySessionSpdy2Test, GoAway) { EXPECT_EQ(1u, spdy_stream1->stream_id()); EXPECT_EQ(3u, spdy_stream2->stream_id()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); // Read and process the GOAWAY frame. data.RunFor(1); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); EXPECT_TRUE(session->IsStreamActive(1)); EXPECT_FALSE(session->IsStreamActive(3)); - scoped_refptr<SpdySession> session2 = GetSession(pair_); + scoped_refptr<SpdySession> session2 = GetSession(key_); spdy_stream1->Close(); EXPECT_EQ(NULL, spdy_stream1.get()); @@ -263,7 +264,7 @@ TEST_F(SpdySessionSpdy2Test, ClientPing) { EXPECT_FALSE(session->check_ping_status_pending()); EXPECT_GE(session->last_activity_time(), before_ping_time); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Delete the first session. session = NULL; @@ -304,7 +305,7 @@ TEST_F(SpdySessionSpdy2Test, ServerPing) { // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunUntilIdle(); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Delete the session. session = NULL; @@ -320,7 +321,7 @@ TEST_F(SpdySessionSpdy2Test, DeleteExpiredPushStreams) { CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); // Give the session a SPDY2 framer. session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(SPDY2, false)); @@ -411,7 +412,7 @@ TEST_F(SpdySessionSpdy2Test, FailedPing) { // Assert session is not closed. EXPECT_FALSE(session->IsClosed()); EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); // We set last time we have received any data in 1 sec less than now. // CheckPingStatus will trigger timeout because hung interval is zero. @@ -422,7 +423,7 @@ TEST_F(SpdySessionSpdy2Test, FailedPing) { EXPECT_TRUE(session->IsClosed()); EXPECT_EQ(0u, session->num_active_streams()); EXPECT_EQ(0u, session->num_unclaimed_pushed_streams()); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Delete the first session. session = NULL; @@ -444,8 +445,9 @@ TEST_F(SpdySessionSpdy2Test, CloseIdleSessions) { // Set up session 1 const std::string kTestHost1("http://www.a.com"); HostPortPair test_host_port_pair1(kTestHost1, 80); - HostPortProxyPair pair1(test_host_port_pair1, ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, InitializeSession( @@ -459,8 +461,9 @@ TEST_F(SpdySessionSpdy2Test, CloseIdleSessions) { session_deps_.socket_factory->AddSocketDataProvider(&data); const std::string kTestHost2("http://www.b.com"); HostPortPair test_host_port_pair2(kTestHost2, 80); - HostPortProxyPair pair2(test_host_port_pair2, ProxyServer::Direct()); - scoped_refptr<SpdySession> session2 = GetSession(pair2); + SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session2 = GetSession(key2); EXPECT_EQ( OK, InitializeSession( @@ -474,8 +477,9 @@ TEST_F(SpdySessionSpdy2Test, CloseIdleSessions) { session_deps_.socket_factory->AddSocketDataProvider(&data); const std::string kTestHost3("http://www.c.com"); HostPortPair test_host_port_pair3(kTestHost3, 80); - HostPortProxyPair pair3(test_host_port_pair3, ProxyServer::Direct()); - scoped_refptr<SpdySession> session3 = GetSession(pair3); + SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session3 = GetSession(key3); EXPECT_EQ( OK, InitializeSession( @@ -843,7 +847,7 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { std::string url; std::string name; std::string iplist; - HostPortProxyPair pair; + SpdySessionKey key; AddressList addresses; } test_hosts[] = { { "http:://www.foo.com", @@ -873,9 +877,10 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { info, &test_hosts[i].addresses, CompletionCallback(), NULL, BoundNetLog()); - // Setup a HostPortProxyPair - test_hosts[i].pair = HostPortProxyPair( - HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); + // Setup a SpdySessionKey + test_hosts[i].key = SpdySessionKey( + HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), + kPrivacyModeDisabled); } MockConnect connect_data(SYNCHRONOUS, OK); @@ -895,10 +900,10 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { // Setup the first session to the first host. SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].key)); scoped_refptr<SpdySession> session = - spdy_session_pool->Get(test_hosts[0].pair, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); + spdy_session_pool->Get(test_hosts[0].key, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].key)); HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); @@ -915,59 +920,60 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. SpdySessionPoolPeer pool_peer(spdy_session_pool); - pool_peer.AddAlias(test_hosts[0].addresses.front(), test_hosts[0].pair); + pool_peer.AddAlias(test_hosts[0].addresses.front(), test_hosts[0].key); // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunUntilIdle(); // The third host has no overlap with the first, so it can't pool IPs. - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].key)); // The second host overlaps with the first, and should IP pool. - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); // Verify that the second host, through a proxy, won't share the IP. - HostPortProxyPair proxy_pair(test_hosts[1].pair.first, - ProxyServer::FromPacString("HTTP http://proxy.foo.com/")); - EXPECT_FALSE(spdy_session_pool->HasSession(proxy_pair)); + SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), + ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), + kPrivacyModeDisabled); + EXPECT_FALSE(spdy_session_pool->HasSession(proxy_key)); // Overlap between 2 and 3 does is not transitive to 1. - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].key)); // Create a new session to host 2. scoped_refptr<SpdySession> session2 = - spdy_session_pool->Get(test_hosts[2].pair, BoundNetLog()); + spdy_session_pool->Get(test_hosts[2].key, BoundNetLog()); // Verify that we have sessions for everything. - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].key)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].key)); // Initialize session for host 2. session_deps.socket_factory->AddSocketDataProvider(&data); - IPPoolingInitializedSession(test_hosts[2].pair.first.ToString(), + IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), transport_params, http_session, session2); // Grab the session to host 1 and verify that it is the same session // we got with host 0, and that is a different than host 2's session. scoped_refptr<SpdySession> session1 = - spdy_session_pool->Get(test_hosts[1].pair, BoundNetLog()); + spdy_session_pool->Get(test_hosts[1].key, BoundNetLog()); EXPECT_EQ(session.get(), session1.get()); EXPECT_NE(session2.get(), session1.get()); // Initialize session for host 1. session_deps.socket_factory->AddSocketDataProvider(&data); - IPPoolingInitializedSession(test_hosts[2].pair.first.ToString(), + IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), transport_params, http_session, session2); // Remove the aliases and observe that we still have a session for host1. - pool_peer.RemoveAliases(test_hosts[0].pair); - pool_peer.RemoveAliases(test_hosts[1].pair); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); + pool_peer.RemoveAliases(test_hosts[0].key); + pool_peer.RemoveAliases(test_hosts[1].key); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); // Expire the host cache session_deps.host_resolver->GetHostCache()->clear(); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); // Cleanup the sessions. switch (close_sessions_type) { @@ -1025,9 +1031,9 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { } // Verify that the map is all cleaned up. - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[1].pair)); - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].key)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[1].key)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].key)); } } // namespace @@ -1083,15 +1089,15 @@ TEST_F(SpdySessionSpdy2Test, CloseSessionOnError) { CapturingBoundNetLog log; scoped_refptr<SpdySession> session = - spdy_session_pool_->Get(pair_, log.bound()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + spdy_session_pool_->Get(key_, log.bound()); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); InitializeSession(http_session_.get(), session.get(), test_host_port_pair_); // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunUntilIdle(); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Check that the NetLog was filled reasonably. net::CapturingNetLog::CapturedEntryList entries; @@ -1376,7 +1382,7 @@ TEST_F(SpdySessionSpdy2Test, VerifyDomainAuthentication) { CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -1445,7 +1451,7 @@ TEST_F(SpdySessionSpdy2Test, ConnectionPooledWithTlsChannelId) { CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -1718,9 +1724,10 @@ TEST_F(SpdySessionSpdy2Test, NeedsCredentials) { const std::string kTestHost("www.foo.com"); const int kTestPort = 80; HostPortPair test_host_port_pair(kTestHost, kTestPort); - HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); - scoped_refptr<SpdySession> session = GetSession(pair); + scoped_refptr<SpdySession> session = GetSession(key); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -2146,7 +2153,7 @@ TEST_F(SpdySessionSpdy2Test, ProtocolNegotiation) { session_deps_.socket_factory->AddSocketDataProvider(&data); CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); EXPECT_TRUE(session->buffered_spdy_framer_ == NULL); @@ -2188,11 +2195,13 @@ TEST_F(SpdySessionSpdy2Test, CloseOneIdleConnection) { HttpNetworkSession::NORMAL_SOCKET_POOL); // Create an idle SPDY session. - HostPortProxyPair pair1(HostPortPair("1.com", 80), ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, - InitializeSession(http_session_.get(), session1.get(), pair1.first)); + InitializeSession(http_session_.get(), session1.get(), + key1.host_port_pair())); EXPECT_FALSE(pool->IsStalled()); // Release the pointer to the session so it can be closed. session1 = NULL; @@ -2240,11 +2249,13 @@ TEST_F(SpdySessionSpdy2Test, CloseOneIdleConnectionSessionStillHeld) { HttpNetworkSession::NORMAL_SOCKET_POOL); // Create an idle SPDY session. - HostPortProxyPair pair1(HostPortPair("1.com", 80), ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, - InitializeSession(http_session_.get(), session1.get(), pair1.first)); + InitializeSession(http_session_.get(), session1.get(), + key1.host_port_pair())); EXPECT_FALSE(pool->IsStalled()); // Trying to create a new connection should cause the pool to be stalled, and @@ -2305,12 +2316,13 @@ TEST_F(SpdySessionSpdy2Test, CloseOneIdleConnectionFailsWhenSessionInUse) { // Create a SPDY session. GURL url1("http://www.google.com"); - HostPortProxyPair pair1(HostPortPair(url1.host(), 80), - ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(HostPortPair(url1.host(), 80), + ProxyServer::Direct(), kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, - InitializeSession(http_session_.get(), session1.get(), pair1.first)); + InitializeSession(http_session_.get(), session1.get(), + key1.host_port_pair())); EXPECT_FALSE(pool->IsStalled()); // Create a stream using the session, and send a request. diff --git a/net/spdy/spdy_session_spdy3_unittest.cc b/net/spdy/spdy_session_spdy3_unittest.cc index fb50ec9..6beeaa6 100644 --- a/net/spdy/spdy_session_spdy3_unittest.cc +++ b/net/spdy/spdy_session_spdy3_unittest.cc @@ -108,7 +108,8 @@ class SpdySessionSpdy3Test : public PlatformTest { spdy_session_pool_(NULL), test_url_(kTestUrl), test_host_port_pair_(kTestHost, kTestPort), - pair_(test_host_port_pair_, ProxyServer::Direct()) { + key_(test_host_port_pair_, ProxyServer::Direct(), + kPrivacyModeDisabled) { } virtual ~SpdySessionSpdy3Test() { @@ -136,17 +137,17 @@ class SpdySessionSpdy3Test : public PlatformTest { spdy_session_pool_ = http_session_->spdy_session_pool(); } - scoped_refptr<SpdySession> GetSession(const HostPortProxyPair& pair) { - EXPECT_FALSE(spdy_session_pool_->HasSession(pair)); + scoped_refptr<SpdySession> GetSession(const SpdySessionKey& key) { + EXPECT_FALSE(spdy_session_pool_->HasSession(key)); scoped_refptr<SpdySession> session = - spdy_session_pool_->Get(pair, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair)); + spdy_session_pool_->Get(key, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool_->HasSession(key)); return session; } // Creates an initialized session to |pair_|. scoped_refptr<SpdySession> CreateInitializedSession() { - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); EXPECT_EQ( OK, InitializeSession( @@ -210,7 +211,7 @@ class SpdySessionSpdy3Test : public PlatformTest { SpdySessionPool* spdy_session_pool_; GURL test_url_; HostPortPair test_host_port_pair_; - HostPortProxyPair pair_; + SpdySessionKey key_; }; TEST_F(SpdySessionSpdy3Test, GoAway) { @@ -271,17 +272,17 @@ TEST_F(SpdySessionSpdy3Test, GoAway) { EXPECT_EQ(1u, spdy_stream1->stream_id()); EXPECT_EQ(3u, spdy_stream2->stream_id()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); // Read and process the GOAWAY frame. data.RunFor(1); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); EXPECT_TRUE(session->IsStreamActive(1)); EXPECT_FALSE(session->IsStreamActive(3)); - scoped_refptr<SpdySession> session2 = GetSession(pair_); + scoped_refptr<SpdySession> session2 = GetSession(key_); spdy_stream1->Close(); EXPECT_EQ(NULL, spdy_stream1.get()); @@ -345,7 +346,7 @@ TEST_F(SpdySessionSpdy3Test, ClientPing) { EXPECT_FALSE(session->check_ping_status_pending()); EXPECT_GE(session->last_activity_time(), before_ping_time); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Delete the first session. session = NULL; @@ -386,7 +387,7 @@ TEST_F(SpdySessionSpdy3Test, ServerPing) { // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunUntilIdle(); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Delete the session. session = NULL; @@ -402,7 +403,7 @@ TEST_F(SpdySessionSpdy3Test, DeleteExpiredPushStreams) { CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); // Give the session a SPDY3 framer. session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(SPDY3, false)); @@ -497,7 +498,7 @@ TEST_F(SpdySessionSpdy3Test, FailedPing) { // Assert session is not closed. EXPECT_FALSE(session->IsClosed()); EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); // We set last time we have received any data in 1 sec less than now. // CheckPingStatus will trigger timeout because hung interval is zero. @@ -508,7 +509,7 @@ TEST_F(SpdySessionSpdy3Test, FailedPing) { EXPECT_TRUE(session->IsClosed()); EXPECT_EQ(0u, session->num_active_streams()); EXPECT_EQ(0u, session->num_unclaimed_pushed_streams()); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Delete the first session. session = NULL; @@ -530,8 +531,9 @@ TEST_F(SpdySessionSpdy3Test, CloseIdleSessions) { // Set up session 1 const std::string kTestHost1("http://www.a.com"); HostPortPair test_host_port_pair1(kTestHost1, 80); - HostPortProxyPair pair1(test_host_port_pair1, ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, InitializeSession( @@ -545,8 +547,9 @@ TEST_F(SpdySessionSpdy3Test, CloseIdleSessions) { session_deps_.socket_factory->AddSocketDataProvider(&data); const std::string kTestHost2("http://www.b.com"); HostPortPair test_host_port_pair2(kTestHost2, 80); - HostPortProxyPair pair2(test_host_port_pair2, ProxyServer::Direct()); - scoped_refptr<SpdySession> session2 = GetSession(pair2); + SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session2 = GetSession(key2); EXPECT_EQ( OK, InitializeSession( @@ -560,8 +563,9 @@ TEST_F(SpdySessionSpdy3Test, CloseIdleSessions) { session_deps_.socket_factory->AddSocketDataProvider(&data); const std::string kTestHost3("http://www.c.com"); HostPortPair test_host_port_pair3(kTestHost3, 80); - HostPortProxyPair pair3(test_host_port_pair3, ProxyServer::Direct()); - scoped_refptr<SpdySession> session3 = GetSession(pair3); + SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session3 = GetSession(key3); EXPECT_EQ( OK, InitializeSession( @@ -934,7 +938,7 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { std::string url; std::string name; std::string iplist; - HostPortProxyPair pair; + SpdySessionKey key; AddressList addresses; } test_hosts[] = { { "http:://www.foo.com", @@ -965,8 +969,9 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { BoundNetLog()); // Setup a HostPortProxyPair - test_hosts[i].pair = HostPortProxyPair( - HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); + test_hosts[i].key = SpdySessionKey( + HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), + kPrivacyModeDisabled); } MockConnect connect_data(SYNCHRONOUS, OK); @@ -986,10 +991,10 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { // Setup the first session to the first host. SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].key)); scoped_refptr<SpdySession> session = - spdy_session_pool->Get(test_hosts[0].pair, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); + spdy_session_pool->Get(test_hosts[0].key, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].key)); HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); @@ -1006,59 +1011,60 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. SpdySessionPoolPeer pool_peer(spdy_session_pool); - pool_peer.AddAlias(test_hosts[0].addresses.front(), test_hosts[0].pair); + pool_peer.AddAlias(test_hosts[0].addresses.front(), test_hosts[0].key); // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunUntilIdle(); // The third host has no overlap with the first, so it can't pool IPs. - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].key)); // The second host overlaps with the first, and should IP pool. - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); // Verify that the second host, through a proxy, won't share the IP. - HostPortProxyPair proxy_pair(test_hosts[1].pair.first, - ProxyServer::FromPacString("HTTP http://proxy.foo.com/")); - EXPECT_FALSE(spdy_session_pool->HasSession(proxy_pair)); + SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), + ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), + kPrivacyModeDisabled); + EXPECT_FALSE(spdy_session_pool->HasSession(proxy_key)); // Overlap between 2 and 3 does is not transitive to 1. - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].key)); // Create a new session to host 2. scoped_refptr<SpdySession> session2 = - spdy_session_pool->Get(test_hosts[2].pair, BoundNetLog()); + spdy_session_pool->Get(test_hosts[2].key, BoundNetLog()); // Verify that we have sessions for everything. - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].key)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].key)); // Initialize session for host 2. session_deps.socket_factory->AddSocketDataProvider(&data); - IPPoolingInitializedSession(test_hosts[2].pair.first.ToString(), + IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), transport_params, http_session, session2); // Grab the session to host 1 and verify that it is the same session // we got with host 0, and that is a different than host 2's session. scoped_refptr<SpdySession> session1 = - spdy_session_pool->Get(test_hosts[1].pair, BoundNetLog()); + spdy_session_pool->Get(test_hosts[1].key, BoundNetLog()); EXPECT_EQ(session.get(), session1.get()); EXPECT_NE(session2.get(), session1.get()); // Initialize session for host 1. session_deps.socket_factory->AddSocketDataProvider(&data); - IPPoolingInitializedSession(test_hosts[2].pair.first.ToString(), + IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), transport_params, http_session, session2); // Remove the aliases and observe that we still have a session for host1. - pool_peer.RemoveAliases(test_hosts[0].pair); - pool_peer.RemoveAliases(test_hosts[1].pair); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); + pool_peer.RemoveAliases(test_hosts[0].key); + pool_peer.RemoveAliases(test_hosts[1].key); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); // Expire the host cache session_deps.host_resolver->GetHostCache()->clear(); - EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); + EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); // Cleanup the sessions. switch (close_sessions_type) { @@ -1118,9 +1124,9 @@ void IPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type) { } // Verify that the map is all cleaned up. - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[1].pair)); - EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].key)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[1].key)); + EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].key)); } } // namespace @@ -1175,8 +1181,8 @@ TEST_F(SpdySessionSpdy3Test, Initialize) { CreateNetworkSession(); scoped_refptr<SpdySession> session = - spdy_session_pool_->Get(pair_, log.bound()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + spdy_session_pool_->Get(key_, log.bound()); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); EXPECT_EQ(OK, InitializeSession( @@ -1225,8 +1231,8 @@ TEST_F(SpdySessionSpdy3Test, CloseSessionOnError) { CapturingBoundNetLog log; scoped_refptr<SpdySession> session = - spdy_session_pool_->Get(pair_, log.bound()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + spdy_session_pool_->Get(key_, log.bound()); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); EXPECT_EQ(OK, InitializeSession( @@ -1235,7 +1241,7 @@ TEST_F(SpdySessionSpdy3Test, CloseSessionOnError) { // Flush the SpdySession::OnReadComplete() task. MessageLoop::current()->RunUntilIdle(); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); // Check that the NetLog was filled reasonably. net::CapturingNetLog::CapturedEntryList entries; @@ -1501,7 +1507,7 @@ TEST_F(SpdySessionSpdy3Test, VerifyDomainAuthentication) { CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -1570,7 +1576,7 @@ TEST_F(SpdySessionSpdy3Test, ConnectionPooledWithTlsChannelId) { CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -1831,9 +1837,10 @@ TEST_F(SpdySessionSpdy3Test, NeedsCredentials) { const GURL url("https:/www.foo.com"); HostPortPair test_host_port_pair(url.host(), 443); - HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); - scoped_refptr<SpdySession> session = GetSession(pair); + scoped_refptr<SpdySession> session = GetSession(key); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -1896,9 +1903,10 @@ TEST_F(SpdySessionSpdy3Test, SendCredentials) { const GURL kTestUrl("https://www.foo.com"); HostPortPair test_host_port_pair(kTestUrl.host(), 443); - HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); - scoped_refptr<SpdySession> session = GetSession(pair); + scoped_refptr<SpdySession> session = GetSession(key); SSLConfig ssl_config; scoped_refptr<TransportSocketParams> transport_params( @@ -1933,7 +1941,7 @@ TEST_F(SpdySessionSpdy3Test, SendCredentials) { MessageLoop::current()->RunUntilIdle(); spdy_session_pool_->Remove(session); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key)); } TEST_F(SpdySessionSpdy3Test, UpdateStreamsSendWindowSize) { @@ -2356,7 +2364,7 @@ TEST_F(SpdySessionSpdy3Test, ProtocolNegotiation) { session_deps_.socket_factory->AddSocketDataProvider(&data); CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); EXPECT_TRUE(session->buffered_spdy_framer_ == NULL); @@ -2390,7 +2398,7 @@ TEST_F(SpdySessionSpdy3Test, ProtocolNegotiation31) { session_deps_.socket_factory->AddSocketDataProvider(&data); CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); EXPECT_TRUE(session->buffered_spdy_framer_ == NULL); @@ -2428,8 +2436,7 @@ TEST_F(SpdySessionSpdy3Test, ProtocolNegotiation4) { session_deps_.socket_factory->AddSocketDataProvider(&data); CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); - + scoped_refptr<SpdySession> session = GetSession(key_); EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); EXPECT_TRUE(session->buffered_spdy_framer_ == NULL); EXPECT_EQ(0, session->session_send_window_size_); @@ -2483,7 +2490,7 @@ TEST_F(SpdySessionSpdy3Test, AdjustRecvWindowSize31) { session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -2529,7 +2536,7 @@ TEST_F(SpdySessionSpdy3Test, AdjustSendWindowSize31) { session_deps_.socket_factory->AddSocketDataProvider(&data); CreateNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -2575,7 +2582,7 @@ TEST_F(SpdySessionSpdy3Test, SessionFlowControlInactiveStream31) { session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -2945,7 +2952,7 @@ void SpdySessionSpdy3Test::RunResumeAfterUnstallTest31( session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -3101,7 +3108,7 @@ TEST_F(SpdySessionSpdy3Test, ResumeByPriorityAfterSendWindowSizeIncrease31) { session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -3267,7 +3274,7 @@ TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedStreams31) { session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -3468,7 +3475,7 @@ TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); CreateDeterministicNetworkSession(); - scoped_refptr<SpdySession> session = GetSession(pair_); + scoped_refptr<SpdySession> session = GetSession(key_); InitializeSession( http_session_.get(), session.get(), test_host_port_pair_); EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, @@ -3523,7 +3530,7 @@ TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { EXPECT_TRUE(stream1->send_stalled_by_flow_control()); EXPECT_TRUE(stream2->send_stalled_by_flow_control()); - EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); // Unstall stream1, which should then post a task to close the // session. @@ -3534,7 +3541,7 @@ TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { // Run the task to close the session. MessageLoop::current()->RunUntilIdle(); - EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); @@ -3576,11 +3583,13 @@ TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnection) { HttpNetworkSession::NORMAL_SOCKET_POOL); // Create an idle SPDY session. - HostPortProxyPair pair1(HostPortPair("1.com", 80), ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, - InitializeSession(http_session_.get(), session1.get(), pair1.first)); + InitializeSession(http_session_.get(), session1.get(), + key1.host_port_pair())); EXPECT_FALSE(pool->IsStalled()); // Release the pointer to the session so it can be closed. session1 = NULL; @@ -3628,11 +3637,13 @@ TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnectionSessionStillHeld) { HttpNetworkSession::NORMAL_SOCKET_POOL); // Create an idle SPDY session. - HostPortProxyPair pair1(HostPortPair("1.com", 80), ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), + kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, - InitializeSession(http_session_.get(), session1.get(), pair1.first)); + InitializeSession(http_session_.get(), session1.get(), + key1.host_port_pair())); EXPECT_FALSE(pool->IsStalled()); // Trying to create a new connection should cause the pool to be stalled, and @@ -3693,12 +3704,13 @@ TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnectionFailsWhenSessionInUse) { // Create a SPDY session. GURL url1("http://www.google.com"); - HostPortProxyPair pair1(HostPortPair(url1.host(), 80), - ProxyServer::Direct()); - scoped_refptr<SpdySession> session1 = GetSession(pair1); + SpdySessionKey key1(HostPortPair(url1.host(), 80), + ProxyServer::Direct(), kPrivacyModeDisabled); + scoped_refptr<SpdySession> session1 = GetSession(key1); EXPECT_EQ( OK, - InitializeSession(http_session_.get(), session1.get(), pair1.first)); + InitializeSession(http_session_.get(), session1.get(), + key1.host_port_pair())); EXPECT_FALSE(pool->IsStalled()); // Create a stream using the session, and send a request. @@ -3749,4 +3761,41 @@ TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnectionFailsWhenSessionInUse) { EXPECT_FALSE(callback2.have_result()); } +// Verify that SpdySessionKey and therefore SpdySession is different when +// privacy mode is enabled or disabled. +TEST_F(SpdySessionSpdy3Test, SpdySessionKeyPrivacyMode) { + CreateDeterministicNetworkSession(); + + HostPortPair host_port_pair("www.google.com", 443); + SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), + kPrivacyModeEnabled); + SpdySessionKey key_privacy_disabled(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); + + EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); + + // Add SpdySession with PrivacyMode Enabled to the pool. + scoped_refptr<SpdySession> session_privacy_enabled = + spdy_session_pool_->Get(key_privacy_enabled, BoundNetLog()); + + EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_enabled)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); + + // Add SpdySession with PrivacyMode Disabled to the pool. + scoped_refptr<SpdySession> session_privacy_disabled = + spdy_session_pool_->Get(key_privacy_disabled, BoundNetLog()); + + EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_enabled)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); + + spdy_session_pool_->Remove(session_privacy_enabled); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); + EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); + + spdy_session_pool_->Remove(session_privacy_disabled); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); + EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); +} + } // namespace net diff --git a/net/spdy/spdy_stream_spdy2_unittest.cc b/net/spdy/spdy_stream_spdy2_unittest.cc index e66953e..d8d0208 100644 --- a/net/spdy/spdy_stream_spdy2_unittest.cc +++ b/net/spdy/spdy_stream_spdy2_unittest.cc @@ -46,9 +46,10 @@ class SpdyStreamSpdy2Test : public testing::Test { session_deps_(kProtoSPDY2) {} scoped_refptr<SpdySession> CreateSpdySession() { - HostPortProxyPair pair(host_port_pair_, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair_, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> session( - session_->spdy_session_pool()->Get(pair, BoundNetLog())); + session_->spdy_session_pool()->Get(key, BoundNetLog())); return session; } diff --git a/net/spdy/spdy_stream_spdy3_unittest.cc b/net/spdy/spdy_stream_spdy3_unittest.cc index 94c2356..2c80211 100644 --- a/net/spdy/spdy_stream_spdy3_unittest.cc +++ b/net/spdy/spdy_stream_spdy3_unittest.cc @@ -44,9 +44,10 @@ class SpdyStreamSpdy3Test : public testing::Test { session_deps_(kProtoSPDY3) {} scoped_refptr<SpdySession> CreateSpdySession() { - HostPortProxyPair pair(host_port_pair_, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair_, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> session( - session_->spdy_session_pool()->Get(pair, BoundNetLog())); + session_->spdy_session_pool()->Get(key, BoundNetLog())); return session; } diff --git a/net/spdy/spdy_test_util_common.cc b/net/spdy/spdy_test_util_common.cc index 4087863..696a01b 100644 --- a/net/spdy/spdy_test_util_common.cc +++ b/net/spdy/spdy_test_util_common.cc @@ -491,12 +491,12 @@ SpdySessionPoolPeer::SpdySessionPoolPeer(SpdySessionPool* pool) : pool_(pool) { void SpdySessionPoolPeer::AddAlias( const IPEndPoint& address, - const HostPortProxyPair& pair) { - pool_->AddAlias(address, pair); + const SpdySessionKey& key) { + pool_->AddAlias(address, key); } -void SpdySessionPoolPeer::RemoveAliases(const HostPortProxyPair& pair) { - pool_->RemoveAliases(pair); +void SpdySessionPoolPeer::RemoveAliases(const SpdySessionKey& key) { + pool_->RemoveAliases(key); } void SpdySessionPoolPeer::RemoveSpdySession( diff --git a/net/spdy/spdy_test_util_common.h b/net/spdy/spdy_test_util_common.h index 1a12bf4..710c8e421 100644 --- a/net/spdy/spdy_test_util_common.h +++ b/net/spdy/spdy_test_util_common.h @@ -255,8 +255,8 @@ class SpdySessionPoolPeer { public: explicit SpdySessionPoolPeer(SpdySessionPool* pool); - void AddAlias(const IPEndPoint& address, const HostPortProxyPair& pair); - void RemoveAliases(const HostPortProxyPair& pair); + void AddAlias(const IPEndPoint& address, const SpdySessionKey& key); + void RemoveAliases(const SpdySessionKey& key); void RemoveSpdySession(const scoped_refptr<SpdySession>& session); void DisableDomainAuthenticationVerification(); void EnableSendingInitialSettings(bool enabled); diff --git a/net/spdy/spdy_websocket_stream_spdy2_unittest.cc b/net/spdy/spdy_websocket_stream_spdy2_unittest.cc index 85b8286..b8e5e2c 100644 --- a/net/spdy/spdy_websocket_stream_spdy2_unittest.cc +++ b/net/spdy/spdy_websocket_stream_spdy2_unittest.cc @@ -196,8 +196,9 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { virtual void SetUp() { host_port_pair_.set_host("example.com"); host_port_pair_.set_port(80); - host_port_proxy_pair_.first = host_port_pair_; - host_port_proxy_pair_.second = ProxyServer::Direct(); + spdy_session_key_ = SpdySessionKey(host_port_pair_, + ProxyServer::Direct(), + kPrivacyModeDisabled); spdy_settings_id_to_set_ = SETTINGS_MAX_CONCURRENT_STREAMS; spdy_settings_flags_to_set_ = SETTINGS_FLAG_PLEASE_PERSIST; @@ -254,9 +255,9 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { spdy_settings_value_to_set_); } - EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); - session_ = spdy_session_pool->Get(host_port_proxy_pair_, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); + EXPECT_FALSE(spdy_session_pool->HasSession(spdy_session_key_)); + session_ = spdy_session_pool->Get(spdy_session_key_, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool->HasSession(spdy_session_key_)); transport_params_ = new TransportSocketParams(host_port_pair_, MEDIUM, false, false, OnHostResolutionCallback()); @@ -301,7 +302,7 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { scoped_ptr<SpdyFrame> message_frame_; scoped_ptr<SpdyFrame> closing_frame_; HostPortPair host_port_pair_; - HostPortProxyPair host_port_proxy_pair_; + SpdySessionKey spdy_session_key_; TestCompletionCallback completion_callback_; TestCompletionCallback sync_callback_; @@ -391,7 +392,7 @@ TEST_F(SpdyWebSocketStreamSpdy2Test, Basic) { // EOF close SPDY session. EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -453,7 +454,7 @@ TEST_F(SpdyWebSocketStreamSpdy2Test, DestructionBeforeClose) { EXPECT_EQ(static_cast<int>(kMessageFrameLength), events[3].result); EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -516,7 +517,7 @@ TEST_F(SpdyWebSocketStreamSpdy2Test, DestructionAfterExplicitClose) { EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_CLOSE, events[4].event_type); EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); } TEST_F(SpdyWebSocketStreamSpdy2Test, IOPending) { @@ -617,7 +618,7 @@ TEST_F(SpdyWebSocketStreamSpdy2Test, IOPending) { // EOF close SPDY session. EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } diff --git a/net/spdy/spdy_websocket_stream_spdy3_unittest.cc b/net/spdy/spdy_websocket_stream_spdy3_unittest.cc index acb6956..76eef3e 100644 --- a/net/spdy/spdy_websocket_stream_spdy3_unittest.cc +++ b/net/spdy/spdy_websocket_stream_spdy3_unittest.cc @@ -196,8 +196,10 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { virtual void SetUp() { host_port_pair_.set_host("example.com"); host_port_pair_.set_port(80); - host_port_proxy_pair_.first = host_port_pair_; - host_port_proxy_pair_.second = ProxyServer::Direct(); + + spdy_session_key_ = SpdySessionKey(host_port_pair_, + ProxyServer::Direct(), + kPrivacyModeDisabled); spdy_settings_id_to_set_ = SETTINGS_MAX_CONCURRENT_STREAMS; spdy_settings_flags_to_set_ = SETTINGS_FLAG_PLEASE_PERSIST; @@ -254,9 +256,9 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { spdy_settings_value_to_set_); } - EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); - session_ = spdy_session_pool->Get(host_port_proxy_pair_, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); + EXPECT_FALSE(spdy_session_pool->HasSession(spdy_session_key_)); + session_ = spdy_session_pool->Get(spdy_session_key_, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool->HasSession(spdy_session_key_)); transport_params_ = new TransportSocketParams(host_port_pair_, MEDIUM, false, false, OnHostResolutionCallback()); @@ -301,7 +303,7 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { scoped_ptr<SpdyFrame> message_frame_; scoped_ptr<SpdyFrame> closing_frame_; HostPortPair host_port_pair_; - HostPortProxyPair host_port_proxy_pair_; + SpdySessionKey spdy_session_key_; TestCompletionCallback completion_callback_; TestCompletionCallback sync_callback_; @@ -391,7 +393,7 @@ TEST_F(SpdyWebSocketStreamSpdy3Test, Basic) { // EOF close SPDY session. EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -453,7 +455,7 @@ TEST_F(SpdyWebSocketStreamSpdy3Test, DestructionBeforeClose) { EXPECT_EQ(static_cast<int>(kMessageFrameLength), events[3].result); EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } @@ -516,7 +518,7 @@ TEST_F(SpdyWebSocketStreamSpdy3Test, DestructionAfterExplicitClose) { EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_CLOSE, events[4].event_type); EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); } TEST_F(SpdyWebSocketStreamSpdy3Test, IOPending) { @@ -617,7 +619,7 @@ TEST_F(SpdyWebSocketStreamSpdy3Test, IOPending) { // EOF close SPDY session. EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession( - host_port_proxy_pair_)); + spdy_session_key_)); EXPECT_TRUE(data()->at_read_eof()); EXPECT_TRUE(data()->at_write_eof()); } |