Bug 799243 - Patch 1: Fix Bluetooth*Manager observer pointer types; r=echou

This commit is contained in:
Kyle Machulis 2012-10-08 21:59:33 -07:00
parent 0e1516c098
commit a276279be3
2 changed files with 49 additions and 13 deletions

View File

@ -40,32 +40,47 @@ public:
NS_DECL_NSIOBSERVER
BluetoothHfpManagerObserver()
{
}
bool Init()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
MOZ_ASSERT(obs);
if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false))) {
NS_WARNING("Failed to add settings change observer!");
return false;
}
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
NS_WARNING("Failed to add shutdown observer!");
return false;
}
return true;
}
bool Shutdown()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs ||
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)))) {
NS_WARNING("Can't unregister observers, or already unregistered!");
return false;
}
return true;
}
~BluetoothHfpManagerObserver()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs &&
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)))) {
NS_WARNING("Can't unregister observers!");
}
Shutdown();
}
};
namespace {
StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
StaticAutoPtr<BluetoothHfpManagerObserver> sHfpObserver;
StaticRefPtr<BluetoothHfpManagerObserver> sHfpObserver;
bool gInShutdown = false;
static nsCOMPtr<nsIThread> sHfpCommandThread;
static bool sStopSendingRingFlag = true;
@ -170,6 +185,9 @@ bool
BluetoothHfpManager::Init()
{
sHfpObserver = new BluetoothHfpManagerObserver();
if (!sHfpObserver->Init()) {
NS_WARNING("Cannot set up Hfp Observers!");
}
mListener = new BluetoothRilListener();
if (!mListener->StartListening()) {
@ -209,6 +227,7 @@ BluetoothHfpManager::Cleanup()
}
}
sHfpObserver->Shutdown();
sHfpObserver = nullptr;
}

View File

@ -32,22 +32,35 @@ public:
NS_DECL_NSIOBSERVER
BluetoothScoManagerObserver()
{
}
bool Init()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
MOZ_ASSERT(obs);
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
NS_WARNING("Failed to add shutdown observer!");
return false;
}
return true;
}
bool Shutdown()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs ||
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)))) {
NS_WARNING("Can't unregister observers!");
return false;
}
return true;
}
~BluetoothScoManagerObserver()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs &&
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)))) {
NS_WARNING("Can't unregister observers!");
}
Shutdown();
}
};
@ -55,7 +68,7 @@ NS_IMPL_ISUPPORTS1(BluetoothScoManagerObserver, nsIObserver)
namespace {
StaticRefPtr<BluetoothScoManager> gBluetoothScoManager;
StaticAutoPtr<BluetoothScoManagerObserver> sScoObserver;
StaticRefPtr<BluetoothScoManagerObserver> sScoObserver;
bool gInShutdown = false;
} // anonymous namespace
@ -82,6 +95,9 @@ bool
BluetoothScoManager::Init()
{
sScoObserver = new BluetoothScoManagerObserver();
if (sScoObserver->Init()) {
NS_WARNING("Cannot set up SCO observers!");
}
return true;
}
@ -93,6 +109,7 @@ BluetoothScoManager::~BluetoothScoManager()
void
BluetoothScoManager::Cleanup()
{
sScoObserver->Shutdown();
sScoObserver = nullptr;
}