0

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=bbudge@chromium.org

Bug: 714018
Change-Id: I3dfbf9194abf30d0f9c36363ef00033eb04b102e
Reviewed-on: https://chromium-review.googlesource.com/c/1475645
Auto-Submit: kylechar <kylechar@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633569}
This commit is contained in:
kylechar
2019-02-20 04:32:19 +00:00
committed by Commit Bot
parent 51f27fe437
commit 444859b4be
8 changed files with 24 additions and 21 deletions

@ -68,8 +68,9 @@ bool ResourceMessageFilter::HandleMessage(const IPC::Message& msg,
// other threads. It would be better to have a thread-safe refcounted
// context.
HostMessageContext context_copy = *context;
runner->PostTask(FROM_HERE, base::Bind(
&ResourceMessageFilter::DispatchMessage, this, msg, context_copy));
runner->PostTask(FROM_HERE,
base::BindOnce(&ResourceMessageFilter::DispatchMessage,
this, msg, context_copy));
}
return true;
}
@ -82,7 +83,7 @@ void ResourceMessageFilter::SendReply(const ReplyMessageContext& context,
if (!reply_thread_task_runner_->BelongsToCurrentThread()) {
reply_thread_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ResourceMessageFilter::SendReply, this, context, msg));
base::BindOnce(&ResourceMessageFilter::SendReply, this, context, msg));
return;
}
if (resource_host_)

@ -216,8 +216,9 @@ TEST_F(ResourceMessageFilterTest, TestHandleMessage) {
// It should be safe to use base::Unretained() because the object won't be
// destroyed before the task is run.
main_message_loop.task_runner()->PostTask(
FROM_HERE, base::Bind(&ResourceMessageFilterTest::TestHandleMessageImpl,
base::Unretained(this)));
FROM_HERE,
base::BindOnce(&ResourceMessageFilterTest::TestHandleMessageImpl,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
}

@ -94,7 +94,7 @@ void StartUpPlugin() {
base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
g_io_thread->task_runner()->PostTask(
FROM_HERE, base::Bind(StartUpManifestServiceOnIOThread, &event));
FROM_HERE, base::BindOnce(StartUpManifestServiceOnIOThread, &event));
event.Wait();
}

@ -440,7 +440,7 @@ FileIOResource::FileHolder::~FileHolder() {
base::TaskRunner* file_task_runner =
PpapiGlobals::Get()->GetFileTaskRunner();
file_task_runner->PostTask(FROM_HERE,
base::Bind(&DoClose, Passed(&file_)));
base::BindOnce(&DoClose, Passed(&file_)));
}
}

@ -99,7 +99,7 @@ MessageHandler::~MessageHandler() {
// The posted task won't have the proxy lock, but that's OK, it doesn't
// touch any internal state; it's a direct call on the plugin's function.
message_loop_->task_runner()->PostTask(
FROM_HERE, base::Bind(handler_if_->Destroy, instance_, user_data_));
FROM_HERE, base::BindOnce(handler_if_->Destroy, instance_, user_data_));
}
}

@ -96,8 +96,8 @@ void PluginMessageFilter::OnMsgResourceReply(
scoped_refptr<base::SingleThreadTaskRunner> target =
resource_reply_thread_registrar_->GetTargetThread(reply_params,
nested_msg);
target->PostTask(
FROM_HERE, base::Bind(&DispatchResourceReply, reply_params, nested_msg));
target->PostTask(FROM_HERE, base::BindOnce(&DispatchResourceReply,
reply_params, nested_msg));
}
// static

@ -390,8 +390,8 @@ void PluginProxyMultiThreadTest::CheckOnThread(ThreadType thread_type) {
void PluginProxyMultiThreadTest::PostQuitForMainThread() {
main_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&PluginProxyMultiThreadTest::QuitNestedLoop,
base::Unretained(this)));
FROM_HERE, base::BindOnce(&PluginProxyMultiThreadTest::QuitNestedLoop,
base::Unretained(this)));
}
void PluginProxyMultiThreadTest::PostQuitForSecondaryThread() {
@ -580,10 +580,10 @@ void TwoWayTest::SetUp() {
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
plugin_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&SetUpRemoteHarness, remote_harness_, pipe.handle0.release(),
base::RetainedRef(io_thread_.task_runner()), &shutdown_event_,
&remote_harness_set_up));
FROM_HERE, base::BindOnce(&SetUpRemoteHarness, remote_harness_,
pipe.handle0.release(),
base::RetainedRef(io_thread_.task_runner()),
&shutdown_event_, &remote_harness_set_up));
remote_harness_set_up.Wait();
local_harness_->SetUpHarnessWithChannel(
pipe.handle1.release(), io_thread_.task_runner().get(), &shutdown_event_,
@ -595,8 +595,8 @@ void TwoWayTest::TearDown() {
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
plugin_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&TearDownRemoteHarness, remote_harness_,
&remote_harness_torn_down));
FROM_HERE, base::BindOnce(&TearDownRemoteHarness, remote_harness_,
&remote_harness_torn_down));
remote_harness_torn_down.Wait();
local_harness_->TearDownHarness();
@ -609,7 +609,7 @@ void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) {
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
plugin_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&RunTaskOnRemoteHarness, task, &task_complete));
FROM_HERE, base::BindOnce(&RunTaskOnRemoteHarness, task, &task_complete));
task_complete.Wait();
}

@ -118,8 +118,9 @@ class ThreadAwareCallbackAbortTest : public proxy::PluginProxyMultiThreadTest {
{
ProxyAutoLock auto_lock;
main_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&ThreadAwareCallbackAbortTest::DeleteCallback,
base::Unretained(this)));
FROM_HERE,
base::BindOnce(&ThreadAwareCallbackAbortTest::DeleteCallback,
base::Unretained(this)));
// |main_thread_callback_| is still valid, even if DeleteCallback() can be
// called before this following statement. That is because |auto_lock| is
// still held by this method, which prevents DeleteCallback() from