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

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

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Fix trybots failure. 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;
41 class HTMLMediaElement; 40 class HTMLMediaElement;
42 41
43 class AutoplayUmaHelper final : public EventListener { 42 class AutoplayUmaHelper final : public EventListener {
44 public: 43 public:
45 static AutoplayUmaHelper* create(HTMLMediaElement*); 44 static AutoplayUmaHelper* create(HTMLMediaElement*);
46 45
47 ~AutoplayUmaHelper(); 46 ~AutoplayUmaHelper();
48 47
49 bool operator==(const EventListener&) const override; 48 bool operator==(const EventListener&) const override;
50 49
51 void onAutoplayInitiated(AutoplaySource); 50 void onAutoplayInitiated(AutoplaySource);
52 51
53 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); 52 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus);
54 53
55 void didMoveToNewDocument(Document& oldDocument); 54 void didMoveToNewDocument(Document& oldDocument);
56 55
57 bool isVisible() const { return m_isVisible; } 56 bool isVisible() const { return m_isVisible; }
58 57
59 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } 58 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; }
60 59
60 void visibilityMaybeChangedforMutedVideo(bool isVisible);
61
61 DECLARE_VIRTUAL_TRACE(); 62 DECLARE_VIRTUAL_TRACE();
62 63
63 private: 64 private:
64 explicit AutoplayUmaHelper(HTMLMediaElement*); 65 explicit AutoplayUmaHelper(HTMLMediaElement*);
65 66
66 void handleEvent(ExecutionContext*, Event*) override; 67 void handleEvent(ExecutionContext*, Event*) override;
67 68
68 void handlePlayingEvent(); 69 void handlePlayingEvent();
69 void handlePauseEvent(); 70 void handlePauseEvent();
70 void handleUnloadEvent(); 71 void handleUnloadEvent();
71 72
72 void maybeUnregisterUnloadListener(); 73 void maybeUnregisterUnloadListener();
73 74
74 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); 75 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible();
75 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); 76 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible);
76 77
77 void maybeStartRecordingMutedVideoOffscreenDuration(); 78 void maybeStartRecordingMutedVideoOffscreenDuration();
78 void maybeStopRecordingMutedVideoOffscreenDuration(); 79 void maybeStopRecordingMutedVideoOffscreenDuration();
79 80
80 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile);
81 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible);
82
83 bool shouldListenToUnloadEvent() const; 81 bool shouldListenToUnloadEvent() const;
84 82
85 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid 83 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid
86 // source. 84 // source.
87 AutoplaySource m_source; 85 AutoplaySource m_source;
88 // The media element this UMA helper is attached to. |m_element| owns |this|. 86 // The media element this UMA helper is attached to. |m_element| owns |this|.
89 Member<HTMLMediaElement> m_element; 87 Member<HTMLMediaElement> m_element;
90 88
91 // The observer is used to observe whether a muted video autoplaying by play() 89 // Indicates whether is observing the visibility of a muted video autoplayed
92 // method become visible at some point. 90 // 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. 91 // true.
94 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver; 92 bool m_isObservingMutedVideoPlayMethodBecomeVisible = false;
95 93
96 // ----------------------------------------------------------------------- 94 // -----------------------------------------------------------------------
97 // Variables used for recording the duration of autoplay muted video playing 95 // Variables used for recording the duration of autoplay muted video playing
98 // offscreen. The variables are valid when 96 // offscreen. The variables are valid when
99 // |m_autoplayOffscrenVisibilityObserver| is non-null. 97 // |m_autoplayOffscrenVisibilityObserver| is non-null.
100 // The recording stops whenever the playback pauses or the page is unloaded. 98 // The recording stops whenever the playback pauses or the page is unloaded.
101 99
102 // The starting time of autoplaying muted video. 100 // The starting time of autoplaying muted video.
103 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS; 101 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS;
104 102
105 // The duration an autoplaying muted video has been in offscreen. 103 // The duration an autoplaying muted video has been in offscreen.
106 int64_t m_mutedVideoAutoplayOffscreenDurationMS; 104 int64_t m_mutedVideoAutoplayOffscreenDurationMS;
107 105
108 // Whether an autoplaying muted video is visible. 106 // Whether an autoplaying muted video is visible.
109 bool m_isVisible; 107 bool m_isVisible;
110 108
111 // The observer is used to observer an autoplaying muted video changing it's 109 // 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 110 // offscreen duration UMA. The UMA is pending for recording as long as this
113 // for recording as long as this observer is non-null. 111 // is true.
114 Member<ElementVisibilityObserver> 112 bool m_isObservingVisibilityOfMutedVideoOffscreenDuration = false;
115 m_mutedVideoOffscreenDurationVisibilityObserver;
116 }; 113 };
117 114
118 } // namespace blink 115 } // namespace blink
119 116
120 #endif // AutoplayUmaHelper_h 117 #endif // AutoplayUmaHelper_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/IntersectionObserver.cpp ('k') | third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698