Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.h

Issue 2856783002: Autoplay time metric (Closed)
Patch Set: use loadstart event Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "public/platform/WebMediaPlayerClient.h"
12 13
13 #include <set> 14 #include <set>
14 15
15 namespace blink { 16 namespace blink {
16 17
17 // These values are used for histograms. Do not reorder. 18 // These values are used for histograms. Do not reorder.
18 enum class AutoplaySource { 19 enum class AutoplaySource {
19 // Autoplay comes from HTMLMediaElement `autoplay` attribute. 20 // Autoplay comes from HTMLMediaElement `autoplay` attribute.
20 kAttribute = 0, 21 kAttribute = 0,
21 // Autoplay comes from `play()` method. 22 // Autoplay comes from `play()` method.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 bool IsVisible() const { return is_visible_; } 82 bool IsVisible() const { return is_visible_; }
82 83
83 bool HasSource() const { return !sources_.empty(); } 84 bool HasSource() const { return !sources_.empty(); }
84 85
85 DECLARE_VIRTUAL_TRACE(); 86 DECLARE_VIRTUAL_TRACE();
86 87
87 private: 88 private:
88 friend class MockAutoplayUmaHelper; 89 friend class MockAutoplayUmaHelper;
89 90
91 // Called when source is initialized and loading starts.
92 void OnLoadStarted();
93
90 explicit AutoplayUmaHelper(HTMLMediaElement*); 94 explicit AutoplayUmaHelper(HTMLMediaElement*);
91 void handleEvent(ExecutionContext*, Event*) override; 95 void handleEvent(ExecutionContext*, Event*) override;
92 void HandlePlayingEvent(); 96 void HandlePlayingEvent();
93 void HandlePauseEvent(); 97 void HandlePauseEvent();
94 virtual void HandleContextDestroyed(); // Make virtual for testing. 98 virtual void HandleContextDestroyed(); // Make virtual for testing.
95 99
96 void MaybeUnregisterContextDestroyedObserver(); 100 void MaybeUnregisterContextDestroyedObserver();
97 void MaybeUnregisterMediaElementPauseListener(); 101 void MaybeUnregisterMediaElementPauseListener();
98 102
99 void MaybeStartRecordingMutedVideoPlayMethodBecomeVisible(); 103 void MaybeStartRecordingMutedVideoPlayMethodBecomeVisible();
100 void MaybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool is_visible); 104 void MaybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool is_visible);
101 105
102 void MaybeStartRecordingMutedVideoOffscreenDuration(); 106 void MaybeStartRecordingMutedVideoOffscreenDuration();
103 void MaybeStopRecordingMutedVideoOffscreenDuration(); 107 void MaybeStopRecordingMutedVideoOffscreenDuration();
104 108
105 void MaybeRecordUserPausedAutoplayingCrossOriginVideo(); 109 void MaybeRecordUserPausedAutoplayingCrossOriginVideo();
106 110
107 void OnVisibilityChangedForMutedVideoOffscreenDuration(bool is_visibile); 111 void OnVisibilityChangedForMutedVideoOffscreenDuration(bool is_visibile);
108 void OnVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool is_visible); 112 void OnVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool is_visible);
109 113
110 bool ShouldListenToContextDestroyed() const; 114 bool ShouldListenToContextDestroyed() const;
111 bool ShouldRecordUserPausedAutoplayingCrossOriginVideo() const; 115 bool ShouldRecordUserPausedAutoplayingCrossOriginVideo() const;
112 116
113 // The autoplay sources. 117 // The autoplay sources.
114 std::set<AutoplaySource> sources_; 118 std::set<AutoplaySource> sources_;
115 119
116 // The media element this UMA helper is attached to. |m_element| owns |this|. 120 // The media element this UMA helper is attached to. |element| owns |this|.
117 Member<HTMLMediaElement> element_; 121 Member<HTMLMediaElement> element_;
118 122
119 // The observer is used to observe whether a muted video autoplaying by play() 123 // The observer is used to observe whether a muted video autoplaying by play()
120 // method become visible at some point. 124 // method become visible at some point.
121 // The UMA is pending for recording as long as this observer is non-null. 125 // The UMA is pending for recording as long as this observer is non-null.
122 Member<ElementVisibilityObserver> 126 Member<ElementVisibilityObserver>
123 muted_video_play_method_visibility_observer_; 127 muted_video_play_method_visibility_observer_;
124 128
125 // ----------------------------------------------------------------------- 129 // -----------------------------------------------------------------------
126 // Variables used for recording the duration of autoplay muted video playing 130 // Variables used for recording the duration of autoplay muted video playing
127 // offscreen. The variables are valid when 131 // offscreen. The variables are valid when
128 // |m_autoplayOffscrenVisibilityObserver| is non-null. 132 // |autoplayOffscrenVisibilityObserver| is non-null.
129 // The recording stops whenever the playback pauses or the page is unloaded. 133 // The recording stops whenever the playback pauses or the page is unloaded.
130 134
131 // The starting time of autoplaying muted video. 135 // The starting time of autoplaying muted video.
132 int64_t muted_video_autoplay_offscreen_start_time_ms_; 136 int64_t muted_video_autoplay_offscreen_start_time_ms_;
133 137
134 // The duration an autoplaying muted video has been in offscreen. 138 // The duration an autoplaying muted video has been in offscreen.
135 int64_t muted_video_autoplay_offscreen_duration_ms_; 139 int64_t muted_video_autoplay_offscreen_duration_ms_;
136 140
137 // Whether an autoplaying muted video is visible. 141 // Whether an autoplaying muted video is visible.
138 bool is_visible_; 142 bool is_visible_;
139 143
140 std::set<CrossOriginAutoplayResult> recorded_cross_origin_autoplay_results_; 144 std::set<CrossOriginAutoplayResult> recorded_cross_origin_autoplay_results_;
141 145
142 // The observer is used to observer an autoplaying muted video changing it's 146 // The observer is used to observer an autoplaying muted video changing it's
143 // visibility, which is used for offscreen duration UMA. The UMA is pending 147 // visibility, which is used for offscreen duration UMA. The UMA is pending
144 // for recording as long as this observer is non-null. 148 // for recording as long as this observer is non-null.
145 Member<ElementVisibilityObserver> 149 Member<ElementVisibilityObserver>
146 muted_video_offscreen_duration_visibility_observer_; 150 muted_video_offscreen_duration_visibility_observer_;
151
152 double load_start_time_ms_;
147 }; 153 };
148 154
149 } // namespace blink 155 } // namespace blink
150 156
151 #endif // AutoplayUmaHelper_h 157 #endif // AutoplayUmaHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698