Bug 830648 - AudioChannelAgent::StartPlaying() should check if already registered to AudioChannelService., r=mchen, a=blocking-b2g
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 25 Jan 2013 16:44:43 +0100
changeset 118339 694c52fd8d8e9dc17e141b8b85b47551a959126a
parent 118338 893e68b73efd5d9f564016c34b9c8e10c774bb28
child 118340 0a2501533cfdf3573e9f0ee0488c282893fdf382
push id362
push useramarchesini@mozilla.com
push dateFri, 25 Jan 2013 15:45:31 +0000
reviewersmchen, blocking-b2g
bugs830648
milestone18.0
Bug 830648 - AudioChannelAgent::StartPlaying() should check if already registered to AudioChannelService., r=mchen, a=blocking-b2g
dom/audiochannel/AudioChannelAgent.cpp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -15,16 +15,19 @@ AudioChannelAgent::AudioChannelAgent()
   , mAudioChannelType(AUDIO_AGENT_CHANNEL_ERROR)
   , mIsRegToService(false)
   , mVisible(true)
 {
 }
 
 AudioChannelAgent::~AudioChannelAgent()
 {
+  if (mIsRegToService) {
+    StopPlaying();
+  }
 }
 
 /* readonly attribute long audioChannelType; */
 NS_IMETHODIMP AudioChannelAgent::GetAudioChannelType(int32_t *aAudioChannelType)
 {
   *aAudioChannelType = mAudioChannelType;
   return NS_OK;
 }
@@ -61,32 +64,32 @@ NS_IMETHODIMP AudioChannelAgent::Init(in
   return NS_OK;
 }
 
 /* boolean startPlaying (); */
 NS_IMETHODIMP AudioChannelAgent::StartPlaying(bool *_retval)
 {
   AudioChannelService *service = AudioChannelService::GetAudioChannelService();
   if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
-      service == nullptr) {
+      service == nullptr || mIsRegToService) {
     return NS_ERROR_FAILURE;
   }
 
   service->RegisterAudioChannelAgent(this,
     static_cast<AudioChannelType>(mAudioChannelType));
   *_retval = !service->GetMuted(this, !mVisible);
   mIsRegToService = true;
   return NS_OK;
 }
 
 /* void stopPlaying (); */
 NS_IMETHODIMP AudioChannelAgent::StopPlaying(void)
 {
   if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
-      mIsRegToService == false) {
+      !mIsRegToService) {
     return NS_ERROR_FAILURE;
   }
 
   AudioChannelService *service = AudioChannelService::GetAudioChannelService();
   service->UnregisterAudioChannelAgent(this);
   mIsRegToService = false;
   return NS_OK;
 }