Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 void recordAutoplaySourceUma(HTMLMediaElement* element, AutoplaySource source) | |
| 23 { | |
| 24 DEFINE_STATIC_LOCAL(EnumerationHistogram, videoHistogram, ("Media.Video.Auto play", static_cast<int>(AutoplaySource::NumberOfSources))); | |
| 25 DEFINE_STATIC_LOCAL(EnumerationHistogram, mutedVideoHistogram, ("Media.Video .Autoplay.Muted", static_cast<int>(AutoplaySource::NumberOfSources))); | |
| 26 DEFINE_STATIC_LOCAL(EnumerationHistogram, audioHistogram, ("Media.Audio.Auto play", static_cast<int>(AutoplaySource::NumberOfSources))); | |
| 27 | |
| 28 if (element->isHTMLVideoElement()) { | |
| 29 videoHistogram.count(static_cast<int>(source)); | |
| 30 if (element->muted()) | |
| 31 mutedVideoHistogram.count(static_cast<int>(source)); | |
| 32 } else { | |
| 33 audioHistogram.count(static_cast<int>(source)); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus status) | |
| 38 { | |
| 39 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V ideo.Autoplay.Muted.UnmuteAction", static_cast<int>(AutoplayUnmuteActionStatus:: NumberOfStatus))); | |
| 40 | |
| 41 autoplayUnmuteHistogram.count(static_cast<int>(status)); | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 AutoplayUmaHelper* AutoplayUmaHelper::create(HTMLMediaElement* element) | |
| 47 { | |
| 48 return new AutoplayUmaHelper(element); | |
| 49 } | |
| 50 | |
| 51 AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element) | |
| 52 : EventListener(CPPEventListenerType) | |
| 53 , m_source(AutoplaySource::NumberOfSources) | |
| 54 , m_element(element) | |
| 55 , m_videoMutedPlayMethodVisibilityObserver(nullptr) | |
| 56 { | |
| 57 m_element->addEventListener(EventTypeNames::playing, this, false); | |
|
haraken
2016/07/07 01:16:36
Nit: Add indent.
haraken
2016/07/07 01:16:36
Wouldn't this cause a flood of events? (i.e., how
mlamouri (slow - plz ping)
2016/07/07 09:23:40
The event is fired when the media element starts p
Zhiqiang Zhang (Slow)
2016/07/07 11:01:09
Done adding indent.
| |
| 58 } | |
| 59 | |
| 60 AutoplayUmaHelper::~AutoplayUmaHelper() = default; | |
| 61 | |
| 62 bool AutoplayUmaHelper::operator==(const EventListener& other) const | |
| 63 { | |
| 64 return this == &other; | |
| 65 } | |
| 66 | |
| 67 void AutoplayUmaHelper::onAutoplayInitiated(AutoplaySource source) | |
| 68 { | |
| 69 m_source = source; | |
| 70 recordAutoplaySourceUma(m_element, m_source); | |
|
mlamouri (slow - plz ping)
2016/07/07 10:17:52
That might be a silly question but why not move th
Zhiqiang Zhang (Slow)
2016/07/07 11:01:09
Done.
I thought it would help if we record the sam
| |
| 71 } | |
|
mlamouri (slow - plz ping)
2016/07/07 10:17:52
Also, would it make sense to do the addEventListen
Zhiqiang Zhang (Slow)
2016/07/07 11:01:09
Done.
| |
| 72 | |
| 73 void AutoplayUmaHelper::onElementDestroyed() | |
| 74 { | |
| 75 if (m_videoMutedPlayMethodVisibilityObserver) { | |
| 76 recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(false); | |
| 77 m_videoMutedPlayMethodVisibilityObserver->stop(); | |
| 78 m_videoMutedPlayMethodVisibilityObserver = nullptr; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void AutoplayUmaHelper::recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus st atus) | |
| 83 { | |
| 84 blink::recordAutoplayUnmuteStatus(status); | |
|
mlamouri (slow - plz ping)
2016/07/07 10:17:52
That might be a silly question but why not move th
Zhiqiang Zhang (Slow)
2016/07/07 11:01:09
Done.
| |
| 85 } | |
| 86 | |
| 87 void AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod(bool isVisibl e) | |
| 88 { | |
| 89 if (!isVisible) | |
| 90 return; | |
| 91 | |
| 92 recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(true); | |
| 93 m_videoMutedPlayMethodVisibilityObserver->stop(); | |
| 94 m_videoMutedPlayMethodVisibilityObserver = nullptr; | |
| 95 } | |
| 96 | |
| 97 void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext, Event* e vent) | |
| 98 { | |
| 99 if (event->type() == EventTypeNames::playing) | |
|
mlamouri (slow - plz ping)
2016/07/07 10:17:52
What about:
```
switch (event->type()) {
case Ev
Zhiqiang Zhang (Slow)
2016/07/07 11:01:09
Actually event->type() is AtomicString XD
| |
| 100 handlePlayEvent(); | |
| 101 } | |
| 102 | |
| 103 void AutoplayUmaHelper::handlePlayEvent() | |
| 104 { | |
| 105 if (m_source == AutoplaySource::Method && m_element->isHTMLVideoElement() && m_element->muted()) { | |
| 106 if (!m_videoMutedPlayMethodVisibilityObserver) { | |
| 107 m_videoMutedPlayMethodVisibilityObserver = new ElementVisibilityObse rver(m_element, WTF::bind(&AutoplayUmaHelper::onVisibilityChangedForVideoMutedPl ayMethod, wrapPersistent(this))); | |
| 108 m_videoMutedPlayMethodVisibilityObserver->start(); | |
| 109 } | |
| 110 } | |
|
mlamouri (slow - plz ping)
2016/07/07 10:17:53
Would it make sense to removeEventListener()?
Zhiqiang Zhang (Slow)
2016/07/07 11:01:09
Done.
| |
| 111 } | |
| 112 | |
| 113 DEFINE_TRACE(AutoplayUmaHelper) | |
| 114 { | |
| 115 EventListener::trace(visitor); | |
| 116 visitor->trace(m_element); | |
| 117 visitor->trace(m_videoMutedPlayMethodVisibilityObserver); | |
| 118 } | |
| 119 | |
| 120 } // namespace blink | |
| OLD | NEW |