summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 18:13:10 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 18:13:10 +0000
commitb846acde84543772099763542d9411eacbe684f9 (patch)
treefd0884ad9b0fd2628fb735a1371e56ccd8cdcda3
parente953ef72bcda93f8e89b7145cbaaa8b7ef23e8da (diff)
downloadchromium_src-b846acde84543772099763542d9411eacbe684f9.zip
chromium_src-b846acde84543772099763542d9411eacbe684f9.tar.gz
chromium_src-b846acde84543772099763542d9411eacbe684f9.tar.bz2
Make SpdySessionPool observe network changes.
BUG=40457 Review URL: http://codereview.chromium.org/2627003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49075 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/http/http_network_layer.cc2
-rw-r--r--net/http/http_network_transaction_unittest.cc4
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc4
-rw-r--r--net/spdy/spdy_session_pool.cc10
-rw-r--r--net/spdy/spdy_session_pool.h23
-rw-r--r--net/spdy/spdy_session_unittest.cc2
-rw-r--r--net/spdy/spdy_stream_unittest.cc4
7 files changed, 37 insertions, 12 deletions
diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc
index f661fde..0b8ed96 100644
--- a/net/http/http_network_layer.cc
+++ b/net/http/http_network_layer.cc
@@ -109,7 +109,7 @@ void HttpNetworkLayer::Suspend(bool suspend) {
HttpNetworkSession* HttpNetworkLayer::GetSession() {
if (!session_) {
DCHECK(proxy_service_);
- SpdySessionPool* spdy_pool = new SpdySessionPool;
+ SpdySessionPool* spdy_pool = new SpdySessionPool(network_change_notifier_);
session_ = new HttpNetworkSession(
network_change_notifier_, host_resolver_, proxy_service_,
socket_factory_, ssl_config_service_, spdy_pool,
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index e34b0f3..9b08622 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -83,7 +83,7 @@ class SessionDependencies {
proxy_service(ProxyService::CreateNull()),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
- spdy_session_pool(new SpdySessionPool) {}
+ spdy_session_pool(new SpdySessionPool(NULL)) {}
// Custom proxy service dependency.
explicit SessionDependencies(ProxyService* proxy_service)
@@ -91,7 +91,7 @@ class SessionDependencies {
proxy_service(proxy_service),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
- spdy_session_pool(new SpdySessionPool) {}
+ spdy_session_pool(new SpdySessionPool(NULL)) {}
scoped_refptr<MockHostResolverBase> host_resolver;
scoped_refptr<ProxyService> proxy_service;
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index d40d86b..09bfd7b 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -54,7 +54,7 @@ class SessionDependencies {
proxy_service(ProxyService::CreateNull()),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
- spdy_session_pool(new SpdySessionPool) {
+ spdy_session_pool(new SpdySessionPool(NULL)) {
// Note: The CancelledTransaction test does cleanup by running all tasks
// in the message loop (RunAllPending). Unfortunately, that doesn't clean
// up tasks on the host resolver thread; and TCPConnectJob is currently
@@ -70,7 +70,7 @@ class SessionDependencies {
proxy_service(proxy_service),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
- spdy_session_pool(new SpdySessionPool) {}
+ spdy_session_pool(new SpdySessionPool(NULL)) {}
scoped_refptr<MockHostResolverBase> host_resolver;
scoped_refptr<ProxyService> proxy_service;
diff --git a/net/spdy/spdy_session_pool.cc b/net/spdy/spdy_session_pool.cc
index a0310e8..1315a0a 100644
--- a/net/spdy/spdy_session_pool.cc
+++ b/net/spdy/spdy_session_pool.cc
@@ -14,9 +14,17 @@ static const size_t kMaxSessionsPerDomain = 1;
int SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain;
-SpdySessionPool::SpdySessionPool() {}
+SpdySessionPool::SpdySessionPool(NetworkChangeNotifier* notifier)
+ : network_change_notifier_(notifier) {
+ if (network_change_notifier_)
+ network_change_notifier_->AddObserver(this);
+}
+
SpdySessionPool::~SpdySessionPool() {
CloseAllSessions();
+
+ if (network_change_notifier_)
+ network_change_notifier_->RemoveObserver(this);
}
scoped_refptr<SpdySession> SpdySessionPool::Get(
diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h
index 2a1cb7b..fa02121e 100644
--- a/net/spdy/spdy_session_pool.h
+++ b/net/spdy/spdy_session_pool.h
@@ -13,19 +13,23 @@
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "net/base/host_port_pair.h"
+#include "net/base/network_change_notifier.h"
namespace net {
+class BoundNetLog;
class ClientSocketHandle;
class HttpNetworkSession;
-class BoundNetLog;
+class NetworkChangeNotifier;
class SpdySession;
// This is a very simple pool for open SpdySessions.
// TODO(mbelshe): Make this production ready.
-class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
+class SpdySessionPool
+ : public base::RefCounted<SpdySessionPool>,
+ public NetworkChangeNotifier::Observer {
public:
- SpdySessionPool();
+ explicit SpdySessionPool(NetworkChangeNotifier* notifier);
// Either returns an existing SpdySession or creates a new SpdySession for
// use.
@@ -59,6 +63,13 @@ class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
// Removes a SpdySession from the SpdySessionPool.
void Remove(const scoped_refptr<SpdySession>& session);
+ // NetworkChangeNotifier::Observer methods:
+
+ // We flush all idle sessions and release references to the active ones so
+ // they won't get re-used. The active ones will either complete successfully
+ // or error out due to the IP address change.
+ virtual void OnIPAddressChanged() { ClearSessions(); }
+
private:
friend class base::RefCounted<SpdySessionPool>;
friend class SpdySessionPoolPeer; // For testing.
@@ -75,12 +86,18 @@ class SpdySessionPool : public base::RefCounted<SpdySessionPool> {
const SpdySessionList* GetSessionList(
const HostPortPair& host_port_pair) const;
void RemoveSessionList(const HostPortPair& host_port_pair);
+ // Releases the SpdySessionPool reference to all sessions. Will result in all
+ // idle sessions being deleted, and the active sessions from being reused, so
+ // they will be deleted once all active streams belonging to that session go
+ // away.
void ClearSessions() { RemoveAllSessions(false); }
void RemoveAllSessions(bool close);
// This is our weak session pool - one session per domain.
SpdySessionsMap sessions_;
+ NetworkChangeNotifier* const network_change_notifier_;
+
static int g_max_sessions_per_domain;
DISALLOW_COPY_AND_ASSIGN(SpdySessionPool);
diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc
index 71c42bf..f26e060 100644
--- a/net/spdy/spdy_session_unittest.cc
+++ b/net/spdy/spdy_session_unittest.cc
@@ -40,7 +40,7 @@ class SessionDependencies {
: host_resolver(new MockHostResolver),
proxy_service(ProxyService::CreateNull()),
ssl_config_service(new SSLConfigServiceDefaults),
- spdy_session_pool(new SpdySessionPool) {
+ spdy_session_pool(new SpdySessionPool(NULL)) {
}
scoped_refptr<MockHostResolverBase> host_resolver;
diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc
index 84db904..9f15fae 100644
--- a/net/spdy/spdy_stream_unittest.cc
+++ b/net/spdy/spdy_stream_unittest.cc
@@ -53,7 +53,7 @@ class SessionDependencies {
proxy_service(CreateNullProxyService()),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
- spdy_session_pool(new SpdySessionPool) {}
+ spdy_session_pool(new SpdySessionPool(NULL)) {}
// Custom proxy service dependency.
explicit SessionDependencies(ProxyService* proxy_service)
@@ -61,7 +61,7 @@ class SessionDependencies {
proxy_service(proxy_service),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
- spdy_session_pool(new SpdySessionPool) {}
+ spdy_session_pool(new SpdySessionPool(NULL)) {}
scoped_refptr<MockHostResolverBase> host_resolver;
scoped_refptr<ProxyService> proxy_service;