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.
This commit is contained in:
Thomas Zimmermann 2014-08-21 10:10:39 +02:00
Родитель ff8788421a
Коммит d3fa537d97
2 изменённых файлов: 16 добавлений и 67 удалений

Просмотреть файл

@ -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<nsIObserverService> 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();

Просмотреть файл

@ -134,6 +134,7 @@ public:
private:
class GetVolumeTask;
class CloseScoTask;
class CloseScoRunnable;
class RespondToBLDNTask;
class MainThreadTask;