| Index: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
|
| diff --git a/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.cc b/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
|
| index 515838fcc5b58ea8564c49baf6508f8f6ab43e29..2d93bd60b290006f96bdd17dde0c72adb8b497da 100644
|
| --- a/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
|
| +++ b/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
|
| @@ -1089,6 +1089,11 @@ void BluetoothLowEnergyAdvertisementFunction::RemoveAdvertisement(
|
| advertisements_manager_->Remove(extension_id(), advertisement_id);
|
| }
|
|
|
| +const base::hash_set<int>*
|
| +BluetoothLowEnergyAdvertisementFunction::GetAdvertisementIds() {
|
| + return advertisements_manager_->GetResourceIds(extension_id());
|
| +}
|
| +
|
| bool BluetoothLowEnergyAdvertisementFunction::RunAsync() {
|
| Initialize();
|
| return BluetoothLowEnergyExtensionFunctionDeprecated::RunAsync();
|
| @@ -1267,6 +1272,70 @@ void BluetoothLowEnergyUnregisterAdvertisementFunction::ErrorCallback(
|
| SendResponse(false);
|
| }
|
|
|
| +// ResetAdvertising:
|
| +
|
| +bool BluetoothLowEnergyResetAdvertisingFunction::DoWork() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + // Check permission in the manifest.
|
| + if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) {
|
| + error_ = kErrorPermissionDenied;
|
| + SendResponse(false);
|
| + return false;
|
| + }
|
| +
|
| + // For this API to be available the app has to be either auto
|
| + // launched in Kiosk Mode or the enable-ble-advertisement-in-apps
|
| + // should be set.
|
| + if (!(IsAutoLaunchedKioskApp(extension()->id()) ||
|
| + IsPeripheralFlagEnabled())) {
|
| + error_ = kErrorPermissionDenied;
|
| + SendResponse(false);
|
| + return false;
|
| + }
|
| +
|
| + BluetoothLowEnergyEventRouter* event_router =
|
| + GetEventRouter(browser_context());
|
| +
|
| + // If we don't have an initialized adapter, resetting advertisements is a
|
| + // no-op.
|
| + if (!event_router->HasAdapter())
|
| + return true;
|
| +
|
| + base::hash_set<int> advertisement_ids;
|
| + if (GetAdvertisementIds()) {
|
| + advertisement_ids = *GetAdvertisementIds();
|
| + }
|
| +
|
| + if (advertisement_ids.size() == 0) {
|
| + SendResponse(true);
|
| + return true;
|
| + }
|
| +
|
| + for (int advertisement_id : advertisement_ids) {
|
| + RemoveAdvertisement(advertisement_id);
|
| + }
|
| +
|
| + event_router->adapter()->ResetAdvertising(
|
| + base::Bind(&BluetoothLowEnergyResetAdvertisingFunction::SuccessCallback,
|
| + this),
|
| + base::Bind(&BluetoothLowEnergyResetAdvertisingFunction::ErrorCallback,
|
| + this));
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void BluetoothLowEnergyResetAdvertisingFunction::SuccessCallback() {
|
| + Respond(NoArguments());
|
| +}
|
| +
|
| +void BluetoothLowEnergyResetAdvertisingFunction::ErrorCallback(
|
| + device::BluetoothAdvertisement::ErrorCode status) {
|
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX)
|
| + Respond(Error(kErrorOperationFailed));
|
| +#endif
|
| +}
|
| +
|
| // SetAdvertisingInterval:
|
|
|
| template class BLEPeripheralExtensionFunction<
|
|
|