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

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

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Addressed miu's comments from PS#5. Created 4 years, 1 month 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/events/EventListener.h" 8 #include "core/events/EventListener.h"
9 #include "platform/heap/Handle.h" 9 #include "platform/heap/Handle.h"
10 10
(...skipping 19 matching lines...) Expand all
30 // These values are used for histograms. Do not reorder. 30 // These values are used for histograms. Do not reorder.
31 enum AutoplayBlockedReason { 31 enum AutoplayBlockedReason {
32 AutoplayBlockedReasonDataSaver = 0, 32 AutoplayBlockedReasonDataSaver = 0,
33 AutoplayBlockedReasonSetting = 1, 33 AutoplayBlockedReasonSetting = 1,
34 AutoplayBlockedReasonDataSaverAndSetting = 2, 34 AutoplayBlockedReasonDataSaverAndSetting = 2,
35 // Keey at the end. 35 // Keey at the end.
36 AutoplayBlockedReasonMax = 3 36 AutoplayBlockedReasonMax = 3
37 }; 37 };
38 38
39 class Document; 39 class Document;
40 class ElementVisibilityObserver; 40 class ElementVisibilityObserver;
Zhiqiang Zhang (Slow) 2016/11/15 11:29:27 nit: remove this forward decl
xjz 2016/11/15 23:03:39 Done.
41 class HTMLMediaElement; 41 class HTMLMediaElement;
42 42
43 class AutoplayUmaHelper final : public EventListener { 43 class AutoplayUmaHelper final : public EventListener {
44 public: 44 public:
45 static AutoplayUmaHelper* create(HTMLMediaElement*); 45 static AutoplayUmaHelper* create(HTMLMediaElement*);
46 46
47 ~AutoplayUmaHelper(); 47 ~AutoplayUmaHelper();
48 48
49 bool operator==(const EventListener&) const override; 49 bool operator==(const EventListener&) const override;
50 50
51 void onAutoplayInitiated(AutoplaySource); 51 void onAutoplayInitiated(AutoplaySource);
52 52
53 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); 53 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus);
54 54
55 void didMoveToNewDocument(Document& oldDocument); 55 void didMoveToNewDocument(Document& oldDocument);
56 56
57 bool isVisible() const { return m_isVisible; } 57 bool isVisible() const { return m_isVisible; }
58 58
59 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } 59 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; }
60 60
61 void visibilityMaybeChangedforMutedVideo(bool isVisible);
62
61 DECLARE_VIRTUAL_TRACE(); 63 DECLARE_VIRTUAL_TRACE();
62 64
63 private: 65 private:
64 explicit AutoplayUmaHelper(HTMLMediaElement*); 66 explicit AutoplayUmaHelper(HTMLMediaElement*);
65 67
66 void handleEvent(ExecutionContext*, Event*) override; 68 void handleEvent(ExecutionContext*, Event*) override;
67 69
68 void handlePlayingEvent(); 70 void handlePlayingEvent();
69 void handlePauseEvent(); 71 void handlePauseEvent();
70 void handleUnloadEvent(); 72 void handleUnloadEvent();
71 73
72 void maybeUnregisterUnloadListener(); 74 void maybeUnregisterUnloadListener();
73 75
74 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); 76 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible();
75 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); 77 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible);
76 78
77 void maybeStartRecordingMutedVideoOffscreenDuration(); 79 void maybeStartRecordingMutedVideoOffscreenDuration();
78 void maybeStopRecordingMutedVideoOffscreenDuration(); 80 void maybeStopRecordingMutedVideoOffscreenDuration();
79 81
80 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile);
81 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible);
82
83 bool shouldListenToUnloadEvent() const; 82 bool shouldListenToUnloadEvent() const;
84 83
85 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid 84 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid
86 // source. 85 // source.
87 AutoplaySource m_source; 86 AutoplaySource m_source;
88 // The media element this UMA helper is attached to. |m_element| owns |this|. 87 // The media element this UMA helper is attached to. |m_element| owns |this|.
89 Member<HTMLMediaElement> m_element; 88 Member<HTMLMediaElement> m_element;
90 89
91 // The observer is used to observe whether a muted video autoplaying by play() 90 // Indicates whether is observing the visibility of a muted video autoplayed
92 // method become visible at some point. 91 // from 'play()' method. The UMA is pending for recording as long as this is
93 // The UMA is pending for recording as long as this observer is non-null. 92 // true.
94 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver; 93 bool m_isObservingVisibilityOfMutedAutoplayVideo = false;
Zhiqiang Zhang (Slow) 2016/11/15 11:29:27 nit: Currently, this is describing more than what
xjz 2016/11/15 23:03:39 Done.
95 94
96 // ----------------------------------------------------------------------- 95 // -----------------------------------------------------------------------
97 // Variables used for recording the duration of autoplay muted video playing 96 // Variables used for recording the duration of autoplay muted video playing
98 // offscreen. The variables are valid when 97 // offscreen. The variables are valid when
99 // |m_autoplayOffscrenVisibilityObserver| is non-null. 98 // |m_autoplayOffscrenVisibilityObserver| is non-null.
100 // The recording stops whenever the playback pauses or the page is unloaded. 99 // The recording stops whenever the playback pauses or the page is unloaded.
101 100
102 // The starting time of autoplaying muted video. 101 // The starting time of autoplaying muted video.
103 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; 102 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS;
104 103
105 // The duration an autoplaying muted video has been in offscreen. 104 // The duration an autoplaying muted video has been in offscreen.
106 int64_t m_mutedVideoAutoplayOffscreenDurationMS; 105 int64_t m_mutedVideoAutoplayOffscreenDurationMS;
107 106
108 // Whether an autoplaying muted video is visible. 107 // Whether an autoplaying muted video is visible.
109 bool m_isVisible; 108 bool m_isVisible;
110 109
111 // The observer is used to observer an autoplaying muted video changing it's 110 // Indicates whether is observing the visibility of a muted autoplay video for
112 // visibility, which is used for offscreen duration UMA. The UMA is pending 111 // offscreen duration UMA. The UMA is pending for recording as long as this
113 // for recording as long as this observer is non-null. 112 // is true.
114 Member<ElementVisibilityObserver> 113 bool m_isObservingVisibilityOfMutedVideoOffscreenDuration = false;
115 m_mutedVideoOffscreenDurationVisibilityObserver;
116 }; 114 };
117 115
118 } // namespace blink 116 } // namespace blink
119 117
120 #endif // AutoplayUmaHelper_h 118 #endif // AutoplayUmaHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698