Skip to content

Commit

Permalink
Apply base_bind_rewriters to //net
Browse files Browse the repository at this point in the history
*** Note: There is no behavior change from this patch. ***

This CL replaces calls to base::{Bind,BindRepeating} with calls to
base::BindOnce, and removes calls to base::AdaptCallbackForRepeating
when the returned base::RepeatingCallback is immediately converted
to a base::OnceCallback.

This CL was uploaded by git cl split.

R=zhongyi@chromium.org

Bug: 714018
Change-Id: I89d91b84381cb4b4598f5df0d0f51dc72be8f312
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778773
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Auto-Submit: Yannic Bonenberger <contact@yannic-bonenberger.com>
Cr-Commit-Position: refs/heads/master@{#693231}
  • Loading branch information
Yannic authored and Commit Bot committed Sep 4, 2019
1 parent c592574 commit cc716d4
Show file tree
Hide file tree
Showing 34 changed files with 199 additions and 196 deletions.
2 changes: 1 addition & 1 deletion net/http/broken_alternative_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void BrokenAlternativeServices ::
expiration_timer_.Stop();
expiration_timer_.Start(
FROM_HERE, delay,
base::Bind(
base::BindOnce(
&BrokenAlternativeServices ::ExpireBrokenAlternateProtocolMappings,
weak_ptr_factory_.GetWeakPtr()));
}
Expand Down
7 changes: 3 additions & 4 deletions net/http/http_response_body_drainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ int HttpResponseBodyDrainer::DoDrainResponseBody() {
next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE;

return stream_->ReadResponseBody(
read_buf_.get(),
kDrainBodyBufferSize - total_read_,
base::Bind(&HttpResponseBodyDrainer::OnIOComplete,
base::Unretained(this)));
read_buf_.get(), kDrainBodyBufferSize - total_read_,
base::BindOnce(&HttpResponseBodyDrainer::OnIOComplete,
base::Unretained(this)));
}

int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) {
Expand Down
5 changes: 2 additions & 3 deletions net/http/http_stream_factory_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,8 @@ int HttpStreamFactory::Job::DoInitConnectionImpl() {
// delay the main job.
delegate_->MaybeSetWaitTimeForMainJob(
quic_request_.GetTimeDelayForWaitingJob());
expect_on_quic_host_resolution_ =
quic_request_.WaitForHostResolution(base::BindRepeating(
&Job::OnQuicHostResolution, base::Unretained(this)));
expect_on_quic_host_resolution_ = quic_request_.WaitForHostResolution(
base::BindOnce(&Job::OnQuicHostResolution, base::Unretained(this)));
}
return rv;
}
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_stream_factory_job_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ int HttpStreamFactory::JobController::DoResolveProxy() {
GURL origin_url = ApplyHostMappingRules(request_info_.url, &destination);

CompletionOnceCallback io_callback =
base::Bind(&JobController::OnIOComplete, base::Unretained(this));
base::BindOnce(&JobController::OnIOComplete, base::Unretained(this));
return session_->proxy_resolution_service()->ResolveProxy(
origin_url, request_info_.method, &proxy_info_, std::move(io_callback),
&proxy_resolve_request_, net_log_);
Expand Down
16 changes: 9 additions & 7 deletions net/http/http_transaction_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ TestTransactionConsumer::~TestTransactionConsumer() = default;
void TestTransactionConsumer::Start(const HttpRequestInfo* request,
const NetLogWithSource& net_log) {
state_ = STARTING;
int result = trans_->Start(
request, base::Bind(&TestTransactionConsumer::OnIOComplete,
base::Unretained(this)), net_log);
int result =
trans_->Start(request,
base::BindOnce(&TestTransactionConsumer::OnIOComplete,
base::Unretained(this)),
net_log);
if (result != ERR_IO_PENDING)
DidStart(result);
}
Expand Down Expand Up @@ -229,10 +231,10 @@ void TestTransactionConsumer::DidFinish(int result) {
void TestTransactionConsumer::Read() {
state_ = READING;
read_buf_ = base::MakeRefCounted<IOBuffer>(1024);
int result = trans_->Read(read_buf_.get(),
1024,
base::Bind(&TestTransactionConsumer::OnIOComplete,
base::Unretained(this)));
int result =
trans_->Read(read_buf_.get(), 1024,
base::BindOnce(&TestTransactionConsumer::OnIOComplete,
base::Unretained(this)));
if (result != ERR_IO_PENDING)
DidRead(result);
}
Expand Down
17 changes: 8 additions & 9 deletions net/server/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ void HttpServer::DoAcceptLoop() {
int rv;
do {
rv = server_socket_->Accept(&accepted_socket_,
base::Bind(&HttpServer::OnAcceptCompleted,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&HttpServer::OnAcceptCompleted,
weak_ptr_factory_.GetWeakPtr()));
if (rv == ERR_IO_PENDING)
return;
rv = HandleAcceptResult(rv);
Expand Down Expand Up @@ -215,10 +215,9 @@ void HttpServer::DoReadLoop(HttpConnection* connection) {
}

rv = connection->socket()->Read(
read_buf,
read_buf->RemainingCapacity(),
base::Bind(&HttpServer::OnReadCompleted,
weak_ptr_factory_.GetWeakPtr(), connection->id()));
read_buf, read_buf->RemainingCapacity(),
base::BindOnce(&HttpServer::OnReadCompleted,
weak_ptr_factory_.GetWeakPtr(), connection->id()));
if (rv == ERR_IO_PENDING)
return;
rv = HandleReadResult(connection, rv);
Expand Down Expand Up @@ -325,9 +324,9 @@ void HttpServer::DoWriteLoop(HttpConnection* connection,
while (rv == OK && write_buf->GetSizeToWrite() > 0) {
rv = connection->socket()->Write(
write_buf, write_buf->GetSizeToWrite(),
base::Bind(&HttpServer::OnWriteCompleted,
weak_ptr_factory_.GetWeakPtr(), connection->id(),
traffic_annotation),
base::BindOnce(&HttpServer::OnWriteCompleted,
weak_ptr_factory_.GetWeakPtr(), connection->id(),
traffic_annotation),
traffic_annotation);
if (rv == ERR_IO_PENDING || rv == OK)
return;
Expand Down
2 changes: 1 addition & 1 deletion net/server/http_server_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class TestHttpClient {
void Write() {
int result = socket_->Write(
write_buffer_.get(), write_buffer_->BytesRemaining(),
base::Bind(&TestHttpClient::OnWrite, base::Unretained(this)),
base::BindOnce(&TestHttpClient::OnWrite, base::Unretained(this)),
TRAFFIC_ANNOTATION_FOR_TESTS);
if (result != ERR_IO_PENDING)
OnWrite(result);
Expand Down
56 changes: 29 additions & 27 deletions net/socket/sequenced_socket_data_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ TEST_F(SequencedSocketDataTest, SyncReadFromCompletionCallback) {
ERR_IO_PENDING,
sock_->Read(
read_buf_.get(), kLen1,
base::Bind(&SequencedSocketDataTest::ReentrantReadCallback,
base::Unretained(this), kMsg1, kLen1, kLen2, kLen2)));
base::BindOnce(&SequencedSocketDataTest::ReentrantReadCallback,
base::Unretained(this), kMsg1, kLen1, kLen2, kLen2)));

base::RunLoop().RunUntilIdle();
AssertReadBufferEquals(kMsg2, kLen2);
Expand Down Expand Up @@ -527,12 +527,12 @@ TEST_F(SequencedSocketDataTest, AsyncReadFromCompletionCallback) {
Initialize(reads, base::span<MockWrite>());

read_buf_ = base::MakeRefCounted<IOBuffer>(kLen1);
ASSERT_EQ(
ERR_IO_PENDING,
sock_->Read(read_buf_.get(), kLen1,
base::Bind(&SequencedSocketDataTest::ReentrantReadCallback,
base::Unretained(this), kMsg1, kLen1, kLen2,
ERR_IO_PENDING)));
ASSERT_EQ(ERR_IO_PENDING,
sock_->Read(
read_buf_.get(), kLen1,
base::BindOnce(&SequencedSocketDataTest::ReentrantReadCallback,
base::Unretained(this), kMsg1, kLen1, kLen2,
ERR_IO_PENDING)));

ASSERT_FALSE(read_callback_.have_result());
ASSERT_EQ(kLen2, read_callback_.WaitForResult());
Expand Down Expand Up @@ -780,12 +780,13 @@ TEST_F(SequencedSocketDataTest, SyncWriteFromCompletionCallback) {

scoped_refptr<IOBuffer> write_buf = base::MakeRefCounted<IOBuffer>(kLen1);
memcpy(write_buf->data(), kMsg1, kLen1);
ASSERT_EQ(ERR_IO_PENDING,
sock_->Write(
write_buf.get(), kLen1,
base::Bind(&SequencedSocketDataTest::ReentrantWriteCallback,
base::Unretained(this), kLen1, kMsg2, kLen2, kLen2),
TRAFFIC_ANNOTATION_FOR_TESTS));
ASSERT_EQ(
ERR_IO_PENDING,
sock_->Write(
write_buf.get(), kLen1,
base::BindOnce(&SequencedSocketDataTest::ReentrantWriteCallback,
base::Unretained(this), kLen1, kMsg2, kLen2, kLen2),
TRAFFIC_ANNOTATION_FOR_TESTS));

base::RunLoop().RunUntilIdle();
}
Expand All @@ -799,13 +800,13 @@ TEST_F(SequencedSocketDataTest, AsyncWriteFromCompletionCallback) {

scoped_refptr<IOBuffer> write_buf = base::MakeRefCounted<IOBuffer>(kLen1);
memcpy(write_buf->data(), kMsg1, kLen1);
ASSERT_EQ(
ERR_IO_PENDING,
sock_->Write(write_buf.get(), kLen1,
base::Bind(&SequencedSocketDataTest::ReentrantWriteCallback,
base::Unretained(this), kLen1, kMsg2, kLen2,
ERR_IO_PENDING),
TRAFFIC_ANNOTATION_FOR_TESTS));
ASSERT_EQ(ERR_IO_PENDING,
sock_->Write(
write_buf.get(), kLen1,
base::BindOnce(&SequencedSocketDataTest::ReentrantWriteCallback,
base::Unretained(this), kLen1, kMsg2, kLen2,
ERR_IO_PENDING),
TRAFFIC_ANNOTATION_FOR_TESTS));

ASSERT_FALSE(write_callback_.have_result());
ASSERT_EQ(kLen2, write_callback_.WaitForResult());
Expand Down Expand Up @@ -977,12 +978,13 @@ TEST_F(SequencedSocketDataTest, AsyncReadFromWriteCompletionCallback) {

scoped_refptr<IOBuffer> write_buf = base::MakeRefCounted<IOBuffer>(kLen1);
memcpy(write_buf->data(), kMsg1, kLen1);
ASSERT_EQ(ERR_IO_PENDING,
sock_->Write(
write_buf.get(), kLen1,
base::Bind(&SequencedSocketDataTest::ReentrantAsyncReadCallback,
base::Unretained(this), kLen1, kLen2),
TRAFFIC_ANNOTATION_FOR_TESTS));
ASSERT_EQ(
ERR_IO_PENDING,
sock_->Write(
write_buf.get(), kLen1,
base::BindOnce(&SequencedSocketDataTest::ReentrantAsyncReadCallback,
base::Unretained(this), kLen1, kLen2),
TRAFFIC_ANNOTATION_FOR_TESTS));

ASSERT_FALSE(read_callback_.have_result());
ASSERT_EQ(kLen2, read_callback_.WaitForResult());
Expand Down
8 changes: 4 additions & 4 deletions net/socket/socket_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ int SocketPosix::Read(IOBuffer* buf,
CompletionOnceCallback callback) {
// Use base::Unretained() is safe here because OnFileCanReadWithoutBlocking()
// won't be called if |this| is gone.
int rv =
ReadIfReady(buf, buf_len,
base::Bind(&SocketPosix::RetryRead, base::Unretained(this)));
int rv = ReadIfReady(
buf, buf_len,
base::BindOnce(&SocketPosix::RetryRead, base::Unretained(this)));
if (rv == ERR_IO_PENDING) {
read_buf_ = buf;
read_buf_len_ = buf_len;
Expand Down Expand Up @@ -502,7 +502,7 @@ void SocketPosix::RetryRead(int rv) {
if (rv == OK) {
rv = ReadIfReady(
read_buf_.get(), read_buf_len_,
base::Bind(&SocketPosix::RetryRead, base::Unretained(this)));
base::BindOnce(&SocketPosix::RetryRead, base::Unretained(this)));
if (rv == ERR_IO_PENDING)
return;
}
Expand Down
12 changes: 6 additions & 6 deletions net/socket/socket_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ int MockTCPClientSocket::Read(IOBuffer* buf,
// takes a weak ptr of the base class, MockClientSocket.
int rv = ReadIfReadyImpl(
buf, buf_len,
base::Bind(&MockTCPClientSocket::RetryRead, base::Unretained(this)));
base::BindOnce(&MockTCPClientSocket::RetryRead, base::Unretained(this)));
if (rv == ERR_IO_PENDING) {
DCHECK(callback);

Expand Down Expand Up @@ -1224,9 +1224,9 @@ void MockTCPClientSocket::RetryRead(int rv) {
DCHECK_LT(0, pending_read_buf_len_);

if (rv == OK) {
rv = ReadIfReadyImpl(
pending_read_buf_.get(), pending_read_buf_len_,
base::Bind(&MockTCPClientSocket::RetryRead, base::Unretained(this)));
rv = ReadIfReadyImpl(pending_read_buf_.get(), pending_read_buf_len_,
base::BindOnce(&MockTCPClientSocket::RetryRead,
base::Unretained(this)));
if (rv == ERR_IO_PENDING)
return;
}
Expand Down Expand Up @@ -2079,8 +2079,8 @@ MockTransportClientSocketPool::MockConnectJob::~MockConnectJob() = default;

int MockTransportClientSocketPool::MockConnectJob::Connect() {
socket_->ApplySocketTag(socket_tag_);
int rv = socket_->Connect(base::Bind(&MockConnectJob::OnConnect,
base::Unretained(this)));
int rv = socket_->Connect(
base::BindOnce(&MockConnectJob::OnConnect, base::Unretained(this)));
if (rv != ERR_IO_PENDING) {
user_callback_.Reset();
OnConnect(rv);
Expand Down
4 changes: 2 additions & 2 deletions net/socket/socks_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ int SOCKSClientSocket::DoHandshakeWrite() {
handshake_buf_len);
return transport_socket_->Write(
handshake_buf_.get(), handshake_buf_len,
base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)),
base::BindOnce(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)),
traffic_annotation_);
}

Expand Down Expand Up @@ -406,7 +406,7 @@ int SOCKSClientSocket::DoHandshakeRead() {
handshake_buf_ = base::MakeRefCounted<IOBuffer>(handshake_buf_len);
return transport_socket_->Read(
handshake_buf_.get(), handshake_buf_len,
base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)));
base::BindOnce(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)));
}

int SOCKSClientSocket::DoHandshakeReadComplete(int result) {
Expand Down
16 changes: 8 additions & 8 deletions net/socket/ssl_client_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ int ReadBufferingStreamSocket::DoRead() {
state_ = STATE_READ_COMPLETE;
return transport_->Read(
read_buffer_.get(), read_buffer_->RemainingCapacity(),
base::Bind(&ReadBufferingStreamSocket::OnReadCompleted,
base::Unretained(this)));
base::BindOnce(&ReadBufferingStreamSocket::OnReadCompleted,
base::Unretained(this)));
}

int ReadBufferingStreamSocket::DoReadComplete(int result) {
Expand Down Expand Up @@ -466,10 +466,10 @@ int FakeBlockingStreamSocket::Read(IOBuffer* buf,
DCHECK_EQ(ERR_IO_PENDING, pending_read_result_);
DCHECK(!callback.is_null());

int rv =
transport_->Read(buf, len,
base::Bind(&FakeBlockingStreamSocket::OnReadCompleted,
base::Unretained(this)));
int rv = transport_->Read(
buf, len,
base::BindOnce(&FakeBlockingStreamSocket::OnReadCompleted,
base::Unretained(this)));
if (rv == ERR_IO_PENDING || should_block_read_) {
// Save the callback to be called later.
pending_read_buf_ = buf;
Expand Down Expand Up @@ -501,8 +501,8 @@ int FakeBlockingStreamSocket::ReadIfReady(IOBuffer* buf,
}
scoped_refptr<IOBuffer> buf_copy = base::MakeRefCounted<IOBuffer>(len);
int rv = Read(buf_copy.get(), len,
base::Bind(&FakeBlockingStreamSocket::CompleteReadIfReady,
base::Unretained(this), buf_copy));
base::BindOnce(&FakeBlockingStreamSocket::CompleteReadIfReady,
base::Unretained(this), buf_copy));
if (rv > 0)
memcpy(buf->data(), buf_copy->data(), rv);
if (rv == ERR_IO_PENDING)
Expand Down
5 changes: 2 additions & 3 deletions net/socket/ssl_server_socket_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ SSLServerContextImpl::SocketImpl::PrivateKeySignCallback(uint8_t* out,
signature_result_ = ERR_IO_PENDING;
context_->private_key_->Sign(
algorithm, base::make_span(in, in_len),
base::BindRepeating(
&SSLServerContextImpl::SocketImpl::OnPrivateKeyComplete,
weak_factory_.GetWeakPtr()));
base::BindOnce(&SSLServerContextImpl::SocketImpl::OnPrivateKeyComplete,
weak_factory_.GetWeakPtr()));
return ssl_private_key_retry;
}

Expand Down
7 changes: 4 additions & 3 deletions net/socket/transport_client_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ void TransportClientSocketTest::SetUp() {
// Get the server's address (including the actual port number).
ASSERT_THAT(listen_sock_->GetLocalAddress(&local_address), IsOk());
listen_port_ = local_address.port();
listen_sock_->Accept(&connected_sock_,
base::Bind(&TransportClientSocketTest::AcceptCallback,
base::Unretained(this)));
listen_sock_->Accept(
&connected_sock_,
base::BindOnce(&TransportClientSocketTest::AcceptCallback,
base::Unretained(this)));

AddressList addr = AddressList::CreateFromIPAddress(
IPAddress::IPv4Localhost(), listen_port_);
Expand Down
12 changes: 6 additions & 6 deletions net/socket/udp_socket_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void UDPSocketPerfTest::WritePacketsToSocket(UDPClientSocket* socket,
memset(io_buffer->data(), 'G', kPacketSize);

while (num_of_packets) {
int rv =
socket->Write(io_buffer.get(), io_buffer->size(),
base::Bind(&UDPSocketPerfTest::DoneWritePacketsToSocket,
weak_factory_.GetWeakPtr(), socket,
num_of_packets - 1, done_callback),
TRAFFIC_ANNOTATION_FOR_TESTS);
int rv = socket->Write(
io_buffer.get(), io_buffer->size(),
base::BindOnce(&UDPSocketPerfTest::DoneWritePacketsToSocket,
weak_factory_.GetWeakPtr(), socket, num_of_packets - 1,
done_callback),
TRAFFIC_ANNOTATION_FOR_TESTS);
if (rv == ERR_IO_PENDING)
break;
--num_of_packets;
Expand Down
6 changes: 3 additions & 3 deletions net/socket/udp_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ void UDPSocketTest::ConnectTest(bool use_nonblocking_io) {
// Test asynchronous read. Server waits for message.
base::RunLoop run_loop;
int read_result = 0;
int rv = server->RecvFrom(
buffer_.get(), kMaxRead, &recv_from_address_,
base::Bind(&ReadCompleteCallback, &read_result, run_loop.QuitClosure()));
int rv = server->RecvFrom(buffer_.get(), kMaxRead, &recv_from_address_,
base::BindOnce(&ReadCompleteCallback, &read_result,
run_loop.QuitClosure()));
EXPECT_THAT(rv, IsError(ERR_IO_PENDING));

// Client sends to the server.
Expand Down
7 changes: 3 additions & 4 deletions net/test/embedded_test_server/default_handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,9 @@ class ExabyteResponse : public net::test_server::BasicHttpResponse {
// for the purpose of testing.
static void SendExabyte(const net::test_server::SendBytesCallback& send) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindRepeating(
send, "echo",
base::BindRepeating(&ExabyteResponse::SendExabyte, send)));
FROM_HERE, base::BindOnce(send, "echo",
base::BindRepeating(
&ExabyteResponse::SendExabyte, send)));
}

DISALLOW_COPY_AND_ASSIGN(ExabyteResponse);
Expand Down
Loading

0 comments on commit cc716d4

Please sign in to comment.