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

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

Issue 2108403003: Measure whether muted videos that started playing with play() become visible at some point (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: this one is ready Created 4 years, 6 months 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
new file mode 100644
index 0000000000000000000000000000000000000000..980643009d2ae0dfd85ea1f9b725ad67dccf1c16
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/AutoplayUmaHelper.h"
+
+#include "core/html/HTMLMediaElement.h"
+#include "platform/Histogram.h"
+
+namespace blink {
+
+namespace {
+
+ void recordMutedVideoOfSourceMethodFinallyVisibleUma(bool visible)
+ {
+ DEFINE_STATIC_LOCAL(BooleanHistogram, histogram, ("Media.Video.Autoplay.Muted.SourceMethod.FinallyVisible"));
+ histogram.count(visible);
+ }
mlamouri (slow - plz ping) 2016/07/01 11:00:07 style: no indentation
Zhiqiang Zhang (Slow) 2016/07/04 14:34:38 Done.
+
+} // namespace
+
+AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element)
+ : m_source(AutoplaySource::NumberOfSources)
+ , m_element(element)
+{
+}
+
+AutoplayUmaHelper::~AutoplayUmaHelper() = default;
+
+void AutoplayUmaHelper::onAutoplayInitiated(AutoplaySource source)
+{
+ m_source = source;
+}
+
+void AutoplayUmaHelper::onAutoplayStarted()
+{
+ if (m_source == AutoplaySource::Method && m_element->isHTMLVideoElement() && m_element->muted())
+ recordMutedVideoOfSourceMethodFinallyVisibleUma(true);
+}
+
+void AutoplayUmaHelper::onElementDestroyed()
mlamouri (slow - plz ping) 2016/07/01 11:00:07 The issue with recording UMA in a dtor is that it
Zhiqiang Zhang (Slow) 2016/07/04 14:34:38 Done.
+{
+ if (m_source == AutoplaySource::Method && m_element->isHTMLVideoElement() && m_element->muted())
+ recordMutedVideoOfSourceMethodFinallyVisibleUma(false);
mlamouri (slow - plz ping) 2016/07/01 11:00:07 Maybe you could have a `m_shouldRecordVisibilityCh
Zhiqiang Zhang (Slow) 2016/07/04 14:34:38 The logic here was wrong. I'm using a ElementVisib
+}
+
+DEFINE_TRACE(AutoplayUmaHelper)
+{
+ visitor->trace(m_element);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698