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 // ClientSocketPoolManager manages access to all ClientSocketPools. It's a 6 // simple container for all of them. Most importantly, it handles the lifetime 7 // and destruction order properly. 8 9 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_ 10 #define NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_ 11 12 #include "base/values.h" 13 #include "net/base/completion_once_callback.h" 14 #include "net/base/net_export.h" 15 #include "net/base/request_priority.h" 16 #include "net/dns/public/secure_dns_policy.h" 17 #include "net/http/http_network_session.h" 18 #include "net/socket/client_socket_pool.h" 19 #include "url/scheme_host_port.h" 20 21 namespace net { 22 23 class ClientSocketHandle; 24 class NetLogWithSource; 25 class NetworkAnonymizationKey; 26 class ProxyInfo; 27 class ProxyChain; 28 29 struct SSLConfig; 30 31 constexpr int kDefaultMaxSocketsPerProxyChain = 32; 32 33 class NET_EXPORT_PRIVATE ClientSocketPoolManager { 34 public: 35 ClientSocketPoolManager(); 36 virtual ~ClientSocketPoolManager(); 37 38 // The setter methods below affect only newly created socket pools after the 39 // methods are called. Normally they should be called at program startup 40 // before any ClientSocketPoolManagerImpl is created. 41 static int max_sockets_per_pool(HttpNetworkSession::SocketPoolType pool_type); 42 static void set_max_sockets_per_pool( 43 HttpNetworkSession::SocketPoolType pool_type, 44 int socket_count); 45 46 static int max_sockets_per_group( 47 HttpNetworkSession::SocketPoolType pool_type); 48 static void set_max_sockets_per_group( 49 HttpNetworkSession::SocketPoolType pool_type, 50 int socket_count); 51 52 static int max_sockets_per_proxy_chain( 53 HttpNetworkSession::SocketPoolType pool_type); 54 static void set_max_sockets_per_proxy_chain( 55 HttpNetworkSession::SocketPoolType pool_type, 56 int socket_count); 57 58 static base::TimeDelta unused_idle_socket_timeout( 59 HttpNetworkSession::SocketPoolType pool_type); 60 61 // The |net_error| is returned to clients of pending socket requests, while 62 // |reason| is logged at the socket layer. 63 virtual void FlushSocketPoolsWithError(int net_error, 64 const char* net_log_reason_utf8) = 0; 65 virtual void CloseIdleSockets(const char* net_log_reason_utf8) = 0; 66 67 // Returns the socket pool for the specified ProxyChain (Which may be 68 // ProxyChain::Direct()). 69 virtual ClientSocketPool* GetSocketPool(const ProxyChain& proxy_chain) = 0; 70 71 // Creates a Value summary of the state of the socket pools. 72 virtual base::Value SocketPoolInfoToValue() const = 0; 73 }; 74 75 // A helper method that uses the passed in proxy information to initialize a 76 // ClientSocketHandle with the relevant socket pool. Use this method for 77 // HTTP/HTTPS requests. `ssl_config_for_origin` is only used if the request 78 // uses SSL and `base_ssl_config_for_proxies` is used if the proxy server(s) 79 // are HTTPS. `resolution_callback` will be invoked after the the hostname is 80 // resolved. If `resolution_callback` does not return OK, then the connection 81 // will be aborted with that value. 82 int InitSocketHandleForHttpRequest( 83 url::SchemeHostPort endpoint, 84 int request_load_flags, 85 RequestPriority request_priority, 86 HttpNetworkSession* session, 87 const ProxyInfo& proxy_info, 88 const SSLConfig& ssl_config_for_origin, 89 const SSLConfig& base_ssl_config_for_proxies, 90 PrivacyMode privacy_mode, 91 NetworkAnonymizationKey network_anonymization_key, 92 SecureDnsPolicy secure_dns_policy, 93 const SocketTag& socket_tag, 94 const NetLogWithSource& net_log, 95 ClientSocketHandle* socket_handle, 96 CompletionOnceCallback callback, 97 const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback); 98 99 // A helper method that uses the passed in proxy information to initialize a 100 // ClientSocketHandle with the relevant socket pool. Use this method for 101 // HTTP/HTTPS requests for WebSocket handshake. 102 // `ssl_config_for_origin` is only used if the request uses SSL and 103 // `base_ssl_config_for_proxies` is used if the proxy server(s) are HTTPS. 104 // `resolution_callback` will be invoked after the the hostname is resolved. If 105 // `resolution_callback` does not return OK, then the connection will be aborted 106 // with that value. This function uses WEBSOCKET_SOCKET_POOL socket pools. 107 int InitSocketHandleForWebSocketRequest( 108 url::SchemeHostPort endpoint, 109 int request_load_flags, 110 RequestPriority request_priority, 111 HttpNetworkSession* session, 112 const ProxyInfo& proxy_info, 113 const SSLConfig& ssl_config_for_origin, 114 const SSLConfig& base_ssl_config_for_proxies, 115 PrivacyMode privacy_mode, 116 NetworkAnonymizationKey network_anonymization_key, 117 const NetLogWithSource& net_log, 118 ClientSocketHandle* socket_handle, 119 CompletionOnceCallback callback, 120 const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback); 121 122 // Similar to InitSocketHandleForHttpRequest except that it initiates the 123 // desired number of preconnect streams from the relevant socket pool. 124 int PreconnectSocketsForHttpRequest( 125 url::SchemeHostPort endpoint, 126 int request_load_flags, 127 RequestPriority request_priority, 128 HttpNetworkSession* session, 129 const ProxyInfo& proxy_info, 130 const SSLConfig& ssl_config_for_origin, 131 const SSLConfig& base_ssl_config_for_proxies, 132 PrivacyMode privacy_mode, 133 NetworkAnonymizationKey network_anonymization_key, 134 SecureDnsPolicy secure_dns_policy, 135 const NetLogWithSource& net_log, 136 int num_preconnect_streams, 137 CompletionOnceCallback callback); 138 139 } // namespace net 140 141 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_ 142