blob: 682e66dcdb32b1fcac36cd0a1543ac98fe53ff05 [file] [log] [blame]
// Copyright (c) 2012 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.
#ifndef NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
#define NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "net/base/completion_once_callback.h"
#include "net/base/completion_repeating_callback.h"
#include "net/base/net_export.h"
#include "net/base/privacy_mode.h"
#include "net/http/http_response_info.h"
#include "net/socket/client_socket_pool.h"
#include "net/socket/client_socket_pool_base.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/ssl_connect_job.h"
#include "net/ssl/ssl_config_service.h"
namespace net {
class CTPolicyEnforcer;
class CertVerifier;
class ClientSocketFactory;
class ConnectJobFactory;
class CTVerifier;
class HttpProxyClientSocketPool;
class NetworkQualityEstimator;
class TransportClientSocketPool;
class TransportSecurityState;
class NET_EXPORT_PRIVATE SSLClientSocketPool
: public ClientSocketPool,
public HigherLayeredPool,
public SSLConfigService::Observer {
public:
typedef SSLSocketParams SocketParams;
// Only the pools that will be used are required. i.e. if you never
// try to create an SSL over SOCKS socket, |socks_pool| may be NULL.
SSLClientSocketPool(int max_sockets,
int max_sockets_per_group,
CertVerifier* cert_verifier,
ChannelIDService* channel_id_service,
TransportSecurityState* transport_security_state,
CTVerifier* cert_transparency_verifier,
CTPolicyEnforcer* ct_policy_enforcer,
SSLClientSessionCache* ssl_client_session_cache,
ClientSocketFactory* client_socket_factory,
TransportClientSocketPool* transport_pool,
TransportClientSocketPool* socks_pool,
HttpProxyClientSocketPool* http_proxy_pool,
SSLConfigService* ssl_config_service,
NetworkQualityEstimator* network_quality_estimator,
NetLog* net_log);
~SSLClientSocketPool() override;
// ClientSocketPool implementation.
int RequestSocket(const std::string& group_name,
const void* connect_params,
RequestPriority priority,
const SocketTag& socket_tag,
RespectLimits respect_limits,
ClientSocketHandle* handle,
CompletionOnceCallback callback,
const NetLogWithSource& net_log) override;
void RequestSockets(const std::string& group_name,
const void* params,
int num_sockets,
const NetLogWithSource& net_log) override;
void SetPriority(const std::string& group_name,
ClientSocketHandle* handle,
RequestPriority priority) override;
void CancelRequest(const std::string& group_name,
ClientSocketHandle* handle) override;
void ReleaseSocket(const std::string& group_name,
std::unique_ptr<StreamSocket> socket,
int id) override;
void FlushWithError(int error) override;
void CloseIdleSockets() override;
void CloseIdleSocketsInGroup(const std::string& group_name) override;
int IdleSocketCount() const override;
int IdleSocketCountInGroup(const std::string& group_name) const override;
LoadState GetLoadState(const std::string& group_name,
const ClientSocketHandle* handle) const override;
// Dumps memory allocation stats. |parent_dump_absolute_name| is the name
// used by the parent MemoryAllocatorDump in the memory dump hierarchy.
void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd,
const std::string& parent_dump_absolute_name) const;
std::unique_ptr<base::DictionaryValue> GetInfoAsValue(
const std::string& name,
const std::string& type,
bool include_nested_pools) const override;
// LowerLayeredPool implementation.
bool IsStalled() const override;
void AddHigherLayeredPool(HigherLayeredPool* higher_pool) override;
void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) override;
// HigherLayeredPool implementation.
bool CloseOneIdleConnection() override;
private:
typedef ClientSocketPoolBase<SSLSocketParams> PoolBase;
// SSLConfigService::Observer implementation.
// When the user changes the SSL config, we flush all idle sockets so they
// won't get re-used.
void OnSSLConfigChanged() override;
class SSLConnectJobFactory : public PoolBase::ConnectJobFactory {
public:
SSLConnectJobFactory(TransportClientSocketPool* transport_pool,
TransportClientSocketPool* socks_pool,
HttpProxyClientSocketPool* http_proxy_pool,
ClientSocketFactory* client_socket_factory,
const SSLClientSocketContext& context,
NetworkQualityEstimator* network_quality_estimator,
NetLog* net_log);
~SSLConnectJobFactory() override;
// ClientSocketPoolBase::ConnectJobFactory methods.
std::unique_ptr<ConnectJob> NewConnectJob(
const std::string& group_name,
const PoolBase::Request& request,
ConnectJob::Delegate* delegate) const override;
private:
TransportClientSocketPool* const transport_pool_;
TransportClientSocketPool* const socks_pool_;
HttpProxyClientSocketPool* const http_proxy_pool_;
ClientSocketFactory* const client_socket_factory_;
const SSLClientSocketContext context_;
NetworkQualityEstimator* const network_quality_estimator_;
NetLog* net_log_;
DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory);
};
TransportClientSocketPool* const transport_pool_;
TransportClientSocketPool* const socks_pool_;
HttpProxyClientSocketPool* const http_proxy_pool_;
PoolBase base_;
SSLConfigService* const ssl_config_service_;
DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool);
};
} // namespace net
#endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_