Bug 1181479: Refine GenerateUuid(); r=jocelyn
☠☠ backed out by 72b0e3dd91ee ☠ ☠
authorBruce Sun <brsun@mozilla.com>
Mon, 21 Sep 2015 14:40:11 +0800
changeset 263900 7c07214ac1526659cb95d133e73455b8a26a1f6a
parent 263899 784aae3f40bf3a42233d8c256dfc18315f0efd60
child 263901 89c64eb24508e349c3f6cc950ed6fb9ebbd6ead2
push id65466
push userbrsun@mozilla.com
push dateWed, 23 Sep 2015 05:23:13 +0000
treeherdermozilla-inbound@778062b31fd9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjocelyn
bugs1181479
milestone44.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 1181479: Refine GenerateUuid(); r=jocelyn
dom/bluetooth/bluedroid/BluetoothGattManager.cpp
dom/bluetooth/common/BluetoothUtils.cpp
dom/bluetooth/common/BluetoothUtils.h
dom/bluetooth/common/webapi/BluetoothGatt.cpp
dom/bluetooth/common/webapi/BluetoothGattServer.cpp
--- a/dom/bluetooth/bluedroid/BluetoothGattManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothGattManager.cpp
@@ -612,17 +612,21 @@ BluetoothGattManager::StartLeScan(const 
                                   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aRunnable);
 
   ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
 
   nsString appUuidStr;
-  GenerateUuid(appUuidStr);
+  if (NS_WARN_IF(NS_FAILED(GenerateUuid(appUuidStr))) || appUuidStr.IsEmpty()) {
+    DispatchReplyError(aRunnable,
+                       NS_LITERAL_STRING("start LE scan failed"));
+    return;
+  }
 
   size_t index = sClients->IndexOf(appUuidStr, 0 /* Start */, UuidComparator());
 
   // Reject the startLeScan request if the clientIf is being used.
   if (NS_WARN_IF(index != sClients->NoIndex)) {
     DispatchReplyError(aRunnable,
                        NS_LITERAL_STRING("start LE scan failed"));
     return;
--- a/dom/bluetooth/common/BluetoothUtils.cpp
+++ b/dom/bluetooth/common/BluetoothUtils.cpp
@@ -62,35 +62,37 @@ StringToUuid(const nsAString& aString, B
   memcpy(&aUuid.mUuid[0], &uuid0, sizeof(uint32_t));
   memcpy(&aUuid.mUuid[4], &uuid1, sizeof(uint16_t));
   memcpy(&aUuid.mUuid[6], &uuid2, sizeof(uint16_t));
   memcpy(&aUuid.mUuid[8], &uuid3, sizeof(uint16_t));
   memcpy(&aUuid.mUuid[10], &uuid4, sizeof(uint32_t));
   memcpy(&aUuid.mUuid[14], &uuid5, sizeof(uint16_t));
 }
 
-void
+nsresult
 GenerateUuid(nsAString &aUuidString)
 {
   nsresult rv;
   nsCOMPtr<nsIUUIDGenerator> uuidGenerator =
     do_GetService("@mozilla.org/uuid-generator;1", &rv);
-  NS_ENSURE_SUCCESS_VOID(rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsID uuid;
   rv = uuidGenerator->GenerateUUIDInPlace(&uuid);
-  NS_ENSURE_SUCCESS_VOID(rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Build a string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format
   char uuidBuffer[NSID_LENGTH];
   uuid.ToProvidedString(uuidBuffer);
   NS_ConvertASCIItoUTF16 uuidString(uuidBuffer);
 
   // Remove {} and the null terminator
   aUuidString.Assign(Substring(uuidString, 1, NSID_LENGTH - 3));
+
+  return NS_OK;
 }
 
 void
 GeneratePathFromGattId(const BluetoothGattId& aId,
                        nsAString& aPath)
 {
   nsString uuidStr;
   UuidToString(aId.mUuid, uuidStr);
--- a/dom/bluetooth/common/BluetoothUtils.h
+++ b/dom/bluetooth/common/BluetoothUtils.h
@@ -38,17 +38,17 @@ UuidToString(const BluetoothUuid& aUuid,
 void
 StringToUuid(const nsAString& aString, BluetoothUuid& aUuid);
 
 /**
  * Generate a random uuid.
  *
  * @param aUuidString [out] String to store the generated uuid.
  */
-void
+nsresult
 GenerateUuid(nsAString &aUuidString);
 
 //
 // Generate bluetooth signal path from GattId
 //
 
 /**
  * Generate bluetooth signal path from a GattId.
--- a/dom/bluetooth/common/webapi/BluetoothGatt.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothGatt.cpp
@@ -108,18 +108,18 @@ BluetoothGatt::Connect(ErrorResult& aRv)
     mConnectionState == BluetoothConnectionState::Disconnected,
     promise,
     NS_ERROR_DOM_INVALID_STATE_ERR);
 
   BluetoothService* bs = BluetoothService::Get();
   BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
 
   if (mAppUuid.IsEmpty()) {
-    GenerateUuid(mAppUuid);
-    BT_ENSURE_TRUE_REJECT(!mAppUuid.IsEmpty(),
+    nsresult rv = GenerateUuid(mAppUuid);
+    BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAppUuid.IsEmpty(),
                           promise,
                           NS_ERROR_DOM_OPERATION_ERR);
     RegisterBluetoothSignalHandler(mAppUuid, this);
   }
 
   UpdateConnectionState(BluetoothConnectionState::Connecting);
   bs->ConnectGattClientInternal(
     mAppUuid, mDeviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
--- a/dom/bluetooth/common/webapi/BluetoothGattServer.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothGattServer.cpp
@@ -132,18 +132,18 @@ BluetoothGattServer::Connect(const nsASt
   nsRefPtr<Promise> promise = Promise::Create(global, aRv);
   NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
 
   BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
   BluetoothService* bs = BluetoothService::Get();
   BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
 
   if (mAppUuid.IsEmpty()) {
-    GenerateUuid(mAppUuid);
-    BT_ENSURE_TRUE_REJECT(!mAppUuid.IsEmpty(),
+    nsresult rv = GenerateUuid(mAppUuid);
+    BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAppUuid.IsEmpty(),
                           promise,
                           NS_ERROR_DOM_OPERATION_ERR);
     RegisterBluetoothSignalHandler(mAppUuid, this);
   }
 
   bs->GattServerConnectPeripheralInternal(
     mAppUuid, aAddress, new BluetoothVoidReplyRunnable(nullptr, promise));