Chromium Code Reviews| Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| index a34580f671f39955f109f5fffe9825a8e96ab18a..85725f1eddd20054c780999c66a4fe9d10feb5dc 100644 |
| --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| @@ -87,6 +87,8 @@ const char kStatusAdvertisementAlreadyExists[] = |
| "An advertisement is already advertising"; |
| const char kStatusAdvertisementDoesNotExist[] = |
| "This advertisement does not exist"; |
| +const char kStatusInvalidAdvertisingInterval[] = |
| + "Invalid advertising interval specified."; |
| // Returns the correct error string based on error status |status|. This is used |
| // to set the value of |chrome.runtime.lastError.message| and should not be |
| @@ -1298,6 +1300,43 @@ void BluetoothLowEnergyUnregisterAdvertisementFunction::ErrorCallback( |
| SendResponse(false); |
| } |
| +// SetAdvertisingInterval: |
| + |
| +template class BLEPeripheralExtensionFunction< |
| + apibtle::SetAdvertisingInterval::Params>; |
| + |
| +void BluetoothLowEnergySetAdvertisingIntervalFunction::DoWork() { |
| + BluetoothLowEnergyEventRouter* event_router = |
| + GetEventRouter(browser_context()); |
| + |
| + event_router->adapter()->SetAdvertisingInterval( |
| + base::TimeDelta::FromMilliseconds(params_->min_interval), |
| + base::TimeDelta::FromMilliseconds(params_->max_interval), |
| + base::Bind( |
| + &BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback, |
| + this), |
| + base::Bind( |
| + &BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback, |
| + this)); |
| +} |
| + |
| +void BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback() { |
| + Respond(NoArguments()); |
| +} |
| + |
| +void BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback( |
| + device::BluetoothAdvertisement::ErrorCode status) { |
| + switch (status) { |
| + case device::BluetoothAdvertisement::ErrorCode:: |
| + ERROR_INVALID_ADVERTISEMENT_INTERVAL: |
| + Respond(Error(kStatusInvalidAdvertisingInterval)); |
| + return; |
|
xiyuan
2016/09/21 16:35:23
nit: remove since we have "break" ? Or keep this a
Rahul Chaturvedi
2016/09/21 18:54:12
Done.
|
| + break; |
| + default: |
| + Respond(Error(kErrorOperationFailed)); |
| + } |
| +} |
| + |
| // createService: |
| template class BLEPeripheralExtensionFunction<apibtle::CreateService::Params>; |