From 58719da6a94c5919c2761e0578d847c4759bd979 Mon Sep 17 00:00:00 2001 From: alwu Date: Wed, 14 Oct 2020 20:04:31 +0000 Subject: [PATCH] Bug 1668139 - part2 : add a telemetry probe to know how many actions are handled by default handler or media session handler. r=chunmin It would be good for us to know how many websites actually use MediaSession API to control (play/pause/stop) their media playback, an how many websites use our default handler. Differential Revision: https://phabricator.services.mozilla.com/D93283 --- dom/media/mediacontrol/ContentMediaController.cpp | 4 ++++ .../mediacontrol/ContentPlaybackController.cpp | 9 +++++++++ toolkit/components/telemetry/Histograms.json | 14 ++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/dom/media/mediacontrol/ContentMediaController.cpp b/dom/media/mediacontrol/ContentMediaController.cpp index b9e7d0627a2e..b13df354f5ab 100644 --- a/dom/media/mediacontrol/ContentMediaController.cpp +++ b/dom/media/mediacontrol/ContentMediaController.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/CanonicalBrowsingContext.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/StaticPtr.h" +#include "mozilla/Telemetry.h" #include "nsDataHashtable.h" #include "nsGlobalWindowOuter.h" @@ -328,6 +329,9 @@ void ContentMediaController::HandleMediaKey(MediaControlKey aKey) { } LOG("Handle '%s' event, receiver num=%zu", ToMediaControlKeyStr(aKey), mReceivers.Length()); + AccumulateCategorical( + mozilla::Telemetry::LABELS_MEDIA_CONTROL_HANDLE_PLAY_PAUSE_STOP_ACTIONS:: + DefaultHandler); // We have default handlers for play, pause and stop. // https://w3c.github.io/mediasession/#ref-for-dom-mediasessionaction-play%E2%91%A3 switch (aKey) { diff --git a/dom/media/mediacontrol/ContentPlaybackController.cpp b/dom/media/mediacontrol/ContentPlaybackController.cpp index a8258ad37149..4f573794883a 100644 --- a/dom/media/mediacontrol/ContentPlaybackController.cpp +++ b/dom/media/mediacontrol/ContentPlaybackController.cpp @@ -7,6 +7,7 @@ #include "MediaControlUtils.h" #include "mozilla/dom/MediaSession.h" #include "mozilla/dom/Navigator.h" +#include "mozilla/Telemetry.h" #include "nsFocusManager.h" // avoid redefined macro in unified build @@ -61,6 +62,14 @@ void ContentPlaybackController::NotifyMediaSession( LOG("Handle '%s' in media session behavior for BC %" PRIu64, ToMediaSessionActionStr(aDetails.mAction), mBC->Id()); MOZ_ASSERT(session->IsActive(), "Notify inactive media session!"); + if (aDetails.mAction == MediaSessionAction::Play || + aDetails.mAction == MediaSessionAction::Pause || + aDetails.mAction == MediaSessionAction::Stop) { + AccumulateCategorical( + mozilla::Telemetry:: + LABELS_MEDIA_CONTROL_HANDLE_PLAY_PAUSE_STOP_ACTIONS:: + MediaSessionHandler); + } session->NotifyHandler(aDetails); } } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index f58db73bd015..ef52faa9cfe4 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -15130,6 +15130,20 @@ "description": "Counts the number of times users enable and use media control on different platforms.", "releaseChannelCollection": "opt-out" }, + "MEDIA_CONTROL_HANDLE_PLAY_PAUSE_STOP_ACTIONS": { + "record_in_processes": ["content"], + "products": ["firefox"], + "alert_emails": [ + "alwu@mozilla.com", + "cchang@mozilla.com" + ], + "bug_numbers": [1668139], + "expires_in_version": "90", + "kind": "categorical", + "labels": ["DefaultHandler", "MediaSessionHandler"], + "description": "The number of times `play/pause/stop` actions are being handled on either default handler or media session action handler.", + "releaseChannelCollection": "opt-out" + }, "QM_QUOTA_INFO_LOAD_TIME_V0": { "record_in_processes": ["main"], "products": ["firefox", "fennec"],