summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 20:26:13 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 20:26:13 +0000
commit2431756ea7ceea7ac837522d948c3628cf83b647 (patch)
tree89e8921ce9f257f2dfeeb2491fb0ea246d4d1050
parent252c50a4cdb5a9506938b231f4bd19afd5365757 (diff)
downloadchromium_src-2431756ea7ceea7ac837522d948c3628cf83b647.zip
chromium_src-2431756ea7ceea7ac837522d948c3628cf83b647.tar.gz
chromium_src-2431756ea7ceea7ac837522d948c3628cf83b647.tar.bz2
Stop refcounting ClientSocketPool.
Establishes that HttpNetworkSession owns all the socket pools. Move out all the socket pools into a ClientSocketPoolManager. This is because of the dependency tree amongst socket pools, which dictates the order in which they must be constructed and destructed. In order to better establish it, I moved them out to their own class. HttpNetworkSession owns the ClientSocketPoolManager which owns the pools. We pass the pools as raw pointers everywhere. Note that ClientSocketPoolManager owns more pools than are publicly accessible via its interface. That's because some of them are wrapped by publicly exposed pools. Also, ClientSocketPoolHistograms used to be reference counted. That's because it can be shared by multiple ClientSocketPools. But it's effectively a global as well, so I make their lifetimes persist for the length of ClientSocketPoolManager too. I also removed internal refcounting in ClientSocketPoolBase. I had refcounted it before I knew about ScopedRunnableMethodFactory back when I first started. I cleaned up the unit tests a lot. Back when I was a young padawan, I didn't really know what I was doing, so I copy/pasted a metric asston of code. Turns out most of it was stupid, so I fixed it. I also stopped the use of implementation inheritance with ClientSocketPoolTest because it's discouraged by the style guide and more importantly because it caused the ClientSocketHandles within the TestSocketRequest vector to be destroyed _after_ the pools themselves were destroyed, which is bad since the handles will call pool_->Release() which blows up. BUG=56215,56215 TEST=Existing unit tests Review URL: http://codereview.chromium.org/3389020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60983 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc18
-rw-r--r--net/http/http_cache.cc3
-rw-r--r--net/http/http_network_session.cc186
-rw-r--r--net/http/http_network_session.h99
-rw-r--r--net/http/http_network_transaction_unittest.cc62
-rw-r--r--net/http/http_proxy_client_socket_pool.cc25
-rw-r--r--net/http/http_proxy_client_socket_pool.h33
-rw-r--r--net/http/http_proxy_client_socket_pool_unittest.cc55
-rw-r--r--net/http/http_response_body_drainer_unittest.cc3
-rw-r--r--net/http/http_stream_request.cc10
-rw-r--r--net/net.gyp2
-rw-r--r--net/socket/client_socket_handle.cc2
-rw-r--r--net/socket/client_socket_handle.h6
-rw-r--r--net/socket/client_socket_pool.h8
-rw-r--r--net/socket/client_socket_pool_base.cc28
-rw-r--r--net/socket/client_socket_pool_base.h59
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc987
-rw-r--r--net/socket/client_socket_pool_histograms.cc3
-rw-r--r--net/socket/client_socket_pool_histograms.h9
-rw-r--r--net/socket/client_socket_pool_manager.cc327
-rw-r--r--net/socket/client_socket_pool_manager.h140
-rw-r--r--net/socket/socket_test_util.cc40
-rw-r--r--net/socket/socket_test_util.h48
-rw-r--r--net/socket/socks_client_socket_pool.cc7
-rw-r--r--net/socket/socks_client_socket_pool.h21
-rw-r--r--net/socket/socks_client_socket_pool_unittest.cc106
-rw-r--r--net/socket/ssl_client_socket_pool.cc58
-rw-r--r--net/socket/ssl_client_socket_pool.h47
-rw-r--r--net/socket/ssl_client_socket_pool_unittest.cc121
-rw-r--r--net/socket/tcp_client_socket_pool.cc2
-rw-r--r--net/socket/tcp_client_socket_pool.h9
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc206
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc4
-rw-r--r--net/spdy/spdy_session.cc1
34 files changed, 1667 insertions, 1068 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 3712a06..d711778 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -90,9 +90,9 @@
#include "net/base/net_module.h"
#include "net/base/network_change_notifier.h"
#include "net/http/http_network_layer.h"
-#include "net/http/http_network_session.h"
#include "net/http/http_stream_factory.h"
#include "net/socket/client_socket_pool_base.h"
+#include "net/socket/client_socket_pool_manager.h"
#include "net/spdy/spdy_session_pool.h"
#if defined(USE_LINUX_BREAKPAD)
@@ -226,15 +226,15 @@ void BrowserMainParts::ConnectionFieldTrial() {
const int connect_trial_group = connect_trial->group();
if (connect_trial_group == connect_5) {
- net::HttpNetworkSession::set_max_sockets_per_group(5);
+ net::ClientSocketPoolManager::set_max_sockets_per_group(5);
} else if (connect_trial_group == connect_6) {
- net::HttpNetworkSession::set_max_sockets_per_group(6);
+ net::ClientSocketPoolManager::set_max_sockets_per_group(6);
} else if (connect_trial_group == connect_7) {
- net::HttpNetworkSession::set_max_sockets_per_group(7);
+ net::ClientSocketPoolManager::set_max_sockets_per_group(7);
} else if (connect_trial_group == connect_8) {
- net::HttpNetworkSession::set_max_sockets_per_group(8);
+ net::ClientSocketPoolManager::set_max_sockets_per_group(8);
} else if (connect_trial_group == connect_9) {
- net::HttpNetworkSession::set_max_sockets_per_group(9);
+ net::ClientSocketPoolManager::set_max_sockets_per_group(9);
} else {
NOTREACHED();
}
@@ -310,11 +310,11 @@ void BrowserMainParts::ProxyConnectionsFieldTrial() {
const int proxy_connections_trial_group = proxy_connection_trial->group();
if (proxy_connections_trial_group == proxy_connections_16) {
- net::HttpNetworkSession::set_max_sockets_per_proxy_server(16);
+ net::ClientSocketPoolManager::set_max_sockets_per_proxy_server(16);
} else if (proxy_connections_trial_group == proxy_connections_32) {
- net::HttpNetworkSession::set_max_sockets_per_proxy_server(32);
+ net::ClientSocketPoolManager::set_max_sockets_per_proxy_server(32);
} else if (proxy_connections_trial_group == proxy_connections_64) {
- net::HttpNetworkSession::set_max_sockets_per_proxy_server(64);
+ net::ClientSocketPoolManager::set_max_sockets_per_proxy_server(64);
} else {
NOTREACHED();
}
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 2dd2347..2b2a221 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -392,8 +392,7 @@ void HttpCache::CloseCurrentConnections() {
static_cast<net::HttpNetworkLayer*>(network_layer_.get());
HttpNetworkSession* session = network->GetSession();
if (session) {
- session->ssl_socket_pool()->Flush();
- session->tcp_socket_pool()->Flush();
+ session->FlushSocketPools();
if (session->spdy_session_pool())
session->spdy_session_pool()->CloseCurrentSessions();
}
diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc
index 851956e..7b4fe0e 100644
--- a/net/http/http_network_session.cc
+++ b/net/http/http_network_session.cc
@@ -17,38 +17,6 @@
namespace net {
-namespace {
-
-// Total limit of sockets.
-int g_max_sockets = 256;
-
-// Default to allow up to 6 connections per host. Experiment and tuning may
-// try other values (greater than 0). Too large may cause many problems, such
-// as home routers blocking the connections!?!? See http://crbug.com/12066.
-int g_max_sockets_per_group = 6;
-
-// The max number of sockets to allow per proxy server. This applies both to
-// http and SOCKS proxies. See http://crbug.com/12066 and
-// http://crbug.com/44501 for details about proxy server connection limits.
-int g_max_sockets_per_proxy_server = 32;
-
-// Appends information about all |socket_pools| to the end of |list|.
-template <class MapType>
-static void AddSocketPoolsToList(ListValue* list,
- const MapType& socket_pools,
- const std::string& type,
- bool include_nested_pools) {
- typename MapType::const_iterator socket_pool_it = socket_pools.begin();
- for (typename MapType::const_iterator it = socket_pools.begin();
- it != socket_pools.end(); it++) {
- list->Append(it->second->GetInfoAsValue(it->first.ToString(),
- type,
- include_nested_pools));
- }
-}
-
-} // namespace
-
// TODO(mbelshe): Move the socket factories into HttpStreamFactory.
HttpNetworkSession::HttpNetworkSession(
HostResolver* host_resolver,
@@ -59,29 +27,15 @@ HttpNetworkSession::HttpNetworkSession(
HttpAuthHandlerFactory* http_auth_handler_factory,
HttpNetworkDelegate* network_delegate,
NetLog* net_log)
- : tcp_pool_histograms_(new ClientSocketPoolHistograms("TCP")),
- tcp_for_http_proxy_pool_histograms_(
- new ClientSocketPoolHistograms("TCPforHTTPProxy")),
- http_proxy_pool_histograms_(new ClientSocketPoolHistograms("HTTPProxy")),
- tcp_for_https_proxy_pool_histograms_(
- new ClientSocketPoolHistograms("TCPforHTTPSProxy")),
- ssl_for_https_proxy_pool_histograms_(
- new ClientSocketPoolHistograms("SSLforHTTPSProxy")),
- tcp_for_socks_pool_histograms_(
- new ClientSocketPoolHistograms("TCPforSOCKS")),
- socks_pool_histograms_(new ClientSocketPoolHistograms("SOCK")),
- ssl_pool_histograms_(new ClientSocketPoolHistograms("SSL")),
- tcp_socket_pool_(new TCPClientSocketPool(
- g_max_sockets, g_max_sockets_per_group, tcp_pool_histograms_,
- host_resolver, client_socket_factory, net_log)),
- ssl_socket_pool_(new SSLClientSocketPool(
- g_max_sockets, g_max_sockets_per_group, ssl_pool_histograms_,
- host_resolver, client_socket_factory, tcp_socket_pool_, NULL,
- NULL, ssl_config_service, net_log)),
- socket_factory_(client_socket_factory),
+ : socket_factory_(client_socket_factory),
host_resolver_(host_resolver),
proxy_service_(proxy_service),
ssl_config_service_(ssl_config_service),
+ socket_pool_manager_(net_log,
+ client_socket_factory,
+ host_resolver,
+ proxy_service,
+ ssl_config_service),
spdy_session_pool_(spdy_session_pool),
http_stream_factory_(new HttpStreamFactory()),
http_auth_handler_factory_(http_auth_handler_factory),
@@ -93,6 +47,7 @@ HttpNetworkSession::HttpNetworkSession(
HttpNetworkSession::~HttpNetworkSession() {
STLDeleteElements(&response_drainers_);
+ spdy_session_pool_->CloseAllSessions();
}
void HttpNetworkSession::AddResponseDrainer(HttpResponseBodyDrainer* drainer) {
@@ -106,131 +61,4 @@ void HttpNetworkSession::RemoveResponseDrainer(
response_drainers_.erase(drainer);
}
-const scoped_refptr<HttpProxyClientSocketPool>&
-HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) {
- HTTPProxySocketPoolMap::const_iterator it =
- http_proxy_socket_pools_.find(http_proxy);
- if (it != http_proxy_socket_pools_.end())
- return it->second;
-
- std::pair<HTTPProxySocketPoolMap::iterator, bool> ret =
- http_proxy_socket_pools_.insert(
- std::make_pair(
- http_proxy,
- new HttpProxyClientSocketPool(
- g_max_sockets_per_proxy_server, g_max_sockets_per_group,
- http_proxy_pool_histograms_, host_resolver_,
- new TCPClientSocketPool(
- g_max_sockets_per_proxy_server, g_max_sockets_per_group,
- tcp_for_http_proxy_pool_histograms_, host_resolver_,
- socket_factory_, net_log_),
- new SSLClientSocketPool(
- g_max_sockets_per_proxy_server, g_max_sockets_per_group,
- ssl_for_https_proxy_pool_histograms_, host_resolver_,
- socket_factory_,
- new TCPClientSocketPool(
- g_max_sockets_per_proxy_server,
- g_max_sockets_per_group,
- tcp_for_https_proxy_pool_histograms_, host_resolver_,
- socket_factory_, net_log_),
- NULL, NULL, ssl_config_service_, net_log_),
- net_log_)));
-
- return ret.first->second;
-}
-
-const scoped_refptr<SOCKSClientSocketPool>&
-HttpNetworkSession::GetSocketPoolForSOCKSProxy(
- const HostPortPair& socks_proxy) {
- SOCKSSocketPoolMap::const_iterator it = socks_socket_pools_.find(socks_proxy);
- if (it != socks_socket_pools_.end())
- return it->second;
-
- std::pair<SOCKSSocketPoolMap::iterator, bool> ret =
- socks_socket_pools_.insert(
- std::make_pair(socks_proxy, new SOCKSClientSocketPool(
- g_max_sockets_per_proxy_server, g_max_sockets_per_group,
- socks_pool_histograms_, host_resolver_,
- new TCPClientSocketPool(g_max_sockets_per_proxy_server,
- g_max_sockets_per_group, tcp_for_socks_pool_histograms_,
- host_resolver_, socket_factory_, net_log_),
- net_log_)));
-
- return ret.first->second;
-}
-
-const scoped_refptr<SSLClientSocketPool>&
-HttpNetworkSession::GetSocketPoolForSSLWithProxy(
- const HostPortPair& proxy_server) {
- SSLSocketPoolMap::const_iterator it =
- ssl_socket_pools_for_proxies_.find(proxy_server);
- if (it != ssl_socket_pools_for_proxies_.end())
- return it->second;
-
- SSLClientSocketPool* new_pool = new SSLClientSocketPool(
- g_max_sockets_per_proxy_server, g_max_sockets_per_group,
- ssl_pool_histograms_, host_resolver_, socket_factory_,
- NULL,
- GetSocketPoolForHTTPProxy(proxy_server),
- GetSocketPoolForSOCKSProxy(proxy_server),
- ssl_config_service_, net_log_);
-
- std::pair<SSLSocketPoolMap::iterator, bool> ret =
- ssl_socket_pools_for_proxies_.insert(std::make_pair(proxy_server,
- new_pool));
-
- return ret.first->second;
-}
-
-Value* HttpNetworkSession::SocketPoolInfoToValue() const {
- ListValue* list = new ListValue();
- list->Append(tcp_socket_pool_->GetInfoAsValue("tcp_socket_pool",
- "tcp_socket_pool",
- false));
- // Third parameter is false because |ssl_socket_pool_| uses |tcp_socket_pool_|
- // internally, and do not want to add it a second time.
- list->Append(ssl_socket_pool_->GetInfoAsValue("ssl_socket_pool",
- "ssl_socket_pool",
- false));
- AddSocketPoolsToList(list,
- http_proxy_socket_pools_,
- "http_proxy_socket_pool",
- true);
- AddSocketPoolsToList(list,
- socks_socket_pools_,
- "socks_socket_pool",
- true);
-
- // Third parameter is false because |ssl_socket_pools_for_proxies_| use
- // socket pools in |http_proxy_socket_pools_| and |socks_socket_pools_|.
- AddSocketPoolsToList(list,
- ssl_socket_pools_for_proxies_,
- "ssl_socket_pool_for_proxies",
- false);
- return list;
-}
-
-// static
-int HttpNetworkSession::max_sockets_per_group() {
- return g_max_sockets_per_group;
-}
-
-// static
-void HttpNetworkSession::set_max_sockets_per_group(int socket_count) {
- DCHECK_LT(0, socket_count);
- // The following is a sanity check... but we should NEVER be near this value.
- DCHECK_GT(100, socket_count);
- g_max_sockets_per_group = socket_count;
-}
-
-// static
-void HttpNetworkSession::set_max_sockets_per_proxy_server(int socket_count) {
- DCHECK_LT(0, socket_count);
- DCHECK_GT(100, socket_count); // Sanity check.
- // Assert this case early on. The max number of sockets per group cannot
- // exceed the max number of sockets per proxy server.
- DCHECK_LE(g_max_sockets_per_group, socket_count);
- g_max_sockets_per_proxy_server = socket_count;
-}
-
} // namespace net
diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h
index dfa535b..3d1211c 100644
--- a/net/http/http_network_session.h
+++ b/net/http/http_network_session.h
@@ -19,23 +19,25 @@
#include "net/http/http_auth_cache.h"
#include "net/http/http_network_delegate.h"
#include "net/http/http_network_transaction.h"
-#include "net/http/http_proxy_client_socket_pool.h"
#include "net/http/http_stream_factory.h"
#include "net/proxy/proxy_service.h"
-#include "net/socket/client_socket_pool_histograms.h"
-#include "net/socket/socks_client_socket_pool.h"
-#include "net/socket/ssl_client_socket_pool.h"
-#include "net/socket/tcp_client_socket_pool.h"
+#include "net/socket/client_socket_pool_manager.h"
#include "net/spdy/spdy_settings_storage.h"
+class Value;
+
namespace net {
class ClientSocketFactory;
class HttpAuthHandlerFactory;
class HttpNetworkDelegate;
class HttpNetworkSessionPeer;
+class HttpProxyClientSocketPool;
class HttpResponseBodyDrainer;
class SpdySessionPool;
+class SOCKSClientSocketPool;
+class SSLClientSocketPool;
+class TCPClientSocketPool;
// This class holds session objects used by HttpNetworkTransaction objects.
class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>,
@@ -75,23 +77,28 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>,
return &spdy_settings_;
}
- // TCP sockets come from the tcp_socket_pool().
- const scoped_refptr<TCPClientSocketPool>& tcp_socket_pool() {
- return tcp_socket_pool_;
+ TCPClientSocketPool* tcp_socket_pool() {
+ return socket_pool_manager_.tcp_socket_pool();
}
- const scoped_refptr<SSLClientSocketPool>& ssl_socket_pool() {
- return ssl_socket_pool_;
+ SSLClientSocketPool* ssl_socket_pool() {
+ return socket_pool_manager_.ssl_socket_pool();
}
- const scoped_refptr<SOCKSClientSocketPool>& GetSocketPoolForSOCKSProxy(
- const HostPortPair& socks_proxy);
+ SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
+ const HostPortPair& socks_proxy) {
+ return socket_pool_manager_.GetSocketPoolForSOCKSProxy(socks_proxy);
+ }
- const scoped_refptr<HttpProxyClientSocketPool>& GetSocketPoolForHTTPProxy(
- const HostPortPair& http_proxy);
+ HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
+ const HostPortPair& http_proxy) {
+ return socket_pool_manager_.GetSocketPoolForHTTPProxy(http_proxy);
+ }
- const scoped_refptr<SSLClientSocketPool>& GetSocketPoolForSSLWithProxy(
- const HostPortPair& proxy_server);
+ SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
+ const HostPortPair& proxy_server) {
+ return socket_pool_manager_.GetSocketPoolForSSLWithProxy(proxy_server);
+ }
// SSL sockets come from the socket_factory().
ClientSocketFactory* socket_factory() { return socket_factory_; }
@@ -114,74 +121,28 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>,
// Creates a Value summary of the state of the socket pools. The caller is
// responsible for deleting the returned value.
- Value* SocketPoolInfoToValue() const;
-
- static int max_sockets_per_group();
- static void set_max_sockets_per_group(int socket_count);
- static void set_max_sockets_per_proxy_server(int socket_count);
+ Value* SocketPoolInfoToValue() const {
+ return socket_pool_manager_.SocketPoolInfoToValue();
+ }
-#ifdef UNIT_TEST
void FlushSocketPools() {
- if (ssl_socket_pool_.get())
- ssl_socket_pool_->Flush();
- if (tcp_socket_pool_.get())
- tcp_socket_pool_->Flush();
-
- for (SSLSocketPoolMap::const_iterator it =
- ssl_socket_pools_for_proxies_.begin();
- it != ssl_socket_pools_for_proxies_.end();
- it++)
- it->second->Flush();
-
- for (SOCKSSocketPoolMap::const_iterator it =
- socks_socket_pools_.begin();
- it != socks_socket_pools_.end();
- it++)
- it->second->Flush();
-
- for (HTTPProxySocketPoolMap::const_iterator it =
- http_proxy_socket_pools_.begin();
- it != http_proxy_socket_pools_.end();
- it++)
- it->second->Flush();
- }
-#endif
+ socket_pool_manager_.FlushSocketPools();
+ }
private:
- typedef std::map<HostPortPair, scoped_refptr<HttpProxyClientSocketPool> >
- HTTPProxySocketPoolMap;
- typedef std::map<HostPortPair, scoped_refptr<SOCKSClientSocketPool> >
- SOCKSSocketPoolMap;
- typedef std::map<HostPortPair, scoped_refptr<SSLClientSocketPool> >
- SSLSocketPoolMap;
-
friend class base::RefCounted<HttpNetworkSession>;
friend class HttpNetworkSessionPeer;
~HttpNetworkSession();
+ ClientSocketFactory* const socket_factory_;
HttpAuthCache auth_cache_;
SSLClientAuthCache ssl_client_auth_cache_;
HttpAlternateProtocols alternate_protocols_;
- scoped_refptr<ClientSocketPoolHistograms> tcp_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms> tcp_for_http_proxy_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms> http_proxy_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms>
- tcp_for_https_proxy_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms>
- ssl_for_https_proxy_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms> tcp_for_socks_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms> socks_pool_histograms_;
- scoped_refptr<ClientSocketPoolHistograms> ssl_pool_histograms_;
- scoped_refptr<TCPClientSocketPool> tcp_socket_pool_;
- scoped_refptr<SSLClientSocketPool> ssl_socket_pool_;
- HTTPProxySocketPoolMap http_proxy_socket_pools_;
- SOCKSSocketPoolMap socks_socket_pools_;
- SSLSocketPoolMap ssl_socket_pools_for_proxies_;
- ClientSocketFactory* socket_factory_;
scoped_refptr<HostResolver> host_resolver_;
scoped_refptr<ProxyService> proxy_service_;
scoped_refptr<SSLConfigService> ssl_config_service_;
+ ClientSocketPoolManager socket_pool_manager_;
scoped_refptr<SpdySessionPool> spdy_session_pool_;
scoped_refptr<HttpStreamFactory> http_stream_factory_;
HttpAuthHandlerFactory* http_auth_handler_factory_;
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index b04a0a5..68e4038 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -72,30 +72,48 @@ class HttpNetworkSessionPeer {
const scoped_refptr<HttpNetworkSession>& session)
: session_(session) {}
- void SetTCPSocketPool(const scoped_refptr<TCPClientSocketPool>& pool) {
- session_->tcp_socket_pool_ = pool;
+ void SetTCPSocketPool(TCPClientSocketPool* pool) {
+ session_->socket_pool_manager_.tcp_socket_pool_.reset(pool);
}
void SetSocketPoolForSOCKSProxy(
const HostPortPair& socks_proxy,
- const scoped_refptr<SOCKSClientSocketPool>& pool) {
- session_->socks_socket_pools_[socks_proxy] = pool;
+ SOCKSClientSocketPool* pool) {
+ ClientSocketPoolManager* socket_pool_manager =
+ &session_->socket_pool_manager_;
+
+ // Call through the public interface to force initialization of the
+ // wrapped socket pools.
+ delete socket_pool_manager->GetSocketPoolForSOCKSProxy(socks_proxy);
+ socket_pool_manager->socks_socket_pools_[socks_proxy] = pool;
}
void SetSocketPoolForHTTPProxy(
const HostPortPair& http_proxy,
- const scoped_refptr<HttpProxyClientSocketPool>& pool) {
- session_->http_proxy_socket_pools_[http_proxy] = pool;
+ HttpProxyClientSocketPool* pool) {
+ ClientSocketPoolManager* socket_pool_manager =
+ &session_->socket_pool_manager_;
+
+ // Call through the public interface to force initialization of the
+ // wrapped socket pools.
+ delete socket_pool_manager->GetSocketPoolForHTTPProxy(http_proxy);
+ socket_pool_manager->http_proxy_socket_pools_[http_proxy] = pool;
}
- void SetSSLSocketPool(const scoped_refptr<SSLClientSocketPool>& pool) {
- session_->ssl_socket_pool_ = pool;
+ void SetSSLSocketPool(SSLClientSocketPool* pool) {
+ session_->socket_pool_manager_.ssl_socket_pool_.reset(pool);
}
void SetSocketPoolForSSLWithProxy(
const HostPortPair& proxy_host,
- const scoped_refptr<SSLClientSocketPool>& pool) {
- session_->ssl_socket_pools_for_proxies_[proxy_host] = pool;
+ SSLClientSocketPool* pool) {
+ ClientSocketPoolManager* socket_pool_manager =
+ &session_->socket_pool_manager_;
+
+ // Call through the public interface to force initialization of the
+ // wrapped socket pools.
+ delete socket_pool_manager->GetSocketPoolForSSLWithProxy(proxy_host);
+ socket_pool_manager->ssl_socket_pools_for_proxies_[proxy_host] = pool;
}
private:
@@ -4837,11 +4855,11 @@ TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) {
SetupSessionForGroupNameTests(tests[i].proxy_server));
HttpNetworkSessionPeer peer(session);
- scoped_refptr<CaptureGroupNameTCPSocketPool> tcp_conn_pool(
- new CaptureGroupNameTCPSocketPool(session.get()));
+ CaptureGroupNameTCPSocketPool* tcp_conn_pool =
+ new CaptureGroupNameTCPSocketPool(session);
peer.SetTCPSocketPool(tcp_conn_pool);
- scoped_refptr<CaptureGroupNameSSLSocketPool> ssl_conn_pool(
- new CaptureGroupNameSSLSocketPool(session.get()));
+ CaptureGroupNameSSLSocketPool* ssl_conn_pool =
+ new CaptureGroupNameSSLSocketPool(session.get());
peer.SetSSLSocketPool(ssl_conn_pool);
EXPECT_EQ(ERR_IO_PENDING,
@@ -4891,11 +4909,11 @@ TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) {
HttpNetworkSessionPeer peer(session);
HostPortPair proxy_host("http_proxy", 80);
- scoped_refptr<CaptureGroupNameHttpProxySocketPool> http_proxy_pool(
- new CaptureGroupNameHttpProxySocketPool(session.get()));
+ CaptureGroupNameHttpProxySocketPool* http_proxy_pool =
+ new CaptureGroupNameHttpProxySocketPool(session);
peer.SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool);
- scoped_refptr<CaptureGroupNameSSLSocketPool> ssl_conn_pool(
- new CaptureGroupNameSSLSocketPool(session.get()));
+ CaptureGroupNameSSLSocketPool* ssl_conn_pool =
+ new CaptureGroupNameSSLSocketPool(session);
peer.SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
EXPECT_EQ(ERR_IO_PENDING,
@@ -4956,11 +4974,11 @@ TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) {
HttpNetworkSessionPeer peer(session);
HostPortPair proxy_host("socks_proxy", 1080);
- scoped_refptr<CaptureGroupNameSOCKSSocketPool> socks_conn_pool(
- new CaptureGroupNameSOCKSSocketPool(session.get()));
+ CaptureGroupNameSOCKSSocketPool* socks_conn_pool =
+ new CaptureGroupNameSOCKSSocketPool(session);
peer.SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool);
- scoped_refptr<CaptureGroupNameSSLSocketPool> ssl_conn_pool(
- new CaptureGroupNameSSLSocketPool(session.get()));
+ CaptureGroupNameSSLSocketPool* ssl_conn_pool =
+ new CaptureGroupNameSSLSocketPool(session);
peer.SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc
index 16f9597..fa49944 100644
--- a/net/http/http_proxy_client_socket_pool.cc
+++ b/net/http/http_proxy_client_socket_pool.cc
@@ -16,8 +16,9 @@
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_base.h"
-#include "net/socket/tcp_client_socket_pool.h"
#include "net/socket/ssl_client_socket.h"
+#include "net/socket/ssl_client_socket_pool.h"
+#include "net/socket/tcp_client_socket_pool.h"
namespace net {
@@ -59,8 +60,8 @@ HttpProxyConnectJob::HttpProxyConnectJob(
const std::string& group_name,
const scoped_refptr<HttpProxySocketParams>& params,
const base::TimeDelta& timeout_duration,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<SSLClientSocketPool>& ssl_pool,
+ TCPClientSocketPool* tcp_pool,
+ SSLClientSocketPool* ssl_pool,
const scoped_refptr<HostResolver>& host_resolver,
Delegate* delegate,
NetLog* net_log)
@@ -237,8 +238,8 @@ int HttpProxyConnectJob::DoHttpProxyConnectComplete(int result) {
HttpProxyClientSocketPool::
HttpProxyConnectJobFactory::HttpProxyConnectJobFactory(
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<SSLClientSocketPool>& ssl_pool,
+ TCPClientSocketPool* tcp_pool,
+ SSLClientSocketPool* ssl_pool,
HostResolver* host_resolver,
NetLog* net_log)
: tcp_pool_(tcp_pool),
@@ -269,10 +270,10 @@ HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob(
HttpProxyClientSocketPool::HttpProxyClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
const scoped_refptr<HostResolver>& host_resolver,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<SSLClientSocketPool>& ssl_pool,
+ TCPClientSocketPool* tcp_pool,
+ SSLClientSocketPool* ssl_pool,
NetLog* net_log)
: tcp_pool_(tcp_pool),
ssl_pool_(ssl_pool),
@@ -311,10 +312,6 @@ void HttpProxyClientSocketPool::ReleaseSocket(const std::string& group_name,
void HttpProxyClientSocketPool::Flush() {
base_.Flush();
- if (ssl_pool_)
- ssl_pool_->Flush();
- if (tcp_pool_)
- tcp_pool_->Flush();
}
void HttpProxyClientSocketPool::CloseIdleSockets() {
@@ -338,12 +335,12 @@ DictionaryValue* HttpProxyClientSocketPool::GetInfoAsValue(
DictionaryValue* dict = base_.GetInfoAsValue(name, type);
if (include_nested_pools) {
ListValue* list = new ListValue();
- if (tcp_pool_.get()) {
+ if (tcp_pool_) {
list->Append(tcp_pool_->GetInfoAsValue("tcp_socket_pool",
"tcp_socket_pool",
true));
}
- if (ssl_pool_.get()) {
+ if (ssl_pool_) {
list->Append(ssl_pool_->GetInfoAsValue("ssl_socket_pool",
"ssl_socket_pool",
true));
diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h
index cfeb9a3..ea3c51f 100644
--- a/net/http/http_proxy_client_socket_pool.h
+++ b/net/http/http_proxy_client_socket_pool.h
@@ -82,8 +82,8 @@ class HttpProxyConnectJob : public ConnectJob {
HttpProxyConnectJob(const std::string& group_name,
const scoped_refptr<HttpProxySocketParams>& params,
const base::TimeDelta& timeout_duration,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<SSLClientSocketPool>& ssl_pool,
+ TCPClientSocketPool* tcp_pool,
+ SSLClientSocketPool* ssl_pool,
const scoped_refptr<HostResolver> &host_resolver,
Delegate* delegate,
NetLog* net_log);
@@ -128,8 +128,8 @@ class HttpProxyConnectJob : public ConnectJob {
int DoHttpProxyConnectComplete(int result);
scoped_refptr<HttpProxySocketParams> params_;
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
- const scoped_refptr<SSLClientSocketPool> ssl_pool_;
+ TCPClientSocketPool* const tcp_pool_;
+ SSLClientSocketPool* const ssl_pool_;
const scoped_refptr<HostResolver> resolver_;
State next_state_;
@@ -146,12 +146,14 @@ class HttpProxyClientSocketPool : public ClientSocketPool {
HttpProxyClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
const scoped_refptr<HostResolver>& host_resolver,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<SSLClientSocketPool>& ssl_pool,
+ TCPClientSocketPool* tcp_pool,
+ SSLClientSocketPool* ssl_pool,
NetLog* net_log);
+ virtual ~HttpProxyClientSocketPool();
+
// ClientSocketPool methods:
virtual int RequestSocket(const std::string& group_name,
const void* connect_params,
@@ -188,21 +190,18 @@ class HttpProxyClientSocketPool : public ClientSocketPool {
return base_.ConnectionTimeout();
}
- virtual scoped_refptr<ClientSocketPoolHistograms> histograms() const {
+ virtual ClientSocketPoolHistograms* histograms() const {
return base_.histograms();
};
- protected:
- virtual ~HttpProxyClientSocketPool();
-
private:
typedef ClientSocketPoolBase<HttpProxySocketParams> PoolBase;
class HttpProxyConnectJobFactory : public PoolBase::ConnectJobFactory {
public:
HttpProxyConnectJobFactory(
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<SSLClientSocketPool>& ssl_pool,
+ TCPClientSocketPool* tcp_pool,
+ SSLClientSocketPool* ssl_pool,
HostResolver* host_resolver,
NetLog* net_log);
@@ -214,8 +213,8 @@ class HttpProxyClientSocketPool : public ClientSocketPool {
virtual base::TimeDelta ConnectionTimeout() const { return timeout_; }
private:
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
- const scoped_refptr<SSLClientSocketPool> ssl_pool_;
+ TCPClientSocketPool* const tcp_pool_;
+ SSLClientSocketPool* const ssl_pool_;
const scoped_refptr<HostResolver> host_resolver_;
NetLog* net_log_;
base::TimeDelta timeout_;
@@ -223,8 +222,8 @@ class HttpProxyClientSocketPool : public ClientSocketPool {
DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJobFactory);
};
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
- const scoped_refptr<SSLClientSocketPool> ssl_pool_;
+ TCPClientSocketPool* const tcp_pool_;
+ SSLClientSocketPool* const ssl_pool_;
PoolBase base_;
DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool);
diff --git a/net/http/http_proxy_client_socket_pool_unittest.cc b/net/http/http_proxy_client_socket_pool_unittest.cc
index 6d03c19..4a68d9b 100644
--- a/net/http/http_proxy_client_socket_pool_unittest.cc
+++ b/net/http/http_proxy_client_socket_pool_unittest.cc
@@ -45,11 +45,16 @@ class HttpProxyClientSocketPoolTest : public TestWithHttpParam {
ignored_ssl_socket_params_(new SSLSocketParams(
ignored_tcp_socket_params_, NULL, NULL, ProxyServer::SCHEME_DIRECT,
"host", ssl_config_, 0, false, false)),
- tcp_histograms_(new ClientSocketPoolHistograms("MockTCP")),
- tcp_socket_pool_(new MockTCPClientSocketPool(kMaxSockets,
- kMaxSocketsPerGroup, tcp_histograms_, &tcp_client_socket_factory_)),
- ssl_socket_pool_(new MockSSLClientSocketPool(kMaxSockets,
- kMaxSocketsPerGroup, tcp_histograms_, &tcp_client_socket_factory_)),
+ tcp_histograms_("MockTCP"),
+ tcp_socket_pool_(
+ kMaxSockets, kMaxSocketsPerGroup,
+ &tcp_histograms_,
+ &tcp_client_socket_factory_),
+ ssl_histograms_("MockSSL"),
+ ssl_socket_pool_(kMaxSockets, kMaxSocketsPerGroup,
+ &ssl_histograms_,
+ &tcp_client_socket_factory_,
+ &tcp_socket_pool_),
host_resolver_(new MockHostResolver),
http_auth_handler_factory_(
HttpAuthHandlerFactory::CreateDefault(host_resolver_)),
@@ -61,11 +66,16 @@ class HttpProxyClientSocketPoolTest : public TestWithHttpParam {
http_auth_handler_factory_.get(),
NULL,
NULL)),
- http_proxy_histograms_(
- new ClientSocketPoolHistograms("HttpProxyUnitTest")),
- pool_(new HttpProxyClientSocketPool(kMaxSockets, kMaxSocketsPerGroup,
- http_proxy_histograms_, NULL, tcp_socket_pool_, ssl_socket_pool_,
- NULL)) {
+ http_proxy_histograms_("HttpProxyUnitTest"),
+ pool_(kMaxSockets, kMaxSocketsPerGroup,
+ &http_proxy_histograms_,
+ NULL,
+ &tcp_socket_pool_,
+ &ssl_socket_pool_,
+ NULL) {
+ }
+
+ virtual ~HttpProxyClientSocketPoolTest() {
}
void AddAuthToCache() {
@@ -114,17 +124,18 @@ class HttpProxyClientSocketPoolTest : public TestWithHttpParam {
scoped_refptr<TCPSocketParams> ignored_tcp_socket_params_;
scoped_refptr<SSLSocketParams> ignored_ssl_socket_params_;
- scoped_refptr<ClientSocketPoolHistograms> tcp_histograms_;
+ ClientSocketPoolHistograms tcp_histograms_;
MockClientSocketFactory tcp_client_socket_factory_;
- scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_;
- scoped_refptr<MockSSLClientSocketPool> ssl_socket_pool_;
+ MockTCPClientSocketPool tcp_socket_pool_;
+ ClientSocketPoolHistograms ssl_histograms_;
+ MockSSLClientSocketPool ssl_socket_pool_;
MockClientSocketFactory socket_factory_;
scoped_refptr<HostResolver> host_resolver_;
scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_;
scoped_refptr<HttpNetworkSession> session_;
- scoped_refptr<ClientSocketPoolHistograms> http_proxy_histograms_;
- scoped_refptr<HttpProxyClientSocketPool> pool_;
+ ClientSocketPoolHistograms http_proxy_histograms_;
+ HttpProxyClientSocketPool pool_;
};
//-----------------------------------------------------------------------------
@@ -140,7 +151,7 @@ TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) {
tcp_client_socket_factory_.AddSocketDataProvider(&data);
ClientSocketHandle handle;
- int rv = handle.Init("a", GetNoTunnelParams(), LOW, NULL, pool_,
+ int rv = handle.Init("a", GetNoTunnelParams(), LOW, NULL, &pool_,
BoundNetLog());
EXPECT_EQ(OK, rv);
EXPECT_TRUE(handle.is_initialized());
@@ -170,7 +181,7 @@ TEST_P(HttpProxyClientSocketPoolTest, NeedAuth) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, pool_,
+ int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -204,7 +215,7 @@ TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, pool_,
+ int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(OK, rv);
EXPECT_TRUE(handle.is_initialized());
@@ -232,7 +243,7 @@ TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, pool_,
+ int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -254,7 +265,7 @@ TEST_P(HttpProxyClientSocketPoolTest, TCPError) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, pool_,
+ int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -288,7 +299,7 @@ TEST_P(HttpProxyClientSocketPoolTest, TunnelUnexpectedClose) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, pool_,
+ int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -317,7 +328,7 @@ TEST_P(HttpProxyClientSocketPoolTest, TunnelSetupError) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, pool_,
+ int rv = handle.Init("a", GetTunnelParams(), LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
diff --git a/net/http/http_response_body_drainer_unittest.cc b/net/http/http_response_body_drainer_unittest.cc
index 413324d..6226b98 100644
--- a/net/http/http_response_body_drainer_unittest.cc
+++ b/net/http/http_response_body_drainer_unittest.cc
@@ -16,6 +16,7 @@
#include "net/http/http_network_session.h"
#include "net/http/http_stream.h"
#include "net/proxy/proxy_service.h"
+#include "net/spdy/spdy_session_pool.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -173,7 +174,7 @@ class HttpResponseBodyDrainerTest : public testing::Test {
ProxyService::CreateDirect(),
NULL,
new SSLConfigServiceDefaults,
- NULL,
+ new SpdySessionPool(NULL),
NULL,
NULL,
NULL)),
diff --git a/net/http/http_stream_request.cc b/net/http/http_stream_request.cc
index 2761e1b..67aefb0 100644
--- a/net/http/http_stream_request.cc
+++ b/net/http/http_stream_request.cc
@@ -15,9 +15,15 @@
#include "net/http/http_basic_stream.h"
#include "net/http/http_network_session.h"
#include "net/http/http_proxy_client_socket.h"
+#include "net/http/http_proxy_client_socket_pool.h"
#include "net/http/http_request_info.h"
#include "net/socket/client_socket_handle.h"
+#include "net/socket/client_socket_handle.h"
+#include "net/socket/socks_client_socket_pool.h"
+#include "net/socket/ssl_client_socket.h"
#include "net/socket/ssl_client_socket.h"
+#include "net/socket/ssl_client_socket_pool.h"
+#include "net/socket/tcp_client_socket_pool.h"
#include "net/spdy/spdy_http_stream.h"
#include "net/spdy/spdy_session.h"
#include "net/spdy/spdy_session_pool.h"
@@ -536,7 +542,7 @@ int HttpStreamRequest::DoInitConnection() {
GenerateSslParams(tcp_params, http_proxy_params, socks_params,
proxy_info()->proxy_server().scheme(),
want_spdy_over_npn);
- scoped_refptr<SSLClientSocketPool> ssl_pool;
+ SSLClientSocketPool* ssl_pool = NULL;
if (proxy_info()->is_direct())
ssl_pool = session_->ssl_socket_pool();
else
@@ -803,7 +809,7 @@ scoped_refptr<SSLSocketParams> HttpStreamRequest::GenerateSslParams(
}
scoped_refptr<SSLSocketParams> ssl_params =
- new SSLSocketParams(tcp_params, http_proxy_params, socks_params,
+ new SSLSocketParams(tcp_params, socks_params, http_proxy_params,
proxy_scheme, request_info().url.HostNoBrackets(),
*ssl_config(), load_flags,
force_spdy_always_ && force_spdy_over_ssl_,
diff --git a/net/net.gyp b/net/net.gyp
index 2128154..5bc0bd8 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -523,6 +523,8 @@
'socket/client_socket_pool_base.h',
'socket/client_socket_pool_histograms.cc',
'socket/client_socket_pool_histograms.h',
+ 'socket/client_socket_pool_manager.cc',
+ 'socket/client_socket_pool_manager.h',
'socket/socket.h',
'socket/socks5_client_socket.cc',
'socket/socks5_client_socket.h',
diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc
index d9ccbd5..f9ab8985 100644
--- a/net/socket/client_socket_handle.cc
+++ b/net/socket/client_socket_handle.cc
@@ -92,7 +92,7 @@ void ClientSocketHandle::HandleInitCompletion(int result) {
CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value.";
setup_time_ = base::TimeTicks::Now() - init_time_;
- scoped_refptr<ClientSocketPoolHistograms> histograms = pool_->histograms();
+ ClientSocketPoolHistograms* histograms = pool_->histograms();
histograms->AddSocketType(reuse_type());
switch (reuse_type()) {
case ClientSocketHandle::UNUSED:
diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h
index e3e6cfb..406b9bb 100644
--- a/net/socket/client_socket_handle.h
+++ b/net/socket/client_socket_handle.h
@@ -74,7 +74,7 @@ class ClientSocketHandle {
const scoped_refptr<SocketParams>& socket_params,
RequestPriority priority,
CompletionCallback* callback,
- const scoped_refptr<PoolType>& pool,
+ PoolType* pool,
const BoundNetLog& net_log);
// An initialized handle can be reset, which causes it to return to the
@@ -162,7 +162,7 @@ class ClientSocketHandle {
void ResetErrorState();
bool is_initialized_;
- scoped_refptr<ClientSocketPool> pool_;
+ ClientSocketPool* pool_;
scoped_ptr<ClientSocket> socket_;
std::string group_name_;
bool is_reused_;
@@ -187,7 +187,7 @@ int ClientSocketHandle::Init(const std::string& group_name,
const scoped_refptr<SocketParams>& socket_params,
RequestPriority priority,
CompletionCallback* callback,
- const scoped_refptr<PoolType>& pool,
+ PoolType* pool,
const BoundNetLog& net_log) {
requesting_source_ = net_log.source();
diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h
index 2a14266..c727345 100644
--- a/net/socket/client_socket_pool.h
+++ b/net/socket/client_socket_pool.h
@@ -29,7 +29,7 @@ class ClientSocketPoolHistograms;
// A ClientSocketPool is used to restrict the number of sockets open at a time.
// It also maintains a list of idle persistent sockets.
//
-class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
+class ClientSocketPool {
public:
// Requests a connected socket for a group_name.
//
@@ -89,7 +89,7 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
// This flushes all state from the ClientSocketPool. This means that all
// idle and connecting sockets are discarded. Active sockets being
// held by ClientSocketPool clients will be discarded when released back to
- // the pool.
+ // the pool. Does not flush any pools wrapped by |this|.
virtual void Flush() = 0;
// Called to close any idle connections held by the connection manager.
@@ -118,7 +118,7 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
// The set of histograms specific to this pool. We can't use the standard
// UMA_HISTOGRAM_* macros because they are callsite static.
- virtual scoped_refptr<ClientSocketPoolHistograms> histograms() const = 0;
+ virtual ClientSocketPoolHistograms* histograms() const = 0;
static int unused_idle_socket_timeout();
static void set_unused_idle_socket_timeout(int timeout);
@@ -131,8 +131,6 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
virtual base::TimeDelta ConnectionTimeout() const = 0;
private:
- friend class base::RefCounted<ClientSocketPool>;
-
DISALLOW_COPY_AND_ASSIGN(ClientSocketPool);
};
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index c40830d..be197f5 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -123,7 +123,9 @@ ClientSocketPoolBaseHelper::Request::Request(
CompletionCallback* callback,
RequestPriority priority,
const BoundNetLog& net_log)
- : handle_(handle), callback_(callback), priority_(priority),
+ : handle_(handle),
+ callback_(callback),
+ priority_(priority),
net_log_(net_log) {}
ClientSocketPoolBaseHelper::Request::~Request() {}
@@ -143,7 +145,8 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
used_idle_socket_timeout_(used_idle_socket_timeout),
connect_job_factory_(connect_job_factory),
connect_backup_jobs_enabled_(false),
- pool_generation_number_(0) {
+ pool_generation_number_(0),
+ method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK_LE(0, max_sockets_per_group);
DCHECK_LE(max_sockets_per_group, max_sockets);
@@ -151,13 +154,11 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
}
ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() {
- CancelAllConnectJobs();
-
- // Clean up any idle sockets. Assert that we have no remaining active
- // sockets or pending requests. They should have all been cleaned up prior
- // to the manager being destroyed.
- CloseIdleSockets();
- CHECK(group_map_.empty());
+ // Clean up any idle sockets and pending connect jobs. Assert that we have no
+ // remaining active sockets or pending requests. They should have all been
+ // cleaned up prior to |this| being destroyed.
+ Flush();
+ DCHECK(group_map_.empty());
DCHECK(pending_callback_map_.empty());
DCHECK_EQ(0, connecting_socket_count_);
@@ -623,12 +624,6 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
BoundNetLog job_log = job->net_log();
- // ConnectJobs may hold references to pools which may hold references back to
- // this pool, so RemoveConnectJob() may eventually lead to something calling
- // Release() on |this| which deletes it in the middle of this function. Hold
- // a self-reference to prevent deletion of |this|.
- const scoped_refptr<ClientSocketPoolBaseHelper> self(this);
-
if (result == OK) {
DCHECK(socket.get());
RemoveConnectJob(job, group);
@@ -854,8 +849,7 @@ void ClientSocketPoolBaseHelper::InvokeUserCallbackLater(
pending_callback_map_[handle] = CallbackResultPair(callback, rv);
MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(
- this,
+ method_factory_.NewRunnableMethod(
&ClientSocketPoolBaseHelper::InvokeUserCallback,
handle));
}
diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
index 2e33abc..ba49e9b 100644
--- a/net/socket/client_socket_pool_base.h
+++ b/net/socket/client_socket_pool_base.h
@@ -131,8 +131,7 @@ namespace internal {
// ClientSocketPoolBaseHelper. This class is not for external use, please use
// ClientSocketPoolBase instead.
class ClientSocketPoolBaseHelper
- : public base::RefCounted<ClientSocketPoolBaseHelper>,
- public ConnectJob::Delegate,
+ : public ConnectJob::Delegate,
public NetworkChangeNotifier::Observer {
public:
class Request {
@@ -181,6 +180,8 @@ class ClientSocketPoolBaseHelper
base::TimeDelta used_idle_socket_timeout,
ConnectJobFactory* connect_job_factory);
+ ~ClientSocketPoolBaseHelper();
+
// See ClientSocketPool::RequestSocket for documentation on this function.
// ClientSocketPoolBaseHelper takes ownership of |request|, which must be
// heap allocated.
@@ -351,8 +352,6 @@ class ClientSocketPoolBaseHelper
typedef std::map<const ClientSocketHandle*, CallbackResultPair>
PendingCallbackMap;
- ~ClientSocketPoolBaseHelper();
-
static void InsertRequestIntoQueue(const Request* r,
RequestQueue* pending_requests);
static const Request* RemoveRequestFromQueue(RequestQueue::iterator it,
@@ -485,6 +484,8 @@ class ClientSocketPoolBaseHelper
// make sure that they are discarded rather than reused.
int pool_generation_number_;
+ ScopedRunnableMethodFactory<ClientSocketPoolBaseHelper> method_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBaseHelper);
};
@@ -538,15 +539,14 @@ class ClientSocketPoolBase {
ClientSocketPoolBase(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
base::TimeDelta unused_idle_socket_timeout,
base::TimeDelta used_idle_socket_timeout,
ConnectJobFactory* connect_job_factory)
: histograms_(histograms),
- helper_(new internal::ClientSocketPoolBaseHelper(
- max_sockets, max_sockets_per_group,
- unused_idle_socket_timeout, used_idle_socket_timeout,
- new ConnectJobFactoryAdaptor(connect_job_factory))) {}
+ helper_(max_sockets, max_sockets_per_group,
+ unused_idle_socket_timeout, used_idle_socket_timeout,
+ new ConnectJobFactoryAdaptor(connect_job_factory)) {}
virtual ~ClientSocketPoolBase() {}
@@ -562,64 +562,64 @@ class ClientSocketPoolBase {
CompletionCallback* callback,
const BoundNetLog& net_log) {
Request* request = new Request(handle, callback, priority, params, net_log);
- return helper_->RequestSocket(group_name, request);
+ return helper_.RequestSocket(group_name, request);
}
void CancelRequest(const std::string& group_name,
ClientSocketHandle* handle) {
- return helper_->CancelRequest(group_name, handle);
+ return helper_.CancelRequest(group_name, handle);
}
void ReleaseSocket(const std::string& group_name, ClientSocket* socket,
int id) {
- return helper_->ReleaseSocket(group_name, socket, id);
+ return helper_.ReleaseSocket(group_name, socket, id);
}
- void CloseIdleSockets() { return helper_->CloseIdleSockets(); }
+ void CloseIdleSockets() { return helper_.CloseIdleSockets(); }
- int idle_socket_count() const { return helper_->idle_socket_count(); }
+ int idle_socket_count() const { return helper_.idle_socket_count(); }
int IdleSocketCountInGroup(const std::string& group_name) const {
- return helper_->IdleSocketCountInGroup(group_name);
+ return helper_.IdleSocketCountInGroup(group_name);
}
LoadState GetLoadState(const std::string& group_name,
const ClientSocketHandle* handle) const {
- return helper_->GetLoadState(group_name, handle);
+ return helper_.GetLoadState(group_name, handle);
}
virtual void OnConnectJobComplete(int result, ConnectJob* job) {
- return helper_->OnConnectJobComplete(result, job);
+ return helper_.OnConnectJobComplete(result, job);
}
int NumConnectJobsInGroup(const std::string& group_name) const {
- return helper_->NumConnectJobsInGroup(group_name);
+ return helper_.NumConnectJobsInGroup(group_name);
}
bool HasGroup(const std::string& group_name) const {
- return helper_->HasGroup(group_name);
+ return helper_.HasGroup(group_name);
}
void CleanupIdleSockets(bool force) {
- return helper_->CleanupIdleSockets(force);
+ return helper_.CleanupIdleSockets(force);
}
DictionaryValue* GetInfoAsValue(const std::string& name,
const std::string& type) const {
- return helper_->GetInfoAsValue(name, type);
+ return helper_.GetInfoAsValue(name, type);
}
base::TimeDelta ConnectionTimeout() const {
- return helper_->ConnectionTimeout();
+ return helper_.ConnectionTimeout();
}
- scoped_refptr<ClientSocketPoolHistograms> histograms() const {
+ ClientSocketPoolHistograms* histograms() const {
return histograms_;
}
- void EnableConnectBackupJobs() { helper_->EnableConnectBackupJobs(); }
+ void EnableConnectBackupJobs() { helper_.EnableConnectBackupJobs(); }
- void Flush() { helper_->Flush(); }
+ void Flush() { helper_.Flush(); }
private:
// This adaptor class exists to bridge the
@@ -654,13 +654,8 @@ class ClientSocketPoolBase {
};
// Histograms for the pool
- const scoped_refptr<ClientSocketPoolHistograms> histograms_;
-
- // The reason for reference counting here is because the operations on
- // the ClientSocketPoolBaseHelper which release sockets can cause the
- // ClientSocketPoolBase<T> reference to drop to zero. While we're deep
- // in cleanup code, we'll often hold a reference to |self|.
- scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_;
+ ClientSocketPoolHistograms* const histograms_;
+ internal::ClientSocketPoolBaseHelper helper_;
DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase);
};
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index 51aa25d..1624a46 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -359,7 +359,7 @@ class TestClientSocketPool : public ClientSocketPool {
TestClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
base::TimeDelta unused_idle_socket_timeout,
base::TimeDelta used_idle_socket_timeout,
TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory)
@@ -367,6 +367,8 @@ class TestClientSocketPool : public ClientSocketPool {
unused_idle_socket_timeout, used_idle_socket_timeout,
connect_job_factory) {}
+ virtual ~TestClientSocketPool() {}
+
virtual int RequestSocket(
const std::string& group_name,
const void* params,
@@ -422,7 +424,7 @@ class TestClientSocketPool : public ClientSocketPool {
return base_.ConnectionTimeout();
}
- virtual scoped_refptr<ClientSocketPoolHistograms> histograms() const {
+ virtual ClientSocketPoolHistograms* histograms() const {
return base_.histograms();
}
@@ -441,8 +443,6 @@ class TestClientSocketPool : public ClientSocketPool {
void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); }
private:
- ~TestClientSocketPool() {}
-
TestClientSocketPoolBase base_;
DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool);
@@ -496,11 +496,13 @@ class TestConnectJobDelegate : public ConnectJob::Delegate {
int result_;
};
-class ClientSocketPoolBaseTest : public ClientSocketPoolTest {
+class ClientSocketPoolBaseTest : public testing::Test {
protected:
ClientSocketPoolBaseTest()
: params_(new TestSocketParams()),
- histograms_(new ClientSocketPoolHistograms("ClientSocketPoolTest")) {}
+ histograms_("ClientSocketPoolTest") {}
+
+ virtual ~ClientSocketPoolBaseTest() {}
void CreatePool(int max_sockets, int max_sockets_per_group) {
CreatePoolWithIdleTimeouts(
@@ -517,45 +519,44 @@ class ClientSocketPoolBaseTest : public ClientSocketPoolTest {
base::TimeDelta used_idle_socket_timeout) {
DCHECK(!pool_.get());
connect_job_factory_ = new TestConnectJobFactory(&client_socket_factory_);
- pool_ = new TestClientSocketPool(max_sockets,
- max_sockets_per_group,
- histograms_,
- unused_idle_socket_timeout,
- used_idle_socket_timeout,
- connect_job_factory_);
+ pool_.reset(new TestClientSocketPool(max_sockets,
+ max_sockets_per_group,
+ &histograms_,
+ unused_idle_socket_timeout,
+ used_idle_socket_timeout,
+ connect_job_factory_));
}
int StartRequest(const std::string& group_name,
net::RequestPriority priority) {
- return StartRequestUsingPool<TestClientSocketPool, TestSocketParams>(
- pool_, group_name, priority, params_);
+ return test_base_.StartRequestUsingPool<
+ TestClientSocketPool, TestSocketParams>(
+ pool_.get(), group_name, priority, params_);
+ }
+
+ int GetOrderOfRequest(size_t index) const {
+ return test_base_.GetOrderOfRequest(index);
+ }
+
+ bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) {
+ return test_base_.ReleaseOneConnection(keep_alive);
}
- virtual void TearDown() {
- // We post all of our delayed tasks with a 2ms delay. I.e. they don't
- // actually become pending until 2ms after they have been created. In order
- // to flush all tasks, we need to wait so that we know there are no
- // soon-to-be-pending tasks waiting.
- PlatformThread::Sleep(10);
- MessageLoop::current()->RunAllPending();
-
- // Need to delete |pool_| before we turn late binding back off. We also need
- // to delete |requests_| because the pool is reference counted and requests
- // keep reference to it.
- // TODO(willchan): Remove this part when late binding becomes the default.
- TestClientSocketPool* pool = pool_.get();
- pool_ = NULL;
- requests_.reset();
- pool = NULL;
-
- ClientSocketPoolTest::TearDown();
+ void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) {
+ test_base_.ReleaseAllConnections(keep_alive);
}
+ TestSocketRequest* request(int i) { return test_base_.request(i); }
+ size_t requests_size() const { return test_base_.requests_size(); }
+ ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); }
+ size_t completion_count() const { return test_base_.completion_count(); }
+
MockClientSocketFactory client_socket_factory_;
TestConnectJobFactory* connect_job_factory_;
scoped_refptr<TestSocketParams> params_;
- scoped_refptr<TestClientSocketPool> pool_;
- scoped_refptr<ClientSocketPoolHistograms> histograms_;
+ ClientSocketPoolHistograms histograms_;
+ scoped_ptr<TestClientSocketPool> pool_;
+ ClientSocketPoolTest test_base_;
};
// Even though a timeout is specified, it doesn't time out on a synchronous
@@ -620,8 +621,13 @@ TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) {
ClientSocketHandle handle;
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
- EXPECT_EQ(OK, handle.Init("a", params_, kDefaultPriority, &callback, pool_,
- log.bound()));
+ EXPECT_EQ(OK,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ log.bound()));
EXPECT_TRUE(handle.is_initialized());
EXPECT_TRUE(handle.socket());
handle.Reset();
@@ -645,18 +651,23 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) {
connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
- TestSocketRequest req(&request_order_, &completion_count_);
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
// Set the additional error state members to ensure that they get cleared.
- req.handle()->set_is_ssl_error(true);
+ handle.set_is_ssl_error(true);
HttpResponseInfo info;
info.headers = new HttpResponseHeaders("");
- req.handle()->set_ssl_error_response_info(info);
- EXPECT_EQ(ERR_CONNECTION_FAILED, req.handle()->Init("a", params_,
- kDefaultPriority, &req,
- pool_, log.bound()));
- EXPECT_FALSE(req.handle()->socket());
- EXPECT_FALSE(req.handle()->is_ssl_error());
- EXPECT_TRUE(req.handle()->ssl_error_response_info().headers.get() == NULL);
+ handle.set_ssl_error_response_info(info);
+ EXPECT_EQ(ERR_CONNECTION_FAILED,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ log.bound()));
+ EXPECT_FALSE(handle.socket());
+ EXPECT_FALSE(handle.is_ssl_error());
+ EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
EXPECT_EQ(3u, log.entries().size());
EXPECT_TRUE(LogContainsBeginEvent(
@@ -678,19 +689,19 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimit) {
EXPECT_EQ(OK, StartRequest("c", kDefaultPriority));
EXPECT_EQ(OK, StartRequest("d", kDefaultPriority));
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSockets, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count());
EXPECT_EQ(ERR_IO_PENDING, StartRequest("e", kDefaultPriority));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("f", kDefaultPriority));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("g", kDefaultPriority));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSockets, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
@@ -701,7 +712,7 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimit) {
EXPECT_EQ(7, GetOrderOfRequest(7));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(8));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8));
}
TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) {
@@ -715,18 +726,18 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) {
EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSockets, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count());
// Now create a new group and verify that we don't starve it.
EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kDefaultPriority));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSockets, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
@@ -735,7 +746,7 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) {
EXPECT_EQ(5, GetOrderOfRequest(5));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(6));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(6));
}
TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) {
@@ -746,16 +757,16 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) {
EXPECT_EQ(OK, StartRequest("b", HIGHEST));
EXPECT_EQ(OK, StartRequest("a", LOWEST));
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", LOWEST));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("b", HIGHEST));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
- EXPECT_EQ(requests_.size() - kDefaultMaxSockets, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count());
// First 4 requests don't have to wait, and finish in order.
EXPECT_EQ(1, GetOrderOfRequest(1));
@@ -770,7 +781,7 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) {
EXPECT_EQ(5, GetOrderOfRequest(7));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(9));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9));
}
TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) {
@@ -781,18 +792,18 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) {
EXPECT_EQ(OK, StartRequest("b", HIGHEST));
EXPECT_EQ(OK, StartRequest("b", MEDIUM));
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", MEDIUM));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("b", HIGHEST));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSockets, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count());
// First 4 requests don't have to wait, and finish in order.
EXPECT_EQ(1, GetOrderOfRequest(1));
@@ -809,7 +820,7 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) {
EXPECT_EQ(7, GetOrderOfRequest(7));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(8));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8));
}
// Make sure that we count connecting sockets against the total limit.
@@ -835,9 +846,9 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) {
connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
EXPECT_EQ(ERR_IO_PENDING, StartRequest("e", kDefaultPriority));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
@@ -847,7 +858,7 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) {
EXPECT_EQ(5, GetOrderOfRequest(5));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(6));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(6));
}
TEST_F(ClientSocketPoolBaseTest, CorrectlyCountStalledGroups) {
@@ -868,12 +879,12 @@ TEST_F(ClientSocketPoolBaseTest, CorrectlyCountStalledGroups) {
EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count());
- EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count());
- EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count());
- EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
- EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count());
}
@@ -883,14 +894,24 @@ TEST_F(ClientSocketPoolBaseTest, StallAndThenCancelAndTriggerAvailableSocket) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
ClientSocketHandle handles[4];
for (size_t i = 0; i < arraysize(handles); ++i) {
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handles[i].Init("b", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handles[i].Init("b",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
}
// One will be stalled, cancel all the handles now.
@@ -908,17 +929,23 @@ TEST_F(ClientSocketPoolBaseTest, CancelStalledSocketAtSocketLimit) {
ClientSocketHandle handles[kDefaultMaxSockets];
TestCompletionCallback callbacks[kDefaultMaxSockets];
for (int i = 0; i < kDefaultMaxSockets; ++i) {
- EXPECT_EQ(OK, handles[i].Init(base::IntToString(i), params_,
+ EXPECT_EQ(OK, handles[i].Init(base::IntToString(i),
+ params_,
kDefaultPriority,
- &callbacks[i], pool_, BoundNetLog()));
+ &callbacks[i],
+ pool_.get(),
+ BoundNetLog()));
}
// Force a stalled group.
ClientSocketHandle stalled_handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_,
- kDefaultPriority, &callback,
- pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// Cancel the stalled request.
stalled_handle.Reset();
@@ -941,18 +968,24 @@ TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) {
ClientSocketHandle handles[kDefaultMaxSockets];
for (int i = 0; i < kDefaultMaxSockets; ++i) {
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handles[i].Init(base::IntToString(i), params_,
- kDefaultPriority, &callback,
- pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handles[i].Init(base::IntToString(i),
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
}
// Force a stalled group.
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
ClientSocketHandle stalled_handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_,
- kDefaultPriority, &callback,
- pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// Since it is stalled, it should have no connect jobs.
EXPECT_EQ(0, pool_->NumConnectJobsInGroup("foo"));
@@ -988,17 +1021,23 @@ TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) {
for (int i = 0; i < kDefaultMaxSockets; ++i) {
TestCompletionCallback callback;
EXPECT_EQ(OK, handles[i].Init(base::StringPrintf("Take 2: %d", i),
- params_, kDefaultPriority, &callback,
- pool_, BoundNetLog()));
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
}
EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count());
EXPECT_EQ(0, pool_->IdleSocketCount());
// Now we will hit the socket limit.
- EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_,
- kDefaultPriority, &callback,
- pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// Dropping out of scope will close all handles and return them to idle.
}
@@ -1020,8 +1059,12 @@ TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) {
for (int i = 0; i < kDefaultMaxSockets; ++i) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(OK, handle.Init(base::IntToString(i), params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(OK, handle.Init(base::IntToString(i),
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
}
// Flush all the DoReleaseSocket tasks.
@@ -1036,7 +1079,11 @@ TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) {
// "0" is special here, since it should be the first entry in the sorted map,
// which is the one which we would close an idle socket for. We shouldn't
// close an idle socket though, since we should reuse the idle socket.
- EXPECT_EQ(OK, handle.Init("0", params_, kDefaultPriority, &callback, pool_,
+ EXPECT_EQ(OK, handle.Init("0",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
BoundNetLog()));
EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count());
@@ -1055,11 +1102,12 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST));
- ReleaseAllConnections(KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE);
EXPECT_EQ(kDefaultMaxSocketsPerGroup,
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSocketsPerGroup, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup,
+ completion_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
@@ -1071,7 +1119,7 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests) {
EXPECT_EQ(7, GetOrderOfRequest(8));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(9));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9));
}
TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) {
@@ -1085,14 +1133,15 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
- for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_.size(); ++i)
- EXPECT_EQ(OK, requests_[i]->WaitForResult());
+ for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_size(); ++i)
+ EXPECT_EQ(OK, request(i)->WaitForResult());
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSocketsPerGroup, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup,
+ completion_count());
}
// This test will start up a RequestSocket() and then immediately Cancel() it.
@@ -1102,10 +1151,15 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) {
CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
- req.handle()->Reset();
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
+ handle.Reset();
}
TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) {
@@ -1114,16 +1168,24 @@ TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
ClientSocketHandle handle;
TestCompletionCallback callback;
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
handle.Reset();
TestCompletionCallback callback2;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback2, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback2,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback2.WaitForResult());
EXPECT_FALSE(callback.have_result());
@@ -1144,26 +1206,27 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequest) {
// Cancel a request.
size_t index_to_cancel = kDefaultMaxSocketsPerGroup + 2;
- EXPECT_FALSE(requests_[index_to_cancel]->handle()->is_initialized());
- requests_[index_to_cancel]->handle()->Reset();
+ EXPECT_FALSE((*requests())[index_to_cancel]->handle()->is_initialized());
+ (*requests())[index_to_cancel]->handle()->Reset();
- ReleaseAllConnections(KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE);
EXPECT_EQ(kDefaultMaxSocketsPerGroup,
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kDefaultMaxSocketsPerGroup - 1,
- completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup - 1,
+ completion_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
EXPECT_EQ(5, GetOrderOfRequest(3));
EXPECT_EQ(3, GetOrderOfRequest(4));
- EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(5)); // Canceled request.
+ EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound,
+ GetOrderOfRequest(5)); // Canceled request.
EXPECT_EQ(4, GetOrderOfRequest(6));
EXPECT_EQ(6, GetOrderOfRequest(7));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(8));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8));
}
class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
@@ -1197,8 +1260,12 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
within_callback_ = true;
TestCompletionCallback next_job_callback;
scoped_refptr<TestSocketParams> params = new TestSocketParams();
- int rv = handle_->Init("a", params, kDefaultPriority, &next_job_callback,
- pool_, BoundNetLog());
+ int rv = handle_->Init("a",
+ params,
+ kDefaultPriority,
+ &next_job_callback,
+ pool_,
+ BoundNetLog());
switch (next_job_type_) {
case TestConnectJob::kMockJob:
EXPECT_EQ(OK, rv);
@@ -1232,7 +1299,7 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
private:
ClientSocketHandle* const handle_;
- const scoped_refptr<TestClientSocketPool> pool_;
+ TestClientSocketPool* const pool_;
bool within_callback_;
TestConnectJobFactory* const test_connect_job_factory_;
TestConnectJob::JobType next_job_type_;
@@ -1247,7 +1314,11 @@ TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) {
RequestSocketCallback callback(
&handle, pool_.get(), connect_job_factory_,
TestConnectJob::kMockPendingJob);
- int rv = handle.Init("a", params_, kDefaultPriority, &callback, pool_,
+ int rv = handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
BoundNetLog());
ASSERT_EQ(ERR_IO_PENDING, rv);
@@ -1261,7 +1332,11 @@ TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) {
ClientSocketHandle handle;
RequestSocketCallback callback(
&handle, pool_.get(), connect_job_factory_, TestConnectJob::kMockJob);
- int rv = handle.Init("a", params_, kDefaultPriority, &callback, pool_,
+ int rv = handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
BoundNetLog());
ASSERT_EQ(ERR_IO_PENDING, rv);
@@ -1286,17 +1361,18 @@ TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) {
// Now, kDefaultMaxSocketsPerGroup requests should be active.
// Let's cancel them.
for (int i = 0; i < kDefaultMaxSocketsPerGroup; ++i) {
- ASSERT_FALSE(requests_[i]->handle()->is_initialized());
- requests_[i]->handle()->Reset();
+ ASSERT_FALSE(request(i)->handle()->is_initialized());
+ request(i)->handle()->Reset();
}
// Let's wait for the rest to complete now.
- for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_.size(); ++i) {
- EXPECT_EQ(OK, requests_[i]->WaitForResult());
- requests_[i]->handle()->Reset();
+ for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_size(); ++i) {
+ EXPECT_EQ(OK, request(i)->WaitForResult());
+ request(i)->handle()->Reset();
}
- EXPECT_EQ(requests_.size() - kDefaultMaxSocketsPerGroup, completion_count_);
+ EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup,
+ completion_count());
}
// Make sure that pending requests get serviced after active requests fail.
@@ -1314,7 +1390,7 @@ TEST_F(ClientSocketPoolBaseTest, FailingActiveRequestWithPendingRequests) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
for (size_t i = 0; i < kNumberOfRequests; ++i)
- EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult());
+ EXPECT_EQ(ERR_CONNECTION_FAILED, request(i)->WaitForResult());
}
TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) {
@@ -1322,21 +1398,29 @@ TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init("a", params_, kDefaultPriority, &req, pool_,
- BoundNetLog());
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ int rv = handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Cancel the active request.
- req.handle()->Reset();
+ handle.Reset();
- rv = req.handle()->Init("a", params_, kDefaultPriority, &req, pool_,
- BoundNetLog());
+ rv = handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, req.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
- EXPECT_FALSE(req.handle()->is_reused());
- EXPECT_EQ(1U, completion_count_);
+ EXPECT_FALSE(handle.is_reused());
EXPECT_EQ(2, client_socket_factory_.allocation_count());
}
@@ -1365,8 +1449,8 @@ TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) {
// the first release will unblock the pending request for "a". The
// second release will unblock a request for "c", becaue it is the next
// high priority socket.
- EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
- EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
// Closing idle sockets should not get us into trouble, but in the bug
// we were hitting a CHECK here.
@@ -1380,15 +1464,21 @@ TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) {
CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
- TestSocketRequest req(&request_order_, &completion_count_);
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
- int rv = req.handle()->Init("a", params_, LOWEST, &req, pool_, log.bound());
+ int rv = handle.Init("a",
+ params_,
+ LOWEST,
+ &callback,
+ pool_.get(),
+ log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
- EXPECT_EQ(OK, req.WaitForResult());
- EXPECT_TRUE(req.handle()->is_initialized());
- EXPECT_TRUE(req.handle()->socket());
- req.handle()->Reset();
+ EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_TRUE(handle.is_initialized());
+ EXPECT_TRUE(handle.socket());
+ handle.Reset();
EXPECT_EQ(4u, log.entries().size());
EXPECT_TRUE(LogContainsBeginEvent(
@@ -1408,19 +1498,24 @@ TEST_F(ClientSocketPoolBaseTest,
CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
- TestSocketRequest req(&request_order_, &completion_count_);
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
// Set the additional error state members to ensure that they get cleared.
- req.handle()->set_is_ssl_error(true);
+ handle.set_is_ssl_error(true);
HttpResponseInfo info;
info.headers = new HttpResponseHeaders("");
- req.handle()->set_ssl_error_response_info(info);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, log.bound()));
- EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
- EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult());
- EXPECT_FALSE(req.handle()->is_ssl_error());
- EXPECT_TRUE(req.handle()->ssl_error_response_info().headers.get() == NULL);
+ handle.set_ssl_error_response_info(info);
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ log.bound()));
+ EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
+ EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
+ EXPECT_FALSE(handle.is_ssl_error());
+ EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
EXPECT_EQ(3u, log.entries().size());
EXPECT_TRUE(LogContainsBeginEvent(
@@ -1438,22 +1533,34 @@ TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) {
CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- TestSocketRequest req2(&request_order_, &completion_count_);
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ ClientSocketHandle handle2;
+ TestCompletionCallback callback2;
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
CapturingBoundNetLog log2(CapturingNetLog::kUnbounded);
- EXPECT_EQ(ERR_IO_PENDING, req2.handle()->Init("a", params_, kDefaultPriority,
- &req2, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle2.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback2,
+ pool_.get(),
+ BoundNetLog()));
- req.handle()->Reset();
+ handle.Reset();
// At this point, request 2 is just waiting for the connect job to finish.
- EXPECT_EQ(OK, req2.WaitForResult());
- req2.handle()->Reset();
+ EXPECT_EQ(OK, callback2.WaitForResult());
+ handle2.Reset();
// Now request 2 has actually finished.
// TODO(eroman): Add back log expectations.
@@ -1470,14 +1577,14 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequestLimitsJobs) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST));
EXPECT_EQ(kDefaultMaxSocketsPerGroup, pool_->NumConnectJobsInGroup("a"));
- requests_[2]->handle()->Reset();
- requests_[3]->handle()->Reset();
+ (*requests())[2]->handle()->Reset();
+ (*requests())[3]->handle()->Reset();
EXPECT_EQ(kDefaultMaxSocketsPerGroup, pool_->NumConnectJobsInGroup("a"));
- requests_[1]->handle()->Reset();
+ (*requests())[1]->handle()->Reset();
EXPECT_EQ(kDefaultMaxSocketsPerGroup, pool_->NumConnectJobsInGroup("a"));
- requests_[0]->handle()->Reset();
+ (*requests())[0]->handle()->Reset();
EXPECT_EQ(kDefaultMaxSocketsPerGroup, pool_->NumConnectJobsInGroup("a"));
}
@@ -1489,8 +1596,13 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) {
// Start job 1 (async OK)
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
- TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", params_, kDefaultPriority, &req1, pool_,
+ std::vector<TestSocketRequest*> request_order;
+ size_t completion_count; // unused
+ TestSocketRequest req1(&request_order, &completion_count);
+ int rv = req1.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req1, pool_.get(),
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, req1.WaitForResult());
@@ -1499,12 +1611,20 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) {
// without a job.
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
- TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init("a", params_, kDefaultPriority, &req2, pool_,
+ TestSocketRequest req2(&request_order, &completion_count);
+ rv = req2.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req2,
+ pool_.get(),
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init("a", params_, kDefaultPriority, &req3, pool_,
+ TestSocketRequest req3(&request_order, &completion_count);
+ rv = req3.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req3,
+ pool_.get(),
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
@@ -1521,10 +1641,10 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) {
client_socket_factory_.SignalJobs();
EXPECT_EQ(OK, req3.WaitForResult());
- ASSERT_EQ(3U, request_order_.size());
- EXPECT_EQ(&req1, request_order_[0]);
- EXPECT_EQ(&req2, request_order_[1]);
- EXPECT_EQ(&req3, request_order_[2]);
+ ASSERT_EQ(3U, request_order.size());
+ EXPECT_EQ(&req1, request_order[0]);
+ EXPECT_EQ(&req2, request_order[1]);
+ EXPECT_EQ(&req3, request_order[2]);
EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
}
@@ -1535,21 +1655,35 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) {
// First two jobs are async.
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
- TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", params_, kDefaultPriority, &req1, pool_,
+ std::vector<TestSocketRequest*> request_order;
+ size_t completion_count; // unused
+ TestSocketRequest req1(&request_order, &completion_count);
+ int rv = req1.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req1,
+ pool_.get(),
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init("a", params_, kDefaultPriority, &req2, pool_,
+ TestSocketRequest req2(&request_order, &completion_count);
+ rv = req2.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req2,
+ pool_.get(),
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// The pending job is sync.
connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
- TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init("a", params_, kDefaultPriority, &req3, pool_,
+ TestSocketRequest req3(&request_order, &completion_count);
+ rv = req3.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req3,
+ pool_.get(),
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
@@ -1557,10 +1691,10 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) {
EXPECT_EQ(OK, req2.WaitForResult());
EXPECT_EQ(ERR_CONNECTION_FAILED, req3.WaitForResult());
- ASSERT_EQ(3U, request_order_.size());
- EXPECT_EQ(&req1, request_order_[0]);
- EXPECT_EQ(&req2, request_order_[1]);
- EXPECT_EQ(&req3, request_order_[2]);
+ ASSERT_EQ(3U, request_order.size());
+ EXPECT_EQ(&req1, request_order[0]);
+ EXPECT_EQ(&req2, request_order[1]);
+ EXPECT_EQ(&req3, request_order[2]);
}
TEST_F(ClientSocketPoolBaseTest, LoadState) {
@@ -1568,34 +1702,44 @@ TEST_F(ClientSocketPoolBaseTest, LoadState) {
connect_job_factory_->set_job_type(
TestConnectJob::kMockAdvancingLoadStateJob);
- TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", params_, kDefaultPriority, &req1, pool_,
- BoundNetLog());
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ int rv = handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(LOAD_STATE_IDLE, req1.handle()->GetLoadState());
+ EXPECT_EQ(LOAD_STATE_IDLE, handle.GetLoadState());
MessageLoop::current()->RunAllPending();
- TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init("a", params_, kDefaultPriority, &req2, pool_,
- BoundNetLog());
+ ClientSocketHandle handle2;
+ TestCompletionCallback callback2;
+ rv = handle2.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback2, pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_NE(LOAD_STATE_IDLE, req1.handle()->GetLoadState());
- EXPECT_NE(LOAD_STATE_IDLE, req2.handle()->GetLoadState());
+ EXPECT_NE(LOAD_STATE_IDLE, handle.GetLoadState());
+ EXPECT_NE(LOAD_STATE_IDLE, handle2.GetLoadState());
}
TEST_F(ClientSocketPoolBaseTest, Recoverable) {
CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
connect_job_factory_->set_job_type(TestConnectJob::kMockRecoverableJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, req.handle()->Init("a", params_,
- kDefaultPriority,
- &req, pool_,
- BoundNetLog()));
- EXPECT_TRUE(req.handle()->is_initialized());
- EXPECT_TRUE(req.handle()->socket());
- req.handle()->Reset();
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback, pool_.get(),
+ BoundNetLog()));
+ EXPECT_TRUE(handle.is_initialized());
+ EXPECT_TRUE(handle.socket());
}
TEST_F(ClientSocketPoolBaseTest, AsyncRecoverable) {
@@ -1603,14 +1747,19 @@ TEST_F(ClientSocketPoolBaseTest, AsyncRecoverable) {
connect_job_factory_->set_job_type(
TestConnectJob::kMockPendingRecoverableJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
- EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
- EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, req.WaitForResult());
- EXPECT_TRUE(req.handle()->is_initialized());
- EXPECT_TRUE(req.handle()->socket());
- req.handle()->Reset();
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
+ EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
+ EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, callback.WaitForResult());
+ EXPECT_TRUE(handle.is_initialized());
+ EXPECT_TRUE(handle.socket());
}
TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateSynchronous) {
@@ -1618,15 +1767,19 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateSynchronous) {
connect_job_factory_->set_job_type(
TestConnectJob::kMockAdditionalErrorStateJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_CONNECTION_FAILED, req.handle()->Init("a", params_,
- kDefaultPriority, &req,
- pool_, BoundNetLog()));
- EXPECT_FALSE(req.handle()->is_initialized());
- EXPECT_FALSE(req.handle()->socket());
- EXPECT_TRUE(req.handle()->is_ssl_error());
- EXPECT_FALSE(req.handle()->ssl_error_response_info().headers.get() == NULL);
- req.handle()->Reset();
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_CONNECTION_FAILED,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
+ EXPECT_FALSE(handle.is_initialized());
+ EXPECT_FALSE(handle.socket());
+ EXPECT_TRUE(handle.is_ssl_error());
+ EXPECT_FALSE(handle.ssl_error_response_info().headers.get() == NULL);
}
TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) {
@@ -1634,16 +1787,21 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) {
connect_job_factory_->set_job_type(
TestConnectJob::kMockPendingAdditionalErrorStateJob);
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
- EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
- EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult());
- EXPECT_FALSE(req.handle()->is_initialized());
- EXPECT_FALSE(req.handle()->socket());
- EXPECT_TRUE(req.handle()->is_ssl_error());
- EXPECT_FALSE(req.handle()->ssl_error_response_info().headers.get() == NULL);
- req.handle()->Reset();
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
+ EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
+ EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
+ EXPECT_FALSE(handle.is_initialized());
+ EXPECT_FALSE(handle.socket());
+ EXPECT_TRUE(handle.is_ssl_error());
+ EXPECT_FALSE(handle.ssl_error_response_info().headers.get() == NULL);
}
TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
@@ -1656,26 +1814,38 @@ TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
// Startup two mock pending connect jobs, which will sit in the MessageLoop.
- TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init("a", params_, LOWEST, &req, pool_, BoundNetLog());
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ int rv = handle.Init("a",
+ params_,
+ LOWEST,
+ &callback,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
+ EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
- TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init("a", params_, LOWEST, &req2, pool_, BoundNetLog());
+ ClientSocketHandle handle2;
+ TestCompletionCallback callback2;
+ rv = handle2.Init("a",
+ params_,
+ LOWEST,
+ &callback2,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req2.handle()));
+ EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle2));
// Cancel one of the requests. Wait for the other, which will get the first
// job. Release the socket. Run the loop again to make sure the second
// socket is sitting idle and the first one is released (since ReleaseSocket()
// just posts a DoReleaseSocket() task).
- req.handle()->Reset();
- EXPECT_EQ(OK, req2.WaitForResult());
+ handle.Reset();
+ EXPECT_EQ(OK, callback2.WaitForResult());
// Use the socket.
- EXPECT_EQ(1, req2.handle()->socket()->Write(NULL, 1, NULL));
- req2.handle()->Reset();
+ EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, NULL));
+ handle2.Reset();
// We post all of our delayed tasks with a 2ms delay. I.e. they don't
// actually become pending until 2ms after they have been created. In order
@@ -1691,9 +1861,14 @@ TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
pool_->CleanupTimedOutIdleSockets();
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
- rv = req.handle()->Init("a", params_, LOWEST, &req, pool_, log.bound());
+ rv = handle.Init("a",
+ params_,
+ LOWEST,
+ &callback,
+ pool_.get(),
+ log.bound());
EXPECT_EQ(OK, rv);
- EXPECT_TRUE(req.handle()->is_reused());
+ EXPECT_TRUE(handle.is_reused());
EXPECT_TRUE(LogContainsEntryWithType(
log.entries(), 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
}
@@ -1710,33 +1885,57 @@ TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) {
// Startup 4 connect jobs. Two of them will be pending.
- TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init("a", params_, LOWEST, &req, pool_, BoundNetLog());
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ int rv = handle.Init("a",
+ params_,
+ LOWEST,
+ &callback,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(OK, rv);
- TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init("a", params_, LOWEST, &req2, pool_, BoundNetLog());
+ ClientSocketHandle handle2;
+ TestCompletionCallback callback2;
+ rv = handle2.Init("a",
+ params_,
+ LOWEST,
+ &callback2,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(OK, rv);
- TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init("a", params_, LOWEST, &req3, pool_, BoundNetLog());
+ ClientSocketHandle handle3;
+ TestCompletionCallback callback3;
+ rv = handle3.Init("a",
+ params_,
+ LOWEST,
+ &callback3,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- TestSocketRequest req4(&request_order_, &completion_count_);
- rv = req4.handle()->Init("a", params_, LOWEST, &req4, pool_, BoundNetLog());
+ ClientSocketHandle handle4;
+ TestCompletionCallback callback4;
+ rv = handle4.Init("a",
+ params_,
+ LOWEST,
+ &callback4,
+ pool_.get(),
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Release two disconnected sockets.
- req.handle()->socket()->Disconnect();
- req.handle()->Reset();
- req2.handle()->socket()->Disconnect();
- req2.handle()->Reset();
+ handle.socket()->Disconnect();
+ handle.Reset();
+ handle2.socket()->Disconnect();
+ handle2.Reset();
- EXPECT_EQ(OK, req3.WaitForResult());
- EXPECT_FALSE(req3.handle()->is_reused());
- EXPECT_EQ(OK, req4.WaitForResult());
- EXPECT_FALSE(req4.handle()->is_reused());
+ EXPECT_EQ(OK, callback3.WaitForResult());
+ EXPECT_FALSE(handle3.is_reused());
+ EXPECT_EQ(OK, callback4.WaitForResult());
+ EXPECT_FALSE(handle4.is_reused());
}
// Regression test for http://crbug.com/42267.
@@ -1752,29 +1951,43 @@ TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) {
// Max out the socket limit with 2 per group.
- scoped_ptr<TestSocketRequest> req_a[4];
- scoped_ptr<TestSocketRequest> req_b[4];
+ ClientSocketHandle handle_a[4];
+ TestCompletionCallback callback_a[4];
+ ClientSocketHandle handle_b[4];
+ TestCompletionCallback callback_b[4];
for (int i = 0; i < 2; ++i) {
- req_a[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
- req_b[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
- EXPECT_EQ(OK, req_a[i]->handle()->Init("a", params_, LOWEST, req_a[i].get(),
- pool_, BoundNetLog()));
- EXPECT_EQ(OK, req_b[i]->handle()->Init("b", params_, LOWEST, req_b[i].get(),
- pool_, BoundNetLog()));
+ EXPECT_EQ(OK, handle_a[i].Init("a",
+ params_,
+ LOWEST,
+ &callback_a[i],
+ pool_.get(),
+ BoundNetLog()));
+ EXPECT_EQ(OK, handle_b[i].Init("b",
+ params_,
+ LOWEST,
+ &callback_b[i],
+ pool_.get(),
+ BoundNetLog()));
}
// Make 4 pending requests, 2 per group.
for (int i = 2; i < 4; ++i) {
- req_a[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
- req_b[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
- EXPECT_EQ(ERR_IO_PENDING, req_a[i]->handle()->Init("a", params_, LOWEST,
- req_a[i].get(), pool_,
- BoundNetLog()));
- EXPECT_EQ(ERR_IO_PENDING, req_b[i]->handle()->Init("b", params_, LOWEST,
- req_b[i].get(), pool_,
- BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle_a[i].Init("a",
+ params_,
+ LOWEST,
+ &callback_a[i],
+ pool_.get(),
+ BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle_b[i].Init("b",
+ params_,
+ LOWEST,
+ &callback_b[i],
+ pool_.get(),
+ BoundNetLog()));
}
// Release b's socket first. The order is important, because in
@@ -1782,22 +1995,22 @@ TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) {
// a are stalled, but 'a' is lower lexicographically, we'll process group 'a'
// first, which has a releasing socket, so it refuses to start up another
// ConnectJob. So, we used to infinite loop on this.
- req_b[0]->handle()->socket()->Disconnect();
- req_b[0]->handle()->Reset();
- req_a[0]->handle()->socket()->Disconnect();
- req_a[0]->handle()->Reset();
+ handle_b[0].socket()->Disconnect();
+ handle_b[0].Reset();
+ handle_a[0].socket()->Disconnect();
+ handle_a[0].Reset();
// Used to get stuck here.
MessageLoop::current()->RunAllPending();
- req_b[1]->handle()->socket()->Disconnect();
- req_b[1]->handle()->Reset();
- req_a[1]->handle()->socket()->Disconnect();
- req_a[1]->handle()->Reset();
+ handle_b[1].socket()->Disconnect();
+ handle_b[1].Reset();
+ handle_a[1].socket()->Disconnect();
+ handle_a[1].Reset();
for (int i = 2; i < 4; ++i) {
- EXPECT_EQ(OK, req_b[i]->WaitForResult());
- EXPECT_EQ(OK, req_a[i]->WaitForResult());
+ EXPECT_EQ(OK, callback_b[i].WaitForResult());
+ EXPECT_EQ(OK, callback_a[i].WaitForResult());
}
}
@@ -1812,17 +2025,17 @@ TEST_F(ClientSocketPoolBaseTest,
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
- EXPECT_EQ(OK, requests_[0]->WaitForResult());
- EXPECT_EQ(OK, requests_[1]->WaitForResult());
- EXPECT_EQ(2u, completion_count_);
+ EXPECT_EQ(OK, (*requests())[0]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[1]->WaitForResult());
+ EXPECT_EQ(2u, completion_count());
// Releases one connection.
- EXPECT_TRUE(ReleaseOneConnection(NO_KEEP_ALIVE));
- EXPECT_EQ(OK, requests_[2]->WaitForResult());
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE));
+ EXPECT_EQ(OK, (*requests())[2]->WaitForResult());
- EXPECT_TRUE(ReleaseOneConnection(NO_KEEP_ALIVE));
- EXPECT_EQ(OK, requests_[3]->WaitForResult());
- EXPECT_EQ(4u, completion_count_);
+ EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE));
+ EXPECT_EQ(OK, (*requests())[3]->WaitForResult());
+ EXPECT_EQ(4u, completion_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
@@ -1830,12 +2043,13 @@ TEST_F(ClientSocketPoolBaseTest,
EXPECT_EQ(4, GetOrderOfRequest(4));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(5));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(5));
}
class TestReleasingSocketRequest : public CallbackRunner< Tuple1<int> > {
public:
- TestReleasingSocketRequest(TestClientSocketPool* pool, int expected_result,
+ TestReleasingSocketRequest(TestClientSocketPool* pool,
+ int expected_result,
bool reset_releasing_handle)
: pool_(pool),
expected_result_(expected_result),
@@ -1852,13 +2066,16 @@ class TestReleasingSocketRequest : public CallbackRunner< Tuple1<int> > {
if (reset_releasing_handle_)
handle_.Reset();
scoped_refptr<TestSocketParams> con_params = new TestSocketParams();
- EXPECT_EQ(expected_result_, handle2_.Init("a", con_params, kDefaultPriority,
- &callback2_, pool_,
+ EXPECT_EQ(expected_result_, handle2_.Init("a",
+ con_params,
+ kDefaultPriority,
+ &callback2_,
+ pool_,
BoundNetLog()));
}
private:
- scoped_refptr<TestClientSocketPool> pool_;
+ TestClientSocketPool* const pool_;
int expected_result_;
bool reset_releasing_handle_;
ClientSocketHandle handle_;
@@ -1875,14 +2092,19 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorSocketsDontUseSlot) {
EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests_size()),
client_socket_factory_.allocation_count());
connect_job_factory_->set_job_type(
TestConnectJob::kMockPendingAdditionalErrorStateJob);
TestReleasingSocketRequest req(pool_.get(), OK, false);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ req.handle()->Init("a",
+ params_,
+ kDefaultPriority,
+ &req,
+ pool_.get(),
+ BoundNetLog()));
// The next job should complete synchronously
connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
@@ -1907,11 +2129,14 @@ TEST_F(ClientSocketPoolBaseTest, CallbackThatReleasesPool) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
- // Simulate flushing the pool.
- pool_ = NULL;
+ pool_->Flush();
// We'll call back into this now.
callback.WaitForResult();
@@ -1923,8 +2148,12 @@ TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type());
@@ -1933,8 +2162,12 @@ TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) {
handle.Reset();
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type());
}
@@ -1944,7 +2177,7 @@ class ConnectWithinCallback : public CallbackRunner< Tuple1<int> > {
ConnectWithinCallback(
const std::string& group_name,
const scoped_refptr<TestSocketParams>& params,
- const scoped_refptr<TestClientSocketPool>& pool)
+ TestClientSocketPool* pool)
: group_name_(group_name), params_(params), pool_(pool) {}
~ConnectWithinCallback() {}
@@ -1971,7 +2204,7 @@ class ConnectWithinCallback : public CallbackRunner< Tuple1<int> > {
private:
const std::string group_name_;
const scoped_refptr<TestSocketParams> params_;
- const scoped_refptr<TestClientSocketPool> pool_;
+ TestClientSocketPool* const pool_;
ClientSocketHandle handle_;
TestCompletionCallback callback_;
TestCompletionCallback nested_callback_;
@@ -1984,9 +2217,13 @@ TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) {
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle;
- ConnectWithinCallback callback("a", params_, pool_);
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ ConnectWithinCallback callback("a", params_, pool_.get());
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// Second job will be started during the first callback, and will
// asynchronously complete with OK.
@@ -2008,16 +2245,24 @@ TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) {
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// Start (MaxSockets - 1) connected sockets to reach max sockets.
connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
ClientSocketHandle handles[kDefaultMaxSockets];
for (int i = 1; i < kDefaultMaxSockets; ++i) {
TestCompletionCallback callback;
- EXPECT_EQ(OK, handles[i].Init("bar", params_, kDefaultPriority, &callback,
- pool_, BoundNetLog()));
+ EXPECT_EQ(OK, handles[i].Init("bar",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
}
MessageLoop::current()->RunAllPending();
@@ -2041,8 +2286,12 @@ TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) {
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
ASSERT_TRUE(pool_->HasGroup("bar"));
EXPECT_EQ(1, pool_->NumConnectJobsInGroup("bar"));
@@ -2065,13 +2314,21 @@ TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) {
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
ClientSocketHandle handle2;
TestCompletionCallback callback2;
- EXPECT_EQ(ERR_IO_PENDING, handle2.Init("bar", params_, kDefaultPriority,
- &callback2, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle2.Init("bar",
+ params_,
+ kDefaultPriority,
+ &callback2,
+ pool_.get(),
+ BoundNetLog()));
ASSERT_TRUE(pool_->HasGroup("bar"));
EXPECT_EQ(2, pool_->NumConnectJobsInGroup("bar"));
@@ -2094,8 +2351,13 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) {
ClientSocketHandle handle1;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle1.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback.WaitForResult());
// No idle sockets, no pending jobs.
@@ -2105,8 +2367,13 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) {
// Create a second socket to the same host, but this one will wait.
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle2;
- EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle2.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// No idle sockets, and one connecting job.
EXPECT_EQ(0, pool_->IdleSocketCount());
EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
@@ -2142,8 +2409,13 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) {
ClientSocketHandle handle1;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle1.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback.WaitForResult());
// No idle sockets, no pending jobs.
@@ -2153,8 +2425,13 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) {
// Create a second socket to the same host, but this one will wait.
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle2;
- EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle2.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// No idle sockets, and one connecting job.
EXPECT_EQ(0, pool_->IdleSocketCount());
EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
@@ -2192,8 +2469,13 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) {
ClientSocketHandle handle1;
TestCompletionCallback callback;
- EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle1.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback.WaitForResult());
// No idle sockets, no pending jobs.
@@ -2203,8 +2485,13 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) {
// Create a second socket to the same host, but this one will wait.
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
ClientSocketHandle handle2;
- EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle2.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback,
+ pool_.get(),
+ BoundNetLog()));
// No idle sockets, and one connecting job.
EXPECT_EQ(0, pool_->IdleSocketCount());
EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
@@ -2245,8 +2532,13 @@ TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) {
ClientSocketHandle handle1;
TestCompletionCallback callback1;
- EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority,
- &callback1, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle1.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback1,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
// Make the second request synchronously fail. This should make the Group
@@ -2256,8 +2548,13 @@ TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) {
TestCompletionCallback callback2;
// It'll be ERR_IO_PENDING now, but the TestConnectJob will synchronously fail
// when created.
- EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority,
- &callback2, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ handle2.Init("a",
+ params_,
+ kDefaultPriority,
+ &callback2,
+ pool_.get(),
+ BoundNetLog()));
EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
diff --git a/net/socket/client_socket_pool_histograms.cc b/net/socket/client_socket_pool_histograms.cc
index 396b4ce..873bd5b 100644
--- a/net/socket/client_socket_pool_histograms.cc
+++ b/net/socket/client_socket_pool_histograms.cc
@@ -45,6 +45,9 @@ ClientSocketPoolHistograms::ClientSocketPoolHistograms(
is_socks_connection_ = true;
}
+ClientSocketPoolHistograms::~ClientSocketPoolHistograms() {
+}
+
void ClientSocketPoolHistograms::AddSocketType(int type) const {
socket_type_->Add(type);
}
diff --git a/net/socket/client_socket_pool_histograms.h b/net/socket/client_socket_pool_histograms.h
index 7485c2f..74be341 100644
--- a/net/socket/client_socket_pool_histograms.h
+++ b/net/socket/client_socket_pool_histograms.h
@@ -13,10 +13,10 @@
namespace net {
-class ClientSocketPoolHistograms
- : public base::RefCounted<ClientSocketPoolHistograms> {
+class ClientSocketPoolHistograms {
public:
ClientSocketPoolHistograms(const std::string& pool_name);
+ ~ClientSocketPoolHistograms();
void AddSocketType(int socket_reuse_type) const;
void AddRequestTime(base::TimeDelta time) const;
@@ -24,9 +24,6 @@ class ClientSocketPoolHistograms
void AddReusedIdleTime(base::TimeDelta time) const;
private:
- friend class base::RefCounted<ClientSocketPoolHistograms>;
- ~ClientSocketPoolHistograms() {}
-
scoped_refptr<Histogram> socket_type_;
scoped_refptr<Histogram> request_time_;
scoped_refptr<Histogram> unused_idle_time_;
@@ -34,6 +31,8 @@ class ClientSocketPoolHistograms
bool is_http_proxy_connection_;
bool is_socks_connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolHistograms);
};
} // namespace net
diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc
new file mode 100644
index 0000000..423f8b2
--- /dev/null
+++ b/net/socket/client_socket_pool_manager.cc
@@ -0,0 +1,327 @@
+// Copyright (c) 2010 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.
+//
+// ClientSocketPoolManager manages access to all ClientSocketPools. It's a
+// simple container for all of them. Most importantly, it handles the lifetime
+// and destruction order properly.
+
+#include "net/socket/client_socket_pool_manager.h"
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "net/base/ssl_config_service.h"
+#include "net/http/http_proxy_client_socket_pool.h"
+#include "net/socket/client_socket_pool_histograms.h"
+#include "net/proxy/proxy_service.h"
+#include "net/socket/socks_client_socket_pool.h"
+#include "net/socket/ssl_client_socket_pool.h"
+#include "net/socket/tcp_client_socket_pool.h"
+
+namespace net {
+
+namespace {
+
+// Total limit of sockets.
+int g_max_sockets = 256;
+
+// Default to allow up to 6 connections per host. Experiment and tuning may
+// try other values (greater than 0). Too large may cause many problems, such
+// as home routers blocking the connections!?!? See http://crbug.com/12066.
+int g_max_sockets_per_group = 6;
+
+// The max number of sockets to allow per proxy server. This applies both to
+// http and SOCKS proxies. See http://crbug.com/12066 and
+// http://crbug.com/44501 for details about proxy server connection limits.
+int g_max_sockets_per_proxy_server = 32;
+
+// Appends information about all |socket_pools| to the end of |list|.
+template <class MapType>
+static void AddSocketPoolsToList(ListValue* list,
+ const MapType& socket_pools,
+ const std::string& type,
+ bool include_nested_pools) {
+ typename MapType::const_iterator socket_pool_it = socket_pools.begin();
+ for (typename MapType::const_iterator it = socket_pools.begin();
+ it != socket_pools.end(); it++) {
+ list->Append(it->second->GetInfoAsValue(it->first.ToString(),
+ type,
+ include_nested_pools));
+ }
+}
+
+} // namespace
+
+ClientSocketPoolManager::ClientSocketPoolManager(
+ NetLog* net_log,
+ ClientSocketFactory* socket_factory,
+ HostResolver* host_resolver,
+ ProxyService* proxy_service,
+ SSLConfigService* ssl_config_service)
+ : net_log_(net_log),
+ socket_factory_(socket_factory),
+ host_resolver_(host_resolver),
+ proxy_service_(proxy_service),
+ ssl_config_service_(ssl_config_service),
+ tcp_pool_histograms_("TCP"),
+ tcp_socket_pool_(new TCPClientSocketPool(
+ g_max_sockets, g_max_sockets_per_group,
+ &tcp_pool_histograms_,
+ host_resolver,
+ socket_factory_,
+ net_log)),
+ ssl_pool_histograms_("SSL2"),
+ ssl_socket_pool_(new SSLClientSocketPool(
+ g_max_sockets, g_max_sockets_per_group,
+ &ssl_pool_histograms_,
+ host_resolver,
+ socket_factory,
+ tcp_socket_pool_.get(),
+ NULL /* no socks proxy */,
+ NULL /* no http proxy */,
+ ssl_config_service,
+ net_log)),
+ tcp_for_socks_pool_histograms_("TCPforSOCKS"),
+ socks_pool_histograms_("SOCK"),
+ tcp_for_http_proxy_pool_histograms_("TCPforHTTPProxy"),
+ tcp_for_https_proxy_pool_histograms_("TCPforHTTPSProxy"),
+ ssl_for_https_proxy_pool_histograms_("SSLforHTTPSProxy"),
+ http_proxy_pool_histograms_("HTTPProxy"),
+ ssl_socket_pool_for_proxies_histograms_("SSLForProxies") {}
+
+ClientSocketPoolManager::~ClientSocketPoolManager() {}
+
+void ClientSocketPoolManager::FlushSocketPools() {
+ // Flush the highest level pools first, since higher level pools may release
+ // stuff to the lower level pools.
+
+ for (SSLSocketPoolMap::const_iterator it =
+ ssl_socket_pools_for_proxies_.begin();
+ it != ssl_socket_pools_for_proxies_.end();
+ ++it)
+ it->second->Flush();
+
+ for (HTTPProxySocketPoolMap::const_iterator it =
+ http_proxy_socket_pools_.begin();
+ it != http_proxy_socket_pools_.end();
+ ++it)
+ it->second->Flush();
+
+ for (SSLSocketPoolMap::const_iterator it =
+ ssl_socket_pools_for_https_proxies_.begin();
+ it != ssl_socket_pools_for_https_proxies_.end();
+ ++it)
+ it->second->Flush();
+
+ for (TCPSocketPoolMap::const_iterator it =
+ tcp_socket_pools_for_https_proxies_.begin();
+ it != tcp_socket_pools_for_https_proxies_.end();
+ ++it)
+ it->second->Flush();
+
+ for (TCPSocketPoolMap::const_iterator it =
+ tcp_socket_pools_for_http_proxies_.begin();
+ it != tcp_socket_pools_for_http_proxies_.end();
+ ++it)
+ it->second->Flush();
+
+ for (SOCKSSocketPoolMap::const_iterator it =
+ socks_socket_pools_.begin();
+ it != socks_socket_pools_.end();
+ ++it)
+ it->second->Flush();
+
+ for (TCPSocketPoolMap::const_iterator it =
+ tcp_socket_pools_for_socks_proxies_.begin();
+ it != tcp_socket_pools_for_socks_proxies_.end();
+ ++it)
+ it->second->Flush();
+
+ ssl_socket_pool_->Flush();
+ tcp_socket_pool_->Flush();
+}
+
+SOCKSClientSocketPool* ClientSocketPoolManager::GetSocketPoolForSOCKSProxy(
+ const HostPortPair& socks_proxy) {
+ SOCKSSocketPoolMap::const_iterator it = socks_socket_pools_.find(socks_proxy);
+ if (it != socks_socket_pools_.end()) {
+ DCHECK(ContainsKey(tcp_socket_pools_for_socks_proxies_, socks_proxy));
+ return it->second;
+ }
+
+ DCHECK(!ContainsKey(tcp_socket_pools_for_socks_proxies_, socks_proxy));
+
+ std::pair<TCPSocketPoolMap::iterator, bool> tcp_ret =
+ tcp_socket_pools_for_socks_proxies_.insert(
+ std::make_pair(
+ socks_proxy,
+ new TCPClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &tcp_for_socks_pool_histograms_,
+ host_resolver_,
+ socket_factory_,
+ net_log_)));
+ DCHECK(tcp_ret.second);
+
+ std::pair<SOCKSSocketPoolMap::iterator, bool> ret =
+ socks_socket_pools_.insert(
+ std::make_pair(socks_proxy, new SOCKSClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &socks_pool_histograms_,
+ host_resolver_,
+ tcp_ret.first->second,
+ net_log_)));
+
+ return ret.first->second;
+}
+
+HttpProxyClientSocketPool* ClientSocketPoolManager::GetSocketPoolForHTTPProxy(
+ const HostPortPair& http_proxy) {
+ HTTPProxySocketPoolMap::const_iterator it =
+ http_proxy_socket_pools_.find(http_proxy);
+ if (it != http_proxy_socket_pools_.end()) {
+ DCHECK(ContainsKey(tcp_socket_pools_for_http_proxies_, http_proxy));
+ DCHECK(ContainsKey(tcp_socket_pools_for_https_proxies_, http_proxy));
+ DCHECK(ContainsKey(ssl_socket_pools_for_https_proxies_, http_proxy));
+ return it->second;
+ }
+
+ DCHECK(!ContainsKey(tcp_socket_pools_for_http_proxies_, http_proxy));
+ DCHECK(!ContainsKey(tcp_socket_pools_for_https_proxies_, http_proxy));
+ DCHECK(!ContainsKey(ssl_socket_pools_for_https_proxies_, http_proxy));
+
+ std::pair<TCPSocketPoolMap::iterator, bool> tcp_http_ret =
+ tcp_socket_pools_for_http_proxies_.insert(
+ std::make_pair(
+ http_proxy,
+ new TCPClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &tcp_for_http_proxy_pool_histograms_,
+ host_resolver_,
+ socket_factory_,
+ net_log_)));
+ DCHECK(tcp_http_ret.second);
+
+ std::pair<TCPSocketPoolMap::iterator, bool> tcp_https_ret =
+ tcp_socket_pools_for_https_proxies_.insert(
+ std::make_pair(
+ http_proxy,
+ new TCPClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &tcp_for_https_proxy_pool_histograms_,
+ host_resolver_,
+ socket_factory_,
+ net_log_)));
+ DCHECK(tcp_https_ret.second);
+
+ std::pair<SSLSocketPoolMap::iterator, bool> ssl_https_ret =
+ ssl_socket_pools_for_https_proxies_.insert(
+ std::make_pair(
+ http_proxy,
+ new SSLClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &ssl_for_https_proxy_pool_histograms_,
+ host_resolver_,
+ socket_factory_,
+ tcp_https_ret.first->second /* https proxy */,
+ NULL /* no socks proxy */,
+ NULL /* no http proxy */,
+ ssl_config_service_, net_log_)));
+ DCHECK(tcp_https_ret.second);
+
+ std::pair<HTTPProxySocketPoolMap::iterator, bool> ret =
+ http_proxy_socket_pools_.insert(
+ std::make_pair(
+ http_proxy,
+ new HttpProxyClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &http_proxy_pool_histograms_,
+ host_resolver_,
+ tcp_http_ret.first->second,
+ ssl_https_ret.first->second,
+ net_log_)));
+
+ return ret.first->second;
+}
+
+SSLClientSocketPool* ClientSocketPoolManager::GetSocketPoolForSSLWithProxy(
+ const HostPortPair& proxy_server) {
+ SSLSocketPoolMap::const_iterator it =
+ ssl_socket_pools_for_proxies_.find(proxy_server);
+ if (it != ssl_socket_pools_for_proxies_.end())
+ return it->second;
+
+ SSLClientSocketPool* new_pool = new SSLClientSocketPool(
+ g_max_sockets_per_proxy_server, g_max_sockets_per_group,
+ &ssl_pool_histograms_,
+ host_resolver_,
+ socket_factory_,
+ NULL, /* no tcp pool, we always go through a proxy */
+ GetSocketPoolForSOCKSProxy(proxy_server),
+ GetSocketPoolForHTTPProxy(proxy_server),
+ ssl_config_service_,
+ net_log_);
+
+ std::pair<SSLSocketPoolMap::iterator, bool> ret =
+ ssl_socket_pools_for_proxies_.insert(std::make_pair(proxy_server,
+ new_pool));
+
+ return ret.first->second;
+}
+
+// static
+int ClientSocketPoolManager::max_sockets_per_group() {
+ return g_max_sockets_per_group;
+}
+
+// static
+void ClientSocketPoolManager::set_max_sockets_per_group(int socket_count) {
+ DCHECK_LT(0, socket_count);
+ // The following is a sanity check... but we should NEVER be near this value.
+ DCHECK_GT(100, socket_count);
+ g_max_sockets_per_group = socket_count;
+
+ DCHECK_GE(g_max_sockets, g_max_sockets_per_group);
+ DCHECK_GE(g_max_sockets_per_proxy_server, g_max_sockets_per_group);
+}
+
+// static
+void ClientSocketPoolManager::set_max_sockets_per_proxy_server(
+ int socket_count) {
+ DCHECK_LT(0, socket_count);
+ DCHECK_GT(100, socket_count); // Sanity check.
+ // Assert this case early on. The max number of sockets per group cannot
+ // exceed the max number of sockets per proxy server.
+ DCHECK_LE(g_max_sockets_per_group, socket_count);
+ g_max_sockets_per_proxy_server = socket_count;
+}
+
+Value* ClientSocketPoolManager::SocketPoolInfoToValue() const {
+ ListValue* list = new ListValue();
+ list->Append(tcp_socket_pool_->GetInfoAsValue("tcp_socket_pool",
+ "tcp_socket_pool",
+ false));
+ // Third parameter is false because |ssl_socket_pool_| uses |tcp_socket_pool_|
+ // internally, and do not want to add it a second time.
+ list->Append(ssl_socket_pool_->GetInfoAsValue("ssl_socket_pool",
+ "ssl_socket_pool",
+ false));
+ AddSocketPoolsToList(list,
+ http_proxy_socket_pools_,
+ "http_proxy_socket_pool",
+ true);
+ AddSocketPoolsToList(list,
+ socks_socket_pools_,
+ "socks_socket_pool",
+ true);
+
+ // Third parameter is false because |ssl_socket_pools_for_proxies_| use
+ // socket pools in |http_proxy_socket_pools_| and |socks_socket_pools_|.
+ AddSocketPoolsToList(list,
+ ssl_socket_pools_for_proxies_,
+ "ssl_socket_pool_for_proxies",
+ false);
+ return list;
+}
+
+} // namespace net
diff --git a/net/socket/client_socket_pool_manager.h b/net/socket/client_socket_pool_manager.h
new file mode 100644
index 0000000..40f831f
--- /dev/null
+++ b/net/socket/client_socket_pool_manager.h
@@ -0,0 +1,140 @@
+// Copyright (c) 2010 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.
+//
+// ClientSocketPoolManager manages access to all ClientSocketPools. It's a
+// simple container for all of them. Most importantly, it handles the lifetime
+// and destruction order properly.
+
+#ifndef NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_
+#define NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_
+#pragma once
+
+#include <map>
+#include "base/basictypes.h"
+#include "base/non_thread_safe.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "base/template_util.h"
+#include "base/stl_util-inl.h"
+#include "net/socket/client_socket_pool_histograms.h"
+
+class Value;
+
+namespace net {
+
+class ClientSocketFactory;
+class ClientSocketPoolHistograms;
+class HostPortPair;
+class HttpProxyClientSocketPool;
+class HostResolver;
+class NetLog;
+class ProxyService;
+class SOCKSClientSocketPool;
+class SSLClientSocketPool;
+class SSLConfigService;
+class TCPClientSocketPool;
+
+namespace internal {
+
+// A helper class for auto-deleting Values in the destructor.
+template <typename Key, typename Value>
+class OwnedPoolMap : public std::map<Key, Value> {
+ public:
+ OwnedPoolMap() {
+ COMPILE_ASSERT(base::is_pointer<Value>::value,
+ value_must_be_a_pointer);
+ }
+
+ ~OwnedPoolMap() {
+ STLDeleteValues(this);
+ }
+};
+
+} // internal
+
+class ClientSocketPoolManager : public NonThreadSafe {
+ public:
+ ClientSocketPoolManager(NetLog* net_log,
+ ClientSocketFactory* socket_factory,
+ HostResolver* host_resolver,
+ ProxyService* proxy_service,
+ SSLConfigService* ssl_config_service);
+ ~ClientSocketPoolManager();
+
+ void FlushSocketPools();
+
+ TCPClientSocketPool* tcp_socket_pool() { return tcp_socket_pool_.get(); }
+
+ SSLClientSocketPool* ssl_socket_pool() { return ssl_socket_pool_.get(); }
+
+ SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
+ const HostPortPair& socks_proxy);
+
+ HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
+ const HostPortPair& http_proxy);
+
+ SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
+ const HostPortPair& proxy_server);
+
+ static int max_sockets_per_group();
+ static void set_max_sockets_per_group(int socket_count);
+ static void set_max_sockets_per_proxy_server(int socket_count);
+
+ // Creates a Value summary of the state of the socket pools. The caller is
+ // responsible for deleting the returned value.
+ Value* SocketPoolInfoToValue() const;
+
+ private:
+ friend class HttpNetworkSessionPeer;
+
+ typedef internal::OwnedPoolMap<HostPortPair, TCPClientSocketPool*>
+ TCPSocketPoolMap;
+ typedef internal::OwnedPoolMap<HostPortPair, SOCKSClientSocketPool*>
+ SOCKSSocketPoolMap;
+ typedef internal::OwnedPoolMap<HostPortPair, HttpProxyClientSocketPool*>
+ HTTPProxySocketPoolMap;
+ typedef internal::OwnedPoolMap<HostPortPair, SSLClientSocketPool*>
+ SSLSocketPoolMap;
+
+ NetLog* const net_log_;
+ ClientSocketFactory* const socket_factory_;
+ const scoped_refptr<HostResolver> host_resolver_;
+ const scoped_refptr<ProxyService> proxy_service_;
+ const scoped_refptr<SSLConfigService> ssl_config_service_;
+
+ // Note: this ordering is important.
+
+ ClientSocketPoolHistograms tcp_pool_histograms_;
+ scoped_ptr<TCPClientSocketPool> tcp_socket_pool_;
+
+ ClientSocketPoolHistograms ssl_pool_histograms_;
+ scoped_ptr<SSLClientSocketPool> ssl_socket_pool_;
+
+ ClientSocketPoolHistograms tcp_for_socks_pool_histograms_;
+ TCPSocketPoolMap tcp_socket_pools_for_socks_proxies_;
+
+ ClientSocketPoolHistograms socks_pool_histograms_;
+ SOCKSSocketPoolMap socks_socket_pools_;
+
+ ClientSocketPoolHistograms tcp_for_http_proxy_pool_histograms_;
+ TCPSocketPoolMap tcp_socket_pools_for_http_proxies_;
+
+ ClientSocketPoolHistograms tcp_for_https_proxy_pool_histograms_;
+ TCPSocketPoolMap tcp_socket_pools_for_https_proxies_;
+
+ ClientSocketPoolHistograms ssl_for_https_proxy_pool_histograms_;
+ SSLSocketPoolMap ssl_socket_pools_for_https_proxies_;
+
+ ClientSocketPoolHistograms http_proxy_pool_histograms_;
+ HTTPProxySocketPoolMap http_proxy_socket_pools_;
+
+ ClientSocketPoolHistograms ssl_socket_pool_for_proxies_histograms_;
+ SSLSocketPoolMap ssl_socket_pools_for_proxies_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolManager);
+};
+
+} // namespace net
+
+#endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc
index 785110d..0c181b6 100644
--- a/net/socket/socket_test_util.cc
+++ b/net/socket/socket_test_util.cc
@@ -1005,26 +1005,10 @@ const int ClientSocketPoolTest::kIndexOutOfBounds = -1;
// static
const int ClientSocketPoolTest::kRequestNotFound = -2;
-void ClientSocketPoolTest::SetUp() {
- completion_count_ = 0;
-}
-
-void ClientSocketPoolTest::TearDown() {
- // The tests often call Reset() on handles at the end which may post
- // DoReleaseSocket() tasks.
- // Pending tasks created by client_socket_pool_base_unittest.cc are
- // posted two milliseconds into the future and thus won't become
- // scheduled until that time.
- // We wait a few milliseconds to make sure that all such future tasks
- // are ready to run, before calling RunAllPending(). This will work
- // correctly even if Sleep() finishes late (and it should never finish
- // early), as all we have to ensure is that actual wall-time has progressed
- // past the scheduled starting time of the pending task.
- PlatformThread::Sleep(10);
- MessageLoop::current()->RunAllPending();
-}
-
-int ClientSocketPoolTest::GetOrderOfRequest(size_t index) {
+ClientSocketPoolTest::ClientSocketPoolTest() : completion_count_(0) {}
+ClientSocketPoolTest::~ClientSocketPoolTest() {}
+
+int ClientSocketPoolTest::GetOrderOfRequest(size_t index) const {
index--;
if (index >= requests_.size())
return kIndexOutOfBounds;
@@ -1108,7 +1092,7 @@ void MockTCPClientSocketPool::MockConnectJob::OnConnect(int rv) {
MockTCPClientSocketPool::MockTCPClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
ClientSocketFactory* socket_factory)
: TCPClientSocketPool(max_sockets, max_sockets_per_group, histograms,
NULL, NULL, NULL),
@@ -1154,8 +1138,8 @@ MockTCPClientSocketPool::~MockTCPClientSocketPool() {}
MockSOCKSClientSocketPool::MockSOCKSClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool)
+ ClientSocketPoolHistograms* histograms,
+ TCPClientSocketPool* tcp_pool)
: SOCKSClientSocketPool(max_sockets, max_sockets_per_group, histograms,
NULL, tcp_pool, NULL),
tcp_pool_(tcp_pool) {
@@ -1201,14 +1185,12 @@ const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
MockSSLClientSocketPool::MockSSLClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
- ClientSocketFactory* socket_factory)
+ ClientSocketPoolHistograms* histograms,
+ ClientSocketFactory* socket_factory,
+ TCPClientSocketPool* tcp_pool)
: SSLClientSocketPool(max_sockets, max_sockets_per_group, histograms,
NULL, socket_factory,
- new MockTCPClientSocketPool(max_sockets,
- max_sockets_per_group,
- histograms,
- socket_factory),
+ tcp_pool,
NULL, NULL, NULL, NULL),
client_socket_factory_(socket_factory),
release_count_(0),
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 7cc6f84..7f83a70 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -702,8 +702,8 @@ class TestSocketRequest : public CallbackRunner< Tuple1<int> > {
TestCompletionCallback callback_;
};
-class ClientSocketPoolTest : public testing::Test {
- protected:
+class ClientSocketPoolTest {
+ public:
enum KeepAlive {
KEEP_ALIVE,
@@ -714,15 +714,15 @@ class ClientSocketPoolTest : public testing::Test {
static const int kIndexOutOfBounds;
static const int kRequestNotFound;
- virtual void SetUp();
- virtual void TearDown();
+ ClientSocketPoolTest();
+ ~ClientSocketPoolTest();
template <typename PoolType, typename SocketParams>
- int StartRequestUsingPool(const scoped_refptr<PoolType>& socket_pool,
+ int StartRequestUsingPool(PoolType* socket_pool,
const std::string& group_name,
RequestPriority priority,
const scoped_refptr<SocketParams>& socket_params) {
- DCHECK(socket_pool.get());
+ DCHECK(socket_pool);
TestSocketRequest* request = new TestSocketRequest(&request_order_,
&completion_count_);
requests_.push_back(request);
@@ -738,7 +738,7 @@ class ClientSocketPoolTest : public testing::Test {
// and returns order in which that request completed, in range 1..n,
// or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound
// if that request did not complete (for example was canceled).
- int GetOrderOfRequest(size_t index);
+ int GetOrderOfRequest(size_t index) const;
// Resets first initialized socket handle from |requests_|. If found such
// a handle, returns true.
@@ -747,6 +747,12 @@ class ClientSocketPoolTest : public testing::Test {
// Releases connections until there is nothing to release.
void ReleaseAllConnections(KeepAlive keep_alive);
+ TestSocketRequest* request(int i) { return requests_[i]; }
+ size_t requests_size() const { return requests_.size(); }
+ ScopedVector<TestSocketRequest>* requests() { return &requests_; }
+ size_t completion_count() const { return completion_count_; }
+
+ private:
ScopedVector<TestSocketRequest> requests_;
std::vector<TestSocketRequest*> request_order_;
size_t completion_count_;
@@ -776,9 +782,11 @@ class MockTCPClientSocketPool : public TCPClientSocketPool {
MockTCPClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
ClientSocketFactory* socket_factory);
+ virtual ~MockTCPClientSocketPool();
+
int release_count() const { return release_count_; }
int cancel_count() const { return cancel_count_; }
@@ -795,9 +803,6 @@ class MockTCPClientSocketPool : public TCPClientSocketPool {
virtual void ReleaseSocket(const std::string& group_name,
ClientSocket* socket, int id);
- protected:
- virtual ~MockTCPClientSocketPool();
-
private:
ClientSocketFactory* client_socket_factory_;
ScopedVector<MockConnectJob> job_list_;
@@ -847,8 +852,10 @@ class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
MockSOCKSClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool);
+ ClientSocketPoolHistograms* histograms,
+ TCPClientSocketPool* tcp_pool);
+
+ virtual ~MockSOCKSClientSocketPool();
// SOCKSClientSocketPool methods.
virtual int RequestSocket(const std::string& group_name,
@@ -863,11 +870,8 @@ class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
virtual void ReleaseSocket(const std::string& group_name,
ClientSocket* socket, int id);
- protected:
- virtual ~MockSOCKSClientSocketPool();
-
private:
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
+ TCPClientSocketPool* const tcp_pool_;
DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
};
@@ -909,8 +913,11 @@ class MockSSLClientSocketPool : public SSLClientSocketPool {
MockSSLClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
- ClientSocketFactory* socket_factory);
+ ClientSocketPoolHistograms* histograms,
+ ClientSocketFactory* socket_factory,
+ TCPClientSocketPool* tcp_pool);
+
+ virtual ~MockSSLClientSocketPool();
int release_count() const { return release_count_; }
int cancel_count() const { return cancel_count_; }
@@ -928,9 +935,6 @@ class MockSSLClientSocketPool : public SSLClientSocketPool {
virtual void ReleaseSocket(const std::string& group_name,
ClientSocket* socket, int id);
- protected:
- virtual ~MockSSLClientSocketPool();
-
private:
ClientSocketFactory* client_socket_factory_;
int release_count_;
diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc
index 42aa1d4..129c075 100644
--- a/net/socket/socks_client_socket_pool.cc
+++ b/net/socket/socks_client_socket_pool.cc
@@ -43,7 +43,7 @@ SOCKSConnectJob::SOCKSConnectJob(
const std::string& group_name,
const scoped_refptr<SOCKSSocketParams>& socks_params,
const base::TimeDelta& timeout_duration,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ TCPClientSocketPool* tcp_pool,
const scoped_refptr<HostResolver>& host_resolver,
Delegate* delegate,
NetLog* net_log)
@@ -180,9 +180,9 @@ SOCKSClientSocketPool::SOCKSConnectJobFactory::ConnectionTimeout() const {
SOCKSClientSocketPool::SOCKSClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
const scoped_refptr<HostResolver>& host_resolver,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ TCPClientSocketPool* tcp_pool,
NetLog* net_log)
: tcp_pool_(tcp_pool),
base_(max_sockets, max_sockets_per_group, histograms,
@@ -219,7 +219,6 @@ void SOCKSClientSocketPool::ReleaseSocket(const std::string& group_name,
void SOCKSClientSocketPool::Flush() {
base_.Flush();
- tcp_pool_->Flush();
}
void SOCKSClientSocketPool::CloseIdleSockets() {
diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h
index fff3984..383de63 100644
--- a/net/socket/socks_client_socket_pool.h
+++ b/net/socket/socks_client_socket_pool.h
@@ -57,7 +57,7 @@ class SOCKSConnectJob : public ConnectJob {
SOCKSConnectJob(const std::string& group_name,
const scoped_refptr<SOCKSSocketParams>& params,
const base::TimeDelta& timeout_duration,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ TCPClientSocketPool* tcp_pool,
const scoped_refptr<HostResolver> &host_resolver,
Delegate* delegate,
NetLog* net_log);
@@ -91,7 +91,7 @@ class SOCKSConnectJob : public ConnectJob {
int DoSOCKSConnectComplete(int result);
scoped_refptr<SOCKSSocketParams> socks_params_;
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
+ TCPClientSocketPool* const tcp_pool_;
const scoped_refptr<HostResolver> resolver_;
State next_state_;
@@ -107,11 +107,13 @@ class SOCKSClientSocketPool : public ClientSocketPool {
SOCKSClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
const scoped_refptr<HostResolver>& host_resolver,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ TCPClientSocketPool* tcp_pool,
NetLog* net_log);
+ virtual ~SOCKSClientSocketPool();
+
// ClientSocketPool methods:
virtual int RequestSocket(const std::string& group_name,
const void* connect_params,
@@ -148,19 +150,16 @@ class SOCKSClientSocketPool : public ClientSocketPool {
return base_.ConnectionTimeout();
}
- virtual scoped_refptr<ClientSocketPoolHistograms> histograms() const {
+ virtual ClientSocketPoolHistograms* histograms() const {
return base_.histograms();
};
- protected:
- virtual ~SOCKSClientSocketPool();
-
private:
typedef ClientSocketPoolBase<SOCKSSocketParams> PoolBase;
class SOCKSConnectJobFactory : public PoolBase::ConnectJobFactory {
public:
- SOCKSConnectJobFactory(const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ SOCKSConnectJobFactory(TCPClientSocketPool* tcp_pool,
HostResolver* host_resolver,
NetLog* net_log)
: tcp_pool_(tcp_pool),
@@ -178,14 +177,14 @@ class SOCKSClientSocketPool : public ClientSocketPool {
virtual base::TimeDelta ConnectionTimeout() const;
private:
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
+ TCPClientSocketPool* const tcp_pool_;
const scoped_refptr<HostResolver> host_resolver_;
NetLog* net_log_;
DISALLOW_COPY_AND_ASSIGN(SOCKSConnectJobFactory);
};
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
+ TCPClientSocketPool* const tcp_pool_;
PoolBase base_;
DISALLOW_COPY_AND_ASSIGN(SOCKSClientSocketPool);
diff --git a/net/socket/socks_client_socket_pool_unittest.cc b/net/socket/socks_client_socket_pool_unittest.cc
index c81e8dca..9627f1a 100644
--- a/net/socket/socks_client_socket_pool_unittest.cc
+++ b/net/socket/socks_client_socket_pool_unittest.cc
@@ -23,7 +23,7 @@ namespace {
const int kMaxSockets = 32;
const int kMaxSocketsPerGroup = 6;
-class SOCKSClientSocketPoolTest : public ClientSocketPoolTest {
+class SOCKSClientSocketPoolTest : public testing::Test {
protected:
class SOCKS5MockData {
public:
@@ -55,30 +55,44 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest {
SOCKSClientSocketPoolTest()
: ignored_tcp_socket_params_(new TCPSocketParams(
HostPortPair("proxy", 80), MEDIUM, GURL(), false)),
- tcp_histograms_(new ClientSocketPoolHistograms("MockTCP")),
- tcp_socket_pool_(new MockTCPClientSocketPool(kMaxSockets,
- kMaxSocketsPerGroup, tcp_histograms_, &tcp_client_socket_factory_)),
+ tcp_histograms_("MockTCP"),
+ tcp_socket_pool_(
+ kMaxSockets, kMaxSocketsPerGroup,
+ &tcp_histograms_,
+ &tcp_client_socket_factory_),
ignored_socket_params_(new SOCKSSocketParams(
ignored_tcp_socket_params_, true, HostPortPair("host", 80), MEDIUM,
GURL())),
- socks_histograms_(new ClientSocketPoolHistograms("SOCKSUnitTest")),
- pool_(new SOCKSClientSocketPool(kMaxSockets, kMaxSocketsPerGroup,
- socks_histograms_, NULL, tcp_socket_pool_, NULL)) {
+ socks_histograms_("SOCKSUnitTest"),
+ pool_(kMaxSockets, kMaxSocketsPerGroup,
+ &socks_histograms_,
+ NULL,
+ &tcp_socket_pool_,
+ NULL) {
}
+ virtual ~SOCKSClientSocketPoolTest() {}
+
int StartRequest(const std::string& group_name, RequestPriority priority) {
- return StartRequestUsingPool(
- pool_, group_name, priority, ignored_socket_params_);
+ return test_base_.StartRequestUsingPool(
+ &pool_, group_name, priority, ignored_socket_params_);
+ }
+
+ int GetOrderOfRequest(size_t index) const {
+ return test_base_.GetOrderOfRequest(index);
}
+ ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); }
+
scoped_refptr<TCPSocketParams> ignored_tcp_socket_params_;
- scoped_refptr<ClientSocketPoolHistograms> tcp_histograms_;
+ ClientSocketPoolHistograms tcp_histograms_;
MockClientSocketFactory tcp_client_socket_factory_;
- scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_;
+ MockTCPClientSocketPool tcp_socket_pool_;
scoped_refptr<SOCKSSocketParams> ignored_socket_params_;
- scoped_refptr<ClientSocketPoolHistograms> socks_histograms_;
- scoped_refptr<SOCKSClientSocketPool> pool_;
+ ClientSocketPoolHistograms socks_histograms_;
+ SOCKSClientSocketPool pool_;
+ ClientSocketPoolTest test_base_;
};
TEST_F(SOCKSClientSocketPoolTest, Simple) {
@@ -87,7 +101,7 @@ TEST_F(SOCKSClientSocketPoolTest, Simple) {
tcp_client_socket_factory_.AddSocketDataProvider(data.data_provider());
ClientSocketHandle handle;
- int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_,
+ int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, &pool_,
BoundNetLog());
EXPECT_EQ(OK, rv);
EXPECT_TRUE(handle.is_initialized());
@@ -100,7 +114,7 @@ TEST_F(SOCKSClientSocketPoolTest, Async) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, pool_,
+ int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -117,7 +131,7 @@ TEST_F(SOCKSClientSocketPoolTest, TCPConnectError) {
tcp_client_socket_factory_.AddSocketDataProvider(socket_data.get());
ClientSocketHandle handle;
- int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_,
+ int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -131,7 +145,7 @@ TEST_F(SOCKSClientSocketPoolTest, AsyncTCPConnectError) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, pool_,
+ int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -152,13 +166,13 @@ TEST_F(SOCKSClientSocketPoolTest, SOCKSConnectError) {
tcp_client_socket_factory_.AddSocketDataProvider(socket_data.get());
ClientSocketHandle handle;
- EXPECT_EQ(0, tcp_socket_pool_->release_count());
- int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_,
+ EXPECT_EQ(0, tcp_socket_pool_.release_count());
+ int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_SOCKS_CONNECTION_FAILED, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
- EXPECT_EQ(1, tcp_socket_pool_->release_count());
+ EXPECT_EQ(1, tcp_socket_pool_.release_count());
}
TEST_F(SOCKSClientSocketPoolTest, AsyncSOCKSConnectError) {
@@ -172,8 +186,8 @@ TEST_F(SOCKSClientSocketPoolTest, AsyncSOCKSConnectError) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- EXPECT_EQ(0, tcp_socket_pool_->release_count());
- int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, pool_,
+ EXPECT_EQ(0, tcp_socket_pool_.release_count());
+ int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -182,7 +196,7 @@ TEST_F(SOCKSClientSocketPoolTest, AsyncSOCKSConnectError) {
EXPECT_EQ(ERR_SOCKS_CONNECTION_FAILED, callback.WaitForResult());
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
- EXPECT_EQ(1, tcp_socket_pool_->release_count());
+ EXPECT_EQ(1, tcp_socket_pool_.release_count());
}
TEST_F(SOCKSClientSocketPoolTest, CancelDuringTCPConnect) {
@@ -193,28 +207,28 @@ TEST_F(SOCKSClientSocketPoolTest, CancelDuringTCPConnect) {
SOCKS5MockData data2(false);
tcp_client_socket_factory_.AddSocketDataProvider(data2.data_provider());
- EXPECT_EQ(0, tcp_socket_pool_->cancel_count());
+ EXPECT_EQ(0, tcp_socket_pool_.cancel_count());
int rv = StartRequest("a", LOW);
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = StartRequest("a", LOW);
EXPECT_EQ(ERR_IO_PENDING, rv);
- pool_->CancelRequest("a", requests_[0]->handle());
- pool_->CancelRequest("a", requests_[1]->handle());
+ pool_.CancelRequest("a", (*requests())[0]->handle());
+ pool_.CancelRequest("a", (*requests())[1]->handle());
// Requests in the connect phase don't actually get cancelled.
- EXPECT_EQ(0, tcp_socket_pool_->cancel_count());
+ EXPECT_EQ(0, tcp_socket_pool_.cancel_count());
// Now wait for the TCP sockets to connect.
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(1));
- EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(2));
- EXPECT_EQ(0, tcp_socket_pool_->cancel_count());
- EXPECT_EQ(2, pool_->IdleSocketCount());
+ EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound, GetOrderOfRequest(1));
+ EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound, GetOrderOfRequest(2));
+ EXPECT_EQ(0, tcp_socket_pool_.cancel_count());
+ EXPECT_EQ(2, pool_.IdleSocketCount());
- requests_[0]->handle()->Reset();
- requests_[1]->handle()->Reset();
+ (*requests())[0]->handle()->Reset();
+ (*requests())[1]->handle()->Reset();
}
TEST_F(SOCKSClientSocketPoolTest, CancelDuringSOCKSConnect) {
@@ -227,31 +241,31 @@ TEST_F(SOCKSClientSocketPoolTest, CancelDuringSOCKSConnect) {
data2.data_provider()->set_connect_data(MockConnect(false, 0));
tcp_client_socket_factory_.AddSocketDataProvider(data2.data_provider());
- EXPECT_EQ(0, tcp_socket_pool_->cancel_count());
- EXPECT_EQ(0, tcp_socket_pool_->release_count());
+ EXPECT_EQ(0, tcp_socket_pool_.cancel_count());
+ EXPECT_EQ(0, tcp_socket_pool_.release_count());
int rv = StartRequest("a", LOW);
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = StartRequest("a", LOW);
EXPECT_EQ(ERR_IO_PENDING, rv);
- pool_->CancelRequest("a", requests_[0]->handle());
- pool_->CancelRequest("a", requests_[1]->handle());
- EXPECT_EQ(0, tcp_socket_pool_->cancel_count());
+ pool_.CancelRequest("a", (*requests())[0]->handle());
+ pool_.CancelRequest("a", (*requests())[1]->handle());
+ EXPECT_EQ(0, tcp_socket_pool_.cancel_count());
// Requests in the connect phase don't actually get cancelled.
- EXPECT_EQ(0, tcp_socket_pool_->release_count());
+ EXPECT_EQ(0, tcp_socket_pool_.release_count());
// Now wait for the async data to reach the SOCKS connect jobs.
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(1));
- EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(2));
- EXPECT_EQ(0, tcp_socket_pool_->cancel_count());
- EXPECT_EQ(0, tcp_socket_pool_->release_count());
- EXPECT_EQ(2, pool_->IdleSocketCount());
+ EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound, GetOrderOfRequest(1));
+ EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound, GetOrderOfRequest(2));
+ EXPECT_EQ(0, tcp_socket_pool_.cancel_count());
+ EXPECT_EQ(0, tcp_socket_pool_.release_count());
+ EXPECT_EQ(2, pool_.IdleSocketCount());
- requests_[0]->handle()->Reset();
- requests_[1]->handle()->Reset();
+ (*requests())[0]->handle()->Reset();
+ (*requests())[1]->handle()->Reset();
}
// It would be nice to also test the timeouts in SOCKSClientSocketPool.
diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc
index e1e4cb9..ea9d04b 100644
--- a/net/socket/ssl_client_socket_pool.cc
+++ b/net/socket/ssl_client_socket_pool.cc
@@ -21,8 +21,8 @@ namespace net {
SSLSocketParams::SSLSocketParams(
const scoped_refptr<TCPSocketParams>& tcp_params,
- const scoped_refptr<HttpProxySocketParams>& http_proxy_params,
const scoped_refptr<SOCKSSocketParams>& socks_params,
+ const scoped_refptr<HttpProxySocketParams>& http_proxy_params,
ProxyServer::Scheme proxy,
const std::string& hostname,
const SSLConfig& ssl_config,
@@ -129,9 +129,9 @@ SSLConnectJob::SSLConnectJob(
const std::string& group_name,
const scoped_refptr<SSLSocketParams>& params,
const base::TimeDelta& timeout_duration,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<HttpProxyClientSocketPool>& http_proxy_pool,
- const scoped_refptr<SOCKSClientSocketPool>& socks_pool,
+ TCPClientSocketPool* tcp_pool,
+ SOCKSClientSocketPool* socks_pool,
+ HttpProxyClientSocketPool* http_proxy_pool,
ClientSocketFactory* client_socket_factory,
const scoped_refptr<HostResolver>& host_resolver,
Delegate* delegate,
@@ -140,8 +140,8 @@ SSLConnectJob::SSLConnectJob(
BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)),
params_(params),
tcp_pool_(tcp_pool),
- http_proxy_pool_(http_proxy_pool),
socks_pool_(socks_pool),
+ http_proxy_pool_(http_proxy_pool),
client_socket_factory_(client_socket_factory),
resolver_(host_resolver),
ALLOW_THIS_IN_INITIALIZER_LIST(
@@ -243,7 +243,7 @@ int SSLConnectJob::DoLoop(int result) {
}
int SSLConnectJob::DoTCPConnect() {
- DCHECK(tcp_pool_.get());
+ DCHECK(tcp_pool_);
if (SSLConfigService::dnssec_enabled())
params_->StartDNSSECResolution();
@@ -264,7 +264,7 @@ int SSLConnectJob::DoTCPConnectComplete(int result) {
}
int SSLConnectJob::DoSOCKSConnect() {
- DCHECK(socks_pool_.get());
+ DCHECK(socks_pool_);
next_state_ = STATE_SOCKS_CONNECT_COMPLETE;
transport_socket_handle_.reset(new ClientSocketHandle());
scoped_refptr<SOCKSSocketParams> socks_params = params_->socks_params();
@@ -281,7 +281,7 @@ int SSLConnectJob::DoSOCKSConnectComplete(int result) {
}
int SSLConnectJob::DoTunnelConnect() {
- DCHECK(http_proxy_pool_.get());
+ DCHECK(http_proxy_pool_);
next_state_ = STATE_TUNNEL_CONNECT_COMPLETE;
transport_socket_handle_.reset(new ClientSocketHandle());
@@ -401,21 +401,21 @@ ConnectJob* SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
const PoolBase::Request& request,
ConnectJob::Delegate* delegate) const {
return new SSLConnectJob(group_name, request.params(), ConnectionTimeout(),
- tcp_pool_, http_proxy_pool_, socks_pool_,
+ tcp_pool_, socks_pool_, http_proxy_pool_,
client_socket_factory_, host_resolver_, delegate,
net_log_);
}
SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<HttpProxyClientSocketPool>& http_proxy_pool,
- const scoped_refptr<SOCKSClientSocketPool>& socks_pool,
+ TCPClientSocketPool* tcp_pool,
+ SOCKSClientSocketPool* socks_pool,
+ HttpProxyClientSocketPool* http_proxy_pool,
ClientSocketFactory* client_socket_factory,
HostResolver* host_resolver,
NetLog* net_log)
: tcp_pool_(tcp_pool),
- http_proxy_pool_(http_proxy_pool),
socks_pool_(socks_pool),
+ http_proxy_pool_(http_proxy_pool),
client_socket_factory_(client_socket_factory),
host_resolver_(host_resolver),
net_log_(net_log) {
@@ -440,22 +440,22 @@ SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
SSLClientSocketPool::SSLClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
const scoped_refptr<HostResolver>& host_resolver,
ClientSocketFactory* client_socket_factory,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<HttpProxyClientSocketPool>& http_proxy_pool,
- const scoped_refptr<SOCKSClientSocketPool>& socks_pool,
+ TCPClientSocketPool* tcp_pool,
+ SOCKSClientSocketPool* socks_pool,
+ HttpProxyClientSocketPool* http_proxy_pool,
SSLConfigService* ssl_config_service,
NetLog* net_log)
: tcp_pool_(tcp_pool),
- http_proxy_pool_(http_proxy_pool),
socks_pool_(socks_pool),
+ http_proxy_pool_(http_proxy_pool),
base_(max_sockets, max_sockets_per_group, histograms,
base::TimeDelta::FromSeconds(
ClientSocketPool::unused_idle_socket_timeout()),
base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout),
- new SSLConnectJobFactory(tcp_pool, http_proxy_pool, socks_pool,
+ new SSLConnectJobFactory(tcp_pool, socks_pool, http_proxy_pool,
client_socket_factory, host_resolver,
net_log)),
ssl_config_service_(ssl_config_service) {
@@ -493,12 +493,6 @@ void SSLClientSocketPool::ReleaseSocket(const std::string& group_name,
void SSLClientSocketPool::Flush() {
base_.Flush();
- if (http_proxy_pool_)
- http_proxy_pool_->Flush();
- if (socks_pool_)
- socks_pool_->Flush();
- if (tcp_pool_)
- tcp_pool_->Flush();
}
void SSLClientSocketPool::CloseIdleSockets() {
@@ -526,21 +520,21 @@ DictionaryValue* SSLClientSocketPool::GetInfoAsValue(
DictionaryValue* dict = base_.GetInfoAsValue(name, type);
if (include_nested_pools) {
ListValue* list = new ListValue();
- if (tcp_pool_.get()) {
+ if (tcp_pool_) {
list->Append(tcp_pool_->GetInfoAsValue("tcp_socket_pool",
"tcp_socket_pool",
false));
}
- if (http_proxy_pool_.get()) {
- list->Append(http_proxy_pool_->GetInfoAsValue("http_proxy_pool",
- "http_proxy_pool",
- true));
- }
- if (socks_pool_.get()) {
+ if (socks_pool_) {
list->Append(socks_pool_->GetInfoAsValue("socks_pool",
"socks_pool",
true));
}
+ if (http_proxy_pool_) {
+ list->Append(http_proxy_pool_->GetInfoAsValue("http_proxy_pool",
+ "http_proxy_pool",
+ true));
+ }
dict->Set("nested_pools", list);
}
return dict;
diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h
index 7a2054b..d84d147 100644
--- a/net/socket/ssl_client_socket_pool.h
+++ b/net/socket/ssl_client_socket_pool.h
@@ -39,8 +39,8 @@ class SSLSocketParams : public base::RefCounted<SSLSocketParams>,
public DNSSECProvider {
public:
SSLSocketParams(const scoped_refptr<TCPSocketParams>& tcp_params,
- const scoped_refptr<HttpProxySocketParams>& http_proxy_params,
const scoped_refptr<SOCKSSocketParams>& socks_params,
+ const scoped_refptr<HttpProxySocketParams>& http_proxy_params,
ProxyServer::Scheme proxy,
const std::string& hostname,
const SSLConfig& ssl_config,
@@ -100,9 +100,9 @@ class SSLConnectJob : public ConnectJob {
const std::string& group_name,
const scoped_refptr<SSLSocketParams>& params,
const base::TimeDelta& timeout_duration,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<HttpProxyClientSocketPool>& http_proxy_pool,
- const scoped_refptr<SOCKSClientSocketPool>& socks_pool,
+ TCPClientSocketPool* tcp_pool,
+ SOCKSClientSocketPool* socks_pool,
+ HttpProxyClientSocketPool* http_proxy_pool,
ClientSocketFactory* client_socket_factory,
const scoped_refptr<HostResolver>& host_resolver,
Delegate* delegate,
@@ -147,9 +147,9 @@ class SSLConnectJob : public ConnectJob {
int DoSSLConnectComplete(int result);
scoped_refptr<SSLSocketParams> params_;
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
- const scoped_refptr<HttpProxyClientSocketPool> http_proxy_pool_;
- const scoped_refptr<SOCKSClientSocketPool> socks_pool_;
+ TCPClientSocketPool* const tcp_pool_;
+ SOCKSClientSocketPool* const socks_pool_;
+ HttpProxyClientSocketPool* const http_proxy_pool_;
ClientSocketFactory* const client_socket_factory_;
const scoped_refptr<HostResolver> resolver_;
@@ -174,15 +174,17 @@ class SSLClientSocketPool : public ClientSocketPool,
SSLClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
const scoped_refptr<HostResolver>& host_resolver,
ClientSocketFactory* client_socket_factory,
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<HttpProxyClientSocketPool>& http_proxy_pool,
- const scoped_refptr<SOCKSClientSocketPool>& socks_pool,
+ TCPClientSocketPool* tcp_pool,
+ SOCKSClientSocketPool* socks_pool,
+ HttpProxyClientSocketPool* http_proxy_pool,
SSLConfigService* ssl_config_service,
NetLog* net_log);
+ virtual ~SSLClientSocketPool();
+
// ClientSocketPool methods:
virtual int RequestSocket(const std::string& group_name,
const void* connect_params,
@@ -219,13 +221,10 @@ class SSLClientSocketPool : public ClientSocketPool,
return base_.ConnectionTimeout();
}
- virtual scoped_refptr<ClientSocketPoolHistograms> histograms() const {
+ virtual ClientSocketPoolHistograms* histograms() const {
return base_.histograms();
};
- protected:
- virtual ~SSLClientSocketPool();
-
private:
// SSLConfigService::Observer methods:
@@ -238,9 +237,9 @@ class SSLClientSocketPool : public ClientSocketPool,
class SSLConnectJobFactory : public PoolBase::ConnectJobFactory {
public:
SSLConnectJobFactory(
- const scoped_refptr<TCPClientSocketPool>& tcp_pool,
- const scoped_refptr<HttpProxyClientSocketPool>& http_proxy_pool,
- const scoped_refptr<SOCKSClientSocketPool>& socks_pool,
+ TCPClientSocketPool* tcp_pool,
+ SOCKSClientSocketPool* socks_pool,
+ HttpProxyClientSocketPool* http_proxy_pool,
ClientSocketFactory* client_socket_factory,
HostResolver* host_resolver,
NetLog* net_log);
@@ -256,9 +255,9 @@ class SSLClientSocketPool : public ClientSocketPool,
virtual base::TimeDelta ConnectionTimeout() const { return timeout_; }
private:
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
- const scoped_refptr<HttpProxyClientSocketPool> http_proxy_pool_;
- const scoped_refptr<SOCKSClientSocketPool> socks_pool_;
+ TCPClientSocketPool* const tcp_pool_;
+ SOCKSClientSocketPool* const socks_pool_;
+ HttpProxyClientSocketPool* const http_proxy_pool_;
ClientSocketFactory* const client_socket_factory_;
const scoped_refptr<HostResolver> host_resolver_;
base::TimeDelta timeout_;
@@ -267,9 +266,9 @@ class SSLClientSocketPool : public ClientSocketPool,
DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory);
};
- const scoped_refptr<TCPClientSocketPool> tcp_pool_;
- const scoped_refptr<HttpProxyClientSocketPool> http_proxy_pool_;
- const scoped_refptr<SOCKSClientSocketPool> socks_pool_;
+ TCPClientSocketPool* const tcp_pool_;
+ SOCKSClientSocketPool* const socks_pool_;
+ HttpProxyClientSocketPool* const http_proxy_pool_;
PoolBase base_;
const scoped_refptr<SSLConfigService> ssl_config_service_;
diff --git a/net/socket/ssl_client_socket_pool_unittest.cc b/net/socket/ssl_client_socket_pool_unittest.cc
index 62d7aac..feac473 100644
--- a/net/socket/ssl_client_socket_pool_unittest.cc
+++ b/net/socket/ssl_client_socket_pool_unittest.cc
@@ -32,7 +32,7 @@ namespace {
const int kMaxSockets = 32;
const int kMaxSocketsPerGroup = 6;
-class SSLClientSocketPoolTest : public ClientSocketPoolTest {
+class SSLClientSocketPoolTest : public testing::Test {
protected:
SSLClientSocketPoolTest()
: host_resolver_(new MockHostResolver),
@@ -48,60 +48,64 @@ class SSLClientSocketPoolTest : public ClientSocketPoolTest {
NULL)),
direct_tcp_socket_params_(new TCPSocketParams(
HostPortPair("host", 443), MEDIUM, GURL(), false)),
- tcp_socket_pool_(new MockTCPClientSocketPool(
+ tcp_histograms_("MockTCP"),
+ tcp_socket_pool_(
kMaxSockets,
kMaxSocketsPerGroup,
- make_scoped_refptr(new ClientSocketPoolHistograms("MockTCP")),
- &socket_factory_)),
+ &tcp_histograms_,
+ &socket_factory_),
proxy_tcp_socket_params_(new TCPSocketParams(
HostPortPair("proxy", 443), MEDIUM, GURL(), false)),
+ socks_socket_params_(new SOCKSSocketParams(
+ proxy_tcp_socket_params_, true, HostPortPair("sockshost", 443),
+ MEDIUM, GURL())),
+ socks_histograms_("MockSOCKS"),
+ socks_socket_pool_(
+ kMaxSockets,
+ kMaxSocketsPerGroup,
+ &socks_histograms_,
+ &tcp_socket_pool_),
http_proxy_socket_params_(new HttpProxySocketParams(
proxy_tcp_socket_params_, NULL, GURL("http://host"), "",
HostPortPair("host", 80),
session_->auth_cache(),
session_->http_auth_handler_factory(),
true)),
- http_proxy_socket_pool_(new HttpProxyClientSocketPool(
+ http_proxy_histograms_("MockHttpProxy"),
+ http_proxy_socket_pool_(
kMaxSockets,
kMaxSocketsPerGroup,
- make_scoped_refptr(new ClientSocketPoolHistograms("MockHttpProxy")),
+ &http_proxy_histograms_,
new MockHostResolver,
- tcp_socket_pool_,
+ &tcp_socket_pool_,
NULL,
- NULL)),
- socks_socket_params_(new SOCKSSocketParams(
- proxy_tcp_socket_params_, true, HostPortPair("sockshost", 443),
- MEDIUM, GURL())),
- socks_socket_pool_(new MockSOCKSClientSocketPool(
- kMaxSockets,
- kMaxSocketsPerGroup,
- make_scoped_refptr(new ClientSocketPoolHistograms("MockSOCKS")),
- tcp_socket_pool_)) {
+ NULL) {
scoped_refptr<SSLConfigService> ssl_config_service(
new SSLConfigServiceDefaults);
ssl_config_service->GetSSLConfig(&ssl_config_);
}
void CreatePool(bool tcp_pool, bool http_proxy_pool, bool socks_pool) {
- pool_ = new SSLClientSocketPool(
+ ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest"));
+ pool_.reset(new SSLClientSocketPool(
kMaxSockets,
kMaxSocketsPerGroup,
- make_scoped_refptr(new ClientSocketPoolHistograms("SSLUnitTest")),
+ ssl_histograms_.get(),
NULL,
&socket_factory_,
- tcp_pool ? tcp_socket_pool_ : NULL,
- http_proxy_pool ? http_proxy_socket_pool_ : NULL,
- socks_pool ? socks_socket_pool_ : NULL,
+ tcp_pool ? &tcp_socket_pool_ : NULL,
+ socks_pool ? &socks_socket_pool_ : NULL,
+ http_proxy_pool ? &http_proxy_socket_pool_ : NULL,
NULL,
- NULL);
+ NULL));
}
scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy,
bool want_spdy_over_npn) {
return make_scoped_refptr(new SSLSocketParams(
proxy == ProxyServer::SCHEME_DIRECT ? direct_tcp_socket_params_ : NULL,
- proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL,
proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL,
+ proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL,
proxy,
"host",
ssl_config_,
@@ -123,17 +127,22 @@ class SSLClientSocketPoolTest : public ClientSocketPoolTest {
scoped_refptr<HttpNetworkSession> session_;
scoped_refptr<TCPSocketParams> direct_tcp_socket_params_;
- scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_;
+ ClientSocketPoolHistograms tcp_histograms_;
+ MockTCPClientSocketPool tcp_socket_pool_;
scoped_refptr<TCPSocketParams> proxy_tcp_socket_params_;
- scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_;
- scoped_refptr<HttpProxyClientSocketPool> http_proxy_socket_pool_;
scoped_refptr<SOCKSSocketParams> socks_socket_params_;
- scoped_refptr<MockSOCKSClientSocketPool> socks_socket_pool_;
+ ClientSocketPoolHistograms socks_histograms_;
+ MockSOCKSClientSocketPool socks_socket_pool_;
+
+ scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_;
+ ClientSocketPoolHistograms http_proxy_histograms_;
+ HttpProxyClientSocketPool http_proxy_socket_pool_;
SSLConfig ssl_config_;
- scoped_refptr<SSLClientSocketPool> pool_;
+ scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_;
+ scoped_ptr<SSLClientSocketPool> pool_;
};
TEST_F(SSLClientSocketPoolTest, TCPFail) {
@@ -146,7 +155,7 @@ TEST_F(SSLClientSocketPoolTest, TCPFail) {
false);
ClientSocketHandle handle;
- int rv = handle.Init("a", params, MEDIUM, NULL, pool_, BoundNetLog());
+ int rv = handle.Init("a", params, MEDIUM, NULL, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_CONNECTION_FAILED, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -164,7 +173,8 @@ TEST_F(SSLClientSocketPoolTest, TCPFailAsync) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -188,7 +198,8 @@ TEST_F(SSLClientSocketPoolTest, BasicDirect) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(OK, rv);
EXPECT_TRUE(handle.is_initialized());
EXPECT_TRUE(handle.socket());
@@ -206,7 +217,8 @@ TEST_F(SSLClientSocketPoolTest, BasicDirectAsync) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -228,7 +240,8 @@ TEST_F(SSLClientSocketPoolTest, DirectCertError) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -250,7 +263,8 @@ TEST_F(SSLClientSocketPoolTest, DirectSSLError) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -275,7 +289,8 @@ TEST_F(SSLClientSocketPoolTest, DirectWithNPN) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -301,7 +316,8 @@ TEST_F(SSLClientSocketPoolTest, DirectNoSPDY) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -326,7 +342,8 @@ TEST_F(SSLClientSocketPoolTest, DirectGotSPDY) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -357,7 +374,8 @@ TEST_F(SSLClientSocketPoolTest, DirectGotBonusSPDY) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -385,7 +403,8 @@ TEST_F(SSLClientSocketPoolTest, SOCKSFail) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_CONNECTION_FAILED, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -403,7 +422,8 @@ TEST_F(SSLClientSocketPoolTest, SOCKSFailAsync) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -427,7 +447,8 @@ TEST_F(SSLClientSocketPoolTest, SOCKSBasic) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(OK, rv);
EXPECT_TRUE(handle.is_initialized());
EXPECT_TRUE(handle.socket());
@@ -445,7 +466,8 @@ TEST_F(SSLClientSocketPoolTest, SOCKSBasicAsync) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -466,7 +488,8 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyFail) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -484,7 +507,8 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyFailAsync) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -520,7 +544,8 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyBasic) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(OK, rv);
EXPECT_TRUE(handle.is_initialized());
EXPECT_TRUE(handle.socket());
@@ -549,7 +574,8 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyBasicAsync) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -583,7 +609,8 @@ TEST_F(SSLClientSocketPoolTest, NeedProxyAuth) {
ClientSocketHandle handle;
TestCompletionCallback callback;
- int rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog());
+ int rv = handle.Init(
+ "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc
index b770f03..89b000e 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -192,7 +192,7 @@ base::TimeDelta
TCPClientSocketPool::TCPClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
HostResolver* host_resolver,
ClientSocketFactory* client_socket_factory,
NetLog* net_log)
diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h
index 8cc06ea..1de3870 100644
--- a/net/socket/tcp_client_socket_pool.h
+++ b/net/socket/tcp_client_socket_pool.h
@@ -115,11 +115,13 @@ class TCPClientSocketPool : public ClientSocketPool {
TCPClientSocketPool(
int max_sockets,
int max_sockets_per_group,
- const scoped_refptr<ClientSocketPoolHistograms>& histograms,
+ ClientSocketPoolHistograms* histograms,
HostResolver* host_resolver,
ClientSocketFactory* client_socket_factory,
NetLog* net_log);
+ virtual ~TCPClientSocketPool();
+
// ClientSocketPool methods:
virtual int RequestSocket(const std::string& group_name,
@@ -159,13 +161,10 @@ class TCPClientSocketPool : public ClientSocketPool {
return base_.ConnectionTimeout();
}
- virtual scoped_refptr<ClientSocketPoolHistograms> histograms() const {
+ virtual ClientSocketPoolHistograms* histograms() const {
return base_.histograms();
}
- protected:
- virtual ~TCPClientSocketPool();
-
private:
typedef ClientSocketPoolBase<TCPSocketParams> PoolBase;
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc
index ddcd5bf..1e701aa 100644
--- a/net/socket/tcp_client_socket_pool_unittest.cc
+++ b/net/socket/tcp_client_socket_pool_unittest.cc
@@ -273,7 +273,7 @@ class MockClientSocketFactory : public ClientSocketFactory {
int client_socket_index_max_;
};
-class TCPClientSocketPoolTest : public ClientSocketPoolTest {
+class TCPClientSocketPoolTest : public testing::Test {
protected:
TCPClientSocketPoolTest()
: params_(new TCPSocketParams(HostPortPair("www.google.com", 80),
@@ -282,32 +282,49 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest {
LOW, GURL(), false)),
histograms_(new ClientSocketPoolHistograms("TCPUnitTest")),
host_resolver_(new MockHostResolver),
- pool_(new TCPClientSocketPool(kMaxSockets,
- kMaxSocketsPerGroup,
- histograms_,
- host_resolver_,
- &client_socket_factory_,
- NULL)) {
+ pool_(kMaxSockets,
+ kMaxSocketsPerGroup,
+ histograms_.get(),
+ host_resolver_,
+ &client_socket_factory_,
+ NULL) {
}
int StartRequest(const std::string& group_name, RequestPriority priority) {
scoped_refptr<TCPSocketParams> params = new TCPSocketParams(
HostPortPair("www.google.com", 80), MEDIUM, GURL(), false);
- return StartRequestUsingPool(pool_, group_name, priority, params);
+ return test_base_.StartRequestUsingPool(
+ &pool_, group_name, priority, params);
}
+ int GetOrderOfRequest(size_t index) {
+ return test_base_.GetOrderOfRequest(index);
+ }
+
+ bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) {
+ return test_base_.ReleaseOneConnection(keep_alive);
+ }
+
+ void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) {
+ test_base_.ReleaseAllConnections(keep_alive);
+ }
+
+ ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); }
+ size_t completion_count() const { return test_base_.completion_count(); }
+
scoped_refptr<TCPSocketParams> params_;
scoped_refptr<TCPSocketParams> low_params_;
- scoped_refptr<ClientSocketPoolHistograms> histograms_;
+ scoped_ptr<ClientSocketPoolHistograms> histograms_;
scoped_refptr<MockHostResolver> host_resolver_;
MockClientSocketFactory client_socket_factory_;
- scoped_refptr<TCPClientSocketPool> pool_;
+ TCPClientSocketPool pool_;
+ ClientSocketPoolTest test_base_;
};
TEST_F(TCPClientSocketPoolTest, Basic) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("a", low_params_, LOW, &callback, pool_, BoundNetLog());
+ int rv = handle.Init("a", low_params_, LOW, &callback, &pool_, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -321,34 +338,36 @@ TEST_F(TCPClientSocketPoolTest, Basic) {
TEST_F(TCPClientSocketPoolTest, InitHostResolutionFailure) {
host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name");
- TestSocketRequest req(&request_order_, &completion_count_);
+ TestCompletionCallback callback;
+ ClientSocketHandle handle;
scoped_refptr<TCPSocketParams> dest = new TCPSocketParams(
"unresolvable.host.name", 80, kDefaultPriority, GURL(), false);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", dest, kDefaultPriority, &req, pool_,
- BoundNetLog()));
- EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req.WaitForResult());
+ handle.Init("a", dest, kDefaultPriority, &callback, &pool_,
+ BoundNetLog()));
+ EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult());
}
TEST_F(TCPClientSocketPoolTest, InitConnectionFailure) {
client_socket_factory_.set_client_socket_type(
MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET);
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
- EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult());
+ TestCompletionCallback callback;
+ ClientSocketHandle handle;
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
+ &callback, &pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
// Make the host resolutions complete synchronously this time.
host_resolver_->set_synchronous_mode(true);
- EXPECT_EQ(ERR_CONNECTION_FAILED, req.handle()->Init("a", params_,
- kDefaultPriority, &req,
- pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_CONNECTION_FAILED, handle.Init("a", params_,
+ kDefaultPriority, &callback,
+ &pool_, BoundNetLog()));
}
TEST_F(TCPClientSocketPoolTest, PendingRequests) {
// First request finishes asynchronously.
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
- EXPECT_EQ(OK, requests_[0]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[0]->WaitForResult());
// Make all subsequent host resolutions complete synchronously.
host_resolver_->set_synchronous_mode(true);
@@ -372,12 +391,12 @@ TEST_F(TCPClientSocketPoolTest, PendingRequests) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST));
- ReleaseAllConnections(KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE);
EXPECT_EQ(kMaxSocketsPerGroup, client_socket_factory_.allocation_count());
// One initial asynchronous request and then 10 pending requests.
- EXPECT_EQ(11U, completion_count_);
+ EXPECT_EQ(11U, completion_count());
// First part of requests, all with the same priority, finishes in FIFO order.
EXPECT_EQ(1, GetOrderOfRequest(1));
@@ -400,13 +419,13 @@ TEST_F(TCPClientSocketPoolTest, PendingRequests) {
EXPECT_EQ(9, GetOrderOfRequest(16));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(17));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(17));
}
TEST_F(TCPClientSocketPoolTest, PendingRequests_NoKeepAlive) {
// First request finishes asynchronously.
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
- EXPECT_EQ(OK, requests_[0]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[0]->WaitForResult());
// Make all subsequent host resolutions complete synchronously.
host_resolver_->set_synchronous_mode(true);
@@ -425,53 +444,48 @@ TEST_F(TCPClientSocketPoolTest, PendingRequests_NoKeepAlive) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
- ReleaseAllConnections(NO_KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
// The pending requests should finish successfully.
- EXPECT_EQ(OK, requests_[6]->WaitForResult());
- EXPECT_EQ(OK, requests_[7]->WaitForResult());
- EXPECT_EQ(OK, requests_[8]->WaitForResult());
- EXPECT_EQ(OK, requests_[9]->WaitForResult());
- EXPECT_EQ(OK, requests_[10]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[6]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[7]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[8]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[9]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[10]->WaitForResult());
- EXPECT_EQ(static_cast<int>(requests_.size()),
+ EXPECT_EQ(static_cast<int>(requests()->size()),
client_socket_factory_.allocation_count());
// First asynchronous request, and then last 5 pending requests.
- EXPECT_EQ(6U, completion_count_);
+ EXPECT_EQ(6U, completion_count());
}
// This test will start up a RequestSocket() and then immediately Cancel() it.
// The pending host resolution will eventually complete, and destroy the
// ClientSocketPool which will crash if the group was not cleared properly.
TEST_F(TCPClientSocketPoolTest, CancelRequestClearGroup) {
- TestSocketRequest req(&request_order_, &completion_count_);
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
- req.handle()->Reset();
-
- // There is a race condition here. If the worker pool doesn't post the task
- // before we get here, then this might not run ConnectingSocket::OnIOComplete
- // and therefore leak the canceled ConnectingSocket. However, other tests
- // after this will call MessageLoop::RunAllPending() which should prevent a
- // leak, unless the worker thread takes longer than all of them.
- PlatformThread::Sleep(10);
- MessageLoop::current()->RunAllPending();
+ TestCompletionCallback callback;
+ ClientSocketHandle handle;
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
+ &callback, &pool_, BoundNetLog()));
+ handle.Reset();
}
TEST_F(TCPClientSocketPoolTest, TwoRequestsCancelOne) {
- TestSocketRequest req(&request_order_, &completion_count_);
- TestSocketRequest req2(&request_order_, &completion_count_);
+ ClientSocketHandle handle;
+ TestCompletionCallback callback;
+ ClientSocketHandle handle2;
+ TestCompletionCallback callback2;
- EXPECT_EQ(ERR_IO_PENDING, req.handle()->Init("a", params_, kDefaultPriority,
- &req, pool_, BoundNetLog()));
- EXPECT_EQ(ERR_IO_PENDING, req2.handle()->Init("a", params_, kDefaultPriority,
- &req2, pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
+ &callback, &pool_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority,
+ &callback2, &pool_, BoundNetLog()));
- req.handle()->Reset();
+ handle.Reset();
- EXPECT_EQ(OK, req2.WaitForResult());
- req2.handle()->Reset();
+ EXPECT_EQ(OK, callback2.WaitForResult());
+ handle2.Reset();
}
TEST_F(TCPClientSocketPoolTest, ConnectCancelConnect) {
@@ -479,16 +493,14 @@ TEST_F(TCPClientSocketPoolTest, ConnectCancelConnect) {
MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET);
ClientSocketHandle handle;
TestCompletionCallback callback;
- TestSocketRequest req(&request_order_, &completion_count_);
-
EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback, pool_, BoundNetLog()));
+ &callback, &pool_, BoundNetLog()));
handle.Reset();
TestCompletionCallback callback2;
EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority,
- &callback2, pool_, BoundNetLog()));
+ &callback2, &pool_, BoundNetLog()));
host_resolver_->set_synchronous_mode(true);
// At this point, handle has two ConnectingSockets out for it. Due to the
@@ -509,7 +521,7 @@ TEST_F(TCPClientSocketPoolTest, ConnectCancelConnect) {
TEST_F(TCPClientSocketPoolTest, CancelRequest) {
// First request finishes asynchronously.
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
- EXPECT_EQ(OK, requests_[0]->WaitForResult());
+ EXPECT_EQ(OK, (*requests())[0]->WaitForResult());
// Make all subsequent host resolutions complete synchronously.
host_resolver_->set_synchronous_mode(true);
@@ -534,14 +546,14 @@ TEST_F(TCPClientSocketPoolTest, CancelRequest) {
// Cancel a request.
size_t index_to_cancel = kMaxSocketsPerGroup + 2;
- EXPECT_FALSE(requests_[index_to_cancel]->handle()->is_initialized());
- requests_[index_to_cancel]->handle()->Reset();
+ EXPECT_FALSE((*requests())[index_to_cancel]->handle()->is_initialized());
+ (*requests())[index_to_cancel]->handle()->Reset();
- ReleaseAllConnections(KEEP_ALIVE);
+ ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE);
EXPECT_EQ(kMaxSocketsPerGroup,
client_socket_factory_.allocation_count());
- EXPECT_EQ(requests_.size() - kMaxSocketsPerGroup, completion_count_);
+ EXPECT_EQ(requests()->size() - kMaxSocketsPerGroup, completion_count());
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
@@ -551,7 +563,8 @@ TEST_F(TCPClientSocketPoolTest, CancelRequest) {
EXPECT_EQ(6, GetOrderOfRequest(6));
EXPECT_EQ(14, GetOrderOfRequest(7));
EXPECT_EQ(7, GetOrderOfRequest(8));
- EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(9)); // Canceled request.
+ EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound,
+ GetOrderOfRequest(9)); // Canceled request.
EXPECT_EQ(9, GetOrderOfRequest(10));
EXPECT_EQ(10, GetOrderOfRequest(11));
EXPECT_EQ(11, GetOrderOfRequest(12));
@@ -561,7 +574,7 @@ TEST_F(TCPClientSocketPoolTest, CancelRequest) {
EXPECT_EQ(15, GetOrderOfRequest(16));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(17));
+ EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(17));
}
class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
@@ -588,8 +601,7 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
within_callback_ = true;
scoped_refptr<TCPSocketParams> dest = new TCPSocketParams(
HostPortPair("www.google.com", 80), LOWEST, GURL(), false);
- int rv = handle_->Init("a", dest, LOWEST, this, pool_,
- BoundNetLog());
+ int rv = handle_->Init("a", dest, LOWEST, this, pool_, BoundNetLog());
EXPECT_EQ(OK, rv);
}
}
@@ -600,17 +612,17 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
private:
ClientSocketHandle* const handle_;
- const scoped_refptr<TCPClientSocketPool> pool_;
+ TCPClientSocketPool* const pool_;
bool within_callback_;
TestCompletionCallback callback_;
};
TEST_F(TCPClientSocketPoolTest, RequestTwice) {
ClientSocketHandle handle;
- RequestSocketCallback callback(&handle, pool_.get());
+ RequestSocketCallback callback(&handle, &pool_);
scoped_refptr<TCPSocketParams> dest = new TCPSocketParams(
HostPortPair("www.google.com", 80), LOWEST, GURL(), false);
- int rv = handle.Init("a", dest, LOWEST, &callback, pool_,
+ int rv = handle.Init("a", dest, LOWEST, &callback, &pool_,
BoundNetLog());
ASSERT_EQ(ERR_IO_PENDING, rv);
@@ -641,17 +653,17 @@ TEST_F(TCPClientSocketPoolTest, CancelActiveRequestWithPendingRequests) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
// Now, kMaxSocketsPerGroup requests should be active. Let's cancel them.
- ASSERT_LE(kMaxSocketsPerGroup, static_cast<int>(requests_.size()));
+ ASSERT_LE(kMaxSocketsPerGroup, static_cast<int>(requests()->size()));
for (int i = 0; i < kMaxSocketsPerGroup; i++)
- requests_[i]->handle()->Reset();
+ (*requests())[i]->handle()->Reset();
// Let's wait for the rest to complete now.
- for (size_t i = kMaxSocketsPerGroup; i < requests_.size(); ++i) {
- EXPECT_EQ(OK, requests_[i]->WaitForResult());
- requests_[i]->handle()->Reset();
+ for (size_t i = kMaxSocketsPerGroup; i < requests()->size(); ++i) {
+ EXPECT_EQ(OK, (*requests())[i]->WaitForResult());
+ (*requests())[i]->handle()->Reset();
}
- EXPECT_EQ(requests_.size() - kMaxSocketsPerGroup, completion_count_);
+ EXPECT_EQ(requests()->size() - kMaxSocketsPerGroup, completion_count());
}
// Make sure that pending requests get serviced after active requests fail.
@@ -667,13 +679,13 @@ TEST_F(TCPClientSocketPoolTest, FailingActiveRequestWithPendingRequests) {
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
for (int i = 0; i < kNumRequests; i++)
- EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult());
+ EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult());
}
TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("a", low_params_, LOW, &callback, pool_, BoundNetLog());
+ int rv = handle.Init("a", low_params_, LOW, &callback, &pool_, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -688,13 +700,13 @@ TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) {
MessageLoop::current()->RunAllPending();
// Now we should have 1 idle socket.
- EXPECT_EQ(1, pool_->IdleSocketCount());
+ EXPECT_EQ(1, pool_.IdleSocketCount());
// After an IP address change, we should have 0 idle sockets.
NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
MessageLoop::current()->RunAllPending(); // Notification happens async.
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
}
TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) {
@@ -724,11 +736,11 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) {
for (size_t index = 0; index < arraysize(cases); ++index) {
client_socket_factory_.set_client_socket_types(cases[index], 2);
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("b", low_params_, LOW, &callback, pool_,
+ int rv = handle.Init("b", low_params_, LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -748,17 +760,11 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) {
EXPECT_TRUE(handle.socket());
// One socket is stalled, the other is active.
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
handle.Reset();
// Close all pending connect jobs and existing sockets.
- pool_->Flush();
-
- // TODO(mbelshe): Flush has a bug. UIt doesn't clean out pending connect
- // jobs. When they complete, they become idle sockets. For now, continue
- // to replace the pool_. But we really need to fix Flush().
- pool_ = new TCPClientSocketPool(kMaxSockets, kMaxSocketsPerGroup,
- histograms_, host_resolver_, &client_socket_factory_, NULL);
+ pool_.Flush();
}
}
@@ -771,11 +777,11 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketCancel) {
enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT };
for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) {
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("c", low_params_, LOW, &callback, pool_,
+ int rv = handle.Init("c", low_params_, LOW, &callback, &pool_,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
@@ -799,7 +805,7 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketCancel) {
EXPECT_FALSE(handle.socket());
// One socket is stalled, the other is active.
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
}
}
@@ -816,11 +822,11 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketFailAfterStall) {
client_socket_factory_.set_client_socket_types(case_types, 2);
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("b", low_params_, LOW, &callback, pool_, BoundNetLog());
+ int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
@@ -841,7 +847,7 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketFailAfterStall) {
EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
handle.Reset();
// Reset for the next case.
@@ -861,11 +867,11 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketFailAfterDelay) {
client_socket_factory_.set_client_socket_types(case_types, 2);
- EXPECT_EQ(0, pool_->IdleSocketCount());
+ EXPECT_EQ(0, pool_.IdleSocketCount());
TestCompletionCallback callback;
ClientSocketHandle handle;
- int rv = handle.Init("b", low_params_, LOW, &callback, pool_, BoundNetLog());
+ int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_FALSE(handle.is_initialized());
EXPECT_FALSE(handle.socket());
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 2131c49..5ddbd40 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -2328,10 +2328,10 @@ TEST_P(SpdyNetworkTransactionTest, RedirectServerPush) {
HttpStreamFactory::set_force_spdy_always(true);
TestDelegate d;
TestDelegate d2;
+ scoped_refptr<SpdyURLRequestContext> spdy_url_request_context(
+ new SpdyURLRequestContext());
{
URLRequest r(GURL("http://www.google.com/"), &d);
- SpdyURLRequestContext* spdy_url_request_context =
- new SpdyURLRequestContext();
r.set_context(spdy_url_request_context);
spdy_url_request_context->socket_factory().
AddSocketDataProvider(data.get());
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 2be38fb..53d1b5a 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -20,6 +20,7 @@
#include "net/base/net_log.h"
#include "net/base/net_util.h"
#include "net/http/http_network_session.h"
+#include "net/socket/ssl_client_socket.h"
#include "net/spdy/spdy_frame_builder.h"
#include "net/spdy/spdy_protocol.h"
#include "net/spdy/spdy_settings_storage.h"