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

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: new implementation 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/LocalDOMWindow.h" 10 #include "core/frame/LocalDOMWindow.h"
11 #include "core/frame/Settings.h" 11 #include "core/frame/Settings.h"
12 #include "core/html/HTMLMediaElement.h" 12 #include "core/html/HTMLMediaElement.h"
13 #include "platform/Histogram.h" 13 #include "platform/Histogram.h"
14 #include "public/platform/Platform.h"
14 #include "wtf/CurrentTime.h" 15 #include "wtf/CurrentTime.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
18 namespace { 19 namespace {
19 20
20 const int32_t maxOffscreenDurationUmaMS = 60 * 60 * 1000; 21 const int32_t maxOffscreenDurationUmaMS = 60 * 60 * 1000;
21 const int32_t offscreenDurationUmaBucketCount = 50; 22 const int32_t offscreenDurationUmaBucketCount = 50;
22 23
23 } // namespace 24 } // namespace
(...skipping 63 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::recordCrossOriginExperimentMetric(
99 AutoplayCrossOriginExperimentMetric metric) {
100 if (!m_element->isHTMLVideoElement())
whywhat 2016/11/29 21:42:04 nit: Should we avoid calling this for non-video el
Zhiqiang Zhang (Slow) 2016/11/30 17:30:52 I think that would introduce a lot of duplicate if
101 return;
102 if (!m_element->isCrossOrigin())
whywhat 2016/11/29 21:42:04 nit: ditto
103 return;
104 if (m_recordedCrossOriginExperimentMetrics.count(metric))
whywhat 2016/11/29 21:42:04 nit: add a comment why we only record each result
Zhiqiang Zhang (Slow) 2016/11/30 17:30:52 Done.
105 return;
106
107 switch (metric) {
108 case AutoplayCrossOriginExperimentMetric::AutoplayAllowed:
109 // Record metric
110 Platform::current()->recordRapporURL(
111 "Media.Autoplay.CrossOriginExperiment.Allowed.ChildFrame",
112 m_element->document().url());
113 Platform::current()->recordRapporURL(
114 "Media.Autoplay.CrossOriginExperiment.Allowed.TopLevelFrame",
115 m_element->document().topDocument().url());
116 break;
117 case AutoplayCrossOriginExperimentMetric::AutoplayBlocked:
118 Platform::current()->recordRapporURL(
119 "Media.Autoplay.CrossOriginExperiment.Blocked.ChildFrame",
120 m_element->document().url());
121 Platform::current()->recordRapporURL(
122 "Media.Autoplay.CrossOriginExperiment.Blocked.TopLevelFrame",
123 m_element->document().topDocument().url());
124 break;
125 case AutoplayCrossOriginExperimentMetric::PlayedWithGesture:
126 if (!m_recordedCrossOriginExperimentMetrics.count(
whywhat 2016/11/29 21:42:04 nit: a comment would help why this check is here.
Zhiqiang Zhang (Slow) 2016/11/30 17:30:52 Done.
127 AutoplayCrossOriginExperimentMetric::AutoplayBlocked)) {
128 return;
129 }
130 Platform::current()->recordRapporURL(
131 "Media.Autoplay.CrossOriginExperiment.PlayedWithGesture.ChildFrame",
132 m_element->document().url());
133 Platform::current()->recordRapporURL(
134 "Media.Autoplay.CrossOriginExperiment.PlayedWithGesture."
135 "TopLevelFrame",
136 m_element->document().topDocument().url());
137 break;
138 default:
139 NOTREACHED();
140 }
141 m_recordedCrossOriginExperimentMetrics.insert(metric);
whywhat 2016/11/29 21:42:04 nit: put this next to the check if the metric is a
Zhiqiang Zhang (Slow) 2016/11/30 17:30:52 Done.
142 }
143
97 void AutoplayUmaHelper::recordAutoplayUnmuteStatus( 144 void AutoplayUmaHelper::recordAutoplayUnmuteStatus(
98 AutoplayUnmuteActionStatus status) { 145 AutoplayUnmuteActionStatus status) {
99 DEFINE_STATIC_LOCAL( 146 DEFINE_STATIC_LOCAL(
100 EnumerationHistogram, autoplayUnmuteHistogram, 147 EnumerationHistogram, autoplayUnmuteHistogram,
101 ("Media.Video.Autoplay.Muted.UnmuteAction", 148 ("Media.Video.Autoplay.Muted.UnmuteAction",
102 static_cast<int>(AutoplayUnmuteActionStatus::NumberOfStatus))); 149 static_cast<int>(AutoplayUnmuteActionStatus::NumberOfStatus)));
103 150
104 autoplayUnmuteHistogram.count(static_cast<int>(status)); 151 autoplayUnmuteHistogram.count(static_cast<int>(status));
105 } 152 }
106 153
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 313 }
267 314
268 DEFINE_TRACE(AutoplayUmaHelper) { 315 DEFINE_TRACE(AutoplayUmaHelper) {
269 EventListener::trace(visitor); 316 EventListener::trace(visitor);
270 visitor->trace(m_element); 317 visitor->trace(m_element);
271 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); 318 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver);
272 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); 319 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver);
273 } 320 }
274 321
275 } // namespace blink 322 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698