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.
This commit is contained in:
Thomas Zimmermann 2015-09-21 11:30:52 +02:00
parent 48a8903713
commit 420a083cd5
2 changed files with 40 additions and 7 deletions

View File

@ -339,6 +339,23 @@ BluetoothAvrcpManager::HandleShutdown()
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)
@ -350,11 +367,28 @@ BluetoothAvrcpManager::Connect(const nsAString& aDeviceAddress,
// AVRCP doesn't require connecting. We just set the remote address here.
mDeviceAddress = aDeviceAddress;
mController = aController;
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)
{
@ -362,11 +396,10 @@ BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController)
MOZ_ASSERT(!mController);
mDeviceAddress.Truncate();
mController = aController;
SetConnected(false);
OnDisconnect(EmptyString());
NS_DispatchToMainThread(new DisconnectRunnable(this));
}
void

View File

@ -62,8 +62,8 @@ protected:
private:
class CleanupAvrcpResultHandler;
class CleanupAvrcpResultHandlerRunnable;
class ConnectResultHandler;
class DisconnectResultHandler;
class ConnectRunnable;
class DisconnectRunnable;
class InitAvrcpResultHandler;
class OnErrorProfileResultHandlerRunnable;