Chromium Code Reviews| 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()) || |
|
tbarzic
2017/06/27 19:04:57
is this the case for all advertisement functions?
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| + 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 |
|
tbarzic
2017/06/27 19:04:57
nit:
If the adapter is not initialized, there is n
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| + // no-op. |
| + if (!event_router->HasAdapter()) |
| + return true; |
|
tbarzic
2017/06/27 19:04:58
SendResponse?
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| + |
| + base::hash_set<int> advertisement_ids; |
|
tbarzic
2017/06/27 19:04:57
can you comment why you have to copy IDs.
maybe s
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| + if (GetAdvertisementIds()) { |
| + advertisement_ids = *GetAdvertisementIds(); |
| + } |
| + |
| + if (advertisement_ids.size() == 0) { |
|
tbarzic
2017/06/27 19:04:57
nit: empty()
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| + 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()); |
|
tbarzic
2017/06/27 19:04:57
I'd be consistent with DoWork and call SendRespons
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| +} |
| + |
| +void BluetoothLowEnergyResetAdvertisingFunction::ErrorCallback( |
| + device::BluetoothAdvertisement::ErrorCode status) { |
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| + Respond(Error(kErrorOperationFailed)); |
|
tbarzic
2017/06/27 19:04:57
error_ = kErrorOperationFailed;
SendResponse(false
Sonny Sasaka
2017/06/27 22:03:14
Done.
|
| +#endif |
| +} |
| + |
| // SetAdvertisingInterval: |
| template class BLEPeripheralExtensionFunction< |