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

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

Issue 2576463002: [Autoplay] Add histogram metrics for cross-origin autoplay muted experiment (Closed)
Patch Set: Created 4 years 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 #include "core/html/AutoplayUmaHelper.h" 5 #include "core/html/AutoplayUmaHelper.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ElementVisibilityObserver.h" 8 #include "core/dom/ElementVisibilityObserver.h"
9 #include "core/events/Event.h" 9 #include "core/events/Event.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } else if (blockedBySetting) { 90 } else if (blockedBySetting) {
91 blockedMutedVideoHistogram.count(AutoplayBlockedReasonSetting); 91 blockedMutedVideoHistogram.count(AutoplayBlockedReasonSetting);
92 } 92 }
93 } 93 }
94 94
95 m_element->addEventListener(EventTypeNames::playing, this, false); 95 m_element->addEventListener(EventTypeNames::playing, this, false);
96 } 96 }
97 97
98 void AutoplayUmaHelper::recordCrossOriginAutoplayResult( 98 void AutoplayUmaHelper::recordCrossOriginAutoplayResult(
99 CrossOriginAutoplayResult result) { 99 CrossOriginAutoplayResult result) {
100 DEFINE_STATIC_LOCAL(
101 EnumerationHistogram, autoplayResultHistogram,
102 ("Media.Autoplay.CrossOrigin.Result",
103 static_cast<int>(CrossOriginAutoplayResult::NumberOfResults)));
104
100 if (!m_element->isHTMLVideoElement()) 105 if (!m_element->isHTMLVideoElement())
101 return; 106 return;
102 if (!m_element->isInCrossOriginFrame()) 107 if (!m_element->isInCrossOriginFrame())
103 return; 108 return;
104 109
105 // Record each metric only once per element, since the metric focuses on the 110 // Record each metric only once per element, since the metric focuses on the
106 // site distribution. If a page calls play() multiple times, it will be 111 // site distribution. If a page calls play() multiple times, it will be
107 // recorded only once. 112 // recorded only once.
108 if (m_recordedCrossOriginAutoplayResults.count(result)) 113 if (m_recordedCrossOriginAutoplayResults.count(result))
109 return; 114 return;
110 115
111 switch (result) { 116 switch (result) {
112 case CrossOriginAutoplayResult::AutoplayAllowed: 117 case CrossOriginAutoplayResult::AutoplayAllowed:
113 // Record metric 118 // Record metric
114 Platform::current()->recordRapporURL( 119 Platform::current()->recordRapporURL(
115 "Media.Autoplay.CrossOrigin.Allowed.ChildFrame", 120 "Media.Autoplay.CrossOrigin.Allowed.ChildFrame",
116 m_element->document().url()); 121 m_element->document().url());
117 Platform::current()->recordRapporURL( 122 Platform::current()->recordRapporURL(
118 "Media.Autoplay.CrossOrigin.Allowed.TopLevelFrame", 123 "Media.Autoplay.CrossOrigin.Allowed.TopLevelFrame",
119 m_element->document().topDocument().url()); 124 m_element->document().topDocument().url());
125 autoplayResultHistogram.count(static_cast<int>(result));
120 m_recordedCrossOriginAutoplayResults.insert(result); 126 m_recordedCrossOriginAutoplayResults.insert(result);
121 break; 127 break;
122 case CrossOriginAutoplayResult::AutoplayBlocked: 128 case CrossOriginAutoplayResult::AutoplayBlocked:
123 Platform::current()->recordRapporURL( 129 Platform::current()->recordRapporURL(
124 "Media.Autoplay.CrossOrigin.Blocked.ChildFrame", 130 "Media.Autoplay.CrossOrigin.Blocked.ChildFrame",
125 m_element->document().url()); 131 m_element->document().url());
126 Platform::current()->recordRapporURL( 132 Platform::current()->recordRapporURL(
127 "Media.Autoplay.CrossOrigin.Blocked.TopLevelFrame", 133 "Media.Autoplay.CrossOrigin.Blocked.TopLevelFrame",
128 m_element->document().topDocument().url()); 134 m_element->document().topDocument().url());
135 autoplayResultHistogram.count(static_cast<int>(result));
129 m_recordedCrossOriginAutoplayResults.insert(result); 136 m_recordedCrossOriginAutoplayResults.insert(result);
130 break; 137 break;
131 case CrossOriginAutoplayResult::PlayedWithGesture: 138 case CrossOriginAutoplayResult::PlayedWithGesture:
132 // Record this metric only when the video has been blocked from autoplay 139 // Record this metric only when the video has been blocked from autoplay
133 // previously. This is to record the sites having videos that are blocked 140 // previously. This is to record the sites having videos that are blocked
134 // to autoplay but the user starts the playback by gesture. 141 // to autoplay but the user starts the playback by gesture.
135 if (!m_recordedCrossOriginAutoplayResults.count( 142 if (!m_recordedCrossOriginAutoplayResults.count(
136 CrossOriginAutoplayResult::AutoplayBlocked)) { 143 CrossOriginAutoplayResult::AutoplayBlocked)) {
137 return; 144 return;
138 } 145 }
139 Platform::current()->recordRapporURL( 146 Platform::current()->recordRapporURL(
140 "Media.Autoplay.CrossOrigin.PlayedWithGestureAfterBlock.ChildFrame", 147 "Media.Autoplay.CrossOrigin.PlayedWithGestureAfterBlock.ChildFrame",
141 m_element->document().url()); 148 m_element->document().url());
142 Platform::current()->recordRapporURL( 149 Platform::current()->recordRapporURL(
143 "Media.Autoplay.CrossOrigin.PlayedWithGestureAfterBlock." 150 "Media.Autoplay.CrossOrigin.PlayedWithGestureAfterBlock."
144 "TopLevelFrame", 151 "TopLevelFrame",
145 m_element->document().topDocument().url()); 152 m_element->document().topDocument().url());
153 autoplayResultHistogram.count(static_cast<int>(result));
154 m_recordedCrossOriginAutoplayResults.insert(result);
155 break;
156 case CrossOriginAutoplayResult::UserPaused:
157 if (!shouldRecordUserPausedAutoplayingCrossOriginVideo())
158 return;
159 if (m_element->ended() || m_element->seeking())
160 return;
161 Platform::current()->recordRapporURL(
162 "Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo.ChildFrame",
163 m_element->document().url());
164 Platform::current()->recordRapporURL(
165 "Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo."
166 "TopLevelFrame",
167 m_element->document().topDocument().url());
168 autoplayResultHistogram.count(static_cast<int>(result));
146 m_recordedCrossOriginAutoplayResults.insert(result); 169 m_recordedCrossOriginAutoplayResults.insert(result);
147 break; 170 break;
148 default: 171 default:
149 NOTREACHED(); 172 NOTREACHED();
150 } 173 }
151 } 174 }
152 175
153 void AutoplayUmaHelper::recordAutoplayUnmuteStatus( 176 void AutoplayUmaHelper::recordAutoplayUnmuteStatus(
154 AutoplayUnmuteActionStatus status) { 177 AutoplayUnmuteActionStatus status) {
155 DEFINE_STATIC_LOCAL( 178 DEFINE_STATIC_LOCAL(
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 durationHistogram.count(boundedTime); 321 durationHistogram.count(boundedTime);
299 } 322 }
300 m_mutedVideoOffscreenDurationVisibilityObserver->stop(); 323 m_mutedVideoOffscreenDurationVisibilityObserver->stop();
301 m_mutedVideoOffscreenDurationVisibilityObserver = nullptr; 324 m_mutedVideoOffscreenDurationVisibilityObserver = nullptr;
302 m_mutedVideoAutoplayOffscreenDurationMS = 0; 325 m_mutedVideoAutoplayOffscreenDurationMS = 0;
303 maybeUnregisterMediaElementPauseListener(); 326 maybeUnregisterMediaElementPauseListener();
304 maybeUnregisterContextDestroyedObserver(); 327 maybeUnregisterContextDestroyedObserver();
305 } 328 }
306 329
307 void AutoplayUmaHelper::maybeRecordUserPausedAutoplayingCrossOriginVideo() { 330 void AutoplayUmaHelper::maybeRecordUserPausedAutoplayingCrossOriginVideo() {
308 if (!shouldRecordUserPausedAutoplayingCrossOriginVideo()) 331 recordCrossOriginAutoplayResult(CrossOriginAutoplayResult::UserPaused);
309 return;
310
311 if (m_element->ended() || m_element->seeking())
312 return;
313
314 Platform::current()->recordRapporURL(
315 "Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo.ChildFrame",
316 m_element->document().url());
317 Platform::current()->recordRapporURL(
318 "Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo."
319 "TopLevelFrame",
320 m_element->document().topDocument().url());
321
322 m_hasRecordedUserPausedAutoplayingCrossOriginVideo = true;
323 maybeUnregisterMediaElementPauseListener(); 332 maybeUnregisterMediaElementPauseListener();
324 } 333 }
325 334
326 void AutoplayUmaHelper::maybeUnregisterContextDestroyedObserver() { 335 void AutoplayUmaHelper::maybeUnregisterContextDestroyedObserver() {
327 if (!shouldListenToContextDestroyed()) { 336 if (!shouldListenToContextDestroyed()) {
328 setContext(nullptr); 337 setContext(nullptr);
329 } 338 }
330 } 339 }
331 340
332 void AutoplayUmaHelper::maybeUnregisterMediaElementPauseListener() { 341 void AutoplayUmaHelper::maybeUnregisterMediaElementPauseListener() {
333 if (m_mutedVideoOffscreenDurationVisibilityObserver) 342 if (m_mutedVideoOffscreenDurationVisibilityObserver)
334 return; 343 return;
335 if (shouldRecordUserPausedAutoplayingCrossOriginVideo()) 344 if (shouldRecordUserPausedAutoplayingCrossOriginVideo())
336 return; 345 return;
337 m_element->removeEventListener(EventTypeNames::pause, this, false); 346 m_element->removeEventListener(EventTypeNames::pause, this, false);
338 } 347 }
339 348
340 bool AutoplayUmaHelper::shouldListenToContextDestroyed() const { 349 bool AutoplayUmaHelper::shouldListenToContextDestroyed() const {
341 return m_mutedVideoPlayMethodVisibilityObserver || 350 return m_mutedVideoPlayMethodVisibilityObserver ||
342 m_mutedVideoOffscreenDurationVisibilityObserver; 351 m_mutedVideoOffscreenDurationVisibilityObserver;
343 } 352 }
344 353
345 bool AutoplayUmaHelper::shouldRecordUserPausedAutoplayingCrossOriginVideo() 354 bool AutoplayUmaHelper::shouldRecordUserPausedAutoplayingCrossOriginVideo()
346 const { 355 const {
347 return m_element->isInCrossOriginFrame() && m_element->isHTMLVideoElement() && 356 return m_element->isInCrossOriginFrame() && m_element->isHTMLVideoElement() &&
348 m_source != AutoplaySource::NumberOfSources && 357 m_source != AutoplaySource::NumberOfSources &&
349 !m_hasRecordedUserPausedAutoplayingCrossOriginVideo; 358 !m_recordedCrossOriginAutoplayResults.count(
359 CrossOriginAutoplayResult::UserPaused);
350 } 360 }
351 361
352 DEFINE_TRACE(AutoplayUmaHelper) { 362 DEFINE_TRACE(AutoplayUmaHelper) {
353 EventListener::trace(visitor); 363 EventListener::trace(visitor);
354 ContextLifecycleObserver::trace(visitor); 364 ContextLifecycleObserver::trace(visitor);
355 visitor->trace(m_element); 365 visitor->trace(m_element);
356 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); 366 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver);
357 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); 367 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver);
358 } 368 }
359 369
360 } // namespace blink 370 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/AutoplayUmaHelper.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698