Commit 756e0dcb authored by kylechar's avatar kylechar Committed by Commit Bot

Use base::BindOnce for PostTask callbacks.

TaskRunner::PostTask() takes a OnceCallback. Replace usage of
base::Bind(), which produces a RepeatingCallback, with base::BindOnce()
when the callback is created as a temporary inside of PostTask(). The
following regex was used to find instances that could be replaced:

(Post(?:Delayed)?Task)\((?:\n\s*)?FROM_HERE,(?:\n)?\s*base::Bind\(

Also replace any usage of base::Passed(&var) with std::move(var) for
variables passed to base::BindOnce(). base::Passed() isn't needed for
move-only types with OnceCallbacks.

This CL was uploaded by git cl split.

R=zea@chromium.org

Bug: 714018
Change-Id: I563c61da47057260e97bb3989d571f1edc2514e7
Reviewed-on: https://chromium-review.googlesource.com/c/1475646
Auto-Submit: kylechar <kylechar@chromium.org>
Reviewed-by: default avatarNicolas Zea <zea@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632766}
parent 3ab06385
......@@ -25,8 +25,8 @@ void TaskPump::WakeTasks() {
if (!stopped_ && !posted_wake_) {
// Do the requested wake up.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr()));
FROM_HERE, base::BindOnce(&TaskPump::CheckAndRunTasks,
weak_factory_.GetWeakPtr()));
posted_wake_ = true;
}
}
......
......@@ -192,10 +192,9 @@ void JingleThreadWrapper::Send(const rtc::Location& posted_from,
// Need to signal |pending_send_event_| here in case the thread is
// sending message to another thread.
pending_send_event_.Signal();
task_runner_->PostTask(FROM_HERE,
base::Bind(&JingleThreadWrapper::ProcessPendingSends,
weak_ptr_));
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&JingleThreadWrapper::ProcessPendingSends, weak_ptr_));
while (!pending_send.done_event.IsSignaled()) {
base::WaitableEvent* events[] = {&pending_send.done_event,
......@@ -247,14 +246,14 @@ void JingleThreadWrapper::PostTaskInternal(const rtc::Location& posted_from,
}
if (delay_ms <= 0) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&JingleThreadWrapper::RunTask,
weak_ptr_, task_id));
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&JingleThreadWrapper::RunTask, weak_ptr_, task_id));
} else {
task_runner_->PostDelayedTask(FROM_HERE,
base::Bind(&JingleThreadWrapper::RunTask,
weak_ptr_, task_id),
base::TimeDelta::FromMilliseconds(delay_ms));
task_runner_->PostDelayedTask(
FROM_HERE,
base::BindOnce(&JingleThreadWrapper::RunTask, weak_ptr_, task_id),
base::TimeDelta::FromMilliseconds(delay_ms));
}
}
......
......@@ -263,8 +263,8 @@ TEST_F(ThreadWrapperTest, SendToOtherThread) {
base::WaitableEvent::InitialState::NOT_SIGNALED);
rtc::Thread* target;
second_thread.task_runner()->PostTask(
FROM_HERE,
base::Bind(&InitializeWrapperForNewThread, &target, &initialized_event));
FROM_HERE, base::BindOnce(&InitializeWrapperForNewThread, &target,
&initialized_event));
initialized_event.Wait();
ASSERT_TRUE(target != NULL);
......@@ -294,8 +294,8 @@ TEST_F(ThreadWrapperTest, SendDuringSend) {
base::WaitableEvent::InitialState::NOT_SIGNALED);
rtc::Thread* target;
second_thread.task_runner()->PostTask(
FROM_HERE,
base::Bind(&InitializeWrapperForNewThread, &target, &initialized_event));
FROM_HERE, base::BindOnce(&InitializeWrapperForNewThread, &target,
&initialized_event));
initialized_event.Wait();
ASSERT_TRUE(target != NULL);
......
......@@ -125,35 +125,31 @@ void NonBlockingPushClient::Core::SendPing() {
void NonBlockingPushClient::Core::OnNotificationsEnabled() {
DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::OnNotificationsEnabled,
parent_push_client_));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnNotificationsEnabled,
parent_push_client_));
}
void NonBlockingPushClient::Core::OnNotificationsDisabled(
NotificationsDisabledReason reason) {
DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::OnNotificationsDisabled,
parent_push_client_, reason));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnNotificationsDisabled,
parent_push_client_, reason));
}
void NonBlockingPushClient::Core::OnIncomingNotification(
const Notification& notification) {
DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::OnIncomingNotification,
parent_push_client_, notification));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnIncomingNotification,
parent_push_client_, notification));
}
void NonBlockingPushClient::Core::OnPingResponse() {
DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::OnPingResponse,
parent_push_client_));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnPingResponse,
parent_push_client_));
}
NonBlockingPushClient::NonBlockingPushClient(
......@@ -165,16 +161,16 @@ NonBlockingPushClient::NonBlockingPushClient(
core_ = new Core(delegate_task_runner_, weak_ptr_factory_.GetWeakPtr());
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::CreateOnDelegateThread,
core_, create_blocking_push_client_callback));
base::BindOnce(&NonBlockingPushClient::Core::CreateOnDelegateThread,
core_, create_blocking_push_client_callback));
}
NonBlockingPushClient::~NonBlockingPushClient() {
DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::DestroyOnDelegateThread,
core_));
base::BindOnce(&NonBlockingPushClient::Core::DestroyOnDelegateThread,
core_));
}
void NonBlockingPushClient::AddObserver(PushClientObserver* observer) {
......@@ -192,8 +188,8 @@ void NonBlockingPushClient::UpdateSubscriptions(
DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::UpdateSubscriptions,
core_, subscriptions));
base::BindOnce(&NonBlockingPushClient::Core::UpdateSubscriptions, core_,
subscriptions));
}
void NonBlockingPushClient::UpdateCredentials(
......@@ -202,24 +198,22 @@ void NonBlockingPushClient::UpdateCredentials(
const net::NetworkTrafficAnnotationTag& traffic_annotation) {
DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask(
FROM_HERE, base::Bind(&NonBlockingPushClient::Core::UpdateCredentials,
core_, email, token, traffic_annotation));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::Core::UpdateCredentials,
core_, email, token, traffic_annotation));
}
void NonBlockingPushClient::SendNotification(
const Notification& notification) {
DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::SendNotification, core_,
notification));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::Core::SendNotification,
core_, notification));
}
void NonBlockingPushClient::SendPing() {
DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::SendPing, core_));
FROM_HERE, base::BindOnce(&NonBlockingPushClient::Core::SendPing, core_));
}
void NonBlockingPushClient::OnNotificationsEnabled() {
......
......@@ -50,8 +50,8 @@ TEST_F(PushClientTest, CreateDefaultOffIOThread) {
base::Thread thread("Non-IO thread");
EXPECT_TRUE(thread.Start());
thread.task_runner()->PostTask(
FROM_HERE, base::Bind(base::IgnoreResult(&PushClient::CreateDefault),
notifier_options_));
FROM_HERE, base::BindOnce(base::IgnoreResult(&PushClient::CreateDefault),
notifier_options_));
thread.Stop();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment