Bug 1633010 - part8 : rename `MediaSessionController` to `MediaStatusManager` r=chunmin

This patch will do :
- rename `MediaSessionController` to `MediaStatusManager`
- move `MediaStatusManager.*` to the folder under `mediacontrol`
- update the comment for `MediaStatusManager`

The advantage of doing so :
- increase the readability

More details :
We've extended the responsibility of `MediaSessionController` and it now handle a broader concept of media related status, not just media session related. Therefore, renaming it to precisely represent o its responsibility.

Differential Revision: https://phabricator.services.mozilla.com/D73493
This commit is contained in:
alwu 2020-05-13 22:09:23 +00:00
Родитель 97b23b9267
Коммит ef4977969c
6 изменённых файлов: 67 добавлений и 66 удалений

Просмотреть файл

@ -23,7 +23,7 @@ namespace mozilla {
namespace dom {
MediaController::MediaController(uint64_t aBrowsingContextId)
: MediaSessionController(aBrowsingContextId) {
: MediaStatusManager(aBrowsingContextId) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(),
"MediaController only runs on Chrome process!");
LOG("Create controller %" PRId64, Id());
@ -128,8 +128,7 @@ void MediaController::NotifyMediaPlaybackChanged(uint64_t aBrowsingContextId,
if (mShutdown) {
return;
}
MediaSessionController::NotifyMediaPlaybackChanged(aBrowsingContextId,
aState);
MediaStatusManager::NotifyMediaPlaybackChanged(aBrowsingContextId, aState);
// Update controller's status according to the media status.
if (ShouldActivateController()) {
@ -146,7 +145,7 @@ void MediaController::NotifyMediaAudibleChanged(uint64_t aBrowsingContextId,
}
bool oldAudible = IsAudible();
MediaSessionController::NotifyMediaAudibleChange(aBrowsingContextId, aState);
MediaStatusManager::NotifyMediaAudibleChanged(aBrowsingContextId, aState);
if (IsAudible() == oldAudible) {
return;
}

Просмотреть файл

@ -10,7 +10,7 @@
#include "ContentMediaController.h"
#include "MediaEventSource.h"
#include "MediaPlaybackStatus.h"
#include "mozilla/dom/MediaSessionController.h"
#include "MediaStatusManager.h"
#include "mozilla/LinkedList.h"
#include "nsDataHashtable.h"
#include "nsISupportsImpl.h"
@ -71,7 +71,7 @@ class IMediaController {
*/
class MediaController final
: public IMediaController,
public MediaSessionController,
public MediaStatusManager,
public LinkedListElement<RefPtr<MediaController>> {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaController, override);

Просмотреть файл

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaSessionController.h"
#include "MediaStatusManager.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/dom/MediaControlUtils.h"
@ -16,13 +16,13 @@
# include "nsIFaviconService.h"
#endif // MOZ_PLACES
mozilla::LazyLogModule gMediaSession("MediaSession");
extern mozilla::LazyLogModule gMediaControlLog;
// avoid redefined macro in unified build
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaSession, LogLevel::Debug, \
("MediaSessionController=%p, " msg, this, ##__VA_ARGS__))
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaStatusManager=%p, " msg, this, ##__VA_ARGS__))
namespace mozilla {
namespace dom {
@ -40,18 +40,18 @@ static bool IsMetadataEmpty(const Maybe<MediaMetadataBase>& aMetadata) {
metadata.mAlbum.IsEmpty() && metadata.mArtwork.IsEmpty();
}
MediaSessionController::MediaSessionController(uint64_t aBrowsingContextId)
MediaStatusManager::MediaStatusManager(uint64_t aBrowsingContextId)
: mTopLevelBrowsingContextId(aBrowsingContextId) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(),
"MediaSessionController only runs on Chrome process!");
"MediaStatusManager only runs on Chrome process!");
}
void MediaSessionController::NotifyMediaAudibleChanged(
uint64_t aBrowsingContextId, MediaAudibleState aState) {
mMediaStatusDelegate.UpdateMediaAudibleState(aBrowsingContextId, aState);
void MediaStatusManager::NotifyMediaAudibleChanged(uint64_t aBrowsingContextId,
MediaAudibleState aState) {
mPlaybackStatusDelegate.UpdateMediaAudibleState(aBrowsingContextId, aState);
}
void MediaSessionController::NotifySessionCreated(uint64_t aBrowsingContextId) {
void MediaStatusManager::NotifySessionCreated(uint64_t aBrowsingContextId) {
if (mMediaSessionInfoMap.Contains(aBrowsingContextId)) {
return;
}
@ -61,8 +61,7 @@ void MediaSessionController::NotifySessionCreated(uint64_t aBrowsingContextId) {
UpdateActiveMediaSessionContextId();
}
void MediaSessionController::NotifySessionDestroyed(
uint64_t aBrowsingContextId) {
void MediaStatusManager::NotifySessionDestroyed(uint64_t aBrowsingContextId) {
if (!mMediaSessionInfoMap.Contains(aBrowsingContextId)) {
return;
}
@ -71,7 +70,7 @@ void MediaSessionController::NotifySessionDestroyed(
UpdateActiveMediaSessionContextId();
}
void MediaSessionController::UpdateMetadata(
void MediaStatusManager::UpdateMetadata(
uint64_t aBrowsingContextId, const Maybe<MediaMetadataBase>& aMetadata) {
if (!mMediaSessionInfoMap.Contains(aBrowsingContextId)) {
return;
@ -97,7 +96,7 @@ void MediaSessionController::UpdateMetadata(
}
}
void MediaSessionController::UpdateActiveMediaSessionContextId() {
void MediaStatusManager::UpdateActiveMediaSessionContextId() {
// If there is a media session created from top level browsing context, it
// would always be chosen as an active media session. Otherwise, we would
// check if we have an active media session already. If we do have, it would
@ -141,7 +140,7 @@ void MediaSessionController::UpdateActiveMediaSessionContextId() {
*mActiveMediaSessionContextId);
}
MediaMetadataBase MediaSessionController::CreateDefaultMetadata() const {
MediaMetadataBase MediaStatusManager::CreateDefaultMetadata() const {
MediaMetadataBase metadata;
metadata.mTitle = GetDefaultTitle();
metadata.mArtwork.AppendElement()->mSrc = GetDefaultFaviconURL();
@ -152,7 +151,7 @@ MediaMetadataBase MediaSessionController::CreateDefaultMetadata() const {
return metadata;
}
nsString MediaSessionController::GetDefaultTitle() const {
nsString MediaStatusManager::GetDefaultTitle() const {
RefPtr<CanonicalBrowsingContext> bc =
CanonicalBrowsingContext::Get(mTopLevelBrowsingContextId);
if (!bc) {
@ -187,7 +186,7 @@ nsString MediaSessionController::GetDefaultTitle() const {
return defaultTitle;
}
nsString MediaSessionController::GetDefaultFaviconURL() const {
nsString MediaStatusManager::GetDefaultFaviconURL() const {
#ifdef MOZ_PLACES
nsCOMPtr<nsIURI> faviconURI;
nsresult rv = NS_NewURI(getter_AddRefs(faviconURI),
@ -213,7 +212,7 @@ nsString MediaSessionController::GetDefaultFaviconURL() const {
return EmptyString();
}
void MediaSessionController::SetDeclaredPlaybackState(
void MediaStatusManager::SetDeclaredPlaybackState(
uint64_t aBrowsingContextId, MediaSessionPlaybackState aState) {
if (!mMediaSessionInfoMap.Contains(aBrowsingContextId)) {
return;
@ -226,8 +225,8 @@ void MediaSessionController::SetDeclaredPlaybackState(
UpdateActualPlaybackState();
}
MediaSessionPlaybackState
MediaSessionController::GetCurrentDeclaredPlaybackState() const {
MediaSessionPlaybackState MediaStatusManager::GetCurrentDeclaredPlaybackState()
const {
if (!mActiveMediaSessionContextId) {
return MediaSessionPlaybackState::None;
}
@ -235,28 +234,27 @@ MediaSessionController::GetCurrentDeclaredPlaybackState() const {
.mDeclaredPlaybackState;
}
void MediaSessionController::NotifyMediaPlaybackChanged(
uint64_t aBrowsingContextId, MediaPlaybackState aState) {
void MediaStatusManager::NotifyMediaPlaybackChanged(uint64_t aBrowsingContextId,
MediaPlaybackState aState) {
LOG("UpdateMediaPlaybackState %s for context %" PRId64,
ToMediaPlaybackStateStr(aState), aBrowsingContextId);
const bool oldPlaying = mMediaStatusDelegate.IsPlaying();
mMediaStatusDelegate.UpdateMediaPlaybackState(aBrowsingContextId, aState);
const bool oldPlaying = mPlaybackStatusDelegate.IsPlaying();
mPlaybackStatusDelegate.UpdateMediaPlaybackState(aBrowsingContextId, aState);
// Playback state doesn't change, we don't need to update the guessed playback
// state. This is used to prevent the state from changing from `none` to
// `paused` when receiving `MediaPlaybackState::eStarted`.
if (mMediaStatusDelegate.IsPlaying() == oldPlaying) {
if (mPlaybackStatusDelegate.IsPlaying() == oldPlaying) {
return;
}
if (mMediaStatusDelegate.IsPlaying()) {
if (mPlaybackStatusDelegate.IsPlaying()) {
SetGuessedPlayState(MediaSessionPlaybackState::Playing);
} else {
SetGuessedPlayState(MediaSessionPlaybackState::Paused);
}
}
void MediaSessionController::SetGuessedPlayState(
MediaSessionPlaybackState aState) {
void MediaStatusManager::SetGuessedPlayState(MediaSessionPlaybackState aState) {
if (aState == mGuessedPlaybackState) {
return;
}
@ -265,7 +263,7 @@ void MediaSessionController::SetGuessedPlayState(
UpdateActualPlaybackState();
}
void MediaSessionController::UpdateActualPlaybackState() {
void MediaStatusManager::UpdateActualPlaybackState() {
// The way to compute the actual playback state is based on the spec.
// https://w3c.github.io/mediasession/#actual-playback-state
MediaSessionPlaybackState newState =
@ -281,7 +279,7 @@ void MediaSessionController::UpdateActualPlaybackState() {
HandleActualPlaybackStateChanged();
}
MediaMetadataBase MediaSessionController::GetCurrentMediaMetadata() const {
MediaMetadataBase MediaStatusManager::GetCurrentMediaMetadata() const {
// If we don't have active media session, active media session doesn't have
// media metadata, or we're in private browsing mode, then we should create a
// default metadata which is using website's title and favicon as title and
@ -299,7 +297,7 @@ MediaMetadataBase MediaSessionController::GetCurrentMediaMetadata() const {
return CreateDefaultMetadata();
}
void MediaSessionController::FillMissingTitleAndArtworkIfNeeded(
void MediaStatusManager::FillMissingTitleAndArtworkIfNeeded(
MediaMetadataBase& aMetadata) const {
// If the metadata doesn't set its title and artwork properly, we would like
// to use default title and favicon instead in order to prevent showing
@ -312,7 +310,7 @@ void MediaSessionController::FillMissingTitleAndArtworkIfNeeded(
}
}
bool MediaSessionController::IsInPrivateBrowsing() const {
bool MediaStatusManager::IsInPrivateBrowsing() const {
RefPtr<CanonicalBrowsingContext> bc =
CanonicalBrowsingContext::Get(mTopLevelBrowsingContextId);
if (!bc) {
@ -325,20 +323,20 @@ bool MediaSessionController::IsInPrivateBrowsing() const {
return nsContentUtils::IsInPrivateBrowsing(element->OwnerDoc());
}
MediaSessionPlaybackState MediaSessionController::GetState() const {
MediaSessionPlaybackState MediaStatusManager::GetState() const {
return mActualPlaybackState;
}
bool MediaSessionController::IsMediaAudible() const {
return mMediaStatusDelegate.IsAudible();
bool MediaStatusManager::IsMediaAudible() const {
return mPlaybackStatusDelegate.IsAudible();
}
bool MediaSessionController::IsMediaPlaying() const {
bool MediaStatusManager::IsMediaPlaying() const {
return mActualPlaybackState == MediaSessionPlaybackState::Playing;
}
bool MediaSessionController::IsAnyMediaBeingControlled() const {
return mMediaStatusDelegate.IsAnyMediaBeingControlled();
bool MediaStatusManager::IsAnyMediaBeingControlled() const {
return mPlaybackStatusDelegate.IsAnyMediaBeingControlled();
}
} // namespace dom

Просмотреть файл

@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIASESSION_MEDIASESSIONCONTROLLER_H_
#define DOM_MEDIA_MEDIASESSION_MEDIASESSIONCONTROLLER_H_
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIASTATUSMANAGER_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIASTATUSMANAGER_H_
#include "mozilla/dom/MediaMetadata.h"
#include "mozilla/dom/MediaSessionBinding.h"
@ -74,26 +74,30 @@ class IMediaInfoUpdater {
};
/**
* MediaSessionController is used to track all alive media sessions within a tab
* MediaStatusManager would decide the media related status which can represents
* the whole tab. The status includes the playback status, tab's metadata and
* the active media session ID if it exists.
*
* We would use `IMediaInfoUpdater` methods to update the media playback related
* information and then use `MediaPlaybackStatus` to determine the final
* playback state.
*
* The metadata would be the one from the active media session, or the default
* one. This class would determine which media session is an active media
* session [1] whithin a tab. It tracks 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.
*
* When media session is created in the content process, we would notify
* MediaSessionController in the parent process to tell it in which browsing
* context media session is created. If there are multiple media sessions
* existing in the same tab, MediaSessionController would take a resbonsibility
* to decide which media session should be an active media session. However,
* the meaning of active media session here is not equal to the definition from
* the spec [1]. We just choose the session which is the active one inside the
* tab, the global active media session among different tabs would be selected
* in other place, which is related to how we select media controller.
* metadata even if there is no media session existing. However, the meaning of
* active media session here is not equal to the definition from the spec [1].
* We just choose the session which is the active one inside the tab, the global
* active media session among different tabs would be the one inside the main
* controller which is determined by MediaControlService.
*
* [1] https://w3c.github.io/mediasession/#active-media-session
*/
class MediaSessionController : public IMediaInfoUpdater {
class MediaStatusManager : public IMediaInfoUpdater {
public:
explicit MediaSessionController(uint64_t aBrowsingContextId);
explicit MediaStatusManager(uint64_t aBrowsingContextId);
// IMediaInfoUpdater's methods
void NotifyMediaPlaybackChanged(uint64_t aBrowsingContextId,
@ -124,7 +128,7 @@ class MediaSessionController : public IMediaInfoUpdater {
MediaSessionPlaybackState GetState() const;
protected:
~MediaSessionController() = default;
~MediaStatusManager() = default;
virtual void HandleActualPlaybackStateChanged() = 0;
uint64_t mTopLevelBrowsingContextId;
@ -170,10 +174,10 @@ class MediaSessionController : public IMediaInfoUpdater {
nsDataHashtable<nsUint64HashKey, MediaSessionInfo> mMediaSessionInfoMap;
MediaEventProducer<MediaMetadataBase> mMetadataChangedEvent;
MediaPlaybackStatus mMediaStatusDelegate;
MediaPlaybackStatus mPlaybackStatusDelegate;
};
} // namespace dom
} // namespace mozilla
#endif // DOM_MEDIA_MEDIASESSION_MEDIASESSIONCONTROLLER_H_
#endif // DOM_MEDIA_MEDIACONTROL_MEDIASTATUSMANAGER_H_

Просмотреть файл

@ -14,6 +14,7 @@ EXPORTS.mozilla.dom += [
'MediaControlService.h',
'MediaControlUtils.h',
'MediaPlaybackStatus.h',
'MediaStatusManager.h',
]
EXPORTS.ipc += [
@ -31,6 +32,7 @@ UNIFIED_SOURCES += [
'MediaControlService.cpp',
'MediaControlUtils.cpp',
'MediaPlaybackStatus.cpp',
'MediaStatusManager.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')

Просмотреть файл

@ -9,7 +9,6 @@ MOCHITEST_MANIFESTS += ['test/mochitest.ini']
EXPORTS.mozilla.dom += [
'MediaMetadata.h',
'MediaSession.h',
'MediaSessionController.h',
'MediaSessionIPCUtils.h',
'MediaSessionUtils.h',
]
@ -17,7 +16,6 @@ EXPORTS.mozilla.dom += [
UNIFIED_SOURCES += [
'MediaMetadata.cpp',
'MediaSession.cpp',
'MediaSessionController.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')