| 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/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/dom/ContextLifecycleObserver.h" | 9 #include "core/dom/ContextLifecycleObserver.h" |
| 10 #include "core/events/EventListener.h" | 10 #include "core/events/EventListener.h" |
| 11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 12 | 12 |
| 13 #include <set> |
| 14 |
| 13 namespace blink { | 15 namespace blink { |
| 14 | 16 |
| 15 // These values are used for histograms. Do not reorder. | 17 // These values are used for histograms. Do not reorder. |
| 16 enum class AutoplaySource { | 18 enum class AutoplaySource { |
| 17 // Autoplay comes from HTMLMediaElement `autoplay` attribute. | 19 // Autoplay comes from HTMLMediaElement `autoplay` attribute. |
| 18 Attribute = 0, | 20 Attribute = 0, |
| 19 // Autoplay comes from `play()` method. | 21 // Autoplay comes from `play()` method. |
| 20 Method = 1, | 22 Method = 1, |
| 21 // This enum value must be last. | 23 // This enum value must be last. |
| 22 NumberOfSources = 2, | 24 NumberOfSources = 2, |
| 23 }; | 25 }; |
| 24 | 26 |
| 25 // These values are used for histograms. Do not reorder. | 27 // These values are used for histograms. Do not reorder. |
| 26 enum class AutoplayUnmuteActionStatus { | 28 enum class AutoplayUnmuteActionStatus { |
| 27 Failure = 0, | 29 Failure = 0, |
| 28 Success = 1, | 30 Success = 1, |
| 29 NumberOfStatus = 2, | 31 NumberOfStatus = 2, |
| 30 }; | 32 }; |
| 31 | 33 |
| 32 // These values are used for histograms. Do not reorder. | 34 // These values are used for histograms. Do not reorder. |
| 33 enum AutoplayBlockedReason { | 35 enum AutoplayBlockedReason { |
| 34 AutoplayBlockedReasonDataSaver = 0, | 36 AutoplayBlockedReasonDataSaver = 0, |
| 35 AutoplayBlockedReasonSetting = 1, | 37 AutoplayBlockedReasonSetting = 1, |
| 36 AutoplayBlockedReasonDataSaverAndSetting = 2, | 38 AutoplayBlockedReasonDataSaverAndSetting = 2, |
| 37 // Keey at the end. | 39 // Keey at the end. |
| 38 AutoplayBlockedReasonMax = 3 | 40 AutoplayBlockedReasonMax = 3 |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 enum class CrossOriginAutoplayResult { |
| 44 AutoplayAllowed, |
| 45 AutoplayBlocked, |
| 46 PlayedWithGesture, |
| 47 }; |
| 48 |
| 41 class Document; | 49 class Document; |
| 42 class ElementVisibilityObserver; | 50 class ElementVisibilityObserver; |
| 43 class HTMLMediaElement; | 51 class HTMLMediaElement; |
| 44 | 52 |
| 45 class CORE_EXPORT AutoplayUmaHelper : public EventListener, | 53 class CORE_EXPORT AutoplayUmaHelper : public EventListener, |
| 46 public ContextLifecycleObserver { | 54 public ContextLifecycleObserver { |
| 47 USING_GARBAGE_COLLECTED_MIXIN(AutoplayUmaHelper); | 55 USING_GARBAGE_COLLECTED_MIXIN(AutoplayUmaHelper); |
| 48 | 56 |
| 49 public: | 57 public: |
| 50 static AutoplayUmaHelper* create(HTMLMediaElement*); | 58 static AutoplayUmaHelper* create(HTMLMediaElement*); |
| 51 | 59 |
| 52 ~AutoplayUmaHelper(); | 60 ~AutoplayUmaHelper(); |
| 53 | 61 |
| 54 bool operator==(const EventListener&) const override; | 62 bool operator==(const EventListener&) const override; |
| 55 | 63 |
| 56 void contextDestroyed() override; | 64 void contextDestroyed() override; |
| 57 | 65 |
| 58 void onAutoplayInitiated(AutoplaySource); | 66 void onAutoplayInitiated(AutoplaySource); |
| 59 | 67 |
| 68 void recordCrossOriginAutoplayResult(CrossOriginAutoplayResult); |
| 60 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); | 69 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); |
| 61 | 70 |
| 62 void didMoveToNewDocument(Document& oldDocument); | 71 void didMoveToNewDocument(Document& oldDocument); |
| 63 | 72 |
| 64 bool isVisible() const { return m_isVisible; } | 73 bool isVisible() const { return m_isVisible; } |
| 65 | 74 |
| 66 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } | 75 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } |
| 67 | 76 |
| 68 DECLARE_VIRTUAL_TRACE(); | 77 DECLARE_VIRTUAL_TRACE(); |
| 69 | 78 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 117 |
| 109 // The starting time of autoplaying muted video. | 118 // The starting time of autoplaying muted video. |
| 110 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; | 119 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; |
| 111 | 120 |
| 112 // The duration an autoplaying muted video has been in offscreen. | 121 // The duration an autoplaying muted video has been in offscreen. |
| 113 int64_t m_mutedVideoAutoplayOffscreenDurationMS; | 122 int64_t m_mutedVideoAutoplayOffscreenDurationMS; |
| 114 | 123 |
| 115 // Whether an autoplaying muted video is visible. | 124 // Whether an autoplaying muted video is visible. |
| 116 bool m_isVisible; | 125 bool m_isVisible; |
| 117 | 126 |
| 127 std::set<CrossOriginAutoplayResult> m_recordedCrossOriginAutoplayResults; |
| 128 |
| 118 // The observer is used to observer an autoplaying muted video changing it's | 129 // The observer is used to observer an autoplaying muted video changing it's |
| 119 // visibility, which is used for offscreen duration UMA. The UMA is pending | 130 // visibility, which is used for offscreen duration UMA. The UMA is pending |
| 120 // for recording as long as this observer is non-null. | 131 // for recording as long as this observer is non-null. |
| 121 Member<ElementVisibilityObserver> | 132 Member<ElementVisibilityObserver> |
| 122 m_mutedVideoOffscreenDurationVisibilityObserver; | 133 m_mutedVideoOffscreenDurationVisibilityObserver; |
| 123 }; | 134 }; |
| 124 | 135 |
| 125 } // namespace blink | 136 } // namespace blink |
| 126 | 137 |
| 127 #endif // AutoplayUmaHelper_h | 138 #endif // AutoplayUmaHelper_h |
| OLD | NEW |