// 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 #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 DnsRRResolver; 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 class OwnedPoolMap : public std::map { public: OwnedPoolMap() { COMPILE_ASSERT(base::is_pointer::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, DnsRRResolver* dnsrr_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 TCPSocketPoolMap; typedef internal::OwnedPoolMap SOCKSSocketPoolMap; typedef internal::OwnedPoolMap HTTPProxySocketPoolMap; typedef internal::OwnedPoolMap SSLSocketPoolMap; NetLog* const net_log_; ClientSocketFactory* const socket_factory_; HostResolver* const host_resolver_; DnsRRResolver* dnsrr_resolver_; const scoped_refptr proxy_service_; const scoped_refptr ssl_config_service_; // Note: this ordering is important. ClientSocketPoolHistograms tcp_pool_histograms_; scoped_ptr tcp_socket_pool_; ClientSocketPoolHistograms ssl_pool_histograms_; scoped_ptr 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_