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

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

Issue 262053003: chrome.bluetoothLowEnergy: Implement getCharacteristic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0bdb9063992fab4bd566d5a9ed6a16f05be83c25..d5b6bbfcb65bf70898a9cf9c56334598de5e661f 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
@@ -21,6 +21,8 @@ namespace {
const char kErrorAdapterNotInitialized[] =
"Could not initialize Bluetooth adapter.";
+const char kErrorCharacteristicNotFoundFormat[] =
+ "Characteristic with ID \"%s\" not found.";
const char kErrorDeviceNotFoundFormat[] =
"Device with address \"%s\" not found.";
const char kErrorServiceNotFoundFormat[] = "Service with ID \"%s\" not found.";
@@ -197,10 +199,40 @@ bool BluetoothLowEnergyGetServicesFunction::DoWork() {
}
bool BluetoothLowEnergyGetCharacteristicFunction::DoWork() {
- // TODO(armansito): Implement.
- SetError("Call not supported.");
- SendResponse(false);
- return false;
+ 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::GetCharacteristic::Params> params(
+ apibtle::GetCharacteristic::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
+
+ std::string characteristic_id = params->characteristic_id;
+
+ apibtle::Characteristic characteristic;
+ if (!event_router->GetCharacteristic(characteristic_id, &characteristic)) {
+ SetError(base::StringPrintf(kErrorCharacteristicNotFoundFormat,
+ characteristic_id.c_str()));
+ SendResponse(false);
+ return false;
+ }
+
+ // Manually construct the result instead of using
+ // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of
+ // enums correctly.
+ SetResult(CharacteristicToValue(&characteristic).release());
rpaquay 2014/05/05 16:07:48 Wasn't this bug was recently fixed? (crbug/ 368368
armansito 2014/05/05 17:39:32 No, it's still a problem. There is a CL that does
+ SendResponse(true);
+
+ return true;
}
bool BluetoothLowEnergyGetCharacteristicsFunction::DoWork() {
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698