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

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

Issue 2524443002: Adding Rappor metrics for disabling cross-origin autoplay with sound experiment (Closed)
Patch Set: s/CrossOriginExperiment/CrossOrigin 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"
11 #include "core/html/HTMLMediaElement.h" 11 #include "core/html/HTMLMediaElement.h"
12 #include "platform/Histogram.h" 12 #include "platform/Histogram.h"
13 #include "public/platform/Platform.h"
13 #include "wtf/CurrentTime.h" 14 #include "wtf/CurrentTime.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 namespace { 18 namespace {
18 19
19 const int32_t maxOffscreenDurationUmaMS = 60 * 60 * 1000; 20 const int32_t maxOffscreenDurationUmaMS = 60 * 60 * 1000;
20 const int32_t offscreenDurationUmaBucketCount = 50; 21 const int32_t offscreenDurationUmaBucketCount = 50;
21 22
22 } // namespace 23 } // namespace
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } else if (dataSaverEnabled) { 88 } else if (dataSaverEnabled) {
88 blockedMutedVideoHistogram.count(AutoplayBlockedReasonDataSaver); 89 blockedMutedVideoHistogram.count(AutoplayBlockedReasonDataSaver);
89 } else if (blockedBySetting) { 90 } else if (blockedBySetting) {
90 blockedMutedVideoHistogram.count(AutoplayBlockedReasonSetting); 91 blockedMutedVideoHistogram.count(AutoplayBlockedReasonSetting);
91 } 92 }
92 } 93 }
93 94
94 m_element->addEventListener(EventTypeNames::playing, this, false); 95 m_element->addEventListener(EventTypeNames::playing, this, false);
95 } 96 }
96 97
98 void AutoplayUmaHelper::recordCrossOriginAutoplayResult(
99 CrossOriginAutoplayResult result) {
100 if (!m_element->isHTMLVideoElement())
101 return;
102 if (!m_element->isInCrossOriginFrame())
103 return;
104
105 // 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
107 // recorded only once.
108 if (m_recordedCrossOriginAutoplayResults.count(result))
109 return;
110
111 switch (result) {
112 case CrossOriginAutoplayResult::AutoplayAllowed:
113 // Record metric
114 Platform::current()->recordRapporURL(
115 "Media.Autoplay.CrossOrigin.Allowed.ChildFrame",
116 m_element->document().url());
117 Platform::current()->recordRapporURL(
118 "Media.Autoplay.CrossOrigin.Allowed.TopLevelFrame",
119 m_element->document().topDocument().url());
120 m_recordedCrossOriginAutoplayResults.insert(result);
121 break;
122 case CrossOriginAutoplayResult::AutoplayBlocked:
123 Platform::current()->recordRapporURL(
124 "Media.Autoplay.CrossOrigin.Blocked.ChildFrame",
125 m_element->document().url());
126 Platform::current()->recordRapporURL(
127 "Media.Autoplay.CrossOrigin.Blocked.TopLevelFrame",
128 m_element->document().topDocument().url());
129 m_recordedCrossOriginAutoplayResults.insert(result);
130 break;
131 case CrossOriginAutoplayResult::PlayedWithGesture:
132 // 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
134 // to autoplay but the user starts the playback by gesture.
135 if (!m_recordedCrossOriginAutoplayResults.count(
136 CrossOriginAutoplayResult::AutoplayBlocked)) {
137 return;
138 }
139 Platform::current()->recordRapporURL(
140 "Media.Autoplay.CrossOrigin.PlayedWithGesture.ChildFrame",
mlamouri (slow - plz ping) 2016/12/08 17:17:06 Should the rapport name be "PlayedWithGestureAfter
Zhiqiang Zhang (Slow) 2016/12/08 17:35:29 Done.
141 m_element->document().url());
142 Platform::current()->recordRapporURL(
143 "Media.Autoplay.CrossOrigin.PlayedWithGesture."
144 "TopLevelFrame",
145 m_element->document().topDocument().url());
146 m_recordedCrossOriginAutoplayResults.insert(result);
147 break;
148 default:
149 NOTREACHED();
150 }
151 }
152
97 void AutoplayUmaHelper::recordAutoplayUnmuteStatus( 153 void AutoplayUmaHelper::recordAutoplayUnmuteStatus(
98 AutoplayUnmuteActionStatus status) { 154 AutoplayUnmuteActionStatus status) {
99 DEFINE_STATIC_LOCAL( 155 DEFINE_STATIC_LOCAL(
100 EnumerationHistogram, autoplayUnmuteHistogram, 156 EnumerationHistogram, autoplayUnmuteHistogram,
101 ("Media.Video.Autoplay.Muted.UnmuteAction", 157 ("Media.Video.Autoplay.Muted.UnmuteAction",
102 static_cast<int>(AutoplayUnmuteActionStatus::NumberOfStatus))); 158 static_cast<int>(AutoplayUnmuteActionStatus::NumberOfStatus)));
103 159
104 autoplayUnmuteHistogram.count(static_cast<int>(status)); 160 autoplayUnmuteHistogram.count(static_cast<int>(status));
105 } 161 }
106 162
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 316
261 DEFINE_TRACE(AutoplayUmaHelper) { 317 DEFINE_TRACE(AutoplayUmaHelper) {
262 EventListener::trace(visitor); 318 EventListener::trace(visitor);
263 ContextLifecycleObserver::trace(visitor); 319 ContextLifecycleObserver::trace(visitor);
264 visitor->trace(m_element); 320 visitor->trace(m_element);
265 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); 321 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver);
266 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); 322 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver);
267 } 323 }
268 324
269 } // namespace blink 325 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698