Bug 977146: Declare ToggleBtAck in header file, r=echou

Declaring ToggleBtAck in the header file of BluetoothService makes
it available ot others classes.
This commit is contained in:
Thomas Zimmermann 2014-03-03 13:07:17 +01:00
parent 79dfb23a1e
commit 8ea9711415
2 changed files with 49 additions and 47 deletions

View File

@ -34,7 +34,6 @@
#include "nsISystemMessagesInternal.h"
#include "nsITimer.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "nsXPCOM.h"
#if defined(MOZ_WIDGET_GONK)
@ -132,59 +131,53 @@ GetAllBluetoothActors(InfallibleTArray<BluetoothParent*>& aActors)
} // anonymous namespace
class BluetoothService::ToggleBtAck : public nsRunnable
BluetoothService::ToggleBtAck::ToggleBtAck(bool aEnabled)
: mEnabled(aEnabled)
{
public:
ToggleBtAck(bool aEnabled)
: mEnabled(aEnabled)
{
MOZ_ASSERT(!NS_IsMainThread());
}
MOZ_ASSERT(!NS_IsMainThread());
}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
NS_METHOD
BluetoothService::ToggleBtAck::Run()
{
MOZ_ASSERT(NS_IsMainThread());
// 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.
// 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)
if (property_set(PROP_BLUETOOTH_ENABLED, mEnabled ? "true" : "false") != 0) {
BT_WARNING("Failed to set bluetooth enabled property");
}
if (property_set(PROP_BLUETOOTH_ENABLED, mEnabled ? "true" : "false") != 0) {
BT_WARNING("Failed to set bluetooth enabled property");
}
#endif
NS_ENSURE_TRUE(sBluetoothService, NS_OK);
if (sInShutdown) {
sBluetoothService = nullptr;
return NS_OK;
}
// Update mEnabled of BluetoothService object since
// StartInternal/StopInternal have been already done.
sBluetoothService->SetEnabled(mEnabled);
sToggleInProgress = false;
nsAutoString signalName;
signalName = mEnabled ? NS_LITERAL_STRING("Enabled")
: NS_LITERAL_STRING("Disabled");
BluetoothSignal signal(signalName, NS_LITERAL_STRING(KEY_MANAGER), true);
sBluetoothService->DistributeSignal(signal);
// Event 'AdapterAdded' has to be fired after firing 'Enabled'
sBluetoothService->TryFiringAdapterAdded();
NS_ENSURE_TRUE(sBluetoothService, NS_OK);
if (sInShutdown) {
sBluetoothService = nullptr;
return NS_OK;
}
private:
bool mEnabled;
};
// Update mEnabled of BluetoothService object since
// StartInternal/StopInternal have been already done.
sBluetoothService->SetEnabled(mEnabled);
sToggleInProgress = false;
nsAutoString signalName;
signalName = mEnabled ? NS_LITERAL_STRING("Enabled")
: NS_LITERAL_STRING("Disabled");
BluetoothSignal signal(signalName, NS_LITERAL_STRING(KEY_MANAGER), true);
sBluetoothService->DistributeSignal(signal);
// Event 'AdapterAdded' has to be fired after firing 'Enabled'
sBluetoothService->TryFiringAdapterAdded();
return NS_OK;
}
class BluetoothService::ToggleBtTask : public nsRunnable
{

View File

@ -16,6 +16,7 @@
#include "nsIObserver.h"
#include "nsIThread.h"
#include "nsTObserverArray.h"
#include "nsThreadUtils.h"
namespace mozilla {
namespace ipc {
@ -35,9 +36,6 @@ typedef mozilla::ObserverList<BluetoothSignal> BluetoothSignalObserverList;
class BluetoothService : public nsIObserver
, public BluetoothSignalObserver
{
class ToggleBtAck;
friend class ToggleBtAck;
class ToggleBtTask;
friend class ToggleBtTask;
@ -45,6 +43,17 @@ class BluetoothService : public nsIObserver
friend class StartupTask;
public:
class ToggleBtAck : public nsRunnable
{
public:
ToggleBtAck(bool aEnabled);
NS_IMETHOD Run();
private:
bool mEnabled;
};
friend class ToggleBtAck;
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER