| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 private: | 79 private: |
| 80 friend class MockAutoplayUmaHelper; | 80 friend class MockAutoplayUmaHelper; |
| 81 | 81 |
| 82 explicit AutoplayUmaHelper(HTMLMediaElement*); | 82 explicit AutoplayUmaHelper(HTMLMediaElement*); |
| 83 void handleEvent(ExecutionContext*, Event*) override; | 83 void handleEvent(ExecutionContext*, Event*) override; |
| 84 void handlePlayingEvent(); | 84 void handlePlayingEvent(); |
| 85 void handlePauseEvent(); | 85 void handlePauseEvent(); |
| 86 virtual void handleContextDestroyed(); // Make virtual for testing. | 86 virtual void handleContextDestroyed(); // Make virtual for testing. |
| 87 | 87 |
| 88 void maybeUnregisterContextDestroyedObserver(); | 88 void maybeUnregisterContextDestroyedObserver(); |
| 89 void maybeUnregisterMediaElementPauseListener(); |
| 89 | 90 |
| 90 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); | 91 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); |
| 91 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); | 92 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); |
| 92 | 93 |
| 93 void maybeStartRecordingMutedVideoOffscreenDuration(); | 94 void maybeStartRecordingMutedVideoOffscreenDuration(); |
| 94 void maybeStopRecordingMutedVideoOffscreenDuration(); | 95 void maybeStopRecordingMutedVideoOffscreenDuration(); |
| 95 | 96 |
| 97 void maybeRecordUserPausedAutoplayingCrossOriginVideo(); |
| 98 |
| 96 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); | 99 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); |
| 97 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); | 100 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); |
| 98 | 101 |
| 99 bool shouldListenToContextDestroyed() const; | 102 bool shouldListenToContextDestroyed() const; |
| 103 bool shouldRecordUserPausedAutoplayingCrossOriginVideo() const; |
| 100 | 104 |
| 101 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid | 105 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid |
| 102 // source. | 106 // source. |
| 103 AutoplaySource m_source; | 107 AutoplaySource m_source; |
| 104 // The media element this UMA helper is attached to. |m_element| owns |this|. | 108 // The media element this UMA helper is attached to. |m_element| owns |this|. |
| 105 Member<HTMLMediaElement> m_element; | 109 Member<HTMLMediaElement> m_element; |
| 106 | 110 |
| 107 // The observer is used to observe whether a muted video autoplaying by play() | 111 // The observer is used to observe whether a muted video autoplaying by play() |
| 108 // method become visible at some point. | 112 // method become visible at some point. |
| 109 // The UMA is pending for recording as long as this observer is non-null. | 113 // The UMA is pending for recording as long as this observer is non-null. |
| 110 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver; | 114 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver; |
| 111 | 115 |
| 112 // ----------------------------------------------------------------------- | 116 // ----------------------------------------------------------------------- |
| 113 // Variables used for recording the duration of autoplay muted video playing | 117 // Variables used for recording the duration of autoplay muted video playing |
| 114 // offscreen. The variables are valid when | 118 // offscreen. The variables are valid when |
| 115 // |m_autoplayOffscrenVisibilityObserver| is non-null. | 119 // |m_autoplayOffscrenVisibilityObserver| is non-null. |
| 116 // The recording stops whenever the playback pauses or the page is unloaded. | 120 // The recording stops whenever the playback pauses or the page is unloaded. |
| 117 | 121 |
| 118 // The starting time of autoplaying muted video. | 122 // The starting time of autoplaying muted video. |
| 119 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; | 123 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; |
| 120 | 124 |
| 121 // The duration an autoplaying muted video has been in offscreen. | 125 // The duration an autoplaying muted video has been in offscreen. |
| 122 int64_t m_mutedVideoAutoplayOffscreenDurationMS; | 126 int64_t m_mutedVideoAutoplayOffscreenDurationMS; |
| 123 | 127 |
| 124 // Whether an autoplaying muted video is visible. | 128 // Whether an autoplaying muted video is visible. |
| 125 bool m_isVisible; | 129 bool m_isVisible; |
| 126 | 130 |
| 127 std::set<CrossOriginAutoplayResult> m_recordedCrossOriginAutoplayResults; | 131 std::set<CrossOriginAutoplayResult> m_recordedCrossOriginAutoplayResults; |
| 128 | 132 |
| 133 // Whether the UMA helper has recorded user pausing a cross-origin video. |
| 134 bool m_hasRecordedUserPausedAutoplayingCrossOriginVideo; |
| 135 |
| 129 // The observer is used to observer an autoplaying muted video changing it's | 136 // The observer is used to observer an autoplaying muted video changing it's |
| 130 // visibility, which is used for offscreen duration UMA. The UMA is pending | 137 // visibility, which is used for offscreen duration UMA. The UMA is pending |
| 131 // for recording as long as this observer is non-null. | 138 // for recording as long as this observer is non-null. |
| 132 Member<ElementVisibilityObserver> | 139 Member<ElementVisibilityObserver> |
| 133 m_mutedVideoOffscreenDurationVisibilityObserver; | 140 m_mutedVideoOffscreenDurationVisibilityObserver; |
| 134 }; | 141 }; |
| 135 | 142 |
| 136 } // namespace blink | 143 } // namespace blink |
| 137 | 144 |
| 138 #endif // AutoplayUmaHelper_h | 145 #endif // AutoplayUmaHelper_h |
| OLD | NEW |