Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp

Issue 2524443002: Adding Rappor metrics for disabling cross-origin autoplay with sound experiment (Closed)
Patch Set: s/CrossOriginExperiment/CrossOrigin Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
diff --git a/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp b/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
index 99241a29d4b5ddcff1e5f9afea45b083805b5543..1addafab307b0ddc5809de33abb571e903dc29bc 100644
--- a/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
+++ b/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
@@ -10,6 +10,7 @@
#include "core/frame/Settings.h"
#include "core/html/HTMLMediaElement.h"
#include "platform/Histogram.h"
+#include "public/platform/Platform.h"
#include "wtf/CurrentTime.h"
namespace blink {
@@ -94,6 +95,61 @@ void AutoplayUmaHelper::onAutoplayInitiated(AutoplaySource source) {
m_element->addEventListener(EventTypeNames::playing, this, false);
}
+void AutoplayUmaHelper::recordCrossOriginAutoplayResult(
+ CrossOriginAutoplayResult result) {
+ if (!m_element->isHTMLVideoElement())
+ return;
+ if (!m_element->isInCrossOriginFrame())
+ return;
+
+ // Record each metric only once per element, since the metric focuses on the
+ // site distribution. If a page calls play() multiple times, it will be
+ // recorded only once.
+ if (m_recordedCrossOriginAutoplayResults.count(result))
+ return;
+
+ switch (result) {
+ case CrossOriginAutoplayResult::AutoplayAllowed:
+ // Record metric
+ Platform::current()->recordRapporURL(
+ "Media.Autoplay.CrossOrigin.Allowed.ChildFrame",
+ m_element->document().url());
+ Platform::current()->recordRapporURL(
+ "Media.Autoplay.CrossOrigin.Allowed.TopLevelFrame",
+ m_element->document().topDocument().url());
+ m_recordedCrossOriginAutoplayResults.insert(result);
+ break;
+ case CrossOriginAutoplayResult::AutoplayBlocked:
+ Platform::current()->recordRapporURL(
+ "Media.Autoplay.CrossOrigin.Blocked.ChildFrame",
+ m_element->document().url());
+ Platform::current()->recordRapporURL(
+ "Media.Autoplay.CrossOrigin.Blocked.TopLevelFrame",
+ m_element->document().topDocument().url());
+ m_recordedCrossOriginAutoplayResults.insert(result);
+ break;
+ case CrossOriginAutoplayResult::PlayedWithGesture:
+ // Record this metric only when the video has been blocked from autoplay
+ // previously. This is to record the sites having videos that are blocked
+ // to autoplay but the user starts the playback by gesture.
+ if (!m_recordedCrossOriginAutoplayResults.count(
+ CrossOriginAutoplayResult::AutoplayBlocked)) {
+ return;
+ }
+ Platform::current()->recordRapporURL(
+ "Media.Autoplay.CrossOrigin.PlayedWithGesture.ChildFrame",
mlamouri (slow - plz ping) 2016/12/08 17:17:06 Should the rapport name be "PlayedWithGestureAfter
Zhiqiang Zhang (Slow) 2016/12/08 17:35:29 Done.
+ m_element->document().url());
+ Platform::current()->recordRapporURL(
+ "Media.Autoplay.CrossOrigin.PlayedWithGesture."
+ "TopLevelFrame",
+ m_element->document().topDocument().url());
+ m_recordedCrossOriginAutoplayResults.insert(result);
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
void AutoplayUmaHelper::recordAutoplayUnmuteStatus(
AutoplayUnmuteActionStatus status) {
DEFINE_STATIC_LOCAL(

Powered by Google App Engine
This is Rietveld 408576698