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

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

Issue 2780403004: Create core/html/media/ and move auxiliary media files in it. (Closed)
Patch Set: actually add autoplay files Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef AutoplayUmaHelper_h
6 #define AutoplayUmaHelper_h
7
8 #include "core/CoreExport.h"
9 #include "core/dom/ContextLifecycleObserver.h"
10 #include "core/events/EventListener.h"
11 #include "platform/heap/Handle.h"
12
13 #include <set>
14
15 namespace blink {
16
17 // These values are used for histograms. Do not reorder.
18 enum class AutoplaySource {
19 // Autoplay comes from HTMLMediaElement `autoplay` attribute.
20 Attribute = 0,
21 // Autoplay comes from `play()` method.
22 Method = 1,
23 // Used for checking dual source.
24 NumberOfSources = 2,
25 // Both sources are used.
26 DualSource = 2,
27 // This enum value must be last.
28 NumberOfUmaSources = 3,
29 };
30
31 // These values are used for histograms. Do not reorder.
32 enum class AutoplayUnmuteActionStatus {
33 Failure = 0,
34 Success = 1,
35 NumberOfStatus = 2,
36 };
37
38 // These values are used for histograms. Do not reorder.
39 enum AutoplayBlockedReason {
40 AutoplayBlockedReasonDataSaver = 0,
41 AutoplayBlockedReasonSetting = 1,
42 AutoplayBlockedReasonDataSaverAndSetting = 2,
43 // Keey at the end.
44 AutoplayBlockedReasonMax = 3
45 };
46
47 enum class CrossOriginAutoplayResult {
48 AutoplayAllowed = 0,
49 AutoplayBlocked = 1,
50 PlayedWithGesture = 2,
51 UserPaused = 3,
52 // Keep at the end.
53 NumberOfResults = 4,
54 };
55
56 class Document;
57 class ElementVisibilityObserver;
58 class HTMLMediaElement;
59
60 class CORE_EXPORT AutoplayUmaHelper : public EventListener,
61 public ContextLifecycleObserver {
62 USING_GARBAGE_COLLECTED_MIXIN(AutoplayUmaHelper);
63
64 public:
65 static AutoplayUmaHelper* create(HTMLMediaElement*);
66
67 ~AutoplayUmaHelper();
68
69 bool operator==(const EventListener&) const override;
70
71 void contextDestroyed(ExecutionContext*) override;
72
73 void onAutoplayInitiated(AutoplaySource);
74
75 void recordCrossOriginAutoplayResult(CrossOriginAutoplayResult);
76 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus);
77
78 void didMoveToNewDocument(Document& oldDocument);
79
80 bool isVisible() const { return m_isVisible; }
81
82 bool hasSource() const { return !m_sources.empty(); }
83
84 DECLARE_VIRTUAL_TRACE();
85
86 private:
87 friend class MockAutoplayUmaHelper;
88
89 explicit AutoplayUmaHelper(HTMLMediaElement*);
90 void handleEvent(ExecutionContext*, Event*) override;
91 void handlePlayingEvent();
92 void handlePauseEvent();
93 virtual void handleContextDestroyed(); // Make virtual for testing.
94
95 void maybeUnregisterContextDestroyedObserver();
96 void maybeUnregisterMediaElementPauseListener();
97
98 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible();
99 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible);
100
101 void maybeStartRecordingMutedVideoOffscreenDuration();
102 void maybeStopRecordingMutedVideoOffscreenDuration();
103
104 void maybeRecordUserPausedAutoplayingCrossOriginVideo();
105
106 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile);
107 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible);
108
109 bool shouldListenToContextDestroyed() const;
110 bool shouldRecordUserPausedAutoplayingCrossOriginVideo() const;
111
112 // The autoplay sources.
113 std::set<AutoplaySource> m_sources;
114
115 // The media element this UMA helper is attached to. |m_element| owns |this|.
116 Member<HTMLMediaElement> m_element;
117
118 // The observer is used to observe whether a muted video autoplaying by play()
119 // method become visible at some point.
120 // The UMA is pending for recording as long as this observer is non-null.
121 Member<ElementVisibilityObserver> m_mutedVideoPlayMethodVisibilityObserver;
122
123 // -----------------------------------------------------------------------
124 // Variables used for recording the duration of autoplay muted video playing
125 // offscreen. The variables are valid when
126 // |m_autoplayOffscrenVisibilityObserver| is non-null.
127 // The recording stops whenever the playback pauses or the page is unloaded.
128
129 // The starting time of autoplaying muted video.
130 int64_t m_mutedVideoAutoplayOffscreenStartTimeMS;
131
132 // The duration an autoplaying muted video has been in offscreen.
133 int64_t m_mutedVideoAutoplayOffscreenDurationMS;
134
135 // Whether an autoplaying muted video is visible.
136 bool m_isVisible;
137
138 std::set<CrossOriginAutoplayResult> m_recordedCrossOriginAutoplayResults;
139
140 // The observer is used to observer an autoplaying muted video changing it's
141 // visibility, which is used for offscreen duration UMA. The UMA is pending
142 // for recording as long as this observer is non-null.
143 Member<ElementVisibilityObserver>
144 m_mutedVideoOffscreenDurationVisibilityObserver;
145 };
146
147 } // namespace blink
148
149 #endif // AutoplayUmaHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698