blob: 7ad5afc3e1f56a0f5c1855afa12d18f25033bf7f [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.
#include "net/socket/transport_client_socket_pool.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h"
#include "base/values.h"
#include "net/base/trace_constants.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source_type.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_base.h"
#include "net/socket/socket_net_log_params.h"
namespace net {
std::unique_ptr<ConnectJob>
TransportClientSocketPool::TransportConnectJobFactory::NewConnectJob(
const std::string& group_name,
const PoolBase::Request& request,
ConnectJob::Delegate* delegate) const {
return std::make_unique<TransportConnectJob>(
group_name, request.priority(), request.socket_tag(),
request.respect_limits() == ClientSocketPool::RespectLimits::ENABLED,
request.params(), client_socket_factory_,
socket_performance_watcher_factory_, host_resolver_, delegate, net_log_);
}
TransportClientSocketPool::TransportClientSocketPool(
int max_sockets,
int max_sockets_per_group,
HostResolver* host_resolver,
ClientSocketFactory* client_socket_factory,
SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
NetLog* net_log)
: base_(NULL,
max_sockets,
max_sockets_per_group,
ClientSocketPool::unused_idle_socket_timeout(),
ClientSocketPool::used_idle_socket_timeout(),
new TransportConnectJobFactory(client_socket_factory,
host_resolver,
socket_performance_watcher_factory,
net_log)),
client_socket_factory_(client_socket_factory) {
base_.EnableConnectBackupJobs();
}
TransportClientSocketPool::~TransportClientSocketPool() = default;
int TransportClientSocketPool::RequestSocket(const std::string& group_name,
const void* params,
RequestPriority priority,
const SocketTag& socket_tag,
RespectLimits respect_limits,
ClientSocketHandle* handle,
CompletionOnceCallback callback,
const NetLogWithSource& net_log) {
const scoped_refptr<TransportSocketParams>* casted_params =
static_cast<const scoped_refptr<TransportSocketParams>*>(params);
NetLogTcpClientSocketPoolRequestedSocket(net_log, casted_params);
return base_.RequestSocket(group_name, *casted_params, priority, socket_tag,
respect_limits, handle, std::move(callback),
net_log);
}
void TransportClientSocketPool::NetLogTcpClientSocketPoolRequestedSocket(
const NetLogWithSource& net_log,
const scoped_refptr<TransportSocketParams>* casted_params) {
if (net_log.IsCapturing()) {
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET,
CreateNetLogHostPortPairCallback(
&casted_params->get()->destination().host_port_pair()));
}
}
void TransportClientSocketPool::RequestSockets(
const std::string& group_name,
const void* params,
int num_sockets,
const NetLogWithSource& net_log) {
const scoped_refptr<TransportSocketParams>* casted_params =
static_cast<const scoped_refptr<TransportSocketParams>*>(params);
if (net_log.IsCapturing()) {
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS,
CreateNetLogHostPortPairCallback(
&casted_params->get()->destination().host_port_pair()));
}
base_.RequestSockets(group_name, *casted_params, num_sockets, net_log);
}
void TransportClientSocketPool::SetPriority(const std::string& group_name,
ClientSocketHandle* handle,
RequestPriority priority) {
base_.SetPriority(group_name, handle, priority);
}
void TransportClientSocketPool::CancelRequest(
const std::string& group_name,
ClientSocketHandle* handle) {
base_.CancelRequest(group_name, handle);
}
void TransportClientSocketPool::ReleaseSocket(
const std::string& group_name,
std::unique_ptr<StreamSocket> socket,
int id) {
base_.ReleaseSocket(group_name, std::move(socket), id);
}
void TransportClientSocketPool::FlushWithError(int error) {
base_.FlushWithError(error);
}
void TransportClientSocketPool::CloseIdleSockets() {
base_.CloseIdleSockets();
}
void TransportClientSocketPool::CloseIdleSocketsInGroup(
const std::string& group_name) {
base_.CloseIdleSocketsInGroup(group_name);
}
int TransportClientSocketPool::IdleSocketCount() const {
return base_.idle_socket_count();
}
int TransportClientSocketPool::IdleSocketCountInGroup(
const std::string& group_name) const {
return base_.IdleSocketCountInGroup(group_name);
}
LoadState TransportClientSocketPool::GetLoadState(
const std::string& group_name, const ClientSocketHandle* handle) const {
return base_.GetLoadState(group_name, handle);
}
std::unique_ptr<base::DictionaryValue>
TransportClientSocketPool::GetInfoAsValue(const std::string& name,
const std::string& type,
bool include_nested_pools) const {
return base_.GetInfoAsValue(name, type);
}
bool TransportClientSocketPool::IsStalled() const {
return base_.IsStalled();
}
void TransportClientSocketPool::AddHigherLayeredPool(
HigherLayeredPool* higher_pool) {
base_.AddHigherLayeredPool(higher_pool);
}
void TransportClientSocketPool::RemoveHigherLayeredPool(
HigherLayeredPool* higher_pool) {
base_.RemoveHigherLayeredPool(higher_pool);
}
} // namespace net