Backed out changeset 40ecdab580b3 (bug 936995) for potential JB build error
authorEric Chou <echou@mozilla.com>
Wed, 20 Nov 2013 15:17:00 +0800
changeset 156484 20bd40612db503dd28cc075f4019b84cf679f334
parent 156483 40ecdab580b351be5e41b9b5be2407bd7225cc82
child 156485 a67b11842906aaf816d2732000e20b16439d8a1a
push id25683
push userryanvm@gmail.com
push dateThu, 21 Nov 2013 01:42:57 +0000
treeherdermozilla-central@cf378dddfac8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs936995
milestone28.0a1
backs out40ecdab580b351be5e41b9b5be2407bd7225cc82
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
Backed out changeset 40ecdab580b3 (bug 936995) for potential JB build error
dom/bluetooth/BluetoothService.cpp
dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp
dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.h
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -141,29 +141,39 @@ public:
   {
     MOZ_ASSERT(!NS_IsMainThread());
   }
 
   NS_IMETHOD Run()
   {
     MOZ_ASSERT(NS_IsMainThread());
 
-    NS_ENSURE_TRUE(gBluetoothService, NS_OK);
+    if (!gBluetoothService) {
+      return NS_OK;
+    }
+
+    if (!gInShutdown) {
+      gBluetoothService->SetEnabled(mEnabled);
+
+      nsAutoString signalName, signalPath;
+      BluetoothValue v = true;
+      if (mEnabled) {
+        signalName = NS_LITERAL_STRING("Enabled");
+      } else {
+        signalName = NS_LITERAL_STRING("Disabled");
+      }
+      signalPath = NS_LITERAL_STRING(KEY_MANAGER);
+      BluetoothSignal signal(signalName, signalPath, v);
+      gBluetoothService->DistributeSignal(signal);
+    }
 
     if (gInShutdown) {
       gBluetoothService = nullptr;
-      return NS_OK;
     }
 
-    nsAutoString signalName;
-    signalName = mEnabled ? NS_LITERAL_STRING("Enabled")
-                          : NS_LITERAL_STRING("Disabled");
-    BluetoothSignal signal(signalName, NS_LITERAL_STRING(KEY_MANAGER), true);
-    gBluetoothService->DistributeSignal(signal);
-
     return NS_OK;
   }
 
 private:
   bool mEnabled;
 };
 
 class BluetoothService::ToggleBtTask : public nsRunnable
@@ -203,20 +213,16 @@ public:
       } else {
         if (NS_FAILED(gBluetoothService->StopInternal())) {
           BT_WARNING("Bluetooth service failed to stop!");
           mEnabled = !mEnabled;
         }
       }
     }
 
-    // Update mEnabled of BluetoothService object since
-    // StartInternal/StopInternal have been already done.
-    gBluetoothService->SetEnabled(mEnabled);
-
     // This is requested in Bug 836516. With settings this property, WLAN
     // firmware could be aware of Bluetooth has been turned on/off, so that the
     // mecahnism of handling coexistence of WIFI and Bluetooth could be started.
     //
     // In the future, we may have our own way instead of setting a system
     // property to let firmware developers be able to sense that Bluetooth has
     // been toggled.
 #if defined(MOZ_WIDGET_GONK)
--- a/dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp
@@ -21,18 +21,16 @@
 #include <hardware/hardware.h>
 
 #include "BluetoothProfileController.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothUtils.h"
 #include "BluetoothUuid.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/ipc/UnixSocket.h"
-#include "mozilla/StaticMutex.h"
-#include "mozilla/StaticPtr.h"
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 USING_BLUETOOTH_NAMESPACE
 
 /**
  *  Classes only used in this file
  */
@@ -72,17 +70,16 @@ static InfallibleTArray<nsString> sAdapt
 static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
 static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sChangeDiscoveryRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetPairedDeviceRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
 static nsTArray<int> sRequestedDeviceCountArray;
-static StaticAutoPtr<Monitor> sToggleBtMonitor;
 
 /**
  *  Static callback functions
  */
 static void
 ClassToIcon(uint32_t aClass, nsAString& aRetIcon)
 {
   switch ((aClass & 0x1f00) >> 8) {
@@ -211,44 +208,41 @@ Setup()
   prop.len = sizeof(mode);
 
   NS_ENSURE_TRUE_VOID(sBtInterface);
 
   int ret = sBtInterface->set_adapter_property(&prop);
   if (ret != BT_STATUS_SUCCESS) {
     BT_LOGR("%s: Fail to set: BT_SCAN_MODE_CONNECTABLE", __FUNCTION__);
   }
-
-  // Event 'AdapterAdded' has to be fired after enabled to notify Gaia
-  // that BluetoothAdapter is ready.
-  BluetoothSignal signal(NS_LITERAL_STRING("AdapterAdded"),
-                         NS_LITERAL_STRING(KEY_MANAGER), true);
-  nsRefPtr<DistributeBluetoothSignalTask>
-    t = new DistributeBluetoothSignalTask(signal);
-  if (NS_FAILED(NS_DispatchToMainThread(t))) {
-    BT_WARNING("Failed to dispatch to main thread!");
-  }
 }
 
 static void
 AdapterStateChangeCallback(bt_state_t aStatus)
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   BT_LOGR("%s, BT_STATE:%d", __FUNCTION__, aStatus);
 
-  sIsBtEnabled = (aStatus == BT_STATE_ON);
-
-  {
-    MonitorAutoLock lock(*sToggleBtMonitor);
-    lock.Notify();
+  nsAutoString signalName;
+  if (aStatus == BT_STATE_ON) {
+    Setup();
+    sIsBtEnabled = true;
+    signalName = NS_LITERAL_STRING("AdapterAdded");
+  } else {
+    sIsBtEnabled = false;
+    signalName = NS_LITERAL_STRING("Disabled");
   }
 
-  if (sIsBtEnabled) {
-    Setup();
+  BluetoothSignal signal(signalName, NS_LITERAL_STRING(KEY_MANAGER),
+                         BluetoothValue(true));
+  nsRefPtr<DistributeBluetoothSignalTask>
+    t = new DistributeBluetoothSignalTask(signal);
+  if (NS_FAILED(NS_DispatchToMainThread(t))) {
+    NS_WARNING("Failed to dispatch to main thread!");
   }
 }
 
 /**
  * AdapterPropertiesChangeCallback will be called after enable() but before
  * AdapterStateChangeCallback sIsBtEnabled get updated.
  * At that moment, both BluetoothManager/BluetoothAdapter does not register
  * observer yet.
@@ -322,17 +316,17 @@ AdapterPropertiesChangeCallback(bt_statu
     }
 
     BluetoothValue value(propertiesArray);
     BluetoothSignal signal(NS_LITERAL_STRING("PropertyChanged"),
                            NS_LITERAL_STRING(KEY_ADAPTER), value);
     nsRefPtr<DistributeBluetoothSignalTask>
       t = new DistributeBluetoothSignalTask(signal);
     if (NS_FAILED(NS_DispatchToMainThread(t))) {
-      BT_WARNING("Failed to dispatch to main thread!");
+      NS_WARNING("Failed to dispatch to main thread!");
     }
 
     // bluedroid BTU task was stored in the task queue, see GKI_send_msg
     if (!sSetPropertyRunnableArray.IsEmpty()) {
       DispatchBluetoothReply(sSetPropertyRunnableArray[0], BluetoothValue(true),
                              EmptyString());
       sSetPropertyRunnableArray.RemoveElementAt(0);
     }
@@ -448,17 +442,17 @@ DeviceFoundCallback(int aNumProperties, 
   }
 
   BluetoothValue value = propertiesArray;
   BluetoothSignal signal(NS_LITERAL_STRING("DeviceFound"),
                          NS_LITERAL_STRING(KEY_ADAPTER), value);
   nsRefPtr<DistributeBluetoothSignalTask>
     t = new DistributeBluetoothSignalTask(signal);
   if (NS_FAILED(NS_DispatchToMainThread(t))) {
-    BT_WARNING("Failed to dispatch to main thread!");
+    NS_WARNING("Failed to dispatch to main thread!");
   }
 }
 
 static void
 DiscoveryStateChangedCallback(bt_discovery_state_t aState)
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
@@ -492,17 +486,17 @@ PinRequestCallback(bt_bdaddr_t* aRemoteB
                           (const char*)aRemoteBdName->name)));
 
   BluetoothValue value = propertiesArray;
   BluetoothSignal signal(NS_LITERAL_STRING("RequestPinCode"),
                          NS_LITERAL_STRING(KEY_LOCAL_AGENT), value);
   nsRefPtr<DistributeBluetoothSignalTask>
     t = new DistributeBluetoothSignalTask(signal);
   if (NS_FAILED(NS_DispatchToMainThread(t))) {
-    BT_WARNING("Failed to dispatch to main thread!");
+    NS_WARNING("Failed to dispatch to main thread!");
   }
 }
 
 static void
 SspRequestCallback(bt_bdaddr_t* aRemoteBdAddress, bt_bdname_t* aRemoteBdName,
                    uint32_t aRemoteClass, bt_ssp_variant_t aPairingVariant,
                    uint32_t aPasskey)
 {
@@ -525,17 +519,17 @@ SspRequestCallback(bt_bdaddr_t* aRemoteB
     BluetoothNamedValue(NS_LITERAL_STRING("passkey"), aPasskey));
 
   BluetoothValue value = propertiesArray;
   BluetoothSignal signal(NS_LITERAL_STRING("RequestConfirmation"),
                          NS_LITERAL_STRING(KEY_LOCAL_AGENT), value);
   nsRefPtr<DistributeBluetoothSignalTask>
     t = new DistributeBluetoothSignalTask(signal);
   if (NS_FAILED(NS_DispatchToMainThread(t))) {
-    BT_WARNING("Failed to dispatch to main thread!");
+    NS_WARNING("Failed to dispatch to main thread!");
   }
 }
 
 static void
 BondStateChangedCallback(bt_status_t aStatus, bt_bdaddr_t* aRemoteBdAddress,
                          bt_bond_state_t aState)
 {
   MOZ_ASSERT(!NS_IsMainThread());
@@ -659,26 +653,19 @@ StartStopGonkBluetooth(bool aShouldEnabl
     int ret = sBtInterface->init(&sBluetoothCallbacks);
     if (ret != BT_STATUS_SUCCESS) {
       BT_LOGR("Error while setting the callbacks %s", __FUNCTION__);
       sBtInterface = nullptr;
       return NS_ERROR_FAILURE;
     }
     sIsBtInterfaceInitialized = true;
   }
-
-  MonitorAutoLock lock(*sToggleBtMonitor);
+  int ret = aShouldEnable ? sBtInterface->enable() : sBtInterface->disable();
 
-  int ret = aShouldEnable ? sBtInterface->enable() : sBtInterface->disable();
-  NS_ENSURE_TRUE(ret == BT_STATUS_SUCCESS, NS_ERROR_FAILURE);
-
-  MonitorAutoLock lock(*sToggleBtMonitor);
-  lock.Wait();
-
-  return NS_OK;
+  return (ret == BT_STATUS_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 static void
 ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable,
                  int aStatusCode, const nsAString& aCustomMsg)
 {
   MOZ_ASSERT(aBluetoothReplyRunnable, "Reply runnable is nullptr");
 
@@ -703,26 +690,16 @@ ReplyStatusError(BluetoothReplyRunnable*
 
   DispatchBluetoothReply(aBluetoothReplyRunnable, BluetoothValue(true),
                          replyError);
 }
 
 /**
  *  Member functions
  */
-BluetoothServiceBluedroid::BluetoothServiceBluedroid()
-{
-  sToggleBtMonitor = new Monitor("BluetoothService.sToggleBtMonitor");
-}
-
-BluetoothServiceBluedroid::~BluetoothServiceBluedroid()
-{
-  sToggleBtMonitor = nullptr;
-}
-
 nsresult
 BluetoothServiceBluedroid::StartInternal()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   nsresult ret = StartStopGonkBluetooth(true);
   if (NS_FAILED(ret)) {
     BT_LOGR("Error: %s", __FUNCTION__);
--- a/dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.h
+++ b/dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.h
@@ -187,17 +187,14 @@ public:
 
   virtual nsresult
   SendSinkMessage(const nsAString& aDeviceAddresses,
                   const nsAString& aMessage) MOZ_OVERRIDE;
 
   virtual nsresult
   SendInputMessage(const nsAString& aDeviceAddresses,
                    const nsAString& aMessage) MOZ_OVERRIDE;
-
-  BluetoothServiceBluedroid();
-  ~BluetoothServiceBluedroid();
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif