Bug 819275 - [Audio] The Usage of nsRefPtr for AudioChannelService is Wrong. r=roc, a=blocking-basecamp
authorMarco Chen <mchen@mozilla.com>
Fri, 07 Dec 2012 19:31:57 +0800
changeset 117481 f24f9052578a7d89ad9b8ab6b634eb6159d3abab
parent 117480 f1c0c74ea9f579de5efb15057a927990250b04c7
child 117482 dcdea948bc16750bd4db3b164ad7e8c735857253
push id1907
push userfdesre@mozilla.com
push dateTue, 11 Dec 2012 17:59:26 +0000
treeherdermozilla-beta@f24f9052578a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, blocking-basecamp
bugs819275
milestone18.0
Bug 819275 - [Audio] The Usage of nsRefPtr for AudioChannelService is Wrong. r=roc, a=blocking-basecamp
dom/audiochannel/AudioChannelAgent.cpp
--- 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));
   }
 }