1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_ 6 #define NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_ 7 8 #include <map> 9 #include <memory> 10 #include <string> 11 #include <type_traits> 12 13 #include "base/compiler_specific.h" 14 #include "base/threading/thread_checker.h" 15 #include "base/values.h" 16 #include "net/base/net_export.h" 17 #include "net/http/http_network_session.h" 18 #include "net/socket/client_socket_pool_manager.h" 19 #include "net/socket/connect_job.h" 20 21 namespace net { 22 23 class ProxyChain; 24 class ClientSocketPool; 25 26 class NET_EXPORT_PRIVATE ClientSocketPoolManagerImpl 27 : public ClientSocketPoolManager { 28 public: 29 // `websocket_common_connect_job_params` is only used for direct WebSocket 30 // connections (No proxies in use). It's never used if `pool_type` is not 31 // HttpNetworkSession::SocketPoolType::WEBSOCKET_SOCKET_POOL. 32 ClientSocketPoolManagerImpl( 33 const CommonConnectJobParams& common_connect_job_params, 34 const CommonConnectJobParams& websocket_common_connect_job_params, 35 HttpNetworkSession::SocketPoolType pool_type, 36 bool cleanup_on_ip_address_change = true); 37 38 ClientSocketPoolManagerImpl(const ClientSocketPoolManagerImpl&) = delete; 39 ClientSocketPoolManagerImpl& operator=(const ClientSocketPoolManagerImpl&) = 40 delete; 41 42 ~ClientSocketPoolManagerImpl() override; 43 44 void FlushSocketPoolsWithError(int net_error, 45 const char* net_log_reason_utf8) override; 46 void CloseIdleSockets(const char* net_log_reason_utf8) override; 47 48 ClientSocketPool* GetSocketPool(const ProxyChain& proxy_chain) override; 49 50 // Creates a Value summary of the state of the socket pools. 51 base::Value SocketPoolInfoToValue() const override; 52 53 private: 54 using SocketPoolMap = std::map<ProxyChain, std::unique_ptr<ClientSocketPool>>; 55 56 const CommonConnectJobParams common_connect_job_params_; 57 // Used only for direct WebSocket connections (i.e., no proxy in use). 58 const CommonConnectJobParams websocket_common_connect_job_params_; 59 60 const HttpNetworkSession::SocketPoolType pool_type_; 61 62 const bool cleanup_on_ip_address_change_; 63 64 SocketPoolMap socket_pools_; 65 66 THREAD_CHECKER(thread_checker_); 67 }; 68 69 } // namespace net 70 71 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_ 72