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

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

Issue 2856783002: Autoplay time metric (Closed)
Patch Set: use loadstart event 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.cpp
diff --git a/third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.cpp b/third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.cpp
index 410dcc50e41ceff3d8ab904d199a1d7c02fe58e0..1869325c8b234a86a47cb1c2cd19e58e575856d9 100644
--- a/third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.cpp
+++ b/third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.cpp
@@ -21,6 +21,8 @@ namespace {
const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000;
const int32_t kOffscreenDurationUmaBucketCount = 50;
+const int32_t kMaxWaitTimeUmaMS = 30 * 1000;
+const int32_t kWaitTimeBucketCount = 50;
} // namespace
@@ -36,7 +38,10 @@ AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element)
muted_video_autoplay_offscreen_start_time_ms_(0),
muted_video_autoplay_offscreen_duration_ms_(0),
is_visible_(false),
- muted_video_offscreen_duration_visibility_observer_(nullptr) {}
+ muted_video_offscreen_duration_visibility_observer_(nullptr),
+ load_start_time_ms_(0.0) {
+ element->addEventListener(EventTypeNames::loadstart, this, false);
+}
AutoplayUmaHelper::~AutoplayUmaHelper() = default;
@@ -44,7 +49,18 @@ bool AutoplayUmaHelper::operator==(const EventListener& other) const {
return this == &other;
}
+void AutoplayUmaHelper::OnLoadStarted() {
+ if (element_->GetLoadType() == WebMediaPlayer::kLoadTypeURL)
+ load_start_time_ms_ = MonotonicallyIncreasingTimeMS();
+}
+
void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) {
+ int32_t autoplay_wait_time_ms = -1;
+ if (load_start_time_ms_ != 0.0) {
+ autoplay_wait_time_ms = static_cast<int32_t>(
+ std::min<int64_t>(MonotonicallyIncreasingTimeMS() - load_start_time_ms_,
+ std::numeric_limits<int32_t>::max()));
+ }
DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram,
("Media.Video.Autoplay",
static_cast<int>(AutoplaySource::kNumberOfUmaSources)));
@@ -58,6 +74,19 @@ void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) {
EnumerationHistogram, blocked_muted_video_histogram,
("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax));
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_attrib_histogram,
+ ("Media.Video.Autoplay.Attribute.WaitTime", 1,
+ kMaxWaitTimeUmaMS, kWaitTimeBucketCount));
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_attrib_histogram,
+ ("Media.Audio.Autoplay.Attribute.WaitTime", 1,
+ kMaxWaitTimeUmaMS, kWaitTimeBucketCount));
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_play_histogram,
+ ("Media.Video.Autoplay.PlayMethod.WaitTime", 1,
+ kMaxWaitTimeUmaMS, kWaitTimeBucketCount));
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_play_histogram,
+ ("Media.Audio.Autoplay.PlayMethod.WaitTime", 1,
+ kMaxWaitTimeUmaMS, kWaitTimeBucketCount));
+
// Autoplay already initiated
if (sources_.count(source))
return;
@@ -69,8 +98,22 @@ void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) {
video_histogram.Count(static_cast<int>(source));
if (element_->muted())
muted_video_histogram.Count(static_cast<int>(source));
+ if (autoplay_wait_time_ms >= 0) {
+ if (source == AutoplaySource::kAttribute) {
+ wait_time_video_attrib_histogram.Count(autoplay_wait_time_ms);
+ } else if (source == AutoplaySource::kMethod) {
+ wait_time_video_play_histogram.Count(autoplay_wait_time_ms);
+ }
+ }
} else {
audio_histogram.Count(static_cast<int>(source));
+ if (autoplay_wait_time_ms >= 0) {
+ if (source == AutoplaySource::kAttribute) {
+ wait_time_audio_attrib_histogram.Count(autoplay_wait_time_ms);
+ } else if (source == AutoplaySource::kMethod) {
+ wait_time_audio_play_histogram.Count(autoplay_wait_time_ms);
+ }
+ }
}
// Record dual source.
@@ -257,7 +300,9 @@ void AutoplayUmaHelper::OnVisibilityChangedForMutedVideoOffscreenDuration(
void AutoplayUmaHelper::handleEvent(ExecutionContext* execution_context,
Event* event) {
- if (event->type() == EventTypeNames::playing)
+ if (event->type() == EventTypeNames::loadstart)
+ OnLoadStarted();
+ else if (event->type() == EventTypeNames::playing)
HandlePlayingEvent();
else if (event->type() == EventTypeNames::pause)
HandlePauseEvent();
« no previous file with comments | « third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698