From d3fa537d97406f1f5b51de163d660b2abec60d0e Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 21 Aug 2014 10:10:39 +0200 Subject: [PATCH] Bug 1053804: Replace |MainThreadTask| by |CloseScoRunnable|, r=shuang |MainThreadTask| performs different operations on the main thread, depending on a given command flag. There is only one command, CLOSE_SCO, in use. This patch removes the command infrastructure and replaces |MainThreadTask| by |CloseScoRunnable|, which implements only this single operation. --- .../bluedroid/hfp/BluetoothHfpManager.cpp | 82 ++++--------------- .../bluedroid/hfp/BluetoothHfpManager.h | 1 + 2 files changed, 16 insertions(+), 67 deletions(-) diff --git a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp index bf4dbd8c9b9e..eceaeee076b9 100644 --- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp @@ -34,9 +34,6 @@ /** * Dispatch task with arguments to main thread. */ -#define BT_HF_DISPATCH_MAIN(args...) \ - NS_DispatchToMainThread(new MainThreadTask(args)) - using namespace mozilla; using namespace mozilla::ipc; USING_BLUETOOTH_NAMESPACE @@ -58,15 +55,6 @@ namespace { static int sBusyToneInterval = 3700; //unit: ms } // anonymous namespace -// Main thread task commands -enum MainThreadTaskCmd { - NOTIFY_CONN_STATE_CHANGED, - NOTIFY_DIALER, - NOTIFY_SCO_VOLUME_CHANGED, - POST_TASK_RESPOND_TO_BLDN, - POST_TASK_CLOSE_SCO -}; - static bool IsValidDtmf(const char aChar) { // Valid DTMF: [*#0-9ABCD] @@ -117,6 +105,20 @@ private: } }; +class BluetoothHfpManager::CloseScoRunnable : public nsRunnable +{ +public: + NS_IMETHOD Run() MOZ_OVERRIDE + { + MOZ_ASSERT(NS_IsMainThread()); + + MessageLoop::current()->PostDelayedTask( + FROM_HERE, new CloseScoTask(), sBusyToneInterval); + + return NS_OK; + } +}; + class BluetoothHfpManager::RespondToBLDNTask : public Task { private: @@ -131,60 +133,6 @@ private: } }; -class BluetoothHfpManager::MainThreadTask : public nsRunnable -{ -public: - MainThreadTask(const int aCommand, - const nsAString& aParameter = EmptyString()) - : mCommand(aCommand), mParameter(aParameter) - { - } - - nsresult Run() - { - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(sBluetoothHfpManager); - - switch (mCommand) { - case MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED: - sBluetoothHfpManager->NotifyConnectionStateChanged(mParameter); - break; - case MainThreadTaskCmd::NOTIFY_DIALER: - sBluetoothHfpManager->NotifyDialer(mParameter); - break; - case MainThreadTaskCmd::NOTIFY_SCO_VOLUME_CHANGED: - { - nsCOMPtr os = - mozilla::services::GetObserverService(); - NS_ENSURE_TRUE(os, NS_OK); - - os->NotifyObservers(nullptr, "bluetooth-volume-change", - mParameter.get()); - } - break; - case MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN: - MessageLoop::current()-> - PostDelayedTask(FROM_HERE, new RespondToBLDNTask(), - sWaitingForDialingInterval); - break; - case MainThreadTaskCmd::POST_TASK_CLOSE_SCO: - MessageLoop::current()-> - PostDelayedTask(FROM_HERE, new CloseScoTask(), - sBusyToneInterval); - break; - default: - BT_WARNING("MainThreadTask: Unknown command %d", mCommand); - break; - } - - return NS_OK; - } - -private: - int mCommand; - nsString mParameter; -}; - NS_IMPL_ISUPPORTS(BluetoothHfpManager::GetVolumeTask, nsISettingsServiceCallback); @@ -1034,7 +982,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex, if (aError.EqualsLiteral("BusyError")) { // FIXME: UpdatePhoneCIND later since it causes SCO close but // Dialer is still playing busy tone via HF. - BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_CLOSE_SCO); + NS_DispatchToMainThread(new CloseScoRunnable()); } ResetCallArray(); diff --git a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h index b114bb7f09cc..1bcb3d2e82d5 100644 --- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h +++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h @@ -134,6 +134,7 @@ public: private: class GetVolumeTask; class CloseScoTask; + class CloseScoRunnable; class RespondToBLDNTask; class MainThreadTask;