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 71529ad7c579caaf562637bb2c63763b418ae330..d69d1bd985e955f452e9353b27406adf8c868e29 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 |
| @@ -793,5 +793,79 @@ void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( |
| SendResponse(false); |
| } |
| +// RegisterAdvertisement: |
| + |
| +bool BluetoothLowEnergyRegisterAdvertisementFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) { |
| + error_ = kErrorPermissionDenied; |
|
armansito
2015/04/21 22:48:08
Call SendResponse(false)
rkc
2015/04/27 18:39:08
Done.
|
| + return false; |
| + } |
| + |
| + BluetoothLowEnergyEventRouter* event_router = |
| + GetEventRouter(browser_context()); |
| + |
| + // The adapter must be initialized at this point, but return an error instead |
| + // of asserting. |
| + if (!event_router->HasAdapter()) { |
| + SetError(kErrorAdapterNotInitialized); |
| + SendResponse(false); |
| + return false; |
| + } |
| + |
| + scoped_ptr<apibtle::RegisterAdvertisement::Params> params( |
| + apibtle::RegisterAdvertisement::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
|
armansito
2015/04/21 22:48:08
Add a TODO here to parse the arguments and do some
rkc
2015/04/27 18:39:08
Done.
|
| + |
| + return true; |
| +} |
| + |
| +void BluetoothLowEnergyRegisterAdvertisementFunction::SuccessCallback() { |
| + results_ = apibtle::RegisterAdvertisement::Results::Create(0); |
|
armansito
2015/04/21 22:48:09
What's the magic "0" here?
rkc
2015/04/27 18:39:08
Success/Failed callbacks removed for now.
Done.
|
| + SendResponse(true); |
| +} |
| + |
| +void BluetoothLowEnergyRegisterAdvertisementFunction::ErrorCallback( |
| + BluetoothLowEnergyEventRouter::Status status) { |
| + SetError(StatusToString(status)); |
| + SendResponse(false); |
| +} |
| + |
| +// UnregisterAdvertisement: |
| + |
| +bool BluetoothLowEnergyUnregisterAdvertisementFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) { |
| + error_ = kErrorPermissionDenied; |
|
armansito
2015/04/21 22:48:08
SendResponse(false);
rkc
2015/04/27 18:39:09
Done.
|
| + return false; |
| + } |
| + |
| + BluetoothLowEnergyEventRouter* event_router = |
| + GetEventRouter(browser_context()); |
| + |
| + // If we don't have an initialized adapter, unregistering is a no-op. |
| + if (!event_router->HasAdapter()) |
| + return true; |
| + |
| + scoped_ptr<apibtle::UnregisterAdvertisement::Params> params( |
| + apibtle::UnregisterAdvertisement::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
| + |
|
armansito
2015/04/21 22:48:09
Add a TODO here.
rkc
2015/04/27 18:39:08
Done.
|
| + return true; |
| +} |
| + |
| +void BluetoothLowEnergyUnregisterAdvertisementFunction::SuccessCallback() { |
| + results_ = apibtle::UnregisterAdvertisement::Results::Create(); |
| + SendResponse(true); |
| +} |
| + |
| +void BluetoothLowEnergyUnregisterAdvertisementFunction::ErrorCallback( |
| + BluetoothLowEnergyEventRouter::Status status) { |
| + SetError(StatusToString(status)); |
| + SendResponse(false); |
| +} |
|
armansito
2015/04/21 22:48:09
Technically these Success/ErrorCallback functions
rkc
2015/04/27 18:39:08
Done.
|
| + |
| } // namespace core_api |
| } // namespace extensions |