Commit 782fc629 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[Code Health] Migrate bluetooth low energy extension API to OnceCallback

This also ended up touching some of //device/bluetooth.

Bug: 834319, 1007786
Change-Id: Iebcf042a74af77d3aac2cce8afb4fc4d2af9d831
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285450
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786060}
parent e62f453c
......@@ -184,12 +184,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattService
// Registers this GATT service. Calling Register will make this service and
// all of its associated attributes available on the local adapters GATT
// database. Call Unregister to make this service no longer available.
virtual void Register(const base::Closure& callback,
virtual void Register(base::OnceClosure callback,
ErrorCallback error_callback) = 0;
// Unregisters this GATT service. This will remove the service from the list
// of services exposed by the adapter this service was registered on.
virtual void Unregister(const base::Closure& callback,
virtual void Unregister(base::OnceClosure callback,
ErrorCallback error_callback) = 0;
// Returns if this service is currently registered.
......
......@@ -167,7 +167,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ final
// service not being discoverable in any further scans of the adapter. Any
// sockets listening on this service will need to be closed separately.
void RemoveServiceRecord(uint32_t handle,
const base::Closure& callback,
base::OnceClosure callback,
const ServiceRecordErrorCallback& error_callback);
// Locates the device object by object path (the devices map and
......@@ -231,13 +231,13 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ final
// Register a GATT service. The service must belong to this adapter.
void RegisterGattService(
BluetoothLocalGattServiceBlueZ* service,
const base::Closure& callback,
base::OnceClosure callback,
device::BluetoothGattService::ErrorCallback error_callback);
// Unregister a GATT service. The service must already be registered.
void UnregisterGattService(
BluetoothLocalGattServiceBlueZ* service,
const base::Closure& callback,
base::OnceClosure callback,
device::BluetoothGattService::ErrorCallback error_callback);
// Returns if a given service is currently registered.
......@@ -363,12 +363,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ final
void PresentChanged(bool present);
// Called by dbus:: on completion of the discoverable property change.
void OnSetDiscoverable(const base::Closure& callback,
void OnSetDiscoverable(base::OnceClosure callback,
const ErrorCallback& error_callback,
bool success);
// Called by dbus:: on completion of an adapter property change.
void OnPropertyChangeCompleted(const base::Closure& callback,
void OnPropertyChangeCompleted(base::OnceClosure callback,
const ErrorCallback& error_callback,
bool success);
......@@ -384,32 +384,32 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ final
void StopScan(DiscoverySessionResultCallback callback) override;
void SetDiscoveryFilter(
std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback);
// Called by dbus:: on completion of the D-Bus method call to start discovery.
void OnStartDiscovery(const base::Closure& callback,
void OnStartDiscovery(base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback);
void OnStartDiscoveryError(const base::Closure& callback,
void OnStartDiscoveryError(base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message);
// Called by dbus:: on completion of the D-Bus method call to stop discovery.
void OnStopDiscovery(const base::Closure& callback);
void OnStopDiscovery(base::OnceClosure callback);
void OnStopDiscoveryError(DiscoverySessionErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message);
void OnPreSetDiscoveryFilter(const base::Closure& callback,
void OnPreSetDiscoveryFilter(base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback);
void OnPreSetDiscoveryFilterError(
const base::Closure& callback,
base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback,
device::UMABluetoothDiscoverySessionOutcome outcome);
void OnSetDiscoveryFilter(const base::Closure& callback,
void OnSetDiscoveryFilter(base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback);
void OnSetDiscoveryFilterError(const base::Closure& callback,
void OnSetDiscoveryFilterError(base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message);
......@@ -437,19 +437,19 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ final
// register even if the initial unregister call fails.
void UpdateRegisteredApplication(
bool ignore_unregister_failure,
const base::Closure& callback,
base::OnceClosure callback,
device::BluetoothGattService::ErrorCallback error_callback);
// Make the call to GattManager1 to register the services currently
// registered.
void RegisterApplication(
const base::Closure& callback,
base::OnceClosure callback,
device::BluetoothGattService::ErrorCallback error_callback);
// Register application, ignoring the given errors. Used to register a GATT
// application even if a previous unregister application call fails.
void RegisterApplicationOnError(
const base::Closure& callback,
base::OnceClosure callback,
device::BluetoothGattService::ErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message);
......
......@@ -59,15 +59,16 @@ bool BluetoothLocalGattServiceBlueZ::IsPrimary() const {
return is_primary_;
}
void BluetoothLocalGattServiceBlueZ::Register(const base::Closure& callback,
void BluetoothLocalGattServiceBlueZ::Register(base::OnceClosure callback,
ErrorCallback error_callback) {
GetAdapter()->RegisterGattService(this, callback, std::move(error_callback));
GetAdapter()->RegisterGattService(this, std::move(callback),
std::move(error_callback));
}
void BluetoothLocalGattServiceBlueZ::Unregister(const base::Closure& callback,
void BluetoothLocalGattServiceBlueZ::Unregister(base::OnceClosure callback,
ErrorCallback error_callback) {
DCHECK(GetAdapter());
GetAdapter()->UnregisterGattService(this, callback,
GetAdapter()->UnregisterGattService(this, std::move(callback),
std::move(error_callback));
}
......
......@@ -40,9 +40,9 @@ class BluetoothLocalGattServiceBlueZ
bool IsPrimary() const override;
// device::BluetoothLocalGattService overrides.
void Register(const base::Closure& callback,
void Register(base::OnceClosure callback,
ErrorCallback error_callback) override;
void Unregister(const base::Closure& callback,
void Unregister(base::OnceClosure callback,
ErrorCallback error_callback) override;
bool IsRegistered() override;
void Delete() override;
......
......@@ -443,8 +443,8 @@ void BluetoothLowEnergyConnectFunction::DoWork() {
event_router->Connect(
persistent, extension(), params_->device_address,
base::Bind(&BluetoothLowEnergyConnectFunction::SuccessCallback, this),
base::Bind(&BluetoothLowEnergyConnectFunction::ErrorCallback, this));
base::BindOnce(&BluetoothLowEnergyConnectFunction::SuccessCallback, this),
base::BindOnce(&BluetoothLowEnergyConnectFunction::ErrorCallback, this));
}
void BluetoothLowEnergyConnectFunction::SuccessCallback() {
......@@ -478,8 +478,10 @@ void BluetoothLowEnergyDisconnectFunction::DoWork() {
event_router->Disconnect(
extension(), params_->device_address,
base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this),
base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this));
base::BindOnce(&BluetoothLowEnergyDisconnectFunction::SuccessCallback,
this),
base::BindOnce(&BluetoothLowEnergyDisconnectFunction::ErrorCallback,
this));
}
void BluetoothLowEnergyDisconnectFunction::SuccessCallback() {
......@@ -766,10 +768,10 @@ void BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() {
instance_id_ = params_->characteristic_id;
event_router->ReadCharacteristicValue(
extension(), instance_id_,
base::Bind(
base::BindOnce(
&BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback,
this),
base::Bind(
base::BindOnce(
&BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback,
this));
}
......@@ -822,10 +824,10 @@ void BluetoothLowEnergyWriteCharacteristicValueFunction::DoWork() {
std::vector<uint8_t> value(params_->value.begin(), params_->value.end());
event_router->WriteCharacteristicValue(
extension(), params_->characteristic_id, value,
base::Bind(
base::BindOnce(
&BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback,
this),
base::Bind(
base::BindOnce(
&BluetoothLowEnergyWriteCharacteristicValueFunction::ErrorCallback,
this));
}
......@@ -868,12 +870,14 @@ void BluetoothLowEnergyStartCharacteristicNotificationsFunction::DoWork() {
event_router->StartCharacteristicNotifications(
persistent, extension(), params_->characteristic_id,
base::Bind(&BluetoothLowEnergyStartCharacteristicNotificationsFunction::
SuccessCallback,
this),
base::Bind(&BluetoothLowEnergyStartCharacteristicNotificationsFunction::
ErrorCallback,
this));
base::BindOnce(
&BluetoothLowEnergyStartCharacteristicNotificationsFunction::
SuccessCallback,
this),
base::BindOnce(
&BluetoothLowEnergyStartCharacteristicNotificationsFunction::
ErrorCallback,
this));
}
void BluetoothLowEnergyStartCharacteristicNotificationsFunction::
......@@ -910,12 +914,14 @@ void BluetoothLowEnergyStopCharacteristicNotificationsFunction::DoWork() {
event_router->StopCharacteristicNotifications(
extension(), params_->characteristic_id,
base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction::
SuccessCallback,
this),
base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction::
ErrorCallback,
this));
base::BindOnce(
&BluetoothLowEnergyStopCharacteristicNotificationsFunction::
SuccessCallback,
this),
base::BindOnce(
&BluetoothLowEnergyStopCharacteristicNotificationsFunction::
ErrorCallback,
this));
}
void BluetoothLowEnergyStopCharacteristicNotificationsFunction::
......@@ -953,11 +959,11 @@ void BluetoothLowEnergyReadDescriptorValueFunction::DoWork() {
instance_id_ = params_->descriptor_id;
event_router->ReadDescriptorValue(
extension(), instance_id_,
base::Bind(
base::BindOnce(
&BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback,
this),
base::Bind(&BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback,
this));
base::BindOnce(
&BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback, this));
}
void BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback() {
......@@ -1008,11 +1014,12 @@ void BluetoothLowEnergyWriteDescriptorValueFunction::DoWork() {
std::vector<uint8_t> value(params_->value.begin(), params_->value.end());
event_router->WriteDescriptorValue(
extension(), params_->descriptor_id, value,
base::Bind(
base::BindOnce(
&BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback,
this),
base::Bind(&BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback,
this));
base::BindOnce(
&BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback,
this));
}
void BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback() {
......@@ -1426,10 +1433,10 @@ bool BluetoothLowEnergyRegisterServiceFunction::ParseParams() {
void BluetoothLowEnergyRegisterServiceFunction::DoWork() {
event_router_->RegisterGattService(
extension(), params_->service_id,
base::Bind(&BluetoothLowEnergyRegisterServiceFunction::SuccessCallback,
this),
base::Bind(&BluetoothLowEnergyRegisterServiceFunction::ErrorCallback,
this));
base::BindOnce(
&BluetoothLowEnergyRegisterServiceFunction::SuccessCallback, this),
base::BindOnce(&BluetoothLowEnergyRegisterServiceFunction::ErrorCallback,
this));
}
void BluetoothLowEnergyRegisterServiceFunction::SuccessCallback() {
......@@ -1457,10 +1464,10 @@ bool BluetoothLowEnergyUnregisterServiceFunction::ParseParams() {
void BluetoothLowEnergyUnregisterServiceFunction::DoWork() {
event_router_->UnregisterGattService(
extension(), params_->service_id,
base::Bind(&BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback,
this),
base::Bind(&BluetoothLowEnergyUnregisterServiceFunction::ErrorCallback,
this));
base::BindOnce(
&BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback, this),
base::BindOnce(
&BluetoothLowEnergyUnregisterServiceFunction::ErrorCallback, this));
}
void BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback() {
......
......@@ -110,7 +110,7 @@ class BluetoothLowEnergyEventRouter
};
// Error callback is used by asynchronous methods to report failures.
using ErrorCallback = base::Callback<void(Status)>;
using ErrorCallback = base::OnceCallback<void(Status)>;
// Returns true if Bluetooth is supported on the current platform or if the
// internal |adapter_| instance has been initialized for testing.
......@@ -135,8 +135,8 @@ class BluetoothLowEnergyEventRouter
void Connect(bool persistent,
const Extension* extension,
const std::string& device_address,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Disconnects the currently open GATT connection of extension |extension| to
// device with address |device_address|. |error_callback| is called with an
......@@ -145,8 +145,8 @@ class BluetoothLowEnergyEventRouter
// extension does not have an open connection to the device.
void Disconnect(const Extension* extension,
const std::string& device_address,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Returns the list of api::bluetooth_low_energy::Service objects
// associated with the Bluetooth device with address |device_address| in
......@@ -219,8 +219,8 @@ class BluetoothLowEnergyEventRouter
// failure. |extension| is the extension that made the call.
void ReadCharacteristicValue(const Extension* extension,
const std::string& instance_id,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Sends a request to write the value of the characteristic with instance ID
// |instance_id|. Invokes |callback| on success and |error_callback| on
......@@ -228,8 +228,8 @@ class BluetoothLowEnergyEventRouter
void WriteCharacteristicValue(const Extension* extension,
const std::string& instance_id,
const std::vector<uint8_t>& value,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Sends a request to start characteristic notifications from characteristic
// with instance ID |instance_id|, for extension |extension|. Invokes
......@@ -238,24 +238,24 @@ class BluetoothLowEnergyEventRouter
void StartCharacteristicNotifications(bool persistent,
const Extension* extension,
const std::string& instance_id,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Sends a request to stop characteristic notifications from characteristic
// with instance ID |instance_id|, for extension |extension|. Invokes
// |callback| on success and |error_callback| on failure.
void StopCharacteristicNotifications(const Extension* extension,
const std::string& instance_id,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Sends a request to read the value of the descriptor with instance ID
// |instance_id|. Invokes |callback| on success and |error_callback| on
// failure. |extension| is the extension that made the call.
void ReadDescriptorValue(const Extension* extension,
const std::string& instance_id,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Sends a request to write the value of the descriptor with instance ID
// |instance_id|. Invokes |callback| on success and |error_callback| on
......@@ -263,8 +263,8 @@ class BluetoothLowEnergyEventRouter
void WriteDescriptorValue(const Extension* extension,
const std::string& instance_id,
const std::vector<uint8_t>& value,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Initializes the adapter for testing. Used by unit tests only.
void SetAdapterForTesting(device::BluetoothAdapter* adapter);
......@@ -372,14 +372,14 @@ class BluetoothLowEnergyEventRouter
// Register a local GATT service.
void RegisterGattService(const Extension* extension,
const std::string& service_id,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Unregister a local GATT service.
void UnregisterGattService(const Extension* extension,
const std::string& service_id,
const base::Closure& callback,
const ErrorCallback& error_callback);
base::OnceClosure callback,
ErrorCallback error_callback);
// Handle a response from the app for the given request id.
void HandleRequestResponse(const Extension* extension,
......@@ -437,11 +437,11 @@ class BluetoothLowEnergyEventRouter
// |callback|.
void OnReadRemoteCharacteristicSuccess(
const std::string& characteristic_instance_id,
const base::Closure& callback,
base::OnceClosure callback,
const std::vector<uint8_t>& value);
// Runs |callback|.
void OnReadRemoteDescriptorSuccess(const base::Closure& callback,
void OnReadRemoteDescriptorSuccess(base::OnceClosure callback,
const std::vector<uint8_t>& value);
// Called by BluetoothDevice in response to a call to CreateGattConnection.
......@@ -449,29 +449,29 @@ class BluetoothLowEnergyEventRouter
bool persistent,
const std::string& extension_id,
const std::string& device_address,
const base::Closure& callback,
base::OnceClosure callback,
std::unique_ptr<device::BluetoothGattConnection> connection);
// Called by BluetoothGattService in response to Register().
void OnRegisterGattServiceSuccess(const std::string& service_id,
const std::string& extension_id,
const base::Closure& callback);
base::OnceClosure callback);
// Called by BluetoothGattService in response to Unregister().
void OnUnregisterGattServiceSuccess(const std::string& service_id,
const std::string& extension_id,
const base::Closure& callback);
base::OnceClosure callback);
// Called by BluetoothRemoteGattCharacteristic and
// BluetoothRemoteGattDescriptor in
// case of an error during the read/write operations.
void OnError(const ErrorCallback& error_callback,
void OnError(ErrorCallback error_callback,
device::BluetoothRemoteGattService::GattErrorCode error_code);
// Called by BluetoothDevice in response to a call to CreateGattConnection.
void OnConnectError(const std::string& extension_id,
const std::string& device_address,
const ErrorCallback& error_callback,
ErrorCallback error_callback,
device::BluetoothDevice::ConnectErrorCode error_code);
// Called by BluetoothRemoteGattCharacteristic in response to a call to
......@@ -480,7 +480,7 @@ class BluetoothLowEnergyEventRouter
bool persistent,
const std::string& extension_id,
const std::string& characteristic_id,
const base::Closure& callback,
base::OnceClosure callback,
std::unique_ptr<device::BluetoothGattNotifySession> session);
// Called by BluetoothRemoteGattCharacteristic in response to a call to
......@@ -488,13 +488,13 @@ class BluetoothLowEnergyEventRouter
void OnStartNotifySessionError(
const std::string& extension_id,
const std::string& characteristic_id,
const ErrorCallback& error_callback,
ErrorCallback error_callback,
device::BluetoothRemoteGattService::GattErrorCode error_code);
// Called by BluetoothGattNotifySession in response to a call to Stop.
void OnStopNotifySession(const std::string& extension_id,
const std::string& characteristic_id,
const base::Closure& callback);
base::OnceClosure callback);
// Finds and returns a BluetoothLowEnergyConnection to device with address
// |device_address| from the managed API resources for extension with ID
......
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