Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3661)

Unified Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc

Issue 263333003: chrome.bluetoothLowEnergy: Implement writeCharacteristicValue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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() {

Powered by Google App Engine
This is Rietveld 408576698