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

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

Issue 293153002: chrome.bluetoothLowEnergy: Implement writeDescriptorValue. (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 fe71360fc3761c100db36a3e9445375165ac2e85..4c29506d6e8808f5cee710d3632a16a4ae216043 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
@@ -37,6 +37,8 @@ const char kErrorPlatformNotSupported[] =
"This operation is not supported on the current platform";
const char kErrorWriteCharacteristicValueFailedFormat[] =
"Failed to write value of characteristic with ID \"%s\".";
+const char kErrorWriteDescriptorValueFailedFormat[] =
+ "Failed to write value of descriptor with ID \"%s\".";
extensions::BluetoothLowEnergyEventRouter* GetEventRouter(
BrowserContext* context) {
@@ -550,10 +552,53 @@ void BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback() {
}
bool BluetoothLowEnergyWriteDescriptorValueFunction::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::WriteDescriptorValue::Params> params(
+ apibtle::WriteDescriptorValue::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
+
+ instance_id_ = params->descriptor_id;
+ std::vector<uint8> value(params->value.begin(), params->value.end());
+
+ if (!event_router->WriteDescriptorValue(
+ instance_id_,
+ value,
+ base::Bind(
+ &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback,
+ this),
+ base::Bind(
+ &BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback,
+ this))) {
+ SetError(base::StringPrintf(kErrorDescriptorNotFoundFormat,
+ instance_id_.c_str()));
+ SendResponse(false);
+ return false;
+ }
+
+ return true;
+}
+
+void BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback() {
+ results_ = apibtle::WriteDescriptorValue::Results::Create();
+ SendResponse(true);
+}
+
+void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback() {
+ SetError(base::StringPrintf(kErrorWriteDescriptorValueFailedFormat,
+ instance_id_.c_str()));
SendResponse(false);
- return false;
}
} // namespace api

Powered by Google App Engine
This is Rietveld 408576698