Bug 1633010 - part5 : extend `IMediaInfoUpdater`. r=chunmin
authoralwu <alwu@mozilla.com>
Wed, 13 May 2020 22:07:44 +0000
changeset 529738 3f13564609362717be2d5521dfdf52d387c6ae96
parent 529737 570cdab31d422de9476bdde28ed5a8624a03124f
child 529739 b32d1b16ace50e307d144e2cee83eabe31986f61
push id37414
push usernbeleuzu@mozilla.com
push dateThu, 14 May 2020 02:40:10 +0000
treeherdermozilla-central@045d696faa87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschunmin
bugs1633010
milestone78.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 1633010 - part5 : extend `IMediaInfoUpdater`. r=chunmin This patch will do : - make all functions which are used to update information from the content process become a part of `IMediaInfoUpdater` The advantage of doing so : - It's clear to use `IMediaInfoUpdater` as the only surface to update the media related status - explictly restrict which functions are available which can avoid using control related functions on those situations Differential Revision: https://phabricator.services.mozilla.com/D73489
dom/ipc/ContentParent.cpp
dom/media/mediacontrol/ContentMediaController.cpp
dom/media/mediacontrol/MediaController.h
dom/media/mediasession/MediaSession.cpp
dom/media/mediasession/MediaSessionController.h
dom/media/mediasession/MediaSessionUtils.h
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -5881,19 +5881,19 @@ mozilla::ipc::IPCResult ContentParent::R
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvNotifyUpdateMediaMetadata(
     const MaybeDiscarded<BrowsingContext>& aContext,
     const Maybe<MediaMetadataBase>& aMetadata) {
   if (aContext.IsNullOrDiscarded()) {
     return IPC_OK();
   }
-  if (RefPtr<MediaController> controller =
+  if (RefPtr<IMediaInfoUpdater> updater =
           aContext.get_canonical()->GetMediaController()) {
-    controller->UpdateMetadata(aContext.ContextId(), aMetadata);
+    updater->UpdateMetadata(aContext.ContextId(), aMetadata);
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 ContentParent::RecvNotifyMediaSessionPlaybackStateChanged(
     const MaybeDiscarded<BrowsingContext>& aContext,
     MediaSessionPlaybackState aPlaybackState) {
--- a/dom/media/mediacontrol/ContentMediaController.cpp
+++ b/dom/media/mediacontrol/ContentMediaController.cpp
@@ -162,19 +162,19 @@ void ContentMediaController::NotifyPictu
   LOG("Notify media Picture-in-Picture mode '%s' in BC %" PRId64,
       aEnabled ? "enabled" : "disabled", bc->Id());
   if (XRE_IsContentProcess()) {
     ContentChild* contentChild = ContentChild::GetSingleton();
     Unused << contentChild->SendNotifyPictureInPictureModeChanged(bc, aEnabled);
   } else {
     // Currently this only happen when we disable e10s, otherwise all controlled
     // media would be run in the content process.
-    if (RefPtr<MediaController> controller =
+    if (RefPtr<IMediaInfoUpdater> updater =
             bc->Canonical()->GetMediaController()) {
-      controller->SetIsInPictureInPictureMode(aEnabled);
+      updater->SetIsInPictureInPictureMode(aEnabled);
     }
   }
 }
 
 void ContentMediaController::HandleEvent(MediaControlKeysEvent aEvent) {
   MOZ_ASSERT(NS_IsMainThread());
   LOG("Handle '%s' event, receiver num=%zu", ToMediaControlKeysEventStr(aEvent),
       mReceivers.Length());
--- a/dom/media/mediacontrol/MediaController.h
+++ b/dom/media/mediacontrol/MediaController.h
@@ -63,20 +63,17 @@ class MediaController final
   void SeekBackward();
   void SeekForward();
 
   // IMediaInfoUpdater's methods
   void NotifyMediaPlaybackChanged(uint64_t aBrowsingContextId,
                                   MediaPlaybackState aState) override;
   void NotifyMediaAudibleChanged(uint64_t aBrowsingContextId,
                                  MediaAudibleState aState) override;
-
-  // If any of controlled media is being used in Picture-In-Picture mode, then
-  // this function should be callled and set the value.
-  void SetIsInPictureInPictureMode(bool aIsInPictureInPictureMode);
+  void SetIsInPictureInPictureMode(bool aIsInPictureInPictureMode) override;
 
   // Reture true if any of controlled media is being used in Picture-In-Picture
   // mode.
   bool IsInPictureInPictureMode() const;
 
   // Calling this method explicitly would mark this controller as deprecated,
   // then calling any its method won't take any effect.
   void Shutdown();
--- a/dom/media/mediasession/MediaSession.cpp
+++ b/dom/media/mediasession/MediaSession.cpp
@@ -191,16 +191,16 @@ void MediaSession::NotifyMetadataUpdated
   }
 
   if (XRE_IsContentProcess()) {
     ContentChild* contentChild = ContentChild::GetSingleton();
     Unused << contentChild->SendNotifyUpdateMediaMetadata(currentBC, metadata);
     return;
   }
   // This would only happen when we disable e10s.
-  if (RefPtr<MediaController> controller =
+  if (RefPtr<IMediaInfoUpdater> updater =
           currentBC->Canonical()->GetMediaController()) {
-    controller->UpdateMetadata(currentBC->Id(), metadata);
+    updater->UpdateMetadata(currentBC->Id(), metadata);
   }
 }
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/media/mediasession/MediaSessionController.h
+++ b/dom/media/mediasession/MediaSessionController.h
@@ -53,16 +53,29 @@ class IMediaInfoUpdater {
   // browsing context where controlled media exists.
   virtual void NotifyMediaAudibleChanged(uint64_t aBrowsingContextId,
                                          MediaAudibleState aState) = 0;
 
   // Use this method to update media session's declared playback state for the
   // specific media session.
   virtual void SetDeclaredPlaybackState(uint64_t aSessionContextId,
                                         MediaSessionPlaybackState aState) = 0;
+
+  // Use these methods to update controller's media session list. We'd use it
+  // when media session is created/destroyed in the content process.
+  virtual void NotifySessionCreated(uint64_t aSessionContextId) = 0;
+  virtual void NotifySessionDestroyed(uint64_t aSessionContextId) = 0;
+
+  // Use this method to update the metadata for the specific media session.
+  virtual void UpdateMetadata(uint64_t aSessionContextId,
+                              const Maybe<MediaMetadataBase>& aMetadata) = 0;
+
+  // Use this method to update if the media in content process is being used in
+  // Picture-in-Picture mode.
+  virtual void SetIsInPictureInPictureMode(bool aIsInPictureInPictureMode) = 0;
 };
 
 /**
  * MediaSessionController is used to track all alive media sessions within a tab
  * and store their metadata which could be used to show on the virtual media
  * control interface. In addition, we can use it to get the current media
  * metadata even if there is no media session existing.
  *
@@ -84,27 +97,20 @@ class MediaSessionController : public IM
 
   // IMediaInfoUpdater's methods
   void NotifyMediaPlaybackChanged(uint64_t aBrowsingContextId,
                                   MediaPlaybackState aState) override;
   void NotifyMediaAudibleChanged(uint64_t aBrowsingContextId,
                                  MediaAudibleState aState) override;
   void SetDeclaredPlaybackState(uint64_t aSessionContextId,
                                 MediaSessionPlaybackState aState) override;
-
-  // Use these functions to ensure that we can track all existing media session
-  // in the same tab when media session is created or destroyed in the content
-  // process.
-  void NotifySessionCreated(uint64_t aSessionContextId);
-  void NotifySessionDestroyed(uint64_t aSessionContextId);
-
-  // Use this function to store the media metadata when media session updated
-  // its metadata in the content process.
+  void NotifySessionCreated(uint64_t aSessionContextId) override;
+  void NotifySessionDestroyed(uint64_t aSessionContextId) override;
   void UpdateMetadata(uint64_t aSessionContextId,
-                      const Maybe<MediaMetadataBase>& aMetadata);
+                      const Maybe<MediaMetadataBase>& aMetadata) override;
 
   // Return active media session's metadata if active media session exists and
   // it has already set its metadata. Otherwise, return default media metadata
   // which is based on website's title and favicon.
   MediaMetadataBase GetCurrentMediaMetadata() const;
   uint64_t Id() const { return mTopLevelBCId; }
 
   bool IsMediaAudible() const;
--- a/dom/media/mediasession/MediaSessionUtils.h
+++ b/dom/media/mediasession/MediaSessionUtils.h
@@ -16,25 +16,25 @@ namespace dom {
 inline void NotfiyMediaSessionCreationOrDeconstruction(
     BrowsingContext* aContext, bool aIsCreated) {
   if (XRE_IsContentProcess()) {
     ContentChild* contentChild = ContentChild::GetSingleton();
     Unused << contentChild->SendNotifyMediaSessionUpdated(aContext, aIsCreated);
     return;
   }
 
-  RefPtr<MediaController> controller =
+  RefPtr<IMediaInfoUpdater> updater =
       aContext->Canonical()->GetMediaController();
-  if (!controller) {
+  if (!updater) {
     return;
   }
   if (aIsCreated) {
-    controller->NotifySessionCreated(aContext->Id());
+    updater->NotifySessionCreated(aContext->Id());
   } else {
-    controller->NotifySessionDestroyed(aContext->Id());
+    updater->NotifySessionDestroyed(aContext->Id());
   }
 }
 
 inline const char* ToMediaSessionPlaybackStateStr(
     const MediaSessionPlaybackState& aState) {
   switch (aState) {
     case MediaSessionPlaybackState::None:
       return "none";