summaryrefslogtreecommitdiffstats
path: root/net/spdy
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 06:35:54 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 06:35:54 +0000
commit6cbfa853c0ae1eded9d08972edd98ed72b25442f (patch)
tree993b90b5b91db5a3a3b8f2babb4c5a0416c9e6bc /net/spdy
parent004432da901260a8b2a4993b6de8bab4f9b825b4 (diff)
downloadchromium_src-6cbfa853c0ae1eded9d08972edd98ed72b25442f.zip
chromium_src-6cbfa853c0ae1eded9d08972edd98ed72b25442f.tar.gz
chromium_src-6cbfa853c0ae1eded9d08972edd98ed72b25442f.tar.bz2
Change SpdySessionPool to explicitly associate IP pooled sessions with the matching hostnames.
BUG=106225 TEST=SpdySessionSpdy\*Test.IPPooling\* Review URL: http://codereview.chromium.org/9621011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r--net/spdy/spdy_session.cc4
-rw-r--r--net/spdy/spdy_session.h12
-rw-r--r--net/spdy/spdy_session_pool.cc30
-rw-r--r--net/spdy/spdy_session_pool.h5
-rw-r--r--net/spdy/spdy_session_spdy2_unittest.cc17
-rw-r--r--net/spdy/spdy_session_spdy3_unittest.cc17
-rw-r--r--net/spdy/spdy_test_util_spdy2.h4
-rw-r--r--net/spdy/spdy_test_util_spdy3.h4
8 files changed, 87 insertions, 6 deletions
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 0c1a314..87c7011 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -589,6 +589,10 @@ bool SpdySession::NeedsCredentials(const HostPortPair& origin) const {
return !credential_state_.HasCredential(origin);
}
+void SpdySession::AddPooledAlias(const HostPortProxyPair& alias) {
+ pooled_aliases_.insert(alias);
+}
+
int SpdySession::WriteSynStream(
spdy::SpdyStreamId stream_id,
RequestPriority priority,
diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h
index 5010fb8..408245b 100644
--- a/net/spdy/spdy_session.h
+++ b/net/spdy/spdy_session.h
@@ -272,6 +272,14 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
// SPDY CREDENTIAL frame to be sent first, with an origin bound certificate.
bool NeedsCredentials(const HostPortPair& origin) const;
+ // Adds |alias| to set of aliases associated with this session.
+ void AddPooledAlias(const HostPortProxyPair& alias);
+
+ // Returns the set of aliases associated with this session.
+ const std::set<HostPortProxyPair>& pooled_aliases() const {
+ return pooled_aliases_;
+ }
+
private:
friend class base::RefCounted<SpdySession>;
@@ -501,6 +509,10 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
// The domain this session is connected to.
const HostPortProxyPair host_port_proxy_pair_;
+ // Set set of HostPortProxyPairs for which this session has serviced
+ // requests.
+ std::set<HostPortProxyPair> 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.
SpdySessionPool* spdy_session_pool_;
diff --git a/net/spdy/spdy_session_pool.cc b/net/spdy/spdy_session_pool.cc
index abd5443..4b86f4b9 100644
--- a/net/spdy/spdy_session_pool.cc
+++ b/net/spdy/spdy_session_pool.cc
@@ -91,6 +91,10 @@ scoped_refptr<SpdySession> SpdySessionPool::GetInternal(
NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL,
make_scoped_refptr(new NetLogSourceParameter(
"session", spdy_session->net_log().source())));
+ // Add this session to the map so that we can find it next time.
+ list = AddSessionList(host_port_proxy_pair);
+ list->push_back(spdy_session);
+ spdy_session->AddPooledAlias(host_port_proxy_pair);
return spdy_session;
} else if (only_use_existing_sessions) {
return NULL;
@@ -183,17 +187,31 @@ bool SpdySessionPool::HasSession(
}
void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) {
- SpdySessionList* list = GetSessionList(session->host_port_proxy_pair());
- DCHECK(list); // We really shouldn't remove if we've already been removed.
- if (!list)
- return;
- list->remove(session);
+ bool ok = RemoveFromSessionList(session, session->host_port_proxy_pair());
+ DCHECK(ok);
session->net_log().AddEvent(
NetLog::TYPE_SPDY_SESSION_POOL_REMOVE_SESSION,
make_scoped_refptr(new NetLogSourceParameter(
"session", session->net_log().source())));
+
+ const std::set<HostPortProxyPair>& aliases = session->pooled_aliases();
+ for (std::set<HostPortProxyPair>::const_iterator it = aliases.begin();
+ it != aliases.end(); ++it) {
+ ok = RemoveFromSessionList(session, *it);
+ DCHECK(ok);
+ }
+}
+
+bool SpdySessionPool::RemoveFromSessionList(
+ const scoped_refptr<SpdySession>& session,
+ const HostPortProxyPair& pair) {
+ SpdySessionList* list = GetSessionList(pair);
+ if (!list)
+ return false;
+ list->remove(session);
if (list->empty())
- RemoveSessionList(session->host_port_proxy_pair());
+ RemoveSessionList(pair);
+ return true;
}
Value* SpdySessionPool::SpdySessionPoolInfoToValue() const {
diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h
index 33e2db1..39f9fe2 100644
--- a/net/spdy/spdy_session_pool.h
+++ b/net/spdy/spdy_session_pool.h
@@ -193,6 +193,11 @@ class NET_EXPORT SpdySessionPool
// Remove all aliases for |pair| from the aliases table.
void RemoveAliases(const HostPortProxyPair& pair);
+ // Removes |session| from the session list associated with |pair|.
+ // Returns true if the session was removed, false otherwise.
+ bool RemoveFromSessionList(const scoped_refptr<SpdySession>& session,
+ const HostPortProxyPair& pair);
+
SpdySettingsStorage spdy_settings_;
HttpServerProperties* const http_server_properties_;
diff --git a/net/spdy/spdy_session_spdy2_unittest.cc b/net/spdy/spdy_session_spdy2_unittest.cc
index a5f8af7..5d85f8f 100644
--- a/net/spdy/spdy_session_spdy2_unittest.cc
+++ b/net/spdy/spdy_session_spdy2_unittest.cc
@@ -4,6 +4,7 @@
#include "net/spdy/spdy_session.h"
+#include "net/base/host_cache.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_log_unittest.h"
#include "net/spdy/spdy_io_buffer.h"
@@ -841,6 +842,22 @@ void IPPoolingTest(bool clean_via_close_current_sessions) {
EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair));
EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].pair));
+ // 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());
+ EXPECT_EQ(session.get(), session1.get());
+ EXPECT_NE(session2.get(), session1.get());
+
+ // 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));
+
+ // Expire the host cache
+ session_deps.host_resolver->GetHostCache()->clear();
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair));
+
// Cleanup the sessions.
if (!clean_via_close_current_sessions) {
spdy_session_pool->Remove(session);
diff --git a/net/spdy/spdy_session_spdy3_unittest.cc b/net/spdy/spdy_session_spdy3_unittest.cc
index d850c6a..2c8f5ac 100644
--- a/net/spdy/spdy_session_spdy3_unittest.cc
+++ b/net/spdy/spdy_session_spdy3_unittest.cc
@@ -4,6 +4,7 @@
#include "net/spdy/spdy_session.h"
+#include "net/base/host_cache.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_log_unittest.h"
#include "net/spdy/spdy_io_buffer.h"
@@ -841,6 +842,22 @@ void IPPoolingTest(bool clean_via_close_current_sessions) {
EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair));
EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].pair));
+ // 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());
+ EXPECT_EQ(session.get(), session1.get());
+ EXPECT_NE(session2.get(), session1.get());
+
+ // 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));
+
+ // Expire the host cache
+ session_deps.host_resolver->GetHostCache()->clear();
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair));
+
// Cleanup the sessions.
if (!clean_via_close_current_sessions) {
spdy_session_pool->Remove(session);
diff --git a/net/spdy/spdy_test_util_spdy2.h b/net/spdy/spdy_test_util_spdy2.h
index f6b329f..a18a37b 100644
--- a/net/spdy/spdy_test_util_spdy2.h
+++ b/net/spdy/spdy_test_util_spdy2.h
@@ -396,6 +396,10 @@ class SpdySessionPoolPeer {
pool_->AddAlias(address, pair);
}
+ void RemoveAliases(const HostPortProxyPair& pair) {
+ pool_->RemoveAliases(pair);
+ }
+
void RemoveSpdySession(const scoped_refptr<SpdySession>& session) {
pool_->Remove(session);
}
diff --git a/net/spdy/spdy_test_util_spdy3.h b/net/spdy/spdy_test_util_spdy3.h
index f0abdfa..7f0d184 100644
--- a/net/spdy/spdy_test_util_spdy3.h
+++ b/net/spdy/spdy_test_util_spdy3.h
@@ -396,6 +396,10 @@ class SpdySessionPoolPeer {
pool_->AddAlias(address, pair);
}
+ void RemoveAliases(const HostPortProxyPair& pair) {
+ pool_->RemoveAliases(pair);
+ }
+
void RemoveSpdySession(const scoped_refptr<SpdySession>& session) {
pool_->Remove(session);
}