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

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: Rebased 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 79caa347965f7b5c06b760eafcd6b1edcc23c40d..cc6507125b5663036f776a9333912d19fcbf11e9 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
@@ -31,6 +31,8 @@ const char kErrorReadCharacteristicValueFailedFormat[] =
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) {
@@ -365,10 +367,53 @@ void BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback() {
}
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