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

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

Issue 1976453002: Add permission parsing and the removeService API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@idl_changes
Patch Set: Created 4 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest_chromeos.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 4b20720e6dcccdfd78ebdc3e221268544a7704b3..46336b14f3c97f4c188fe994bb865a6ebd2ac1a1 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
@@ -180,6 +180,15 @@ bool HasProperty(
return false;
}
+bool HasPermission(
+ const std::vector<apibtle::DescriptorPermission>& api_permissions,
+ apibtle::DescriptorPermission permission) {
+ if (find(api_permissions.begin(), api_permissions.end(), permission) !=
xiyuan 2016/05/12 19:25:37 nit: just a return ? return find(api_permission
rkc 2016/05/12 20:32:53 Done.
+ api_permissions.end())
+ return true;
+ return false;
+}
+
device::BluetoothGattCharacteristic::Properties GetBluetoothProperties(
const std::vector<apibtle::CharacteristicProperty>& api_properties) {
device::BluetoothGattCharacteristic::Properties properties =
@@ -194,10 +203,12 @@ device::BluetoothGattCharacteristic::Properties GetBluetoothProperties(
if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_READ))
properties |= device::BluetoothGattCharacteristic::PROPERTY_READ;
+
if (HasProperty(api_properties,
apibtle::CHARACTERISTIC_PROPERTY_WRITEWITHOUTRESPONSE))
properties |=
xiyuan 2016/05/12 19:25:37 nit: wrap with {} if condition and branch takes mo
rkc 2016/05/12 20:32:53 Done.
device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE;
+
if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_WRITE))
properties |= device::BluetoothGattCharacteristic::PROPERTY_WRITE;
@@ -211,21 +222,79 @@ device::BluetoothGattCharacteristic::Properties GetBluetoothProperties(
apibtle::CHARACTERISTIC_PROPERTY_AUTHENTICATEDSIGNEDWRITES))
properties |= device::BluetoothGattCharacteristic::
PROPERTY_AUTHENTICATED_SIGNED_WRITES;
+
if (HasProperty(api_properties,
apibtle::CHARACTERISTIC_PROPERTY_EXTENDEDPROPERTIES))
properties |=
device::BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES;
+
if (HasProperty(api_properties,
apibtle::CHARACTERISTIC_PROPERTY_RELIABLEWRITE))
properties |= device::BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE;
+
if (HasProperty(api_properties,
apibtle::CHARACTERISTIC_PROPERTY_WRITABLEAUXILIARIES))
properties |=
device::BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES;
+ if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTREAD))
+ properties |= device::BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED;
+
+ if (HasProperty(api_properties,
+ apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTWRITE))
+ properties |= device::BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED;
+
+ if (HasProperty(api_properties,
+ apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTAUTHENTICATEDREAD))
+ properties |= device::BluetoothGattCharacteristic::
+ PROPERTY_READ_ENCRYPTED_AUTHENTICATED;
+
+ if (HasProperty(api_properties,
+ apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTAUTHENTICATEDWRITE))
+ properties |= device::BluetoothGattCharacteristic::
+ PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED;
+
return properties;
}
+device::BluetoothGattCharacteristic::Permissions GetBluetoothPermissions(
+ const std::vector<apibtle::DescriptorPermission>& api_permissions) {
+ device::BluetoothGattCharacteristic::Permissions permissions =
+ device::BluetoothGattCharacteristic::PERMISSION_NONE;
+
+ static_assert(
+ apibtle::DESCRIPTOR_PERMISSION_LAST == 6,
+ "Update required if the number of characteristic properties changes.");
+
+ if (HasPermission(api_permissions, apibtle::DESCRIPTOR_PERMISSION_READ))
+ permissions |= device::BluetoothGattCharacteristic::PERMISSION_READ;
+
+ if (HasPermission(api_permissions, apibtle::DESCRIPTOR_PERMISSION_WRITE))
+ permissions |= device::BluetoothGattCharacteristic::PERMISSION_WRITE;
+
+ if (HasPermission(api_permissions,
+ apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDREAD))
+ permissions |=
+ device::BluetoothGattCharacteristic::PERMISSION_READ_ENCRYPTED;
+
+ if (HasPermission(api_permissions,
+ apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDWRITE))
+ permissions |=
+ device::BluetoothGattCharacteristic::PERMISSION_WRITE_ENCRYPTED;
+
+ if (HasPermission(api_permissions,
+ apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDREAD))
+ permissions |= device::BluetoothGattCharacteristic::
+ PERMISSION_READ_ENCRYPTED_AUTHENTICATED;
+
+ if (HasPermission(api_permissions,
+ apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDWRITE))
+ permissions |= device::BluetoothGattCharacteristic::
+ PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED;
+
+ return permissions;
+}
+
} // namespace
@@ -1264,7 +1333,8 @@ void BluetoothLowEnergyCreateDescriptorFunction::DoWork() {
base::WeakPtr<device::BluetoothLocalGattDescriptor> descriptor =
device::BluetoothLocalGattDescriptor::Create(
device::BluetoothUUID(params_->descriptor.uuid),
- device::BluetoothGattCharacteristic::Permissions(), characteristic);
+ GetBluetoothPermissions(params_->descriptor.permissions),
+ characteristic);
Respond(ArgumentList(
apibtle::CreateDescriptor::Results::Create(descriptor->GetIdentifier())));
@@ -1329,7 +1399,15 @@ void BluetoothLowEnergyNotifyCharacteristicValueChangedFunction::DoWork() {
template class BLEPeripheralExtensionFunction<apibtle::RemoveService::Params>;
void BluetoothLowEnergyRemoveServiceFunction::DoWork() {
- Respond(Error(kErrorPermissionDenied));
+ device::BluetoothLocalGattService* service =
+ event_router_->adapter()->GetGattService(params_->service_id);
+ if (!service) {
+ Respond(Error(kErrorInvalidServiceId));
+ return;
+ }
+ event_router_->RemoveServiceFromApp(extension_id(), service->GetIdentifier());
+ service->Delete();
+ Respond(NoArguments());
}
// sendRequestResponse:
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698