summaryrefslogtreecommitdiffstats
path: root/net/spdy
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 00:15:21 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 00:15:21 +0000
commit367ead44729ca97c8ed94365b0fe5e24de54fd4f (patch)
treeaa89fb816ddc75519802c65357d41c0a49537747 /net/spdy
parentd77ca3edc4b240592b94d3287047386b3ab5470c (diff)
downloadchromium_src-367ead44729ca97c8ed94365b0fe5e24de54fd4f.zip
chromium_src-367ead44729ca97c8ed94365b0fe5e24de54fd4f.tar.gz
chromium_src-367ead44729ca97c8ed94365b0fe5e24de54fd4f.tar.bz2
Fix SpdySessionPool to take a host port pair instead of just the host.
BUG=28595 Review URL: http://codereview.chromium.org/660107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r--net/spdy/spdy_network_transaction.cc3
-rw-r--r--net/spdy/spdy_session.cc11
-rw-r--r--net/spdy/spdy_session.h7
-rw-r--r--net/spdy/spdy_session_pool.cc49
-rw-r--r--net/spdy/spdy_session_pool.h36
-rw-r--r--net/spdy/spdy_stream_unittest.cc4
6 files changed, 62 insertions, 48 deletions
diff --git a/net/spdy/spdy_network_transaction.cc b/net/spdy/spdy_network_transaction.cc
index 76b3097..9ae31c2b8 100644
--- a/net/spdy/spdy_network_transaction.cc
+++ b/net/spdy/spdy_network_transaction.cc
@@ -232,8 +232,9 @@ int SpdyNetworkTransaction::DoInitConnection() {
connection_group.append(host);
HostResolver::RequestInfo resolve_info(host, port);
+ HostPortPair host_port_pair(host, port);
- spdy_ = session_->spdy_session_pool()->Get(resolve_info, session_);
+ spdy_ = session_->spdy_session_pool()->Get(host_port_pair, session_);
DCHECK(spdy_);
return spdy_->Connect(
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index e8b3238..172b5d7 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -182,7 +182,8 @@ void AdjustSocketBufferSizes(ClientSocket* socket) {
// static
bool SpdySession::use_ssl_ = true;
-SpdySession::SpdySession(const std::string& host, HttpNetworkSession* session)
+SpdySession::SpdySession(const HostPortPair& host_port_pair,
+ HttpNetworkSession* session)
: ALLOW_THIS_IN_INITIALIZER_LIST(
connect_callback_(this, &SpdySession::OnTCPConnect)),
ALLOW_THIS_IN_INITIALIZER_LIST(
@@ -191,7 +192,7 @@ SpdySession::SpdySession(const std::string& host, HttpNetworkSession* session)
read_callback_(this, &SpdySession::OnReadComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(
write_callback_(this, &SpdySession::OnWriteComplete)),
- domain_(host),
+ host_port_pair_(host_port_pair),
session_(session),
connection_(new ClientSocketHandle),
read_buffer_(new IOBuffer(kReadBufferSize)),
@@ -222,9 +223,7 @@ SpdySession::~SpdySession() {
connection_->socket()->Disconnect();
}
- // TODO(willchan): Don't hardcode port 80 here.
- DCHECK(!session_->spdy_session_pool()->HasSession(
- HostResolver::RequestInfo(domain_, 80)));
+ DCHECK(!session_->spdy_session_pool()->HasSession(host_port_pair()));
// Record per-session histograms here.
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamsPerSession",
@@ -273,7 +272,7 @@ net::Error SpdySession::Connect(const std::string& group_name,
spdy_sessions.Increment();
int rv = connection_->Init(group_name, host, priority, &connect_callback_,
- session_->tcp_socket_pool(), load_log);
+ session_->tcp_socket_pool(), load_log);
DCHECK(rv <= 0);
// If the connect is pending, we still return ok. The APIs enqueue
diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h
index e173a6a..01ac1a7 100644
--- a/net/spdy/spdy_session.h
+++ b/net/spdy/spdy_session.h
@@ -38,8 +38,7 @@ class SSLInfo;
class SpdySession : public base::RefCounted<SpdySession>,
public spdy::SpdyFramerVisitorInterface {
public:
- // Get the domain for this SpdySession.
- const std::string& domain() const { return domain_; }
+ const HostPortPair& host_port_pair() const { return host_port_pair_; }
// Connect the Spdy Socket.
// Returns net::Error::OK on success.
@@ -93,7 +92,7 @@ class SpdySession : public base::RefCounted<SpdySession>,
// Create a new SpdySession.
// |host| is the hostname that this session connects to.
- SpdySession(const std::string& host, HttpNetworkSession* session);
+ SpdySession(const HostPortPair& host_port_pair, HttpNetworkSession* session);
// Closes all open streams. Used as part of shutdown.
void CloseAllStreams(net::Error code);
@@ -165,7 +164,7 @@ class SpdySession : public base::RefCounted<SpdySession>,
CompletionCallbackImpl<SpdySession> write_callback_;
// The domain this session is connected to.
- std::string domain_;
+ const HostPortPair host_port_pair_;
SSLConfig ssl_config_;
diff --git a/net/spdy/spdy_session_pool.cc b/net/spdy/spdy_session_pool.cc
index 5e60350..0f012fb 100644
--- a/net/spdy/spdy_session_pool.cc
+++ b/net/spdy/spdy_session_pool.cc
@@ -18,22 +18,21 @@ SpdySessionPool::~SpdySessionPool() {
}
scoped_refptr<SpdySession> SpdySessionPool::Get(
- const HostResolver::RequestInfo& info, HttpNetworkSession* session) {
- const std::string& domain = info.hostname();
+ const HostPortPair& host_port_pair, HttpNetworkSession* session) {
scoped_refptr<SpdySession> spdy_session;
- SpdySessionList* list = GetSessionList(domain);
+ SpdySessionList* list = GetSessionList(host_port_pair);
if (list) {
if (list->size() >= kMaxSessionsPerDomain) {
spdy_session = list->front();
list->pop_front();
}
} else {
- list = AddSessionList(domain);
+ list = AddSessionList(host_port_pair);
}
DCHECK(list);
if (!spdy_session)
- spdy_session = new SpdySession(domain, session);
+ spdy_session = new SpdySession(host_port_pair, session);
DCHECK(spdy_session);
list->push_back(spdy_session);
@@ -42,63 +41,61 @@ scoped_refptr<SpdySession> SpdySessionPool::Get(
}
scoped_refptr<SpdySession> SpdySessionPool::GetSpdySessionFromSSLSocket(
- const HostResolver::RequestInfo& info,
+ const HostPortPair& host_port_pair,
HttpNetworkSession* session,
ClientSocketHandle* connection) {
- const std::string& domain = info.hostname();
- SpdySessionList* list = GetSessionList(domain);
+ SpdySessionList* list = GetSessionList(host_port_pair);
if (!list)
- list = AddSessionList(domain);
+ list = AddSessionList(host_port_pair);
DCHECK(list->empty());
- scoped_refptr<SpdySession> spdy_session(new SpdySession(domain, session));
+ scoped_refptr<SpdySession> spdy_session(
+ new SpdySession(host_port_pair, session));
spdy_session->InitializeWithSSLSocket(connection);
list->push_back(spdy_session);
return spdy_session;
}
-bool SpdySessionPool::HasSession(const HostResolver::RequestInfo& info) const {
- const std::string& domain = info.hostname();
- if (GetSessionList(domain))
+bool SpdySessionPool::HasSession(const HostPortPair& host_port_pair) const {
+ if (GetSessionList(host_port_pair))
return true;
return false;
}
void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) {
- std::string domain = session->domain();
- SpdySessionList* list = GetSessionList(domain);
+ SpdySessionList* list = GetSessionList(session->host_port_pair());
CHECK(list);
list->remove(session);
if (list->empty())
- RemoveSessionList(domain);
+ RemoveSessionList(session->host_port_pair());
}
SpdySessionPool::SpdySessionList*
- SpdySessionPool::AddSessionList(const std::string& domain) {
- DCHECK(sessions_.find(domain) == sessions_.end());
- return sessions_[domain] = new SpdySessionList();
+ SpdySessionPool::AddSessionList(const HostPortPair& host_port_pair) {
+ DCHECK(sessions_.find(host_port_pair) == sessions_.end());
+ return sessions_[host_port_pair] = new SpdySessionList();
}
SpdySessionPool::SpdySessionList*
- SpdySessionPool::GetSessionList(const std::string& domain) {
- SpdySessionsMap::iterator it = sessions_.find(domain);
+ SpdySessionPool::GetSessionList(const HostPortPair& host_port_pair) {
+ SpdySessionsMap::iterator it = sessions_.find(host_port_pair);
if (it == sessions_.end())
return NULL;
return it->second;
}
const SpdySessionPool::SpdySessionList*
- SpdySessionPool::GetSessionList(const std::string& domain) const {
- SpdySessionsMap::const_iterator it = sessions_.find(domain);
+ SpdySessionPool::GetSessionList(const HostPortPair& host_port_pair) const {
+ SpdySessionsMap::const_iterator it = sessions_.find(host_port_pair);
if (it == sessions_.end())
return NULL;
return it->second;
}
-void SpdySessionPool::RemoveSessionList(const std::string& domain) {
- SpdySessionList* list = GetSessionList(domain);
+void SpdySessionPool::RemoveSessionList(const HostPortPair& host_port_pair) {
+ SpdySessionList* list = GetSessionList(host_port_pair);
if (list) {
delete list;
- sessions_.erase(domain);
+ sessions_.erase(host_port_pair);
} else {
DCHECK(false) << "removing orphaned session list";
}
diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h
index f118dbd..8cf8c60 100644
--- a/net/spdy/spdy_session_pool.h
+++ b/net/spdy/spdy_session_pool.h
@@ -9,9 +9,9 @@
#include <list>
#include <string>
+#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
-#include "net/base/host_resolver.h"
namespace net {
@@ -19,6 +19,23 @@ class ClientSocketHandle;
class HttpNetworkSession;
class SpdySession;
+// TODO(willchan): Move this to net/base.
+struct HostPortPair {
+ HostPortPair() {}
+ HostPortPair(const std::string& in_host, uint16 in_port)
+ : host(in_host), port(in_port) {}
+
+ // Comparator function so this can be placed in a std::map.
+ bool operator<(const HostPortPair& other) const {
+ if (host != other.host)
+ return host < other.host;
+ return port < other.port;
+ }
+
+ std::string host;
+ uint16 port;
+};
+
// This is a very simple pool for open SpdySessions.
// TODO(mbelshe): Make this production ready.
class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
@@ -28,20 +45,20 @@ class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
// Either returns an existing SpdySession or creates a new SpdySession for
// use.
scoped_refptr<SpdySession> Get(
- const HostResolver::RequestInfo& info, HttpNetworkSession* session);
+ const HostPortPair& host_port_pair, HttpNetworkSession* session);
// Builds a SpdySession from an existing SSL socket. Users should try
// calling Get() first to use an existing SpdySession so we don't get
// multiple SpdySessions per domain. Note that ownership of |connection| is
// transferred from the caller to the SpdySession.
scoped_refptr<SpdySession> GetSpdySessionFromSSLSocket(
- const HostResolver::RequestInfo& info,
+ const HostPortPair& host_port_pair,
HttpNetworkSession* session,
ClientSocketHandle* connection);
// TODO(willchan): Consider renaming to HasReusableSession, since perhaps we
// should be creating a new session.
- bool HasSession(const HostResolver::RequestInfo& info) const;
+ bool HasSession(const HostPortPair& host_port_pair)const;
// Close all Spdy Sessions; used for debugging.
void CloseAllSessions();
@@ -52,7 +69,7 @@ class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
friend class SpdySessionPoolPeer; // For testing.
typedef std::list<scoped_refptr<SpdySession> > SpdySessionList;
- typedef std::map<std::string, SpdySessionList*> SpdySessionsMap;
+ typedef std::map<HostPortPair, SpdySessionList*> SpdySessionsMap;
virtual ~SpdySessionPool();
@@ -60,10 +77,11 @@ class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
void Remove(const scoped_refptr<SpdySession>& session);
// Helper functions for manipulating the lists.
- SpdySessionList* AddSessionList(const std::string& domain);
- SpdySessionList* GetSessionList(const std::string& domain);
- const SpdySessionList* GetSessionList(const std::string& domain) const;
- void RemoveSessionList(const std::string& domain);
+ SpdySessionList* AddSessionList(const HostPortPair& host_port_pair);
+ SpdySessionList* GetSessionList(const HostPortPair& host_port_pair);
+ const SpdySessionList* GetSessionList(
+ const HostPortPair& host_port_pair) const;
+ void RemoveSessionList(const HostPortPair& host_port_pair);
// This is our weak session pool - one session per domain.
SpdySessionsMap sessions_;
diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc
index eb8ca5fc..8911d9a 100644
--- a/net/spdy/spdy_stream_unittest.cc
+++ b/net/spdy/spdy_stream_unittest.cc
@@ -88,9 +88,9 @@ class SpdyStreamTest : public testing::Test {
pool_peer_(session_->spdy_session_pool()) {}
scoped_refptr<SpdySession> CreateSpdySession() {
- HostResolver::RequestInfo resolve_info("www.google.com", 80);
+ HostPortPair host_port_pair("www.google.com", 80);
scoped_refptr<SpdySession> session(
- session_->spdy_session_pool()->Get(resolve_info, session_));
+ session_->spdy_session_pool()->Get(host_port_pair, session_));
return session;
}