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 124585 2224b34281aac95ff31d8978ea870e9cd5922818
parent 124584 3ba90f85653a9d69fa167adbe5dade6aaecb9023
child 124586 64dabdd4df4a93e1ac4a84bd6fecfa6da84107b8
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, blocking-basecamp
bugs819275
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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));
   }
 }