client_socket_pool_manager.h 5.9 KB

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