Skip to content

Commit 990a74a

Browse files
Eric OrthCommit Bot
Eric Orth
authored and
Commit Bot
committed
Cleanup dead code in DnsSocketPool
Remove everything related to the "default" socket pool that is completely unused. Also simplify the DnsSocketPool interface for the remaining much simpler usage of the class. Also delete dns_session_unittest.cc since it was really only testing that allocated sockets were properly freed in the pool, but that no longer matters and it wasn't worth maintaining the mockability and hooks in the pool needed for the test. Bug: 1116579 Change-Id: Ib322bffb653e85a9c33a4b3835f4067fd8d29530 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2357615 Commit-Queue: Eric Orth <ericorth@chromium.org> Reviewed-by: Dan McArdle <dmcardle@chromium.org> Cr-Commit-Position: refs/heads/master@{#800248}
1 parent b63ab0c commit 990a74a

11 files changed

+102
-568
lines changed

net/dns/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ source_set("tests") {
391391
"dns_hosts_unittest.cc",
392392
"dns_query_unittest.cc",
393393
"dns_response_unittest.cc",
394-
"dns_session_unittest.cc",
395394
"dns_socket_pool_unittest.cc",
396395
"dns_transaction_unittest.cc",
397396
"dns_udp_tracker_unittest.cc",

net/dns/dns_client.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ class DnsClientImpl : public DnsClient {
245245
if (new_effective_config) {
246246
DCHECK(new_effective_config.value().IsValid());
247247

248-
std::unique_ptr<DnsSocketPool> socket_pool(
249-
DnsSocketPool::CreateNull(socket_factory_, rand_int_callback_));
248+
auto socket_pool = std::make_unique<DnsSocketPool>(
249+
socket_factory_, new_effective_config.value().nameservers, net_log_);
250250
session_ =
251251
new DnsSession(std::move(new_effective_config).value(),
252252
std::move(socket_pool), rand_int_callback_, net_log_);

net/dns/dns_session.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ DnsSession::DnsSession(const DnsConfig& config,
4848
0,
4949
std::numeric_limits<uint16_t>::max())),
5050
net_log_(net_log) {
51-
socket_pool_->Initialize(&config_.nameservers, net_log);
5251
UMA_HISTOGRAM_CUSTOM_COUNTS("AsyncDNS.ServerCount",
5352
config_.nameservers.size(), 1, 10, 11);
5453
}
@@ -65,7 +64,7 @@ std::unique_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket(
6564
const NetLogSource& source) {
6665
std::unique_ptr<DatagramClientSocket> socket;
6766

68-
socket = socket_pool_->AllocateSocket(server_index);
67+
socket = socket_pool_->CreateConnectedUdpSocket(server_index);
6968
if (!socket.get())
7069
return std::unique_ptr<SocketLease>();
7170

@@ -79,7 +78,7 @@ std::unique_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket(
7978
std::unique_ptr<StreamSocket> DnsSession::CreateTCPSocket(
8079
size_t server_index,
8180
const NetLogSource& source) {
82-
return socket_pool_->CreateTCPSocket(server_index, source);
81+
return socket_pool_->CreateTcpSocket(server_index, source);
8382
}
8483

8584
void DnsSession::InvalidateWeakPtrsForTesting() {
@@ -92,8 +91,6 @@ void DnsSession::FreeSocket(size_t server_index,
9291
DCHECK(socket.get());
9392

9493
socket->NetLog().EndEvent(NetLogEventType::SOCKET_IN_USE);
95-
96-
socket_pool_->FreeSocket(server_index, std::move(socket));
9794
}
9895

9996
} // namespace net

net/dns/dns_session.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class NET_EXPORT_PRIVATE DnsSession : public base::RefCounted<DnsSession> {
3838
public:
3939
typedef base::RepeatingCallback<int()> RandCallback;
4040

41+
// TODO(crbug.com/1116579): Remove this unnecessary abstraction now that DNS
42+
// sockets are not pooled and do not need a special release signal.
4143
class NET_EXPORT_PRIVATE SocketLease {
4244
public:
4345
SocketLease(scoped_refptr<DnsSession> session,
@@ -71,11 +73,13 @@ class NET_EXPORT_PRIVATE DnsSession : public base::RefCounted<DnsSession> {
7173

7274
// Allocate a socket, already connected to the server address.
7375
// When the SocketLease is destroyed, the socket will be freed.
76+
// TODO(crbug.com/1116579): Remove this and directly call into DnsSocketPool.
7477
std::unique_ptr<SocketLease> AllocateSocket(size_t server_index,
7578
const NetLogSource& source);
7679

7780
// Creates a StreamSocket from the factory for a transaction over TCP. These
7881
// sockets are not pooled.
82+
// TODO(crbug.com/1116579): Remove this and directly call into DnsSocketPool.
7983
std::unique_ptr<StreamSocket> CreateTCPSocket(size_t server_index,
8084
const NetLogSource& source);
8185

net/dns/dns_session_unittest.cc

-244
This file was deleted.

0 commit comments

Comments
 (0)