Skip to content

Commit

Permalink
Change dbus Get/Set Property callback to OnceCallback.
Browse files Browse the repository at this point in the history
These callbacks are only called once, so change them to the correct
spelling. This will allow bluetooth code to be converted to OnceCallback
as well, which will then allow content code to be converted.

TBR=hashimoto,rkc

Bug: 953861
Change-Id: I49b0fcf6e00721e5e6bbb4439bad7c5cbb0d6463
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572204
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Auto-Submit: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652169}
  • Loading branch information
danakj authored and Commit Bot committed Apr 18, 2019
1 parent 30322cd commit c78039d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 37 deletions.
22 changes: 8 additions & 14 deletions dbus/property.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,9 @@ void PropertySet::Get(PropertyBase* property, GetCallback callback) {
writer.AppendString(property->name());

DCHECK(object_proxy_);
object_proxy_->CallMethod(&method_call,
ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&PropertySet::OnGet,
GetWeakPtr(),
property,
callback));
object_proxy_->CallMethod(&method_call, ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&PropertySet::OnGet, GetWeakPtr(),
property, std::move(callback)));
}

void PropertySet::OnGet(PropertyBase* property, GetCallback callback,
Expand All @@ -132,7 +129,7 @@ void PropertySet::OnGet(PropertyBase* property, GetCallback callback,
}

if (!callback.is_null())
callback.Run(response);
std::move(callback).Run(response);
}

bool PropertySet::GetAndBlock(PropertyBase* property) {
Expand Down Expand Up @@ -196,12 +193,9 @@ void PropertySet::Set(PropertyBase* property, SetCallback callback) {
property->AppendSetValueToWriter(&writer);

DCHECK(object_proxy_);
object_proxy_->CallMethod(&method_call,
ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&PropertySet::OnSet,
GetWeakPtr(),
property,
callback));
object_proxy_->CallMethod(&method_call, ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&PropertySet::OnSet, GetWeakPtr(),
property, std::move(callback)));
}

bool PropertySet::SetAndBlock(PropertyBase* property) {
Expand All @@ -224,7 +218,7 @@ void PropertySet::OnSet(PropertyBase* property,
Response* response) {
LOG_IF(WARNING, !response) << property->name() << ": Set: failed.";
if (!callback.is_null())
callback.Run(response);
std::move(callback).Run(response);
}

bool PropertySet::UpdatePropertiesFromReader(MessageReader* reader) {
Expand Down
8 changes: 4 additions & 4 deletions dbus/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class CHROME_DBUS_EXPORT PropertySet {
// Callback for Get() method, |success| indicates whether or not the
// value could be retrived, if true the new value can be obtained by
// calling value() on the property.
typedef base::Callback<void(bool success)> GetCallback;
using GetCallback = base::OnceCallback<void(bool success)>;

// Requests an updated value from the remote object for |property|
// incurring a round-trip. |callback| will be called when the new
Expand All @@ -274,7 +274,7 @@ class CHROME_DBUS_EXPORT PropertySet {

// Callback for Set() method, |success| indicates whether or not the
// new property value was accepted by the remote object.
typedef base::Callback<void(bool success)> SetCallback;
using SetCallback = base::OnceCallback<void(bool success)>;

// Requests that the remote object for |property| change the property to
// its new value. |callback| will be called to indicate the success or
Expand Down Expand Up @@ -387,7 +387,7 @@ class CHROME_DBUS_EXPORT Property : public PropertyBase {
// round-trip. |callback| will be called when the new value is available.
// This may not be implemented by some interfaces.
virtual void Get(dbus::PropertySet::GetCallback callback) {
property_set()->Get(this, callback);
property_set()->Get(this, std::move(callback));
}

// The synchronous version of Get().
Expand All @@ -402,7 +402,7 @@ class CHROME_DBUS_EXPORT Property : public PropertyBase {
// remote object.
virtual void Set(const T& value, dbus::PropertySet::SetCallback callback) {
set_value_ = value;
property_set()->Set(this, callback);
property_set()->Set(this, std::move(callback));
}

// The synchronous version of Set().
Expand Down
6 changes: 3 additions & 3 deletions device/bluetooth/dbus/fake_bluetooth_adapter_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void FakeBluetoothAdapterClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

void FakeBluetoothAdapterClient::Properties::GetAll() {
Expand All @@ -66,10 +66,10 @@ void FakeBluetoothAdapterClient::Properties::Set(
if (property->name() == powered.name() || property->name() == alias.name() ||
property->name() == discoverable.name() ||
property->name() == discoverable_timeout.name()) {
callback.Run(true);
std::move(callback).Run(true);
property->ReplaceValueWithSetValue();
} else {
callback.Run(false);
std::move(callback).Run(false);
}
}

Expand Down
6 changes: 3 additions & 3 deletions device/bluetooth/dbus/fake_bluetooth_device_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void FakeBluetoothDeviceClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

void FakeBluetoothDeviceClient::Properties::GetAll() {
Expand All @@ -291,10 +291,10 @@ void FakeBluetoothDeviceClient::Properties::Set(
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
if (property->name() == trusted.name()) {
callback.Run(true);
std::move(callback).Run(true);
property->ReplaceValueWithSetValue();
} else {
callback.Run(false);
std::move(callback).Run(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void FakeBluetoothGattCharacteristicClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(true);
std::move(callback).Run(true);
}

void FakeBluetoothGattCharacteristicClient::Properties::GetAll() {
Expand All @@ -73,7 +73,7 @@ void FakeBluetoothGattCharacteristicClient::Properties::Set(
dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

FakeBluetoothGattCharacteristicClient::FakeBluetoothGattCharacteristicClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void FakeBluetoothGattDescriptorClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(true);
std::move(callback).Run(true);
}

void FakeBluetoothGattDescriptorClient::Properties::GetAll() {
Expand All @@ -48,7 +48,7 @@ void FakeBluetoothGattDescriptorClient::Properties::Set(
dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

FakeBluetoothGattDescriptorClient::DescriptorData::DescriptorData() = default;
Expand Down
6 changes: 3 additions & 3 deletions device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void FakeBluetoothGattServiceClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

void FakeBluetoothGattServiceClient::Properties::GetAll() {
Expand All @@ -50,9 +50,9 @@ void FakeBluetoothGattServiceClient::Properties::GetAll() {

void FakeBluetoothGattServiceClient::Properties::Set(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

FakeBluetoothGattServiceClient::FakeBluetoothGattServiceClient()
Expand Down
4 changes: 2 additions & 2 deletions device/bluetooth/dbus/fake_bluetooth_input_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void FakeBluetoothInputClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

void FakeBluetoothInputClient::Properties::GetAll() {
Expand All @@ -42,7 +42,7 @@ void FakeBluetoothInputClient::Properties::Set(
dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

FakeBluetoothInputClient::FakeBluetoothInputClient() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void FakeBluetoothMediaTransportClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

void FakeBluetoothMediaTransportClient::Properties::GetAll() {
Expand All @@ -85,7 +85,7 @@ void FakeBluetoothMediaTransportClient::Properties::Set(
dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
callback.Run(false);
std::move(callback).Run(false);
}

FakeBluetoothMediaTransportClient::Transport::Transport(
Expand Down
5 changes: 3 additions & 2 deletions services/device/bluetooth/bluetooth_system_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ class DEVICE_BLUETOOTH_EXPORT TestBluetoothAdapterClient
++set_powered_call_count_;
last_set_powered_value_ = powered.GetSetValueForTesting();
if (next_set_powered_response_) {
callback.Run(GetValueAndReset(&next_set_powered_response_));
std::move(callback).Run(
GetValueAndReset(&next_set_powered_response_));
return;
}
set_powered_callbacks_.push_back(callback);
set_powered_callbacks_.push_back(std::move(callback));
} else {
NOTIMPLEMENTED();
}
Expand Down

0 comments on commit c78039d

Please sign in to comment.