Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef AutoplayUmaHelper_h | 5 #ifndef AutoplayUmaHelper_h |
| 6 #define AutoplayUmaHelper_h | 6 #define AutoplayUmaHelper_h |
| 7 | 7 |
| 8 #include "core/events/EventListener.h" | 8 #include "core/events/EventListener.h" |
| 9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 | 10 |
| 11 #include <set> | |
| 12 | |
| 11 namespace blink { | 13 namespace blink { |
| 12 | 14 |
| 13 // These values are used for histograms. Do not reorder. | 15 // These values are used for histograms. Do not reorder. |
| 14 enum class AutoplaySource { | 16 enum class AutoplaySource { |
| 15 // Autoplay comes from HTMLMediaElement `autoplay` attribute. | 17 // Autoplay comes from HTMLMediaElement `autoplay` attribute. |
| 16 Attribute = 0, | 18 Attribute = 0, |
| 17 // Autoplay comes from `play()` method. | 19 // Autoplay comes from `play()` method. |
| 18 Method = 1, | 20 Method = 1, |
| 19 // This enum value must be last. | 21 // This enum value must be last. |
| 20 NumberOfSources = 2, | 22 NumberOfSources = 2, |
| 21 }; | 23 }; |
| 22 | 24 |
| 23 // These values are used for histograms. Do not reorder. | 25 // These values are used for histograms. Do not reorder. |
| 24 enum class AutoplayUnmuteActionStatus { | 26 enum class AutoplayUnmuteActionStatus { |
| 25 Failure = 0, | 27 Failure = 0, |
| 26 Success = 1, | 28 Success = 1, |
| 27 NumberOfStatus = 2, | 29 NumberOfStatus = 2, |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 // These values are used for histograms. Do not reorder. | 32 // These values are used for histograms. Do not reorder. |
| 31 enum AutoplayBlockedReason { | 33 enum AutoplayBlockedReason { |
| 32 AutoplayBlockedReasonDataSaver = 0, | 34 AutoplayBlockedReasonDataSaver = 0, |
| 33 AutoplayBlockedReasonSetting = 1, | 35 AutoplayBlockedReasonSetting = 1, |
| 34 AutoplayBlockedReasonDataSaverAndSetting = 2, | 36 AutoplayBlockedReasonDataSaverAndSetting = 2, |
| 35 // Keey at the end. | 37 // Keey at the end. |
| 36 AutoplayBlockedReasonMax = 3 | 38 AutoplayBlockedReasonMax = 3 |
| 37 }; | 39 }; |
| 38 | 40 |
| 41 enum class AutoplayCrossOriginExperimentMetric { | |
|
whywhat
2016/11/29 21:42:04
nit: I think we could avoid having experiment and
Zhiqiang Zhang (Slow)
2016/11/30 17:30:52
Done.
| |
| 42 AutoplayAllowed, | |
| 43 AutoplayBlocked, | |
| 44 PlayedWithGesture, | |
| 45 }; | |
| 46 | |
| 39 class Document; | 47 class Document; |
| 40 class ElementVisibilityObserver; | 48 class ElementVisibilityObserver; |
| 41 class HTMLMediaElement; | 49 class HTMLMediaElement; |
| 42 | 50 |
| 43 class AutoplayUmaHelper final : public EventListener { | 51 class AutoplayUmaHelper final : public EventListener { |
| 44 public: | 52 public: |
| 45 static AutoplayUmaHelper* create(HTMLMediaElement*); | 53 static AutoplayUmaHelper* create(HTMLMediaElement*); |
| 46 | 54 |
| 47 ~AutoplayUmaHelper(); | 55 ~AutoplayUmaHelper(); |
| 48 | 56 |
| 49 bool operator==(const EventListener&) const override; | 57 bool operator==(const EventListener&) const override; |
| 50 | 58 |
| 51 void onAutoplayInitiated(AutoplaySource); | 59 void onAutoplayInitiated(AutoplaySource); |
| 52 | 60 |
| 61 void recordCrossOriginExperimentMetric(AutoplayCrossOriginExperimentMetric); | |
| 53 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); | 62 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); |
| 54 | 63 |
| 55 void didMoveToNewDocument(Document& oldDocument); | 64 void didMoveToNewDocument(Document& oldDocument); |
| 56 | 65 |
| 57 bool isVisible() const { return m_isVisible; } | 66 bool isVisible() const { return m_isVisible; } |
| 58 | 67 |
| 59 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } | 68 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } |
| 60 | 69 |
| 61 DECLARE_VIRTUAL_TRACE(); | 70 DECLARE_VIRTUAL_TRACE(); |
| 62 | 71 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 110 |
| 102 // The starting time of autoplaying muted video. | 111 // The starting time of autoplaying muted video. |
| 103 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; | 112 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; |
| 104 | 113 |
| 105 // The duration an autoplaying muted video has been in offscreen. | 114 // The duration an autoplaying muted video has been in offscreen. |
| 106 int64_t m_mutedVideoAutoplayOffscreenDurationMS; | 115 int64_t m_mutedVideoAutoplayOffscreenDurationMS; |
| 107 | 116 |
| 108 // Whether an autoplaying muted video is visible. | 117 // Whether an autoplaying muted video is visible. |
| 109 bool m_isVisible; | 118 bool m_isVisible; |
| 110 | 119 |
| 120 std::set<AutoplayCrossOriginExperimentMetric> | |
| 121 m_recordedCrossOriginExperimentMetrics; | |
| 122 | |
| 111 // The observer is used to observer an autoplaying muted video changing it's | 123 // The observer is used to observer an autoplaying muted video changing it's |
| 112 // visibility, which is used for offscreen duration UMA. The UMA is pending | 124 // visibility, which is used for offscreen duration UMA. The UMA is pending |
| 113 // for recording as long as this observer is non-null. | 125 // for recording as long as this observer is non-null. |
| 114 Member<ElementVisibilityObserver> | 126 Member<ElementVisibilityObserver> |
| 115 m_mutedVideoOffscreenDurationVisibilityObserver; | 127 m_mutedVideoOffscreenDurationVisibilityObserver; |
| 116 }; | 128 }; |
| 117 | 129 |
| 118 } // namespace blink | 130 } // namespace blink |
| 119 | 131 |
| 120 #endif // AutoplayUmaHelper_h | 132 #endif // AutoplayUmaHelper_h |
| OLD | NEW |