Backed out changeset a0c4559f5d2e for cpp unitest orange
authorEd Morley <emorley@mozilla.com>
Fri, 25 Jan 2013 13:36:17 +0000
changeset 119871 6007dc9023854e7c44c5b88388c767d7086b29fb
parent 119870 a0c4559f5d2e8aff1acff339960594b5122c16a2
child 119872 5197fd7963037347ab71ec9307d8812d0c2bc77a
push id1317
push userryanvm@gmail.com
push dateSun, 27 Jan 2013 02:21:57 +0000
treeherderfx-team@47684913d63d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone21.0a1
backs outa0c4559f5d2e8aff1acff339960594b5122c16a2
Backed out changeset a0c4559f5d2e for cpp unitest orange
dom/audiochannel/AudioChannelService.cpp
dom/audiochannel/AudioChannelService.h
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -62,17 +62,16 @@ AudioChannelService::Shutdown()
     gAudioChannelService = nullptr;
   }
 }
 
 NS_IMPL_ISUPPORTS0(AudioChannelService)
 
 AudioChannelService::AudioChannelService()
 : mCurrentHigherChannel(AUDIO_CHANNEL_LAST)
-, mActiveContentChildIDsFrozen(false)
 {
   // Creation of the hash table.
   mAgents.Init();
 
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
       obs->AddObserver(this, "ipc:content-shutdown", false);
@@ -165,48 +164,28 @@ AudioChannelService::GetMutedInternal(Au
   AudioChannelInternalType newType = GetInternalType(aType, aElementHidden);
   AudioChannelInternalType oldType = GetInternalType(aType, aElementWasHidden);
 
   if (newType != oldType) {
     mChannelCounters[newType].AppendElement(aChildID);
     mChannelCounters[oldType].RemoveElement(aChildID);
   }
 
-  // If the audio content channel is visible, let's remember this ChildID.
-  if (newType == AUDIO_CHANNEL_INT_CONTENT &&
-      oldType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
-      !mActiveContentChildIDs.Contains(aChildID)) {
-
-    if (mActiveContentChildIDsFrozen) {
-      mActiveContentChildIDsFrozen = false;
-      mActiveContentChildIDs.Clear();
-    }
-
-    mActiveContentChildIDs.AppendElement(aChildID);
-  }
-
-  // If nothing is visible, the list has to been frozen.
-  else if (newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
-           oldType == AUDIO_CHANNEL_INT_CONTENT &&
-           !mActiveContentChildIDsFrozen &&
-           mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) {
-    mActiveContentChildIDsFrozen = true;
-  }
-
   // Let play any visible audio channel.
   if (!aElementHidden) {
     return false;
   }
 
   bool muted = false;
 
   // We are not visible, maybe we have to mute.
   if (newType == AUDIO_CHANNEL_INT_NORMAL_HIDDEN ||
       (newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
-       !mActiveContentChildIDs.Contains(aChildID))) {
+       (!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty() ||
+        HasMoreThanOneContentChannelHidden()))) {
     muted = true;
   }
 
   if (!muted) {
     MOZ_ASSERT(newType != AUDIO_CHANNEL_INT_NORMAL_HIDDEN);
     muted = ChannelsActiveWithHigherPriorityThan(newType);
   }
 
@@ -215,16 +194,35 @@ AudioChannelService::GetMutedInternal(Au
 
 bool
 AudioChannelService::ContentChannelIsActive()
 {
   return !mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty() ||
          !mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].IsEmpty();
 }
 
+bool
+AudioChannelService::HasMoreThanOneContentChannelHidden()
+{
+  uint32_t childId = CONTENT_PARENT_UNKNOWN_CHILD_ID;
+  bool empty = true;
+  for (uint32_t i = 0;
+       i < mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].Length();
+       ++i) {
+    if (empty) {
+      childId = mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN][i];
+      empty = false;
+    } else if (childId != mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN][i]) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 void
 AudioChannelService::SendAudioChannelChangedNotification()
 {
   if (XRE_GetProcessType() != GeckoProcessType_Default) {
     return;
   }
 
   // Calculating the most important active channel.
@@ -276,17 +274,18 @@ AudioChannelService::SendAudioChannelCha
     higher = AUDIO_CHANNEL_ALARM;
   }
 
   else if (!mChannelCounters[AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN].IsEmpty()) {
     higher = AUDIO_CHANNEL_NOTIFICATION;
   }
 
   // Content channels play in background if just one is active.
-  else if (!mActiveContentChildIDs.IsEmpty()) {
+  else if ((!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].IsEmpty() &&
+            !HasMoreThanOneContentChannelHidden())) {
     higher = AUDIO_CHANNEL_CONTENT;
   }
 
   if (higher != mCurrentHigherChannel) {
     mCurrentHigherChannel = higher;
 
     nsString channelName;
     if (mCurrentHigherChannel != AUDIO_CHANNEL_LAST) {
@@ -387,20 +386,16 @@ AudioChannelService::Observe(nsISupports
   if (NS_SUCCEEDED(rv)) {
     for (int32_t type = AUDIO_CHANNEL_INT_NORMAL;
          type < AUDIO_CHANNEL_INT_LAST;
          ++type) {
       int32_t index;
       while ((index = mChannelCounters[type].IndexOf(childID)) != -1) {
         mChannelCounters[type].RemoveElementAt(index);
       }
-
-      if ((index = mActiveContentChildIDs.IndexOf(childID)) != -1) {
-        mActiveContentChildIDs.RemoveElementAt(index);
-      }
     }
 
     // We don't have to remove the agents from the mAgents hashtable because if
     // that table contains only agents running on the same process.
 
     SendAudioChannelChangedNotification();
     Notify();
   } else {
--- a/dom/audiochannel/AudioChannelService.h
+++ b/dom/audiochannel/AudioChannelService.h
@@ -93,16 +93,18 @@ protected:
     AUDIO_CHANNEL_INT_RINGER_HIDDEN,
     AUDIO_CHANNEL_INT_PUBLICNOTIFICATION,
     AUDIO_CHANNEL_INT_PUBLICNOTIFICATION_HIDDEN,
     AUDIO_CHANNEL_INT_LAST
   };
 
   bool ChannelsActiveWithHigherPriorityThan(AudioChannelInternalType aType);
 
+  bool HasMoreThanOneContentChannelHidden();
+
   const char* ChannelName(AudioChannelType aType);
 
   AudioChannelInternalType GetInternalType(AudioChannelType aType,
                                            bool aElementHidden);
 
   class AudioChannelAgentData {
   public:
     AudioChannelAgentData(AudioChannelType aType,
@@ -123,19 +125,16 @@ protected:
                    AudioChannelAgentData* aData, void *aUnused);
 
   nsClassHashtable< nsPtrHashKey<AudioChannelAgent>, AudioChannelAgentData > mAgents;
 
   nsTArray<uint64_t> mChannelCounters[AUDIO_CHANNEL_INT_LAST];
 
   AudioChannelType mCurrentHigherChannel;
 
-  nsTArray<uint64_t> mActiveContentChildIDs;
-  bool mActiveContentChildIDsFrozen;
-
   // This is needed for IPC comunication between
   // AudioChannelServiceChild and this class.
   friend class ContentParent;
   friend class ContentChild;
 };
 
 } // namespace dom
 } // namespace mozilla