| 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> | 13 #include <set> |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 // These values are used for histograms. Do not reorder. | 17 // These values are used for histograms. Do not reorder. |
| 18 enum class AutoplaySource { | 18 enum class AutoplaySource { |
| 19 // Autoplay comes from HTMLMediaElement `autoplay` attribute. | 19 // Autoplay comes from HTMLMediaElement `autoplay` attribute. |
| 20 Attribute = 0, | 20 Attribute = 0, |
| 21 // Autoplay comes from `play()` method. | 21 // Autoplay comes from `play()` method. |
| 22 Method = 1, | 22 Method = 1, |
| 23 // Used for checking dual source. |
| 24 NumberOfSources = 2, |
| 25 // Both sources are used. |
| 26 DualSource = 2, |
| 23 // This enum value must be last. | 27 // This enum value must be last. |
| 24 NumberOfSources = 2, | 28 NumberOfUmaSources = 3, |
| 25 }; | 29 }; |
| 26 | 30 |
| 27 // These values are used for histograms. Do not reorder. | 31 // These values are used for histograms. Do not reorder. |
| 28 enum class AutoplayUnmuteActionStatus { | 32 enum class AutoplayUnmuteActionStatus { |
| 29 Failure = 0, | 33 Failure = 0, |
| 30 Success = 1, | 34 Success = 1, |
| 31 NumberOfStatus = 2, | 35 NumberOfStatus = 2, |
| 32 }; | 36 }; |
| 33 | 37 |
| 34 // These values are used for histograms. Do not reorder. | 38 // These values are used for histograms. Do not reorder. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 72 |
| 69 void onAutoplayInitiated(AutoplaySource); | 73 void onAutoplayInitiated(AutoplaySource); |
| 70 | 74 |
| 71 void recordCrossOriginAutoplayResult(CrossOriginAutoplayResult); | 75 void recordCrossOriginAutoplayResult(CrossOriginAutoplayResult); |
| 72 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); | 76 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); |
| 73 | 77 |
| 74 void didMoveToNewDocument(Document& oldDocument); | 78 void didMoveToNewDocument(Document& oldDocument); |
| 75 | 79 |
| 76 bool isVisible() const { return m_isVisible; } | 80 bool isVisible() const { return m_isVisible; } |
| 77 | 81 |
| 78 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } | 82 bool hasSource() const { return !m_sources.empty(); } |
| 79 | 83 |
| 80 DECLARE_VIRTUAL_TRACE(); | 84 DECLARE_VIRTUAL_TRACE(); |
| 81 | 85 |
| 82 private: | 86 private: |
| 83 friend class MockAutoplayUmaHelper; | 87 friend class MockAutoplayUmaHelper; |
| 84 | 88 |
| 85 explicit AutoplayUmaHelper(HTMLMediaElement*); | 89 explicit AutoplayUmaHelper(HTMLMediaElement*); |
| 86 void handleEvent(ExecutionContext*, Event*) override; | 90 void handleEvent(ExecutionContext*, Event*) override; |
| 87 void handlePlayingEvent(); | 91 void handlePlayingEvent(); |
| 88 void handlePauseEvent(); | 92 void handlePauseEvent(); |
| 89 virtual void handleContextDestroyed(); // Make virtual for testing. | 93 virtual void handleContextDestroyed(); // Make virtual for testing. |
| 90 | 94 |
| 91 void maybeUnregisterContextDestroyedObserver(); | 95 void maybeUnregisterContextDestroyedObserver(); |
| 92 void maybeUnregisterMediaElementPauseListener(); | 96 void maybeUnregisterMediaElementPauseListener(); |
| 93 | 97 |
| 94 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); | 98 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); |
| 95 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); | 99 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); |
| 96 | 100 |
| 97 void maybeStartRecordingMutedVideoOffscreenDuration(); | 101 void maybeStartRecordingMutedVideoOffscreenDuration(); |
| 98 void maybeStopRecordingMutedVideoOffscreenDuration(); | 102 void maybeStopRecordingMutedVideoOffscreenDuration(); |
| 99 | 103 |
| 100 void maybeRecordUserPausedAutoplayingCrossOriginVideo(); | 104 void maybeRecordUserPausedAutoplayingCrossOriginVideo(); |
| 101 | 105 |
| 102 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); | 106 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); |
| 103 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); | 107 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); |
| 104 | 108 |
| 105 bool shouldListenToContextDestroyed() const; | 109 bool shouldListenToContextDestroyed() const; |
| 106 bool shouldRecordUserPausedAutoplayingCrossOriginVideo() const; | 110 bool shouldRecordUserPausedAutoplayingCrossOriginVideo() const; |
| 107 | 111 |
| 108 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid | 112 // The autoplay sources. |
| 109 // source. | 113 std::set<AutoplaySource> m_sources; |
| 110 AutoplaySource m_source; | 114 |
| 111 // The media element this UMA helper is attached to. |m_element| owns |this|. | 115 // The media element this UMA helper is attached to. |m_element| owns |this|. |
| 112 Member<HTMLMediaElement> m_element; | 116 Member<HTMLMediaElement> m_element; |
| 113 | 117 |
| 114 // The observer is used to observe whether a muted video autoplaying by play() | 118 // The observer is used to observe whether a muted video autoplaying by play() |
| 115 // method become visible at some point. | 119 // method become visible at some point. |
| 116 // The UMA is pending for recording as long as this observer is non-null. | 120 // The UMA is pending for recording as long as this observer is non-null. |
| 117 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver; | 121 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver; |
| 118 | 122 |
| 119 // ----------------------------------------------------------------------- | 123 // ----------------------------------------------------------------------- |
| 120 // Variables used for recording the duration of autoplay muted video playing | 124 // Variables used for recording the duration of autoplay muted video playing |
| (...skipping 15 matching lines...) Expand all Loading... |
| 136 // The observer is used to observer an autoplaying muted video changing it's | 140 // The observer is used to observer an autoplaying muted video changing it's |
| 137 // visibility, which is used for offscreen duration UMA. The UMA is pending | 141 // visibility, which is used for offscreen duration UMA. The UMA is pending |
| 138 // for recording as long as this observer is non-null. | 142 // for recording as long as this observer is non-null. |
| 139 Member<ElementVisibilityObserver> | 143 Member<ElementVisibilityObserver> |
| 140 m_mutedVideoOffscreenDurationVisibilityObserver; | 144 m_mutedVideoOffscreenDurationVisibilityObserver; |
| 141 }; | 145 }; |
| 142 | 146 |
| 143 } // namespace blink | 147 } // namespace blink |
| 144 | 148 |
| 145 #endif // AutoplayUmaHelper_h | 149 #endif // AutoplayUmaHelper_h |
| OLD | NEW |