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

Side by Side 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: fixed layout tests Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/html/AutoplayUmaHelper.h"
6
7 #include "core/dom/ElementVisibilityObserver.h"
8 #include "core/events/Event.h"
9 #include "core/html/HTMLMediaElement.h"
10 #include "platform/Histogram.h"
11
12 namespace blink {
13
14 namespace {
15
16 void recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(bool visible)
17 {
18 DEFINE_STATIC_LOCAL(BooleanHistogram, histogram, ("Media.Video.Autoplay.Mute d.PlayMethod.BecomesVisible"));
19 histogram.count(visible);
20 }
21
22 } // namespace
23
24 AutoplayUmaHelper* AutoplayUmaHelper::create(HTMLMediaElement* element)
25 {
26 return new AutoplayUmaHelper(element);
27 }
28
29 AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element)
30 : EventListener(CPPEventListenerType)
31 , m_source(AutoplaySource::NumberOfSources)
32 , m_element(element)
33 , m_videoMutedPlayMethodVisibilityObserver(nullptr) { }
34
35 AutoplayUmaHelper::~AutoplayUmaHelper() = default;
36
37 bool AutoplayUmaHelper::operator==(const EventListener& other) const
38 {
39 return this == &other;
40 }
41
42 void AutoplayUmaHelper::onAutoplayInitiated(AutoplaySource source)
43 {
44 DEFINE_STATIC_LOCAL(EnumerationHistogram, videoHistogram, ("Media.Video.Auto play", static_cast<int>(AutoplaySource::NumberOfSources)));
45 DEFINE_STATIC_LOCAL(EnumerationHistogram, mutedVideoHistogram, ("Media.Video .Autoplay.Muted", static_cast<int>(AutoplaySource::NumberOfSources)));
46 DEFINE_STATIC_LOCAL(EnumerationHistogram, audioHistogram, ("Media.Audio.Auto play", static_cast<int>(AutoplaySource::NumberOfSources)));
47
48 m_source = source;
49
50 if (m_element->isHTMLVideoElement()) {
51 videoHistogram.count(static_cast<int>(m_source));
52 if (m_element->muted())
53 mutedVideoHistogram.count(static_cast<int>(m_source));
54 } else {
55 audioHistogram.count(static_cast<int>(m_source));
56 }
57
58 if (m_source == AutoplaySource::Method && m_element->isHTMLVideoElement() && m_element->muted())
59 m_element->addEventListener(EventTypeNames::playing, this, false);
60 }
61
62 void AutoplayUmaHelper::onElementDestroyed()
63 {
64 if (m_videoMutedPlayMethodVisibilityObserver) {
65 recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(false);
66 m_videoMutedPlayMethodVisibilityObserver->stop();
67 m_videoMutedPlayMethodVisibilityObserver = nullptr;
68 }
69 }
70
71 void AutoplayUmaHelper::recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus st atus)
72 {
73 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V ideo.Autoplay.Muted.UnmuteAction", static_cast<int>(AutoplayUnmuteActionStatus:: NumberOfStatus)));
74
75 autoplayUnmuteHistogram.count(static_cast<int>(status));
76 }
77
78 void AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod(bool isVisibl e)
79 {
80 if (!isVisible)
81 return;
82
83 recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(true);
84 m_videoMutedPlayMethodVisibilityObserver->stop();
85 m_videoMutedPlayMethodVisibilityObserver = nullptr;
86 }
87
88 void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext, Event* e vent)
89 {
90 DCHECK(event->type() == EventTypeNames::playing);
91 handlePlayingEvent();
92 }
93
94 void AutoplayUmaHelper::handlePlayingEvent()
95 {
96 if (m_source == AutoplaySource::Method && m_element->isHTMLVideoElement() && m_element->muted()) {
97 if (!m_videoMutedPlayMethodVisibilityObserver) {
98 m_videoMutedPlayMethodVisibilityObserver = new ElementVisibilityObse rver(m_element, WTF::bind(&AutoplayUmaHelper::onVisibilityChangedForVideoMutedPl ayMethod, wrapPersistent(this)));
99 m_videoMutedPlayMethodVisibilityObserver->start();
100 }
101 }
102 m_element->removeEventListener(EventTypeNames::playing, this, false);
Dan Beam 2016/07/12 18:01:02 maybe removeEventListener() needs to be called eve
103 }
104
105 DEFINE_TRACE(AutoplayUmaHelper)
106 {
107 EventListener::trace(visitor);
108 visitor->trace(m_element);
109 visitor->trace(m_videoMutedPlayMethodVisibilityObserver);
110 }
111
112 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/AutoplayUmaHelper.h ('k') | third_party/WebKit/Source/core/html/HTMLMediaElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698