Bug 1663128 - part3 : the event source should do the cleanup when it closes. r=chunmin

When close the event source, it should be responsible to clear up and reset the virtual control interface, rather than doing so by `Media Control Server` via setting some empty results.

Differential Revision: https://phabricator.services.mozilla.com/D92116
This commit is contained in:
alwu 2020-10-06 21:43:25 +00:00
Родитель 8fa7fe5499
Коммит d81f601202
7 изменённых файлов: 56 добавлений и 34 удалений

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

@ -86,9 +86,20 @@ bool MediaControlKeyManager::StartMonitoringControlKeys() {
}
void MediaControlKeyManager::StopMonitoringControlKeys() {
if (mEventSource && mEventSource->IsOpened()) {
LOG_INFO("StopMonitoringControlKeys");
mEventSource->Close();
if (!mEventSource || !mEventSource->IsOpened()) {
return;
}
LOG_INFO("StopMonitoringControlKeys");
mEventSource->Close();
if (StaticPrefs::media_mediacontrol_testingevents_enabled()) {
// Close the source would reset the displayed playback state and metadata.
if (nsCOMPtr<nsIObserverService> obs = services::GetObserverService()) {
obs->NotifyObservers(nullptr, "media-displayed-playback-changed",
nullptr);
obs->NotifyObservers(nullptr, "media-displayed-metadata-changed",
nullptr);
}
}
}

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

@ -404,9 +404,6 @@ void MediaControlService::ControllerManager::UpdateMainControllerInternal(
if (!mMainController) {
LOG_MAINCONTROLLER_INFO("Clear main controller");
mSource->Close();
mSource->SetPlaybackState(MediaSessionPlaybackState::None);
mSource->SetMediaMetadata(MediaMetadataBase::EmptyData());
mSource->SetSupportedMediaKeys(MediaKeysArray());
DisconnectMainControllerEvents();
} else {
LOG_MAINCONTROLLER_INFO("Set controller %" PRId64 " as main controller",

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

@ -137,6 +137,7 @@ bool MediaHardwareKeysEventSourceMacMediaCenter::Open() {
void MediaHardwareKeysEventSourceMacMediaCenter::Close() {
LOG("Close MediaHardwareKeysEventSourceMacMediaCenter");
SetPlaybackState(dom::MediaSessionPlaybackState::None);
EndListeningForEvents();
mOpened = false;
MediaControlKeySource::Close();

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

@ -334,6 +334,10 @@ void MPRISServiceHandler::Close() {
gchar serviceName[256];
SprintfLiteral(serviceName, DBUS_MPRIS_SERVICE_NAME ".instance%d", getpid());
// Reset playback state and metadata before disconnect from dbus.
SetPlaybackState(dom::MediaSessionPlaybackState::None);
ClearMetadata();
OnNameLost(mConnection, serviceName);
if (mOwnerId != 0) {
@ -345,18 +349,6 @@ void MPRISServiceHandler::Close() {
mInitialized = false;
MediaControlKeySource::Close();
mImageFetchRequest.DisconnectIfExists();
RemoveAllLocalImages();
mMPRISMetadata.Clear();
mCurrentImageUrl.Truncate();
mFetchingUrl.Truncate();
mNextImageIndex = 0;
mSupportedKeys = 0;
}
bool MPRISServiceHandler::IsOpened() const { return mInitialized; }
@ -484,6 +476,17 @@ void MPRISServiceHandler::SetMediaMetadataInternal(
EmitMetadataChanged();
}
void MPRISServiceHandler::ClearMetadata() {
mMPRISMetadata.Clear();
mImageFetchRequest.DisconnectIfExists();
RemoveAllLocalImages();
mCurrentImageUrl.Truncate();
mFetchingUrl.Truncate();
mNextImageIndex = 0;
mSupportedKeys = 0;
EmitMetadataChanged();
}
void MPRISServiceHandler::LoadImageAtIndex(const size_t aIndex) {
MOZ_ASSERT(NS_IsMainThread());

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

@ -176,6 +176,8 @@ class MPRISServiceHandler final : public dom::MediaControlKeySource {
bool aSupported) const;
bool EmitPropertiesChangedSignal(GVariant* aParameters) const;
void ClearMetadata();
};
} // namespace widget

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

@ -172,26 +172,19 @@ bool WindowsSMTCProvider::Open() {
void WindowsSMTCProvider::Close() {
MediaControlKeySource::Close();
if (mInitialized) { // Prevent calling Set methods when init failed
// Prevent calling Set methods when init failed
if (mInitialized) {
SetPlaybackState(mozilla::dom::MediaSessionPlaybackState::None);
UnregisterEvents();
ClearMetadata();
// We have observed an Windows issue, if we modify `mControls` , (such as
// setting metadata, disable buttons) before disabling control, and those
// operations are not done sequentially within a same main thread task,
// then it would cause a problem where the SMTC wasn't clean up completely
// and show the executable name.
EnableControl(false);
mInitialized = false;
}
UnregisterEvents();
// Cancel the pending image fetch process
mImageFetchRequest.DisconnectIfExists();
CancelPendingStoreAsyncOperation();
// Clear the cached image urls
mThumbnailUrl.Truncate();
mProcessingUrl.Truncate();
mNextImageIndex = 0;
mSupportedKeys = 0;
}
void WindowsSMTCProvider::SetPlaybackState(
@ -236,6 +229,19 @@ void WindowsSMTCProvider::SetMediaMetadata(
LoadThumbnail(aMetadata.mArtwork);
}
void WindowsSMTCProvider::ClearMetadata() {
MOZ_ASSERT(mDisplay);
if (FAILED(mDisplay->ClearAll())) {
LOG("Failed to clear SMTC display");
}
mImageFetchRequest.DisconnectIfExists();
CancelPendingStoreAsyncOperation();
mThumbnailUrl.Truncate();
mProcessingUrl.Truncate();
mNextImageIndex = 0;
mSupportedKeys = 0;
}
void WindowsSMTCProvider::SetSupportedMediaKeys(
const MediaKeysArray& aSupportedKeys) {
MOZ_ASSERT(mInitialized);

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

@ -82,6 +82,8 @@ class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource {
bool UpdateThumbnail(const nsAString& aUrl);
void CancelPendingStoreAsyncOperation() const;
void ClearMetadata();
bool mInitialized = false;
// A bit table indicating what keys are enabled