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() { ...@@ -25,8 +25,8 @@ void TaskPump::WakeTasks() {
if (!stopped_ && !posted_wake_) { if (!stopped_ && !posted_wake_) {
// Do the requested wake up. // Do the requested wake up.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&TaskPump::CheckAndRunTasks,
base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
posted_wake_ = true; posted_wake_ = true;
} }
} }
......
...@@ -192,10 +192,9 @@ void JingleThreadWrapper::Send(const rtc::Location& posted_from, ...@@ -192,10 +192,9 @@ void JingleThreadWrapper::Send(const rtc::Location& posted_from,
// Need to signal |pending_send_event_| here in case the thread is // Need to signal |pending_send_event_| here in case the thread is
// sending message to another thread. // sending message to another thread.
pending_send_event_.Signal(); pending_send_event_.Signal();
task_runner_->PostTask(FROM_HERE, task_runner_->PostTask(
base::Bind(&JingleThreadWrapper::ProcessPendingSends, FROM_HERE,
weak_ptr_)); base::BindOnce(&JingleThreadWrapper::ProcessPendingSends, weak_ptr_));
while (!pending_send.done_event.IsSignaled()) { while (!pending_send.done_event.IsSignaled()) {
base::WaitableEvent* events[] = {&pending_send.done_event, base::WaitableEvent* events[] = {&pending_send.done_event,
...@@ -247,14 +246,14 @@ void JingleThreadWrapper::PostTaskInternal(const rtc::Location& posted_from, ...@@ -247,14 +246,14 @@ void JingleThreadWrapper::PostTaskInternal(const rtc::Location& posted_from,
} }
if (delay_ms <= 0) { if (delay_ms <= 0) {
task_runner_->PostTask(FROM_HERE, task_runner_->PostTask(
base::Bind(&JingleThreadWrapper::RunTask, FROM_HERE,
weak_ptr_, task_id)); base::BindOnce(&JingleThreadWrapper::RunTask, weak_ptr_, task_id));
} else { } else {
task_runner_->PostDelayedTask(FROM_HERE, task_runner_->PostDelayedTask(
base::Bind(&JingleThreadWrapper::RunTask, FROM_HERE,
weak_ptr_, task_id), base::BindOnce(&JingleThreadWrapper::RunTask, weak_ptr_, task_id),
base::TimeDelta::FromMilliseconds(delay_ms)); base::TimeDelta::FromMilliseconds(delay_ms));
} }
} }
......
...@@ -263,8 +263,8 @@ TEST_F(ThreadWrapperTest, SendToOtherThread) { ...@@ -263,8 +263,8 @@ TEST_F(ThreadWrapperTest, SendToOtherThread) {
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
rtc::Thread* target; rtc::Thread* target;
second_thread.task_runner()->PostTask( second_thread.task_runner()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&InitializeWrapperForNewThread, &target,
base::Bind(&InitializeWrapperForNewThread, &target, &initialized_event)); &initialized_event));
initialized_event.Wait(); initialized_event.Wait();
ASSERT_TRUE(target != NULL); ASSERT_TRUE(target != NULL);
...@@ -294,8 +294,8 @@ TEST_F(ThreadWrapperTest, SendDuringSend) { ...@@ -294,8 +294,8 @@ TEST_F(ThreadWrapperTest, SendDuringSend) {
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
rtc::Thread* target; rtc::Thread* target;
second_thread.task_runner()->PostTask( second_thread.task_runner()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&InitializeWrapperForNewThread, &target,
base::Bind(&InitializeWrapperForNewThread, &target, &initialized_event)); &initialized_event));
initialized_event.Wait(); initialized_event.Wait();
ASSERT_TRUE(target != NULL); ASSERT_TRUE(target != NULL);
......
...@@ -125,35 +125,31 @@ void NonBlockingPushClient::Core::SendPing() { ...@@ -125,35 +125,31 @@ void NonBlockingPushClient::Core::SendPing() {
void NonBlockingPushClient::Core::OnNotificationsEnabled() { void NonBlockingPushClient::Core::OnNotificationsEnabled() {
DCHECK(delegate_task_runner_->BelongsToCurrentThread()); DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask( parent_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnNotificationsEnabled,
base::Bind(&NonBlockingPushClient::OnNotificationsEnabled, parent_push_client_));
parent_push_client_));
} }
void NonBlockingPushClient::Core::OnNotificationsDisabled( void NonBlockingPushClient::Core::OnNotificationsDisabled(
NotificationsDisabledReason reason) { NotificationsDisabledReason reason) {
DCHECK(delegate_task_runner_->BelongsToCurrentThread()); DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask( parent_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnNotificationsDisabled,
base::Bind(&NonBlockingPushClient::OnNotificationsDisabled, parent_push_client_, reason));
parent_push_client_, reason));
} }
void NonBlockingPushClient::Core::OnIncomingNotification( void NonBlockingPushClient::Core::OnIncomingNotification(
const Notification& notification) { const Notification& notification) {
DCHECK(delegate_task_runner_->BelongsToCurrentThread()); DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask( parent_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnIncomingNotification,
base::Bind(&NonBlockingPushClient::OnIncomingNotification, parent_push_client_, notification));
parent_push_client_, notification));
} }
void NonBlockingPushClient::Core::OnPingResponse() { void NonBlockingPushClient::Core::OnPingResponse() {
DCHECK(delegate_task_runner_->BelongsToCurrentThread()); DCHECK(delegate_task_runner_->BelongsToCurrentThread());
parent_task_runner_->PostTask( parent_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&NonBlockingPushClient::OnPingResponse,
base::Bind(&NonBlockingPushClient::OnPingResponse, parent_push_client_));
parent_push_client_));
} }
NonBlockingPushClient::NonBlockingPushClient( NonBlockingPushClient::NonBlockingPushClient(
...@@ -165,16 +161,16 @@ NonBlockingPushClient::NonBlockingPushClient( ...@@ -165,16 +161,16 @@ NonBlockingPushClient::NonBlockingPushClient(
core_ = new Core(delegate_task_runner_, weak_ptr_factory_.GetWeakPtr()); core_ = new Core(delegate_task_runner_, weak_ptr_factory_.GetWeakPtr());
delegate_task_runner_->PostTask( delegate_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::CreateOnDelegateThread, base::BindOnce(&NonBlockingPushClient::Core::CreateOnDelegateThread,
core_, create_blocking_push_client_callback)); core_, create_blocking_push_client_callback));
} }
NonBlockingPushClient::~NonBlockingPushClient() { NonBlockingPushClient::~NonBlockingPushClient() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask( delegate_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::DestroyOnDelegateThread, base::BindOnce(&NonBlockingPushClient::Core::DestroyOnDelegateThread,
core_)); core_));
} }
void NonBlockingPushClient::AddObserver(PushClientObserver* observer) { void NonBlockingPushClient::AddObserver(PushClientObserver* observer) {
...@@ -192,8 +188,8 @@ void NonBlockingPushClient::UpdateSubscriptions( ...@@ -192,8 +188,8 @@ void NonBlockingPushClient::UpdateSubscriptions(
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask( delegate_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&NonBlockingPushClient::Core::UpdateSubscriptions, base::BindOnce(&NonBlockingPushClient::Core::UpdateSubscriptions, core_,
core_, subscriptions)); subscriptions));
} }
void NonBlockingPushClient::UpdateCredentials( void NonBlockingPushClient::UpdateCredentials(
...@@ -202,24 +198,22 @@ void NonBlockingPushClient::UpdateCredentials( ...@@ -202,24 +198,22 @@ void NonBlockingPushClient::UpdateCredentials(
const net::NetworkTrafficAnnotationTag& traffic_annotation) { const net::NetworkTrafficAnnotationTag& traffic_annotation) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask( delegate_task_runner_->PostTask(
FROM_HERE, base::Bind(&NonBlockingPushClient::Core::UpdateCredentials, FROM_HERE, base::BindOnce(&NonBlockingPushClient::Core::UpdateCredentials,
core_, email, token, traffic_annotation)); core_, email, token, traffic_annotation));
} }
void NonBlockingPushClient::SendNotification( void NonBlockingPushClient::SendNotification(
const Notification& notification) { const Notification& notification) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask( delegate_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&NonBlockingPushClient::Core::SendNotification,
base::Bind(&NonBlockingPushClient::Core::SendNotification, core_, core_, notification));
notification));
} }
void NonBlockingPushClient::SendPing() { void NonBlockingPushClient::SendPing() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
delegate_task_runner_->PostTask( delegate_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&NonBlockingPushClient::Core::SendPing, core_));
base::Bind(&NonBlockingPushClient::Core::SendPing, core_));
} }
void NonBlockingPushClient::OnNotificationsEnabled() { void NonBlockingPushClient::OnNotificationsEnabled() {
......
...@@ -50,8 +50,8 @@ TEST_F(PushClientTest, CreateDefaultOffIOThread) { ...@@ -50,8 +50,8 @@ TEST_F(PushClientTest, CreateDefaultOffIOThread) {
base::Thread thread("Non-IO thread"); base::Thread thread("Non-IO thread");
EXPECT_TRUE(thread.Start()); EXPECT_TRUE(thread.Start());
thread.task_runner()->PostTask( thread.task_runner()->PostTask(
FROM_HERE, base::Bind(base::IgnoreResult(&PushClient::CreateDefault), FROM_HERE, base::BindOnce(base::IgnoreResult(&PushClient::CreateDefault),
notifier_options_)); notifier_options_));
thread.Stop(); 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