Skip to content

Commit

Permalink
Use base::BindOnce for PostTask callbacks.
Browse files Browse the repository at this point in the history
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=stevenjb@chromium.org

Bug: 714018
Change-Id: I70dce39d3975123cf0709f1787cc68f49ba9a57d
Reviewed-on: https://chromium-review.googlesource.com/c/1475733
Auto-Submit: kylechar <kylechar@chromium.org>
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633334}
  • Loading branch information
kylechar authored and Commit Bot committed Feb 19, 2019
1 parent 78e7335 commit 39c3928
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 93 deletions.
58 changes: 24 additions & 34 deletions dbus/bus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Timeout {
void StartMonitoring(Bus* bus) {
bus->GetDBusTaskRunner()->PostDelayedTask(
FROM_HERE,
base::Bind(&Timeout::HandleTimeout, weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&Timeout::HandleTimeout, weak_ptr_factory_.GetWeakPtr()),
GetInterval());
}

Expand Down Expand Up @@ -237,9 +237,8 @@ bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name,
object_proxy_table_.erase(iter);
// Object is present. Remove it now and Detach on the DBus thread.
GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::RemoveObjectProxyInternal,
this, object_proxy, callback));
FROM_HERE, base::BindOnce(&Bus::RemoveObjectProxyInternal, this,
object_proxy, callback));
return true;
}
return false;
Expand Down Expand Up @@ -288,9 +287,8 @@ void Bus::UnregisterExportedObject(const ObjectPath& object_path) {
// SequencedTaskRunner, there is a guarantee that this will happen before any
// future registration call.
GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::UnregisterExportedObjectInternal,
this, exported_object));
FROM_HERE, base::BindOnce(&Bus::UnregisterExportedObjectInternal, this,
exported_object));
}

void Bus::UnregisterExportedObjectInternal(
Expand Down Expand Up @@ -334,9 +332,8 @@ bool Bus::RemoveObjectManager(const std::string& service_name,
object_manager_table_.erase(iter);

GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::RemoveObjectManagerInternal,
this, object_manager, callback));
FROM_HERE, base::BindOnce(&Bus::RemoveObjectManagerInternal, this,
object_manager, callback));

return true;
}
Expand All @@ -352,9 +349,8 @@ void Bus::RemoveObjectManagerInternal(
// The ObjectManager has to be deleted on the origin thread since it was
// created there.
GetOriginTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::RemoveObjectManagerInternalHelper,
this, object_manager, callback));
FROM_HERE, base::BindOnce(&Bus::RemoveObjectManagerInternalHelper, this,
object_manager, callback));
}

void Bus::RemoveObjectManagerInternalHelper(
Expand Down Expand Up @@ -498,7 +494,7 @@ void Bus::ShutdownOnDBusThreadAndBlock() {

GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::ShutdownOnDBusThreadAndBlockInternal, this));
base::BindOnce(&Bus::ShutdownOnDBusThreadAndBlockInternal, this));

// http://crbug.com/125222
base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait;
Expand All @@ -517,9 +513,8 @@ void Bus::RequestOwnership(const std::string& service_name,
AssertOnOriginThread();

GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::RequestOwnershipInternal,
this, service_name, options, on_ownership_callback));
FROM_HERE, base::BindOnce(&Bus::RequestOwnershipInternal, this,
service_name, options, on_ownership_callback));
}

void Bus::RequestOwnershipInternal(const std::string& service_name,
Expand All @@ -531,10 +526,8 @@ void Bus::RequestOwnershipInternal(const std::string& service_name,
if (success)
success = RequestOwnershipAndBlock(service_name, options);

GetOriginTaskRunner()->PostTask(FROM_HERE,
base::Bind(on_ownership_callback,
service_name,
success));
GetOriginTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(on_ownership_callback, service_name, success));
}

bool Bus::RequestOwnershipAndBlock(const std::string& service_name,
Expand Down Expand Up @@ -892,8 +885,8 @@ void Bus::GetServiceOwner(const std::string& service_name,
AssertOnOriginThread();

GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::GetServiceOwnerInternal, this, service_name, callback));
FROM_HERE, base::BindOnce(&Bus::GetServiceOwnerInternal, this,
service_name, callback));
}

void Bus::GetServiceOwnerInternal(const std::string& service_name,
Expand All @@ -904,7 +897,7 @@ void Bus::GetServiceOwnerInternal(const std::string& service_name,
if (Connect())
service_owner = GetServiceOwnerAndBlock(service_name, SUPPRESS_ERRORS);
GetOriginTaskRunner()->PostTask(FROM_HERE,
base::Bind(callback, service_owner));
base::BindOnce(callback, service_owner));
}

void Bus::ListenForServiceOwnerChange(
Expand All @@ -915,9 +908,8 @@ void Bus::ListenForServiceOwnerChange(
DCHECK(!callback.is_null());

GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::ListenForServiceOwnerChangeInternal,
this, service_name, callback));
FROM_HERE, base::BindOnce(&Bus::ListenForServiceOwnerChangeInternal, this,
service_name, callback));
}

void Bus::ListenForServiceOwnerChangeInternal(
Expand Down Expand Up @@ -969,9 +961,8 @@ void Bus::UnlistenForServiceOwnerChange(
DCHECK(!callback.is_null());

GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&Bus::UnlistenForServiceOwnerChangeInternal,
this, service_name, callback));
FROM_HERE, base::BindOnce(&Bus::UnlistenForServiceOwnerChangeInternal,
this, service_name, callback));
}

void Bus::UnlistenForServiceOwnerChangeInternal(
Expand Down Expand Up @@ -1093,9 +1084,8 @@ void Bus::OnDispatchStatusChanged(DBusConnection* connection,
// dbus_connection_dispatch() inside DBusDispatchStatusFunction is
// prohibited by the D-Bus library. Hence, we post a task here instead.
// See comments for dbus_connection_set_dispatch_status_function().
GetDBusTaskRunner()->PostTask(FROM_HERE,
base::Bind(&Bus::ProcessAllIncomingDataIfAny,
this));
GetDBusTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&Bus::ProcessAllIncomingDataIfAny, this));
}

void Bus::OnServiceOwnerChanged(DBusMessage* message) {
Expand Down Expand Up @@ -1132,7 +1122,7 @@ void Bus::OnServiceOwnerChanged(DBusMessage* message) {
const std::vector<GetServiceOwnerCallback>& callbacks = it->second;
for (size_t i = 0; i < callbacks.size(); ++i) {
GetOriginTaskRunner()->PostTask(FROM_HERE,
base::Bind(callbacks[i], new_owner));
base::BindOnce(callbacks[i], new_owner));
}
}

Expand Down
22 changes: 8 additions & 14 deletions dbus/exported_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,8 @@ void ExportedObject::SendSignal(Signal* signal) {
SendSignalInternal(start_time, signal_message);
} else {
bus_->GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ExportedObject::SendSignalInternal,
this,
start_time,
signal_message));
FROM_HERE, base::BindOnce(&ExportedObject::SendSignalInternal, this,
start_time, signal_message));
}
}

Expand All @@ -161,13 +158,10 @@ void ExportedObject::ExportMethodInternal(
const bool success = ExportMethodAndBlock(interface_name,
method_name,
method_call_callback);
bus_->GetOriginTaskRunner()->PostTask(FROM_HERE,
base::Bind(&ExportedObject::OnExported,
this,
on_exported_calback,
interface_name,
method_name,
success));
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&ExportedObject::OnExported, this, on_exported_calback,
interface_name, method_name, success));
}

void ExportedObject::UnexportMethodInternal(
Expand All @@ -179,8 +173,8 @@ void ExportedObject::UnexportMethodInternal(
const bool success = UnexportMethodAndBlock(interface_name, method_name);
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ExportedObject::OnUnexported, this, on_unexported_calback,
interface_name, method_name, success));
base::BindOnce(&ExportedObject::OnUnexported, this, on_unexported_calback,
interface_name, method_name, success));
}

void ExportedObject::OnExported(OnExportedCallback on_exported_callback,
Expand Down
9 changes: 3 additions & 6 deletions dbus/object_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,8 @@ DBusHandlerResult ObjectManager::HandleMessage(DBusConnection* connection,
// |signal| to NotifyPropertiesChanged, which will handle the clean up.
Signal* released_signal = signal.release();
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ObjectManager::NotifyPropertiesChanged,
this, path,
released_signal));
FROM_HERE, base::BindOnce(&ObjectManager::NotifyPropertiesChanged, this,
path, released_signal));
} else {
// If the D-Bus thread is not used, just call the callback on the
// current thread. Transfer the ownership of |signal| to
Expand All @@ -334,8 +332,7 @@ void ObjectManager::NotifyPropertiesChanged(

// Delete the message on the D-Bus thread. See comments in HandleMessage.
bus_->GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&base::DeletePointer<Signal>, signal));
FROM_HERE, base::BindOnce(&base::DeletePointer<Signal>, signal));
}

void ObjectManager::NotifyPropertiesChangedHelper(
Expand Down
5 changes: 3 additions & 2 deletions dbus/object_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,9 @@ TEST_F(ObjectManagerTest, PropertiesChangedAsObjectsReceived) {
// the PropertiesChanged event right after that. If we don't receive it within
// 2 seconds, then fail the test.
message_loop_.task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&ObjectManagerTest::PropertiesChangedTestTimeout,
base::Unretained(this)),
FROM_HERE,
base::BindOnce(&ObjectManagerTest::PropertiesChangedTestTimeout,
base::Unretained(this)),
base::TimeDelta::FromSeconds(2));

while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) {
Expand Down
22 changes: 9 additions & 13 deletions dbus/object_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,9 @@ DBusHandlerResult ObjectProxy::HandleMessage(
// Transfer the ownership of |signal| to RunMethod().
// |released_signal| will be deleted in RunMethod().
Signal* released_signal = signal.release();
bus_->GetOriginTaskRunner()->PostTask(FROM_HERE,
base::Bind(&ObjectProxy::RunMethod,
this,
start_time,
iter->second,
released_signal));
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&ObjectProxy::RunMethod, this, start_time,
iter->second, released_signal));
} else {
const base::TimeTicks start_time = base::TimeTicks::Now();
// If the D-Bus thread is not used, just call the callback on the
Expand All @@ -582,8 +579,7 @@ void ObjectProxy::RunMethod(base::TimeTicks start_time,
// Delete the message on the D-Bus thread. See comments in
// RunResponseOrErrorCallback().
bus_->GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&base::DeletePointer<Signal>, signal));
FROM_HERE, base::BindOnce(&base::DeletePointer<Signal>, signal));

// Record time spent for handling the signal.
UMA_HISTOGRAM_TIMES("DBus.SignalHandleTime",
Expand Down Expand Up @@ -725,16 +721,16 @@ DBusHandlerResult ObjectProxy::HandleNameOwnerChanged(
name == service_name_) {
service_name_owner_ = new_owner;
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ObjectProxy::RunNameOwnerChangedCallback,
this, old_owner, new_owner));
FROM_HERE, base::BindOnce(&ObjectProxy::RunNameOwnerChangedCallback,
this, old_owner, new_owner));

const bool service_is_available = !service_name_owner_.empty();
if (service_is_available) {
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ObjectProxy::RunWaitForServiceToBeAvailableCallbacks,
this, service_is_available));
base::BindOnce(
&ObjectProxy::RunWaitForServiceToBeAvailableCallbacks, this,
service_is_available));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dbus/signal_sender_verification_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class SignalSenderVerificationTest : public testing::Test {
// PostTask to quit the MessageLoop as this is called from D-Bus thread.
message_loop_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&SignalSenderVerificationTest::OnOwnershipInternal,
base::Unretained(this)));
base::BindOnce(&SignalSenderVerificationTest::OnOwnershipInternal,
base::Unretained(this)));
}

void OnOwnershipInternal() {
Expand Down
Loading

0 comments on commit 39c3928

Please sign in to comment.