| 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 d5b6bbfcb65bf70898a9cf9c56334598de5e661f..0dad81672e55344cc2bdee6b771e3227aad0f902 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
|
| @@ -28,6 +28,8 @@ const char kErrorDeviceNotFoundFormat[] =
|
| const char kErrorServiceNotFoundFormat[] = "Service with ID \"%s\" not found.";
|
| const char kErrorPlatformNotSupported[] =
|
| "This operation is not supported on the current platform";
|
| +const char kErrorWriteCharacteristicValueFailedFormat[] =
|
| + "Failed to write value of characteristic with ID \"%s\".";
|
|
|
| extensions::BluetoothLowEnergyEventRouter* GetEventRouter(
|
| BrowserContext* context) {
|
| @@ -336,10 +338,53 @@ bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() {
|
| }
|
|
|
| bool BluetoothLowEnergyWriteCharacteristicValueFunction::DoWork() {
|
| - // TODO(armansito): Implement.
|
| - SetError("Call not supported.");
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + 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::WriteCharacteristicValue::Params> params(
|
| + apibtle::WriteCharacteristicValue::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
|
| +
|
| + instance_id_ = params->characteristic_id;
|
| + std::vector<uint8> value(params->value.begin(), params->value.end());
|
| +
|
| + if (!event_router->WriteCharacteristicValue(
|
| + instance_id_,
|
| + value,
|
| + base::Bind(&BluetoothLowEnergyWriteCharacteristicValueFunction::
|
| + SuccessCallback,
|
| + this),
|
| + base::Bind(&BluetoothLowEnergyWriteCharacteristicValueFunction::
|
| + ErrorCallback,
|
| + this))) {
|
| + SetError(base::StringPrintf(kErrorCharacteristicNotFoundFormat,
|
| + instance_id_.c_str()));
|
| + SendResponse(false);
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback() {
|
| + results_ = apibtle::WriteCharacteristicValue::Results::Create();
|
| + SendResponse(true);
|
| +}
|
| +
|
| +void BluetoothLowEnergyWriteCharacteristicValueFunction::ErrorCallback() {
|
| + SetError(base::StringPrintf(kErrorWriteCharacteristicValueFailedFormat,
|
| + instance_id_.c_str()));
|
| SendResponse(false);
|
| - return false;
|
| }
|
|
|
| bool BluetoothLowEnergyReadDescriptorValueFunction::DoWork() {
|
|
|