diff options
Diffstat (limited to 'net')
50 files changed, 934 insertions, 468 deletions
diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc index 485f5bb..5a69b86 100644 --- a/net/base/network_delegate.cc +++ b/net/base/network_delegate.cc @@ -118,6 +118,20 @@ bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const { return OnCanThrottleRequest(request); } +bool NetworkDelegate::CanEnablePrivacyMode( + const GURL& url, + const GURL& first_party_for_cookies) const { + DCHECK(CalledOnValidThread()); + return OnCanEnablePrivacyMode(url, first_party_for_cookies); +} + +bool NetworkDelegate::OnCanEnablePrivacyMode( + const GURL& url, + const GURL& first_party_for_cookies) const { + // Default implementation disables privacy mode. + return false; +} + int NetworkDelegate::NotifyBeforeSocketStreamConnect( SocketStream* socket, const CompletionCallback& callback) { diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h index 0d99d02..9c2913d 100644 --- a/net/base/network_delegate.h +++ b/net/base/network_delegate.h @@ -97,6 +97,8 @@ class NET_EXPORT NetworkDelegate : public base::NonThreadSafe { bool CanAccessFile(const URLRequest& request, const base::FilePath& path) const; bool CanThrottleRequest(const URLRequest& request) const; + bool CanEnablePrivacyMode(const GURL& url, + const GURL& first_party_for_cookies) const; int NotifyBeforeSocketStreamConnect(SocketStream* socket, const CompletionCallback& callback); @@ -225,6 +227,13 @@ class NET_EXPORT NetworkDelegate : public base::NonThreadSafe { // request is overloaded or down. virtual bool OnCanThrottleRequest(const URLRequest& request) const = 0; + // Returns true if the given |url| has to be requested over connection that + // is not tracked by the server. Usually is false, unless user privacy + // settings block cookies from being get or set. + virtual bool OnCanEnablePrivacyMode( + const GURL& url, + const GURL& first_party_for_cookies) const; + // Called before a SocketStream tries to connect. virtual int OnBeforeSocketStreamConnect( SocketStream* socket, const CompletionCallback& callback) = 0; diff --git a/net/base/privacy_mode.h b/net/base/privacy_mode.h new file mode 100644 index 0000000..082ef26 --- /dev/null +++ b/net/base/privacy_mode.h @@ -0,0 +1,20 @@ +// 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_BASE_PRIVACY_MODE_H_ +#define NET_BASE_PRIVACY_MODE_H_ + +namespace net { + +// Privacy Mode is enabled if cookies to particular site are blocked, so +// Channel ID is disabled on that connection (https or spdy). +enum PrivacyMode { + kPrivacyModeDisabled = 0, + kPrivacyModeEnabled = 1, +}; + +}; // namespace net + +#endif // NET_BASE_PRIVACY_MODE_H_ + diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index e111e41..ab991e4 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -177,6 +177,12 @@ int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, proxy_ssl_config_.rev_checking_enabled = false; } + // Channel ID is enabled unless --disable-tls-channel-id flag is set, + // or if privacy mode is enabled. + bool channel_id_enabled = server_ssl_config_.channel_id_enabled && + (request_->privacy_mode == kPrivacyModeDisabled); + server_ssl_config_.channel_id_enabled = channel_id_enabled; + next_state_ = STATE_CREATE_STREAM; int rv = DoLoop(OK); if (rv == ERR_IO_PENDING) diff --git a/net/http/http_network_transaction_spdy2_unittest.cc b/net/http/http_network_transaction_spdy2_unittest.cc index 42eea1a..86254ff 100644 --- a/net/http/http_network_transaction_spdy2_unittest.cc +++ b/net/http/http_network_transaction_spdy2_unittest.cc @@ -8804,9 +8804,10 @@ TEST_F(HttpNetworkTransactionSpdy2Test, // Set up an initial SpdySession in the pool to reuse. HostPortPair host_port_pair("www.google.com", 443); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> spdy_session = - session->spdy_session_pool()->Get(pair, BoundNetLog()); + session->spdy_session_pool()->Get(key, BoundNetLog()); scoped_refptr<TransportSocketParams> transport_params( new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback())); @@ -9965,9 +9966,10 @@ TEST_F(HttpNetworkTransactionSpdy2Test, PreconnectWithExistingSpdySession) { // Set up an initial SpdySession in the pool to reuse. HostPortPair host_port_pair("www.google.com", 443); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> spdy_session = - session->spdy_session_pool()->Get(pair, BoundNetLog()); + session->spdy_session_pool()->Get(key, BoundNetLog()); scoped_refptr<TransportSocketParams> transport_params( new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback())); @@ -11283,10 +11285,10 @@ TEST_F(HttpNetworkTransactionSpdy2Test, CloseIdleSpdySessionToOpenNewOne) { session_deps_.socket_factory->AddSocketDataProvider(&http_data); HostPortPair host_port_pair_a("www.a.com", 443); - HostPortProxyPair host_port_proxy_pair_a( - host_port_pair_a, ProxyServer::Direct()); + SpdySessionKey spdy_session_key_a( + host_port_pair_a, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); TestCompletionCallback callback; HttpRequestInfo request1; @@ -11312,13 +11314,13 @@ TEST_F(HttpNetworkTransactionSpdy2Test, CloseIdleSpdySessionToOpenNewOne) { EXPECT_EQ("hello!", response_data); trans.reset(); EXPECT_TRUE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); HostPortPair host_port_pair_b("www.b.com", 443); - HostPortProxyPair host_port_proxy_pair_b( - host_port_pair_b, ProxyServer::Direct()); + SpdySessionKey spdy_session_key_b( + host_port_pair_b, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); + session->spdy_session_pool()->HasSession(spdy_session_key_b)); HttpRequestInfo request2; request2.method = "GET"; request2.url = GURL("https://www.b.com/"); @@ -11338,15 +11340,15 @@ TEST_F(HttpNetworkTransactionSpdy2Test, CloseIdleSpdySessionToOpenNewOne) { ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello!", response_data); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); EXPECT_TRUE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); + session->spdy_session_pool()->HasSession(spdy_session_key_b)); HostPortPair host_port_pair_a1("www.a.com", 80); - HostPortProxyPair host_port_proxy_pair_a1( - host_port_pair_a1, ProxyServer::Direct()); + SpdySessionKey spdy_session_key_a1( + host_port_pair_a1, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a1)); + session->spdy_session_pool()->HasSession(spdy_session_key_a1)); HttpRequestInfo request3; request3.method = "GET"; request3.url = GURL("http://www.a.com/"); @@ -11366,9 +11368,9 @@ TEST_F(HttpNetworkTransactionSpdy2Test, CloseIdleSpdySessionToOpenNewOne) { ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello!", response_data); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); + session->spdy_session_pool()->HasSession(spdy_session_key_b)); HttpStreamFactory::SetNextProtos(std::vector<std::string>()); } diff --git a/net/http/http_network_transaction_spdy3_unittest.cc b/net/http/http_network_transaction_spdy3_unittest.cc index 706a8bb..e6a3681 100644 --- a/net/http/http_network_transaction_spdy3_unittest.cc +++ b/net/http/http_network_transaction_spdy3_unittest.cc @@ -8787,9 +8787,10 @@ TEST_F(HttpNetworkTransactionSpdy3Test, // Set up an initial SpdySession in the pool to reuse. HostPortPair host_port_pair("www.google.com", 443); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> spdy_session = - session->spdy_session_pool()->Get(pair, BoundNetLog()); + session->spdy_session_pool()->Get(key, BoundNetLog()); scoped_refptr<TransportSocketParams> transport_params( new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback())); @@ -9949,9 +9950,10 @@ TEST_F(HttpNetworkTransactionSpdy3Test, PreconnectWithExistingSpdySession) { // Set up an initial SpdySession in the pool to reuse. HostPortPair host_port_pair("www.google.com", 443); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> spdy_session = - session->spdy_session_pool()->Get(pair, BoundNetLog()); + session->spdy_session_pool()->Get(key, BoundNetLog()); scoped_refptr<TransportSocketParams> transport_params( new TransportSocketParams(host_port_pair, MEDIUM, false, false, OnHostResolutionCallback())); @@ -11236,10 +11238,10 @@ TEST_F(HttpNetworkTransactionSpdy3Test, CloseIdleSpdySessionToOpenNewOne) { session_deps_.socket_factory->AddSocketDataProvider(&http_data); HostPortPair host_port_pair_a("www.a.com", 443); - HostPortProxyPair host_port_proxy_pair_a( - host_port_pair_a, ProxyServer::Direct()); + SpdySessionKey spdy_session_key_a( + host_port_pair_a, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); TestCompletionCallback callback; HttpRequestInfo request1; @@ -11265,13 +11267,13 @@ TEST_F(HttpNetworkTransactionSpdy3Test, CloseIdleSpdySessionToOpenNewOne) { EXPECT_EQ("hello!", response_data); trans.reset(); EXPECT_TRUE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); HostPortPair host_port_pair_b("www.b.com", 443); - HostPortProxyPair host_port_proxy_pair_b( - host_port_pair_b, ProxyServer::Direct()); + SpdySessionKey spdy_session_key_b( + host_port_pair_b, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); + session->spdy_session_pool()->HasSession(spdy_session_key_b)); HttpRequestInfo request2; request2.method = "GET"; request2.url = GURL("https://www.b.com/"); @@ -11291,15 +11293,15 @@ TEST_F(HttpNetworkTransactionSpdy3Test, CloseIdleSpdySessionToOpenNewOne) { ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello!", response_data); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); EXPECT_TRUE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); + session->spdy_session_pool()->HasSession(spdy_session_key_b)); HostPortPair host_port_pair_a1("www.a.com", 80); - HostPortProxyPair host_port_proxy_pair_a1( - host_port_pair_a1, ProxyServer::Direct()); + SpdySessionKey spdy_session_key_a1( + host_port_pair_a1, ProxyServer::Direct(), kPrivacyModeDisabled); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a1)); + session->spdy_session_pool()->HasSession(spdy_session_key_a1)); HttpRequestInfo request3; request3.method = "GET"; request3.url = GURL("http://www.a.com/"); @@ -11319,9 +11321,9 @@ TEST_F(HttpNetworkTransactionSpdy3Test, CloseIdleSpdySessionToOpenNewOne) { ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello!", response_data); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); + session->spdy_session_pool()->HasSession(spdy_session_key_a)); EXPECT_FALSE( - session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); + session->spdy_session_pool()->HasSession(spdy_session_key_b)); HttpStreamFactory::SetNextProtos(std::vector<std::string>()); } diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc index 03b43ed..b6bed9e 100644 --- a/net/http/http_proxy_client_socket_pool.cc +++ b/net/http/http_proxy_client_socket_pool.cc @@ -201,9 +201,10 @@ int HttpProxyConnectJob::DoTransportConnectComplete(int result) { int HttpProxyConnectJob::DoSSLConnect() { if (params_->tunnel()) { - HostPortProxyPair pair(params_->destination().host_port_pair(), - ProxyServer::Direct()); - if (params_->spdy_session_pool()->HasSession(pair)) { + SpdySessionKey key(params_->destination().host_port_pair(), + ProxyServer::Direct(), + kPrivacyModeDisabled); + if (params_->spdy_session_pool()->HasSession(key)) { using_spdy_ = true; next_state_ = STATE_SPDY_PROXY_CREATE_STREAM; return OK; @@ -297,23 +298,23 @@ int HttpProxyConnectJob::DoHttpProxyConnectComplete(int result) { int HttpProxyConnectJob::DoSpdyProxyCreateStream() { DCHECK(using_spdy_); DCHECK(params_->tunnel()); - - HostPortProxyPair pair(params_->destination().host_port_pair(), - ProxyServer::Direct()); + SpdySessionKey key(params_->destination().host_port_pair(), + ProxyServer::Direct(), + kPrivacyModeDisabled); SpdySessionPool* spdy_pool = params_->spdy_session_pool(); scoped_refptr<SpdySession> spdy_session; // It's possible that a session to the proxy has recently been created - if (spdy_pool->HasSession(pair)) { + if (spdy_pool->HasSession(key)) { if (transport_socket_handle_.get()) { if (transport_socket_handle_->socket()) transport_socket_handle_->socket()->Disconnect(); transport_socket_handle_->Reset(); } - spdy_session = spdy_pool->Get(pair, net_log()); + spdy_session = spdy_pool->Get(key, net_log()); } else { // Create a session direct to the proxy itself int rv = spdy_pool->GetSpdySessionFromSocket( - pair, transport_socket_handle_.release(), + key, transport_socket_handle_.release(), net_log(), OK, &spdy_session, /*using_ssl_*/ true); if (rv < 0) return rv; diff --git a/net/http/http_request_info.cc b/net/http/http_request_info.cc index c5d4752..7feb4ac 100644 --- a/net/http/http_request_info.cc +++ b/net/http/http_request_info.cc @@ -10,7 +10,8 @@ HttpRequestInfo::HttpRequestInfo() : upload_data_stream(NULL), load_flags(0), motivation(NORMAL_MOTIVATION), - request_id(0) { + request_id(0), + privacy_mode(kPrivacyModeDisabled) { } HttpRequestInfo::~HttpRequestInfo() {} diff --git a/net/http/http_request_info.h b/net/http/http_request_info.h index 1f8c80c..5b94427 100644 --- a/net/http/http_request_info.h +++ b/net/http/http_request_info.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "googleurl/src/gurl.h" #include "net/base/net_export.h" +#include "net/base/privacy_mode.h" #include "net/http/http_request_headers.h" namespace net { @@ -51,6 +52,10 @@ struct NET_EXPORT HttpRequestInfo { // An optional globally unique identifier for this request for use by the // consumer. 0 is invalid. uint64 request_id; + + // If enabled, then request must be sent over connection that cannot be + // tracked by the server (e.g. without channel id). + PrivacyMode privacy_mode; }; } // namespace net diff --git a/net/http/http_stream_factory_impl.cc b/net/http/http_stream_factory_impl.cc index 9225392..d86c690 100644 --- a/net/http/http_stream_factory_impl.cc +++ b/net/http/http_stream_factory_impl.cc @@ -222,8 +222,8 @@ void HttpStreamFactoryImpl::OnSpdySessionReady( NextProto protocol_negotiated, bool using_spdy, const BoundNetLog& net_log) { - const HostPortProxyPair& spdy_session_key = - spdy_session->host_port_proxy_pair(); + const SpdySessionKey& spdy_session_key = + spdy_session->spdy_session_key(); while (!spdy_session->IsClosed()) { // Each iteration may empty out the RequestSet for |spdy_session_key_ in // |spdy_session_request_map_|. So each time, check for RequestSet and use diff --git a/net/http/http_stream_factory_impl.h b/net/http/http_stream_factory_impl.h index 8cb54bb..80e96ce 100644 --- a/net/http/http_stream_factory_impl.h +++ b/net/http/http_stream_factory_impl.h @@ -16,6 +16,7 @@ #include "net/http/http_stream_factory.h" #include "net/proxy/proxy_server.h" #include "net/socket/ssl_client_socket.h" +#include "net/spdy/spdy_session_key.h" namespace net { @@ -57,7 +58,7 @@ class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : typedef std::set<Request*> RequestSet; typedef std::vector<Request*> RequestVector; - typedef std::map<HostPortProxyPair, RequestSet> SpdySessionRequestMap; + typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; typedef std::map<HttpPipelinedHost::Key, RequestVector> HttpPipeliningRequestMap; diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc index d9e7f24..da7ea68 100644 --- a/net/http/http_stream_factory_impl_job.cc +++ b/net/http/http_stream_factory_impl_job.cc @@ -252,15 +252,19 @@ void HttpStreamFactoryImpl::Job::GetSSLInfo() { ssl_socket->GetSSLInfo(&ssl_info_); } -HostPortProxyPair HttpStreamFactoryImpl::Job::GetSpdySessionKey() const { +SpdySessionKey HttpStreamFactoryImpl::Job::GetSpdySessionKey() const { // In the case that we're using an HTTPS proxy for an HTTP url, // we look for a SPDY session *to* the proxy, instead of to the // origin server. + PrivacyMode privacy_mode = request_info_.privacy_mode; if (IsHttpsProxyAndHttpUrl()) { - return HostPortProxyPair(proxy_info_.proxy_server().host_port_pair(), - ProxyServer::Direct()); + return SpdySessionKey(proxy_info_.proxy_server().host_port_pair(), + ProxyServer::Direct(), + privacy_mode); } else { - return HostPortProxyPair(origin_, proxy_info_.proxy_server()); + return SpdySessionKey(origin_, + proxy_info_.proxy_server(), + privacy_mode); } } @@ -377,7 +381,7 @@ void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { // static int HttpStreamFactoryImpl::Job::OnHostResolution( SpdySessionPool* spdy_session_pool, - const HostPortProxyPair& spdy_session_key, + const SpdySessionKey& spdy_session_key, const AddressList& addresses, const BoundNetLog& net_log) { // It is OK to dereference spdy_session_pool, because the @@ -704,7 +708,7 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() { // Check first if we have a spdy session for this group. If so, then go // straight to using that. - HostPortProxyPair spdy_session_key = GetSpdySessionKey(); + SpdySessionKey spdy_session_key = GetSpdySessionKey(); scoped_refptr<SpdySession> spdy_session = session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); if (spdy_session && CanUseExistingSpdySession()) { @@ -779,6 +783,7 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() { want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, + request_info_.privacy_mode, net_log_, num_streams_); } else { @@ -791,7 +796,8 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() { return InitSocketHandleForHttpRequest( origin_url_, request_info_.extra_headers, request_info_.load_flags, priority_, session_, proxy_info_, ShouldForceSpdySSL(), - want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, + want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, + request_info_.privacy_mode, net_log_, connection_.get(), resolution_callback, io_callback_); } } @@ -805,7 +811,7 @@ int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { // We found a SPDY connection after resolving the host. This is // probably an IP pooled connection. - HostPortProxyPair spdy_session_key = GetSpdySessionKey(); + SpdySessionKey spdy_session_key = GetSpdySessionKey(); existing_spdy_session_ = session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); if (existing_spdy_session_) { @@ -997,12 +1003,15 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() { bool direct = true; const ProxyServer& proxy_server = proxy_info_.proxy_server(); - HostPortProxyPair pair(origin_, proxy_server); + PrivacyMode privacy_mode = request_info_.privacy_mode; + SpdySessionKey spdy_session_key(origin_, proxy_server, privacy_mode); if (IsHttpsProxyAndHttpUrl()) { // If we don't have a direct SPDY session, and we're using an HTTPS // proxy, then we might have a SPDY session to the proxy. - pair = HostPortProxyPair(proxy_server.host_port_pair(), - ProxyServer::Direct()); + // We never use privacy mode for connection to proxy server. + spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(), + ProxyServer::Direct(), + kPrivacyModeDisabled); direct = false; } @@ -1015,14 +1024,14 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() { spdy_session.swap(existing_spdy_session_); } else { SpdySessionPool* spdy_pool = session_->spdy_session_pool(); - spdy_session = spdy_pool->GetIfExists(pair, net_log_); + spdy_session = spdy_pool->GetIfExists(spdy_session_key, net_log_); if (!spdy_session) { int error = spdy_pool->GetSpdySessionFromSocket( - pair, connection_.release(), net_log_, spdy_certificate_error_, - &new_spdy_session_, using_ssl_); + spdy_session_key, connection_.release(), net_log_, + spdy_certificate_error_, &new_spdy_session_, using_ssl_); if (error != OK) return error; - const HostPortPair& host_port_pair = pair.first; + const HostPortPair& host_port_pair = spdy_session_key.host_port_pair(); HttpServerProperties* http_server_properties = session_->http_server_properties(); if (http_server_properties) @@ -1171,6 +1180,10 @@ void HttpStreamFactoryImpl::Job::InitSSLConfig( if (request_info_.load_flags & LOAD_VERIFY_EV_CERT) ssl_config->verify_ev_cert = true; + + // Disable Channel ID if privacy mode is enabled. + if (request_info_.privacy_mode == kPrivacyModeEnabled) + ssl_config->channel_id_enabled = false; } diff --git a/net/http/http_stream_factory_impl_job.h b/net/http/http_stream_factory_impl_job.h index 6e7d47b..a6a3603 100644 --- a/net/http/http_stream_factory_impl_job.h +++ b/net/http/http_stream_factory_impl_job.h @@ -20,6 +20,7 @@ #include "net/quic/quic_stream_factory.h" #include "net/socket/client_socket_handle.h" #include "net/socket/ssl_client_socket.h" +#include "net/spdy/spdy_session_key.h" #include "net/ssl/ssl_config_service.h" namespace net { @@ -177,7 +178,7 @@ class HttpStreamFactoryImpl::Job { // After calling, the caller can use ssl_info_. void GetSSLInfo(); - HostPortProxyPair GetSpdySessionKey() const; + SpdySessionKey GetSpdySessionKey() const; // Returns true if the current request can use an existing spdy session. bool CanUseExistingSpdySession() const; @@ -220,7 +221,7 @@ class HttpStreamFactoryImpl::Job { // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a // session is found, and OK otherwise. static int OnHostResolution(SpdySessionPool* spdy_session_pool, - const HostPortProxyPair& spdy_session_key, + const SpdySessionKey& spdy_session_key, const AddressList& addresses, const BoundNetLog& net_log); diff --git a/net/http/http_stream_factory_impl_request.cc b/net/http/http_stream_factory_impl_request.cc index 6195552..23aa5ff 100644 --- a/net/http/http_stream_factory_impl_request.cc +++ b/net/http/http_stream_factory_impl_request.cc @@ -49,9 +49,9 @@ HttpStreamFactoryImpl::Request::~Request() { } void HttpStreamFactoryImpl::Request::SetSpdySessionKey( - const HostPortProxyPair& spdy_session_key) { + const SpdySessionKey& spdy_session_key) { DCHECK(!spdy_session_key_.get()); - spdy_session_key_.reset(new HostPortProxyPair(spdy_session_key)); + spdy_session_key_.reset(new SpdySessionKey(spdy_session_key)); RequestSet& request_set = factory_->spdy_session_request_map_[spdy_session_key]; DCHECK(!ContainsKey(request_set, this)); diff --git a/net/http/http_stream_factory_impl_request.h b/net/http/http_stream_factory_impl_request.h index f0b5335..18633fa 100644 --- a/net/http/http_stream_factory_impl_request.h +++ b/net/http/http_stream_factory_impl_request.h @@ -11,6 +11,7 @@ #include "net/base/net_log.h" #include "net/http/http_stream_factory_impl.h" #include "net/socket/ssl_client_socket.h" +#include "net/spdy/spdy_session_key.h" namespace net { @@ -27,9 +28,9 @@ class HttpStreamFactoryImpl::Request : public HttpStreamRequest { // Called when the Job determines the appropriate |spdy_session_key| for the // Request. Note that this does not mean that SPDY is necessarily supported - // for this HostPortProxyPair, since we may need to wait for NPN to complete + // for this SpdySessionKey, since we may need to wait for NPN to complete // before knowing if SPDY is available. - void SetSpdySessionKey(const HostPortProxyPair& spdy_session_key); + void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); // Called when the Job determines the appropriate |http_pipelining_key| for // the Request. Registers this Request with the factory, so that if an @@ -113,7 +114,7 @@ class HttpStreamFactoryImpl::Request : public HttpStreamRequest { // At the point where Job is irrevocably tied to the Request, we set this. scoped_ptr<Job> bound_job_; std::set<HttpStreamFactoryImpl::Job*> jobs_; - scoped_ptr<const HostPortProxyPair> spdy_session_key_; + scoped_ptr<const SpdySessionKey> spdy_session_key_; scoped_ptr<const HttpPipelinedHost::Key> http_pipelining_key_; bool completed_; diff --git a/net/http/http_stream_factory_impl_unittest.cc b/net/http/http_stream_factory_impl_unittest.cc index f228d9a..5c39f2f 100644 --- a/net/http/http_stream_factory_impl_unittest.cc +++ b/net/http/http_stream_factory_impl_unittest.cc @@ -14,6 +14,7 @@ #include "net/http/http_auth_handler_factory.h" #include "net/http/http_network_session.h" #include "net/http/http_network_session_peer.h" +#include "net/http/http_network_transaction.h" #include "net/http/http_request_info.h" #include "net/http/http_server_properties_impl.h" #include "net/http/http_stream.h" @@ -74,6 +75,7 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate { if (waiting_for_stream_) MessageLoop::current()->Quit(); stream_.reset(stream); + used_ssl_config_ = used_ssl_config; } virtual void OnStreamFailed( @@ -106,10 +108,20 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate { } } + const SSLConfig& used_ssl_config() const { + return used_ssl_config_; + } + + HttpStreamBase* stream() { + return stream_.get(); + } + + private: bool waiting_for_stream_; bool stream_done_; scoped_ptr<HttpStreamBase> stream_; + SSLConfig used_ssl_config_; DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); }; @@ -380,9 +392,10 @@ TEST(HttpStreamFactoryTest, PreconnectDirectWithExistingSpdySession) { // Set an existing SpdySession in the pool. HostPortPair host_port_pair("www.google.com", 443); - HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeDisabled); scoped_refptr<SpdySession> spdy_session = - session->spdy_session_pool()->Get(pair, BoundNetLog()); + session->spdy_session_pool()->Get(key, BoundNetLog()); CapturePreconnectsTransportSocketPool* transport_conn_pool = new CapturePreconnectsTransportSocketPool( @@ -470,6 +483,109 @@ TEST(HttpStreamFactoryTest, JobNotifiesProxy) { EXPECT_TRUE(iter != retry_info.end()); } +TEST(HttpStreamFactoryTest, PrivacyModeDisablesChannelId) { + SessionDependencies session_deps(ProxyService::CreateDirect()); + + StaticSocketDataProvider socket_data; + socket_data.set_connect_data(MockConnect(ASYNC, OK)); + session_deps.socket_factory.AddSocketDataProvider(&socket_data); + + SSLSocketDataProvider ssl(ASYNC, OK); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); + + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); + + // Set an existing SpdySession in the pool. + HostPortPair host_port_pair("www.google.com", 443); + SpdySessionKey key(host_port_pair, ProxyServer::Direct(), + kPrivacyModeEnabled); + + HttpRequestInfo request_info; + request_info.method = "GET"; + request_info.url = GURL("https://www.google.com"); + request_info.load_flags = 0; + request_info.privacy_mode = kPrivacyModeDisabled; + + SSLConfig ssl_config; + StreamRequestWaiter waiter; + scoped_ptr<HttpStreamRequest> request( + session->http_stream_factory()->RequestStream( + request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, + &waiter, BoundNetLog())); + waiter.WaitForStream(); + + // The stream shouldn't come from spdy as we are using different privacy mode + EXPECT_FALSE(request->using_spdy()); + + SSLConfig used_ssl_config = waiter.used_ssl_config(); + EXPECT_EQ(used_ssl_config.channel_id_enabled, ssl_config.channel_id_enabled); +} + +namespace { +// Return count of distinct groups in given socket pool. +int GetSocketPoolGroupCount(ClientSocketPool* pool) { + int count = 0; + scoped_ptr<base::DictionaryValue> dict(pool->GetInfoAsValue("", "", false)); + EXPECT_TRUE(dict != NULL); + base::DictionaryValue* groups = NULL; + if (dict->GetDictionary("groups", &groups) && (groups != NULL)) { + count = static_cast<int>(groups->size()); + } + return count; +} +}; + +TEST(HttpStreamFactoryTest, PrivacyModeUsesDifferentSocketPoolGroup) { + SessionDependencies session_deps(ProxyService::CreateDirect()); + + StaticSocketDataProvider socket_data; + socket_data.set_connect_data(MockConnect(ASYNC, OK)); + session_deps.socket_factory.AddSocketDataProvider(&socket_data); + + SSLSocketDataProvider ssl(ASYNC, OK); + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); + + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); + SSLClientSocketPool* ssl_pool = session->GetSSLSocketPool( + HttpNetworkSession::NORMAL_SOCKET_POOL); + + EXPECT_EQ(GetSocketPoolGroupCount(ssl_pool), 0); + + HttpRequestInfo request_info; + request_info.method = "GET"; + request_info.url = GURL("https://www.google.com"); + request_info.load_flags = 0; + request_info.privacy_mode = kPrivacyModeDisabled; + + SSLConfig ssl_config; + StreamRequestWaiter waiter; + + scoped_ptr<HttpStreamRequest> request1( + session->http_stream_factory()->RequestStream( + request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, + &waiter, BoundNetLog())); + waiter.WaitForStream(); + + EXPECT_EQ(GetSocketPoolGroupCount(ssl_pool), 1); + + scoped_ptr<HttpStreamRequest> request2( + session->http_stream_factory()->RequestStream( + request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, + &waiter, BoundNetLog())); + waiter.WaitForStream(); + + EXPECT_EQ(GetSocketPoolGroupCount(ssl_pool), 1); + + request_info.privacy_mode = kPrivacyModeEnabled; + scoped_ptr<HttpStreamRequest> request3( + session->http_stream_factory()->RequestStream( + request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, + &waiter, BoundNetLog())); + waiter.WaitForStream(); + + EXPECT_EQ(GetSocketPoolGroupCount(ssl_pool), 2); +} + } // namespace } // namespace net diff --git a/net/net.gyp b/net/net.gyp index 6bdb387..0aa47a9 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -917,6 +917,8 @@ 'spdy/spdy_read_queue.h', 'spdy/spdy_session.cc', 'spdy/spdy_session.h', + 'spdy/spdy_session_key.cc', + 'spdy/spdy_session_key.h', 'spdy/spdy_session_pool.cc', 'spdy/spdy_session_pool.h', 'spdy/spdy_stream.cc', diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc index 71b9d6d..cd4f10f 100644 --- a/net/socket/client_socket_pool_manager.cc +++ b/net/socket/client_socket_pool_manager.cc @@ -77,6 +77,7 @@ int InitSocketPoolHelper(const GURL& request_url, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, bool force_tunnel, + PrivacyMode privacy_mode, const BoundNetLog& net_log, int num_preconnect_streams, ClientSocketHandle* socket_handle, @@ -227,6 +228,10 @@ int InitSocketPoolHelper(const GURL& request_url, load_flags, force_spdy_over_ssl, want_spdy_over_npn); + // Change group name if privacy mode is enabled. + if (privacy_mode == kPrivacyModeEnabled) + connection_group = "pm/" + connection_group; + SSLClientSocketPool* ssl_pool = NULL; if (proxy_info.is_direct()) { ssl_pool = session->GetSSLSocketPool( @@ -375,6 +380,7 @@ int InitSocketHandleForHttpRequest( bool want_spdy_over_npn, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, + PrivacyMode privacy_mode, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, const OnHostResolutionCallback& resolution_callback, @@ -383,8 +389,8 @@ int InitSocketHandleForHttpRequest( return InitSocketPoolHelper( request_url, request_extra_headers, request_load_flags, request_priority, session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, - ssl_config_for_origin, ssl_config_for_proxy, false, net_log, 0, - socket_handle, resolution_callback, callback); + ssl_config_for_origin, ssl_config_for_proxy, false, privacy_mode, net_log, + 0, socket_handle, resolution_callback, callback); } int InitSocketHandleForRawConnect( @@ -393,6 +399,7 @@ int InitSocketHandleForRawConnect( const ProxyInfo& proxy_info, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, + PrivacyMode privacy_mode, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, const CompletionCallback& callback) { @@ -406,7 +413,7 @@ int InitSocketHandleForRawConnect( return InitSocketPoolHelper( request_url, request_extra_headers, request_load_flags, request_priority, session, proxy_info, false, false, ssl_config_for_origin, - ssl_config_for_proxy, true, net_log, 0, socket_handle, + ssl_config_for_proxy, true, privacy_mode, net_log, 0, socket_handle, OnHostResolutionCallback(), callback); } @@ -421,12 +428,13 @@ int PreconnectSocketsForHttpRequest( bool want_spdy_over_npn, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, + PrivacyMode privacy_mode, const BoundNetLog& net_log, int num_preconnect_streams) { return InitSocketPoolHelper( request_url, request_extra_headers, request_load_flags, request_priority, session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, - ssl_config_for_origin, ssl_config_for_proxy, false, net_log, + ssl_config_for_origin, ssl_config_for_proxy, false, privacy_mode, net_log, num_preconnect_streams, NULL, OnHostResolutionCallback(), CompletionCallback()); } diff --git a/net/socket/client_socket_pool_manager.h b/net/socket/client_socket_pool_manager.h index a92d218..434a463 100644 --- a/net/socket/client_socket_pool_manager.h +++ b/net/socket/client_socket_pool_manager.h @@ -100,6 +100,7 @@ int InitSocketHandleForHttpRequest( bool want_spdy_over_npn, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, + PrivacyMode privacy_mode, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, const OnHostResolutionCallback& resolution_callback, @@ -115,6 +116,7 @@ NET_EXPORT int InitSocketHandleForRawConnect( const ProxyInfo& proxy_info, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, + PrivacyMode privacy_mode, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, const CompletionCallback& callback); @@ -132,6 +134,7 @@ int PreconnectSocketsForHttpRequest( bool want_spdy_over_npn, const SSLConfig& ssl_config_for_origin, const SSLConfig& ssl_config_for_proxy, + PrivacyMode privacy_mode, const BoundNetLog& net_log, int num_preconnect_streams); diff --git a/net/socket/ssl_client_socket_pool_unittest.cc b/net/socket/ssl_client_socket_pool_unittest.cc index fe7e3d2..fbfa338 100644 --- a/net/socket/ssl_client_socket_pool_unittest.cc +++ b/net/socket/ssl_client_socket_pool_unittest.cc @@ -720,7 +720,7 @@ TEST_F(SSLClientSocketPoolTest, IPPooling) { struct TestHosts { std::string name; std::string iplist; - HostPortProxyPair pair; + SpdySessionKey key; AddressList addresses; } test_hosts[] = { { "www.webkit.org", "192.0.2.33,192.168.0.1,192.168.0.5" }, @@ -739,9 +739,10 @@ TEST_F(SSLClientSocketPoolTest, IPPooling) { host_resolver_.Resolve(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); } MockRead reads[] = { @@ -782,17 +783,17 @@ TEST_F(SSLClientSocketPoolTest, IPPooling) { // TODO(rtenneti): MockClientSocket::GetPeerAddress returns 0 as the port // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. SpdySessionPoolPeer pool_peer(session_->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); scoped_refptr<SpdySession> spdy_session; rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( - test_hosts[0].pair, handle.release(), BoundNetLog(), 0, + test_hosts[0].key, handle.release(), BoundNetLog(), 0, &spdy_session, true); EXPECT_EQ(0, rv); - EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); - EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); - EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); + EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].key)); + EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].key)); + EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].key)); session_->spdy_session_pool()->CloseAllSessions(); } @@ -803,7 +804,7 @@ void SSLClientSocketPoolTest::TestIPPoolingDisabled( struct TestHosts { std::string name; std::string iplist; - HostPortProxyPair pair; + SpdySessionKey key; AddressList addresses; } test_hosts[] = { { "www.webkit.org", "192.0.2.33,192.168.0.1,192.168.0.5" }, @@ -823,9 +824,10 @@ void SSLClientSocketPoolTest::TestIPPoolingDisabled( callback.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, callback.GetResult(rv)); - // 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); } MockRead reads[] = { @@ -861,16 +863,16 @@ void SSLClientSocketPoolTest::TestIPPoolingDisabled( // TODO(rtenneti): MockClientSocket::GetPeerAddress returns 0 as the port // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. SpdySessionPoolPeer pool_peer(session_->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); scoped_refptr<SpdySession> spdy_session; rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( - test_hosts[0].pair, handle.release(), BoundNetLog(), 0, + test_hosts[0].key, handle.release(), BoundNetLog(), 0, &spdy_session, true); EXPECT_EQ(0, rv); - EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); - EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); + EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].key)); + EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].key)); session_->spdy_session_pool()->CloseAllSessions(); } diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 8e5fa70..98c4166 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -99,6 +99,7 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) proxy_mode_(kDirectConnection), proxy_url_(url), pac_request_(NULL), + privacy_mode_(kPrivacyModeDisabled), // Unretained() is required; without it, Bind() creates a circular // dependency and the SocketStream object will not be freed. io_callback_(base::Bind(&SocketStream::OnIOCompleted, @@ -162,6 +163,17 @@ void SocketStream::set_context(const URLRequestContext* context) { } } +void SocketStream::CheckPrivacyMode() { + if (context_ && context_->network_delegate()) { + bool enable = context_->network_delegate()->CanEnablePrivacyMode(url_, + url_); + privacy_mode_ = enable ? kPrivacyModeEnabled : kPrivacyModeDisabled; + // Disable Channel ID if privacy mode is enabled. + if (enable) + server_ssl_config_.channel_id_enabled = false; + } +} + void SocketStream::Connect() { DCHECK(MessageLoop::current()) << "The current MessageLoop must exist"; @@ -171,6 +183,8 @@ void SocketStream::Connect() { ssl_config_service()->GetSSLConfig(&server_ssl_config_); proxy_ssl_config_ = server_ssl_config_; } + CheckPrivacyMode(); + DCHECK_EQ(next_state_, STATE_NONE); AddRef(); // Released in Finish() diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 50386c3e..e4c505b 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -18,6 +18,7 @@ #include "net/base/net_errors.h" #include "net/base/net_export.h" #include "net/base/net_log.h" +#include "net/base/privacy_mode.h" #include "net/proxy/proxy_service.h" #include "net/ssl/ssl_config_service.h" #include "net/url_request/url_request.h" @@ -130,6 +131,10 @@ class NET_EXPORT SocketStream const URLRequestContext* context() const { return context_; } void set_context(const URLRequestContext* context); + const SSLConfig& server_ssl_config() const { return server_ssl_config_; } + PrivacyMode privacy_mode() const { return privacy_mode_; } + void CheckPrivacyMode(); + BoundNetLog* net_log() { return &net_log_; } // Opens the connection on the IO thread. @@ -366,6 +371,7 @@ class NET_EXPORT SocketStream SSLConfig server_ssl_config_; SSLConfig proxy_ssl_config_; + PrivacyMode privacy_mode_; CompletionCallback io_callback_; 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()); } diff --git a/net/ssl/ssl_config_service.h b/net/ssl/ssl_config_service.h index f8ee03b..c3a892b 100644 --- a/net/ssl/ssl_config_service.h +++ b/net/ssl/ssl_config_service.h @@ -88,7 +88,7 @@ struct NET_EXPORT SSLConfig { std::vector<uint16> disabled_cipher_suites; bool cached_info_enabled; // True if TLS cached info extension is enabled. - bool channel_id_enabled; // True if TLS channel ID extension is enabled. + bool channel_id_enabled; // True if TLS channel ID extension is enabled. bool false_start_enabled; // True if we'll use TLS False Start. // If |unrestricted_ssl3_fallback_enabled| is true, SSL 3.0 fallback will be diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index c6daf04..3487c71 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -1010,6 +1010,14 @@ bool URLRequest::CanSetCookie(const std::string& cookie_line, return g_default_can_use_cookies; } +bool URLRequest::CanEnablePrivacyMode() const { + if (network_delegate_) { + return network_delegate_->CanEnablePrivacyMode(url(), + first_party_for_cookies_); + } + return !g_default_can_use_cookies; +} + void URLRequest::NotifyReadCompleted(int bytes_read) { // Notify in case the entire URL Request has been finished. diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 111f8d3..0e33af5 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -731,6 +731,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), bool CanGetCookies(const CookieList& cookie_list) const; bool CanSetCookie(const std::string& cookie_line, CookieOptions* options) const; + bool CanEnablePrivacyMode() const; // Called when the delegate blocks or unblocks this request when intercepting // certain requests. diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index d367dc6..7b38fa1 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -315,6 +315,16 @@ void URLRequestHttpJob::Start() { request_info_.method = request_->method(); request_info_.load_flags = request_->load_flags(); request_info_.request_id = request_->identifier(); + // Enable privacy mode if cookie settings or flags tell us not send or + // save cookies. + bool enable_privacy_mode = + (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) || + (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) || + CanEnablePrivacyMode(); + // Privacy mode could still be disabled in OnCookiesLoaded if we are going + // to send previously saved cookies. + request_info_.privacy_mode = enable_privacy_mode ? + kPrivacyModeEnabled : kPrivacyModeDisabled; // Strip Referer from request_info_.extra_headers to prevent, e.g., plugins // from overriding headers that are controlled using other means. Otherwise a @@ -624,6 +634,8 @@ void URLRequestHttpJob::OnCookiesLoaded(const std::string& cookie_line) { if (!cookie_line.empty()) { request_info_.extra_headers.SetHeader( HttpRequestHeaders::kCookie, cookie_line); + // Disable privacy mode as we are sending cookies anyway. + request_info_.privacy_mode = kPrivacyModeDisabled; } DoStartTransaction(); } diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index edb1515..18133af 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -266,6 +266,13 @@ bool URLRequestJob::CanSetCookie(const std::string& cookie_line, return request_->CanSetCookie(cookie_line, options); } +bool URLRequestJob::CanEnablePrivacyMode() const { + if (!request_) + return false; // The request was destroyed, so there is no more work to do. + + return request_->CanEnablePrivacyMode(); +} + void URLRequestJob::NotifyHeadersComplete() { if (!request_ || !request_->has_delegate()) return; // The request was destroyed, so there is no more work to do. diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index a9cec85..1995508 100644 --- a/net/url_request/url_request_job.h +++ b/net/url_request/url_request_job.h @@ -227,6 +227,9 @@ class NET_EXPORT URLRequestJob bool CanSetCookie(const std::string& cookie_line, CookieOptions* options) const; + // Delegates to URLRequest::Delegate. + bool CanEnablePrivacyMode() const; + // Notifies the job that headers have been received. void NotifyHeadersComplete(); diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index 76fc04f..225793e 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -390,6 +390,10 @@ void WebSocketJob::AddCookieHeaderAndSend() { void WebSocketJob::LoadCookieCallback(const std::string& cookie) { if (!cookie.empty()) + // TODO(tyoshino): Sending cookie means that connection doesn't need + // kPrivacyModeEnabled as cookies may be server-bound and channel id + // wouldn't negatively affect privacy anyway. Need to restart connection + // or refactor to determine cookie status prior to connecting. handshake_request_->AppendHeaderIfMissing("Cookie", cookie); DoSendData(); } @@ -589,15 +593,16 @@ int WebSocketJob::TrySpdyStream() { if (!session.get()) return OK; SpdySessionPool* spdy_pool = session->spdy_session_pool(); - const HostPortProxyPair pair(HostPortPair::FromURL(socket_->url()), - socket_->proxy_server()); - if (!spdy_pool->HasSession(pair)) + PrivacyMode privacy_mode = socket_->privacy_mode(); + const SpdySessionKey key(HostPortPair::FromURL(socket_->url()), + socket_->proxy_server(), privacy_mode); + if (!spdy_pool->HasSession(key)) return OK; // Forbid wss downgrade to SPDY without SSL. // TODO(toyoshim): Does it realize the same policy with HTTP? scoped_refptr<SpdySession> spdy_session = - spdy_pool->Get(pair, *socket_->net_log()); + spdy_pool->Get(key, *socket_->net_log()); SSLInfo ssl_info; bool was_npn_negotiated; NextProto protocol_negotiated = kProtoUnknown; diff --git a/net/websockets/websocket_job_spdy2_unittest.cc b/net/websockets/websocket_job_spdy2_unittest.cc index 7825c77..bde8c51 100644 --- a/net/websockets/websocket_job_spdy2_unittest.cc +++ b/net/websockets/websocket_job_spdy2_unittest.cc @@ -272,15 +272,16 @@ class MockHttpTransactionFactory : public HttpTransactionFactory { SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); 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); SpdySessionPool* spdy_session_pool = http_session_->spdy_session_pool(); DCHECK(spdy_session_pool); - EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); + EXPECT_FALSE(spdy_session_pool->HasSession(spdy_session_key_)); session_ = - spdy_session_pool->Get(host_port_proxy_pair_, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); + spdy_session_pool->Get(spdy_session_key_, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool->HasSession(spdy_session_key_)); transport_params_ = new TransportSocketParams(host_port_pair_, @@ -323,7 +324,7 @@ class MockHttpTransactionFactory : public HttpTransactionFactory { scoped_refptr<TransportSocketParams> transport_params_; scoped_refptr<SpdySession> session_; HostPortPair host_port_pair_; - HostPortProxyPair host_port_proxy_pair_; + SpdySessionKey spdy_session_key_; }; } // namespace diff --git a/net/websockets/websocket_job_spdy3_unittest.cc b/net/websockets/websocket_job_spdy3_unittest.cc index 41fb38b..24b69ef 100644 --- a/net/websockets/websocket_job_spdy3_unittest.cc +++ b/net/websockets/websocket_job_spdy3_unittest.cc @@ -276,15 +276,16 @@ class MockHttpTransactionFactory : public HttpTransactionFactory { SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); 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); SpdySessionPool* spdy_session_pool = http_session_->spdy_session_pool(); DCHECK(spdy_session_pool); - EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); + EXPECT_FALSE(spdy_session_pool->HasSession(spdy_session_key_)); session_ = - spdy_session_pool->Get(host_port_proxy_pair_, BoundNetLog()); - EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); + spdy_session_pool->Get(spdy_session_key_, BoundNetLog()); + EXPECT_TRUE(spdy_session_pool->HasSession(spdy_session_key_)); transport_params_ = new TransportSocketParams(host_port_pair_, @@ -323,7 +324,7 @@ class MockHttpTransactionFactory : public HttpTransactionFactory { scoped_refptr<TransportSocketParams> transport_params_; scoped_refptr<SpdySession> session_; HostPortPair host_port_pair_; - HostPortProxyPair host_port_proxy_pair_; + SpdySessionKey spdy_session_key_; }; } // namespace |