Bug 1223722: Transfer arrays of Bluetooth UUIDs in |BluetoothValue|, r=brsun

Bluetooth's UUID arrays are sorted and stripped from duplicates. This code is
now executed in the client process. This reduces the amount of privilegued
code and accounts the required computation time to the process that actually
uses it.

The change also makes the IPDL interface a bit less fragile, as the client
does not expect sorted arrays from the chrome process. It's a detail of the
client's implementation that manifested itself in the interface.
This commit is contained in:
Thomas Zimmermann 2016-01-05 12:01:33 +01:00
parent 388ee1f523
commit 1025acb217
3 changed files with 32 additions and 32 deletions

View File

@ -2207,19 +2207,7 @@ BluetoothServiceBluedroid::RemoteDevicePropertiesNotification(
}
// Handler for |FetchUuidsInternal|
nsTArray<nsString> uuids;
// Construct a sorted uuid set
for (index = 0; index < p.mUuidArray.Length(); ++index) {
nsAutoString uuid;
UuidToString(p.mUuidArray[index], uuid);
if (!uuids.Contains(uuid)) { // filter out duplicate uuids
uuids.InsertElementSorted(uuid);
}
}
AppendNamedValue(propertiesArray, "UUIDs", uuids);
AppendNamedValue(propertiesArray, "UUIDs", p.mUuidArray);
} else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
AppendNamedValue(propertiesArray, "Type",
@ -2327,18 +2315,7 @@ BluetoothServiceBluedroid::DeviceFoundNotification(
AppendNamedValue(propertiesArray, "Cod", p.mUint32);
} else if (p.mType == PROPERTY_UUIDS) {
nsTArray<nsString> uuids;
// Construct a sorted uuid set
for (uint32_t index = 0; index < p.mUuidArray.Length(); ++index) {
nsAutoString uuid;
UuidToString(p.mUuidArray[index], uuid);
if (!uuids.Contains(uuid)) { // filter out duplicate uuids
uuids.InsertElementSorted(uuid);
}
}
AppendNamedValue(propertiesArray, "UUIDs", uuids);
AppendNamedValue(propertiesArray, "UUIDs", p.mUuidArray);
} else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
AppendNamedValue(propertiesArray, "Type",

View File

@ -154,10 +154,19 @@ BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue)
} else if (name.EqualsLiteral("Paired")) {
mPaired = value.get_bool();
} else if (name.EqualsLiteral("UUIDs")) {
// We assume the received uuids array is sorted without duplicate items.
// If it's not, we require additional processing before assigning it
// directly.
mUuids = value.get_ArrayOfnsString();
// While converting to strings, we sort the received UUIDs and remove
// any duplicates.
const nsTArray<BluetoothUuid>& uuids = value.get_ArrayOfBluetoothUuid();
nsTArray<nsString> uuidStrs;
for (uint32_t index = 0; index < uuids.Length(); ++index) {
nsAutoString uuidStr;
UuidToString(uuids[index], uuidStr);
if (!uuidStrs.Contains(uuidStr)) { // filter out duplicate UUIDs
uuidStrs.InsertElementSorted(uuidStr);
}
}
mUuids = Move(uuidStrs);
BluetoothDeviceBinding::ClearCachedUuidsValue(this);
} else if (name.EqualsLiteral("Type")) {
mType = ConvertUint32ToDeviceType(value.get_uint32_t());
@ -260,12 +269,25 @@ BluetoothDevice::IsDeviceAttributeChanged(BluetoothDeviceAttribute aType,
MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
return mPaired != aValue.get_bool();
case BluetoothDeviceAttribute::Uuids: {
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfnsString);
const InfallibleTArray<nsString>& uuids = aValue.get_ArrayOfnsString();
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothUuid);
const auto& uuids = aValue.get_ArrayOfBluetoothUuid();
nsTArray<nsString> uuidStrs;
// Construct a sorted uuid set
for (size_t index = 0; index < uuids.Length(); ++index) {
nsAutoString uuidStr;
UuidToString(uuids[index], uuidStr);
if (!uuidStrs.Contains(uuidStr)) { // filter out duplicate uuids
uuidStrs.InsertElementSorted(uuidStr);
}
}
// We assume the received uuids array is sorted without duplicate items.
// If it's not, we require additional processing before comparing it
// directly.
return mUuids != uuids;
return mUuids != uuidStrs;
}
default:
BT_WARNING("Type %d is not handled", uint32_t(aType));

View File

@ -61,6 +61,7 @@ union BluetoothValue
BluetoothAttributeHandle;
BluetoothRemoteName;
BluetoothUuid;
BluetoothUuid[];
};
/**