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

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

Issue 2856783002: Autoplay time metric (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/media/AutoplayUmaHelper.h" 5 #include "core/html/media/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/frame/UseCounter.h" 11 #include "core/frame/UseCounter.h"
12 #include "core/html/HTMLMediaElement.h" 12 #include "core/html/HTMLMediaElement.h"
13 #include "core/html/media/AutoplayPolicy.h" 13 #include "core/html/media/AutoplayPolicy.h"
14 #include "platform/Histogram.h" 14 #include "platform/Histogram.h"
15 #include "platform/wtf/CurrentTime.h" 15 #include "platform/wtf/CurrentTime.h"
16 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 namespace { 20 namespace {
21 21
22 const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000; 22 const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000;
23 const int32_t kOffscreenDurationUmaBucketCount = 50; 23 const int32_t kOffscreenDurationUmaBucketCount = 50;
24 const int32_t kMaxWaitTimeUmaMS = 30 * 1000;
25 const int32_t kWaitTimeBucketCount = 50;
24 26
25 } // namespace 27 } // namespace
26 28
27 AutoplayUmaHelper* AutoplayUmaHelper::Create(HTMLMediaElement* element) { 29 AutoplayUmaHelper* AutoplayUmaHelper::Create(HTMLMediaElement* element) {
28 return new AutoplayUmaHelper(element); 30 return new AutoplayUmaHelper(element);
29 } 31 }
30 32
31 AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element) 33 AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element)
32 : EventListener(kCPPEventListenerType), 34 : EventListener(kCPPEventListenerType),
33 ContextLifecycleObserver(nullptr), 35 ContextLifecycleObserver(nullptr),
34 element_(element), 36 element_(element),
35 muted_video_play_method_visibility_observer_(nullptr), 37 muted_video_play_method_visibility_observer_(nullptr),
36 muted_video_autoplay_offscreen_start_time_ms_(0), 38 muted_video_autoplay_offscreen_start_time_ms_(0),
37 muted_video_autoplay_offscreen_duration_ms_(0), 39 muted_video_autoplay_offscreen_duration_ms_(0),
38 is_visible_(false), 40 is_visible_(false),
39 muted_video_offscreen_duration_visibility_observer_(nullptr) {} 41 muted_video_offscreen_duration_visibility_observer_(nullptr),
42 created_time_ms_(MonotonicallyIncreasingTimeMS()) {}
40 43
41 AutoplayUmaHelper::~AutoplayUmaHelper() = default; 44 AutoplayUmaHelper::~AutoplayUmaHelper() = default;
42 45
43 bool AutoplayUmaHelper::operator==(const EventListener& other) const { 46 bool AutoplayUmaHelper::operator==(const EventListener& other) const {
44 return this == &other; 47 return this == &other;
45 } 48 }
46 49
47 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { 50 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) {
51 int32_t autoplay_wait_time_ms = static_cast<int32_t>(
Zhiqiang Zhang (Slow) 2017/05/01 23:44:55 Do we need to distinguish the autoplay sources?
hubbe 2017/05/02 00:05:31 That's probably a good idea, done.
52 std::min<int64_t>(MonotonicallyIncreasingTimeMS() - created_time_ms_,
53 std::numeric_limits<int32_t>::max()));
54
48 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, 55 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram,
49 ("Media.Video.Autoplay", 56 ("Media.Video.Autoplay",
50 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); 57 static_cast<int>(AutoplaySource::kNumberOfUmaSources)));
51 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, 58 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram,
52 ("Media.Video.Autoplay.Muted", 59 ("Media.Video.Autoplay.Muted",
53 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); 60 static_cast<int>(AutoplaySource::kNumberOfUmaSources)));
54 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, 61 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram,
55 ("Media.Audio.Autoplay", 62 ("Media.Audio.Autoplay",
56 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); 63 static_cast<int>(AutoplaySource::kNumberOfUmaSources)));
57 DEFINE_STATIC_LOCAL( 64 DEFINE_STATIC_LOCAL(
58 EnumerationHistogram, blocked_muted_video_histogram, 65 EnumerationHistogram, blocked_muted_video_histogram,
59 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); 66 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax));
60 67
68 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_histogram,
69 ("Media.Video.Autoplay.Video.WaitTimeMS", 1,
Zhiqiang Zhang (Slow) 2017/05/01 23:44:55 You probably forgot to add the new histograms to h
hubbe 2017/05/02 00:05:31 OOps, yes added. (Should I add you as an additiona
Zhiqiang Zhang (Slow) 2017/05/02 00:12:05 I left chromium recently so no need to add me.
70 kMaxWaitTimeUmaMS, kWaitTimeBucketCount));
71 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_histogram,
72 ("Media.Video.Autoplay.Audio.WaitTimeMS", 1,
73 kMaxWaitTimeUmaMS, kWaitTimeBucketCount));
74
75 bool first_autoplay = sources_.empty();
76
61 // Autoplay already initiated 77 // Autoplay already initiated
62 if (sources_.count(source)) 78 if (sources_.count(source))
63 return; 79 return;
64 80
65 sources_.insert(source); 81 sources_.insert(source);
66 82
67 // Record the source. 83 // Record the source.
68 if (element_->IsHTMLVideoElement()) { 84 if (element_->IsHTMLVideoElement()) {
69 video_histogram.Count(static_cast<int>(source)); 85 video_histogram.Count(static_cast<int>(source));
70 if (element_->muted()) 86 if (element_->muted())
71 muted_video_histogram.Count(static_cast<int>(source)); 87 muted_video_histogram.Count(static_cast<int>(source));
72 } else { 88 } else {
73 audio_histogram.Count(static_cast<int>(source)); 89 audio_histogram.Count(static_cast<int>(source));
74 } 90 }
75 91
76 // Record dual source. 92 // Record dual source.
77 if (sources_.size() == 93 if (sources_.size() ==
78 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { 94 static_cast<size_t>(AutoplaySource::kNumberOfSources)) {
79 if (element_->IsHTMLVideoElement()) { 95 if (element_->IsHTMLVideoElement()) {
80 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); 96 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource));
81 if (element_->muted()) 97 if (element_->muted())
82 muted_video_histogram.Count( 98 muted_video_histogram.Count(
83 static_cast<int>(AutoplaySource::kDualSource)); 99 static_cast<int>(AutoplaySource::kDualSource));
84 } else { 100 } else {
85 audio_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); 101 audio_histogram.Count(static_cast<int>(AutoplaySource::kDualSource));
86 } 102 }
87 } 103 }
88 104
105 if (first_autoplay) {
106 if (element_->IsHTMLVideoElement()) {
107 wait_time_video_histogram.Count(autoplay_wait_time_ms);
108 } else {
109 wait_time_audio_histogram.Count(autoplay_wait_time_ms);
110 }
111 }
112
89 // Record the child frame and top-level frame URLs for autoplay muted videos 113 // Record the child frame and top-level frame URLs for autoplay muted videos
90 // by attribute. 114 // by attribute.
91 if (element_->IsHTMLVideoElement() && element_->muted()) { 115 if (element_->IsHTMLVideoElement() && element_->muted()) {
92 if (sources_.size() == 116 if (sources_.size() ==
93 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { 117 static_cast<size_t>(AutoplaySource::kNumberOfSources)) {
94 Platform::Current()->RecordRapporURL( 118 Platform::Current()->RecordRapporURL(
95 "Media.Video.Autoplay.Muted.DualSource.Frame", 119 "Media.Video.Autoplay.Muted.DualSource.Frame",
96 element_->GetDocument().Url()); 120 element_->GetDocument().Url());
97 } else if (source == AutoplaySource::kAttribute) { 121 } else if (source == AutoplaySource::kAttribute) {
98 Platform::Current()->RecordRapporURL( 122 Platform::Current()->RecordRapporURL(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 423
400 DEFINE_TRACE(AutoplayUmaHelper) { 424 DEFINE_TRACE(AutoplayUmaHelper) {
401 EventListener::Trace(visitor); 425 EventListener::Trace(visitor);
402 ContextLifecycleObserver::Trace(visitor); 426 ContextLifecycleObserver::Trace(visitor);
403 visitor->Trace(element_); 427 visitor->Trace(element_);
404 visitor->Trace(muted_video_play_method_visibility_observer_); 428 visitor->Trace(muted_video_play_method_visibility_observer_);
405 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); 429 visitor->Trace(muted_video_offscreen_duration_visibility_observer_);
406 } 430 }
407 431
408 } // namespace blink 432 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698