Bug 1595618 - Optimize SourceListener iteration on devicechange. r=pehrsons
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 12 Nov 2019 14:50:24 +0000
changeset 501599 3b21c6bc1e1c58fefc34c71ad370fe903c42613f
parent 501598 7edb2cd99ae5d26020e939561d161ab7ea1dab2b
child 501600 d1ea0724b6caa33111426ec69a7e288cfde79dee
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1595618
milestone72.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 1595618 - Optimize SourceListener iteration on devicechange. r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D52598
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2189,48 +2189,22 @@ void MediaManager::DeviceListChanged() {
             }
             // For any removed devices, notify their listeners cleanly that the
             // source has stopped, so JS knows and usage indicators update.
             for (auto& id : mDeviceIDs) {
               if (deviceIDs.Contains(id)) {
                 // Device has not been removed
                 continue;
               }
-
-              // Stop the coresponding SourceListener
-              nsGlobalWindowInner::InnerWindowByIdTable* windowsById =
-                  nsGlobalWindowInner::GetWindowsTable();
-              if (!windowsById) {
-                // We're in shutdown
-                continue;
-              }
-
-              for (auto iter = windowsById->Iter(); !iter.Done(); iter.Next()) {
-                nsGlobalWindowInner* window = iter.Data();
-                if (!window->IsCurrentInnerWindow()) {
-                  // Ignore non-current inner windows
-                  continue;
-                }
-                if (!window->GetOuterWindow()->IsTopLevelWindow()) {
-                  // Ignore non-top-level inner windows, to avoid hitting them
-                  // twice, since we'll be using IterateWindowListeners(). This
-                  // shouldn't miss any iframes, as they generally can't be
-                  // removed from DOM without OnNavigation. If it does miss them
-                  // OnNavigation does a comparable job (minus notifying the JS
-                  // that's about to be unloaded).
-                  continue;
-                }
-                IterateWindowListeners(
-                    window,
-                    [&id](const RefPtr<GetUserMediaWindowListener>& aListener) {
-                      aListener->StopRawID(id);
-                    });
+              // Stop the corresponding SourceListener
+              for (auto iter = mActiveWindows.Iter(); !iter.Done();
+                   iter.Next()) {
+                iter.UserData()->StopRawID(id);
               }
             }
-
             mDeviceIDs = deviceIDs;
           },
           [](RefPtr<MediaMgrError>&& reason) {});
 }
 
 nsresult MediaManager::GenerateUUID(nsAString& aResult) {
   nsresult rv;
   nsCOMPtr<nsIUUIDGenerator> uuidgen =