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 ProxyServer; 28 29 struct SSLConfig; 30 31 constexpr int kDefaultMaxSocketsPerProxyServer = 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_server( 53 HttpNetworkSession::SocketPoolType pool_type); 54 static void set_max_sockets_per_proxy_server( 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 ProxyServer (Which may be 68 // ProxyServer::Direct()). 69 virtual ClientSocketPool* GetSocketPool(const ProxyServer& proxy_server) = 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 |ssl_config_for_proxy| is used if the proxy server is HTTPS. 79 // |resolution_callback| will be invoked after the the hostname is 80 // resolved. If |resolution_callback| does not return OK, then the 81 // connection 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& ssl_config_for_proxy, 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 103 // uses SSL and |ssl_config_for_proxy| is used if the proxy server is HTTPS. 104 // |resolution_callback| will be invoked after the the hostname is 105 // resolved. If |resolution_callback| does not return OK, then the 106 // connection will be aborted with that value. 107 // This function uses WEBSOCKET_SOCKET_POOL socket pools. 108 int InitSocketHandleForWebSocketRequest( 109 url::SchemeHostPort endpoint, 110 int request_load_flags, 111 RequestPriority request_priority, 112 HttpNetworkSession* session, 113 const ProxyInfo& proxy_info, 114 const SSLConfig& ssl_config_for_origin, 115 const SSLConfig& ssl_config_for_proxy, 116 PrivacyMode privacy_mode, 117 NetworkAnonymizationKey network_anonymization_key, 118 const NetLogWithSource& net_log, 119 ClientSocketHandle* socket_handle, 120 CompletionOnceCallback callback, 121 const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback); 122 123 // Similar to InitSocketHandleForHttpRequest except that it initiates the 124 // desired number of preconnect streams from the relevant socket pool. 125 int PreconnectSocketsForHttpRequest( 126 url::SchemeHostPort endpoint, 127 int request_load_flags, 128 RequestPriority request_priority, 129 HttpNetworkSession* session, 130 const ProxyInfo& proxy_info, 131 const SSLConfig& ssl_config_for_origin, 132 const SSLConfig& ssl_config_for_proxy, 133 PrivacyMode privacy_mode, 134 NetworkAnonymizationKey network_anonymization_key, 135 SecureDnsPolicy secure_dns_policy, 136 const NetLogWithSource& net_log, 137 int num_preconnect_streams, 138 CompletionOnceCallback callback); 139 140 } // namespace net 141 142 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_H_ 143