Bug 1204497: Complete AVRCP connect/disconnect from separate runnables, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 21 Sep 2015 11:30:52 +0200
changeset 263571 abd2dfe8eaf1dfba3d00596dfd8e1c92369a3708
parent 263570 cea992dbc0312078a5e57a922ba3310c8291551f
child 263572 a2c4215b89952f1aef49601ec3911356bb451681
push id65352
push userkwierso@gmail.com
push dateMon, 21 Sep 2015 16:52:59 +0000
treeherdermozilla-inbound@ee92eb117e92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1204497
milestone43.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 1204497: Complete AVRCP connect/disconnect from separate runnables, r=shuang A2DP connects and disconnects are completed from a separate result-handler runnable. Dispatching runnables to complete AVRCP (dis-)connects implements the same behavior for AVRCP.
dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp
dom/bluetooth/bluedroid/BluetoothAvrcpManager.h
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp
@@ -334,44 +334,77 @@ void
 BluetoothAvrcpManager::HandleShutdown()
 {
   MOZ_ASSERT(NS_IsMainThread());
   sInShutdown = true;
   Disconnect(nullptr);
   sBluetoothAvrcpManager = nullptr;
 }
 
+class BluetoothAvrcpManager::ConnectRunnable final : public nsRunnable
+{
+public:
+  ConnectRunnable(BluetoothAvrcpManager* aManager)
+    : mManager(aManager)
+  {
+    MOZ_ASSERT(mManager);
+  }
+  NS_METHOD Run() override
+  {
+    mManager->OnConnect(EmptyString());
+    return NS_OK;
+  }
+private:
+  BluetoothAvrcpManager* mManager;
+};
+
 void
 BluetoothAvrcpManager::Connect(const nsAString& aDeviceAddress,
                                BluetoothProfileController* aController)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!aDeviceAddress.IsEmpty());
   MOZ_ASSERT(aController);
 
   // AVRCP doesn't require connecting. We just set the remote address here.
   mDeviceAddress = aDeviceAddress;
   mController = aController;
+  SetConnected(true);
 
-  SetConnected(true);
-  OnConnect(EmptyString());
+  NS_DispatchToMainThread(new ConnectRunnable(this));
 }
 
+class BluetoothAvrcpManager::DisconnectRunnable final : public nsRunnable
+{
+public:
+  DisconnectRunnable(BluetoothAvrcpManager* aManager)
+    : mManager(aManager)
+  {
+    MOZ_ASSERT(mManager);
+  }
+  NS_METHOD Run() override
+  {
+    mManager->OnDisconnect(EmptyString());
+    return NS_OK;
+  }
+private:
+  BluetoothAvrcpManager* mManager;
+};
+
 void
 BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!mController);
 
   mDeviceAddress.Truncate();
-
   mController = aController;
+  SetConnected(false);
 
-  SetConnected(false);
-  OnDisconnect(EmptyString());
+  NS_DispatchToMainThread(new DisconnectRunnable(this));
 }
 
 void
 BluetoothAvrcpManager::OnConnect(const nsAString& aErrorStr)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   /**
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h
@@ -57,18 +57,18 @@ public:
   void HandleBackendError();
 
 protected:
   virtual ~BluetoothAvrcpManager();
 
 private:
   class CleanupAvrcpResultHandler;
   class CleanupAvrcpResultHandlerRunnable;
-  class ConnectResultHandler;
-  class DisconnectResultHandler;
+  class ConnectRunnable;
+  class DisconnectRunnable;
   class InitAvrcpResultHandler;
   class OnErrorProfileResultHandlerRunnable;
 
   BluetoothAvrcpManager();
 
   void HandleShutdown();
   void NotifyConnectionStatusChanged();