Bug 1208371 - Guard LoadManagerSingleton with a WeakPtr. r=pkerr

LoadManagerSingleton has a separate shutdown path (xpcom-shutdown) from
its users (Audio/VideoConduit - garbage collected). These have appeared
racy, so in some cases the singleton was destructed before the users had
deregistered (e.g., when conduits destructed by SnowWhiteKiller).

A WeakPtr can solve this.

MozReview-Commit-ID: AVrpd3QqOGx

--HG--
extra : rebase_source : c5d50f7619940b772c7d1f3dee3ac0b6568ccfd9
This commit is contained in:
Andreas Pehrson 2016-01-05 10:16:32 +08:00
parent 903e51a6f9
commit 79cdda9e6f

View File

@ -7,6 +7,7 @@
#define _LOADMANAGER_H_
#include "LoadMonitor.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Services.h"
@ -23,12 +24,15 @@ namespace mozilla {
class LoadManagerSingleton : public LoadNotificationCallback,
public webrtc::CPULoadStateCallbackInvoker,
public webrtc::CpuOveruseObserver,
public SupportsWeakPtr<LoadManagerSingleton>,
public nsIObserver
{
public:
static LoadManagerSingleton* Get();
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LoadManagerSingleton)
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
@ -86,23 +90,31 @@ public:
void AddObserver(webrtc::CPULoadStateObserver * aObserver) override
{
if (mManager) {
mManager->AddObserver(aObserver);
}
}
void RemoveObserver(webrtc::CPULoadStateObserver * aObserver) override
{
if (mManager) {
mManager->RemoveObserver(aObserver);
}
}
void OveruseDetected() override
{
if (mManager) {
mManager->OveruseDetected();
}
}
void NormalUsage() override
{
if (mManager) {
mManager->NormalUsage();
}
}
private:
LoadManagerSingleton* mManager;
WeakPtr<LoadManagerSingleton> mManager;
};
} //namespace