Bug 819275 - [Audio] The Usage of nsRefPtr for AudioChannelService is Wrong. r=roc, a=blocking-basecamp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -5,30 +5,26 @@
#include "AudioChannelAgent.h"
#include "AudioChannelCommon.h"
#include "AudioChannelService.h"
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS1(AudioChannelAgent, nsIAudioChannelAgent)
-static nsRefPtr<AudioChannelService> gAudioChannelService;
-
AudioChannelAgent::AudioChannelAgent()
: mCallback(nullptr)
, mAudioChannelType(AUDIO_AGENT_CHANNEL_ERROR)
, mIsRegToService(false)
, mVisible(true)
{
- gAudioChannelService = AudioChannelService::GetAudioChannelService();
}
AudioChannelAgent::~AudioChannelAgent()
{
- gAudioChannelService = nullptr;
}
/* readonly attribute long audioChannelType; */
NS_IMETHODIMP AudioChannelAgent::GetAudioChannelType(int32_t *aAudioChannelType)
{
*aAudioChannelType = mAudioChannelType;
return NS_OK;
}
@@ -63,54 +59,58 @@ NS_IMETHODIMP AudioChannelAgent::Init(in
mAudioChannelType = channelType;
mCallback = callback;
return NS_OK;
}
/* boolean startPlaying (); */
NS_IMETHODIMP AudioChannelAgent::StartPlaying(bool *_retval)
{
+ AudioChannelService *service = AudioChannelService::GetAudioChannelService();
if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
- gAudioChannelService == nullptr) {
+ service == nullptr) {
return NS_ERROR_FAILURE;
}
- gAudioChannelService->RegisterAudioChannelAgent(this,
+ service->RegisterAudioChannelAgent(this,
static_cast<AudioChannelType>(mAudioChannelType));
- *_retval = !gAudioChannelService->GetMuted(static_cast<AudioChannelType>(mAudioChannelType), !mVisible);
+ *_retval = !service->GetMuted(static_cast<AudioChannelType>(mAudioChannelType), !mVisible);
mIsRegToService = true;
return NS_OK;
}
/* void stopPlaying (); */
NS_IMETHODIMP AudioChannelAgent::StopPlaying(void)
{
if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
mIsRegToService == false) {
return NS_ERROR_FAILURE;
}
- gAudioChannelService->UnregisterAudioChannelAgent(this);
+ AudioChannelService *service = AudioChannelService::GetAudioChannelService();
+ service->UnregisterAudioChannelAgent(this);
mIsRegToService = false;
return NS_OK;
}
/* void setVisibilityState (in boolean visible); */
NS_IMETHODIMP AudioChannelAgent::SetVisibilityState(bool visible)
{
bool oldVisibility = mVisible;
mVisible = visible;
if (mIsRegToService && oldVisibility != mVisible && mCallback != nullptr) {
- mCallback->CanPlayChanged(!gAudioChannelService->GetMuted(static_cast<AudioChannelType>(mAudioChannelType),
+ AudioChannelService *service = AudioChannelService::GetAudioChannelService();
+ mCallback->CanPlayChanged(!service->GetMuted(static_cast<AudioChannelType>(mAudioChannelType),
!mVisible));
}
return NS_OK;
}
void AudioChannelAgent::NotifyAudioChannelStateChanged()
{
if (mCallback != nullptr) {
- mCallback->CanPlayChanged(!gAudioChannelService->GetMuted(static_cast<AudioChannelType>(mAudioChannelType),
+ AudioChannelService *service = AudioChannelService::GetAudioChannelService();
+ mCallback->CanPlayChanged(!service->GetMuted(static_cast<AudioChannelType>(mAudioChannelType),
!mVisible));
}
}