Bug 1223722: Transfer arrays of Bluetooth UUIDs in |BluetoothValue|, r=brsun
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 05 Jan 2016 12:01:33 +0100
changeset 313589 d32bbbc72726ab9bdff8f0734511b0fdb3253230
parent 313588 a3eb613f20c97bff735f2a803d803d7fe721d33b
child 313590 8970bb2cb1e324a6aef73d26a4cf6f1569b393e6
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrsun
bugs1223722
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
dom/bluetooth/common/webapi/BluetoothDevice.cpp
dom/bluetooth/ipc/BluetoothTypes.ipdlh
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -2202,29 +2202,17 @@ BluetoothServiceBluedroid::RemoteDeviceP
 
       if (index < mGetRemoteServicesArray.Length()) {
         mGetRemoteServicesArray[index].mManager->OnUpdateSdpRecords(aBdAddr);
         mGetRemoteServicesArray.RemoveElementAt(index);
         continue; // continue with outer loop
       }
 
       // 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",
                        static_cast<uint32_t>(p.mTypeOfDevice));
 
     } else if (p.mType == PROPERTY_SERVICE_RECORD) {
 
       size_t i;
@@ -2322,28 +2310,17 @@ BluetoothServiceBluedroid::DeviceFoundNo
       bdAddr = p.mBdAddress;
     } else if (p.mType == PROPERTY_BDNAME) {
       AppendNamedValue(propertiesArray, "Name", p.mRemoteName);
       bdName = p.mRemoteName;
     } else if (p.mType == PROPERTY_CLASS_OF_DEVICE) {
       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",
                        static_cast<uint32_t>(p.mTypeOfDevice));
 
     } else if (p.mType == PROPERTY_UNKNOWN) {
       /* Bug 1065999: working around unknown properties */
     } else {
--- a/dom/bluetooth/common/webapi/BluetoothDevice.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothDevice.cpp
@@ -149,20 +149,29 @@ BluetoothDevice::SetPropertyByValue(cons
     RemoteNameToString(value.get_BluetoothRemoteName(), mName);
   } else if (name.EqualsLiteral("Address")) {
     AddressToString(value.get_BluetoothAddress(), mAddress);
   } else if (name.EqualsLiteral("Cod")) {
     mCod->Update(value.get_uint32_t());
   } 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());
   } else if (name.EqualsLiteral("GattAdv")) {
     MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfuint8_t);
     nsTArray<uint8_t> advData;
     advData = value.get_ArrayOfuint8_t();
     UpdatePropertiesFromAdvData(advData);
@@ -255,22 +264,35 @@ BluetoothDevice::IsDeviceAttributeChange
         nsAutoString remoteNameStr;
         RemoteNameToString(aValue.get_BluetoothRemoteName(), remoteNameStr);
         return !mName.Equals(remoteNameStr);
       }
     case BluetoothDeviceAttribute::Paired:
       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));
       return false;
   }
 }
 
 void
--- a/dom/bluetooth/ipc/BluetoothTypes.ipdlh
+++ b/dom/bluetooth/ipc/BluetoothTypes.ipdlh
@@ -56,16 +56,17 @@ union BluetoothValue
   BluetoothGattServiceId;
   BluetoothGattServiceId[];
   BluetoothGattCharAttribute[];
   BluetoothAddress;
   BluetoothAddress[];
   BluetoothAttributeHandle;
   BluetoothRemoteName;
   BluetoothUuid;
+  BluetoothUuid[];
 };
 
 /**
  * Key-value pair for dicts returned by the bluetooth backend. Used for things
  * like property updates, where the property will have a name and a type.
  */
 struct BluetoothNamedValue
 {