Commit 76fb49b6 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Use TimeTicks and TimeDelta in AutoplayUmaHelper.

It's cleaner and more consistent with Chromium.

Change-Id: Ib2e4fa6d55f5e85c48673fb48b3cd90de8b11240
Reviewed-on: https://chromium-review.googlesource.com/1106042Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568814}
parent a7e3fbfd
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/platform/histogram.h" #include "third_party/blink/renderer/platform/histogram.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h" #include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
namespace blink { namespace blink {
...@@ -59,11 +58,8 @@ AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element) ...@@ -59,11 +58,8 @@ AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element)
ContextLifecycleObserver(nullptr), ContextLifecycleObserver(nullptr),
element_(element), element_(element),
muted_video_play_method_visibility_observer_(nullptr), muted_video_play_method_visibility_observer_(nullptr),
muted_video_autoplay_offscreen_start_time_ms_(0),
muted_video_autoplay_offscreen_duration_ms_(0),
is_visible_(false), 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); element->addEventListener(EventTypeNames::loadstart, this, false);
} }
...@@ -75,14 +71,14 @@ bool AutoplayUmaHelper::operator==(const EventListener& other) const { ...@@ -75,14 +71,14 @@ bool AutoplayUmaHelper::operator==(const EventListener& other) const {
void AutoplayUmaHelper::OnLoadStarted() { void AutoplayUmaHelper::OnLoadStarted() {
if (element_->GetLoadType() == WebMediaPlayer::kLoadTypeURL) if (element_->GetLoadType() == WebMediaPlayer::kLoadTypeURL)
load_start_time_ms_ = CurrentTimeTicksInMilliseconds(); load_start_time_ = CurrentTimeTicks();
} }
void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) {
int32_t autoplay_wait_time_ms = -1; int32_t autoplay_wait_time_ms = -1;
if (load_start_time_ms_ != 0.0) { if (!load_start_time_.is_null()) {
autoplay_wait_time_ms = static_cast<int32_t>(std::min<int64_t>( autoplay_wait_time_ms = static_cast<int32_t>(std::min<int64_t>(
CurrentTimeTicksInMilliseconds() - load_start_time_ms_, (CurrentTimeTicks() - load_start_time_).InMilliseconds(),
std::numeric_limits<int32_t>::max())); std::numeric_limits<int32_t>::max()));
} }
DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram,
...@@ -352,12 +348,10 @@ void AutoplayUmaHelper::OnVisibilityChangedForMutedVideoOffscreenDuration( ...@@ -352,12 +348,10 @@ void AutoplayUmaHelper::OnVisibilityChangedForMutedVideoOffscreenDuration(
return; return;
if (is_visible) { if (is_visible) {
muted_video_autoplay_offscreen_duration_ms_ += muted_video_autoplay_offscreen_duration_ +=
static_cast<int64_t>(CurrentTimeTicksInMilliseconds()) - CurrentTimeTicks() - muted_video_autoplay_offscreen_start_time_;
muted_video_autoplay_offscreen_start_time_ms_;
} else { } else {
muted_video_autoplay_offscreen_start_time_ms_ = muted_video_autoplay_offscreen_start_time_ = CurrentTimeTicks();
static_cast<int64_t>(CurrentTimeTicksInMilliseconds());
} }
is_visible_ = is_visible; is_visible_ = is_visible;
...@@ -430,8 +424,7 @@ void AutoplayUmaHelper::MaybeStartRecordingMutedVideoOffscreenDuration() { ...@@ -430,8 +424,7 @@ void AutoplayUmaHelper::MaybeStartRecordingMutedVideoOffscreenDuration() {
return; return;
// Start recording muted video playing offscreen duration. // Start recording muted video playing offscreen duration.
muted_video_autoplay_offscreen_start_time_ms_ = muted_video_autoplay_offscreen_start_time_ = CurrentTimeTicks();
static_cast<int64_t>(CurrentTimeTicksInMilliseconds());
is_visible_ = false; is_visible_ = false;
muted_video_offscreen_duration_visibility_observer_ = muted_video_offscreen_duration_visibility_observer_ =
new ElementVisibilityObserver( new ElementVisibilityObserver(
...@@ -449,15 +442,14 @@ void AutoplayUmaHelper::MaybeStopRecordingMutedVideoOffscreenDuration() { ...@@ -449,15 +442,14 @@ void AutoplayUmaHelper::MaybeStopRecordingMutedVideoOffscreenDuration() {
return; return;
if (!is_visible_) { if (!is_visible_) {
muted_video_autoplay_offscreen_duration_ms_ += muted_video_autoplay_offscreen_duration_ +=
static_cast<int64_t>(CurrentTimeTicksInMilliseconds()) - CurrentTimeTicks() - muted_video_autoplay_offscreen_start_time_;
muted_video_autoplay_offscreen_start_time_ms_;
} }
// Since histograms uses int32_t, the duration needs to be limited to // Since histograms uses int32_t, the duration needs to be limited to
// std::numeric_limits<int32_t>::max(). // std::numeric_limits<int32_t>::max().
int32_t bounded_time = static_cast<int32_t>( int32_t bounded_time = static_cast<int32_t>(std::min<int64_t>(
std::min<int64_t>(muted_video_autoplay_offscreen_duration_ms_, muted_video_autoplay_offscreen_duration_.InMilliseconds(),
std::numeric_limits<int32_t>::max())); std::numeric_limits<int32_t>::max()));
DCHECK(sources_.count(AutoplaySource::kMethod)); DCHECK(sources_.count(AutoplaySource::kMethod));
...@@ -470,7 +462,7 @@ void AutoplayUmaHelper::MaybeStopRecordingMutedVideoOffscreenDuration() { ...@@ -470,7 +462,7 @@ void AutoplayUmaHelper::MaybeStopRecordingMutedVideoOffscreenDuration() {
muted_video_offscreen_duration_visibility_observer_->Stop(); muted_video_offscreen_duration_visibility_observer_->Stop();
muted_video_offscreen_duration_visibility_observer_ = nullptr; muted_video_offscreen_duration_visibility_observer_ = nullptr;
muted_video_autoplay_offscreen_duration_ms_ = 0; muted_video_autoplay_offscreen_duration_ = TimeDelta();
MaybeUnregisterMediaElementPauseListener(); MaybeUnregisterMediaElementPauseListener();
MaybeUnregisterContextDestroyedObserver(); MaybeUnregisterContextDestroyedObserver();
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/dom/events/event_listener.h" #include "third_party/blink/renderer/core/dom/events/event_listener.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
#include <set> #include <set>
...@@ -133,10 +134,10 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener, ...@@ -133,10 +134,10 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener,
// The recording stops whenever the playback pauses or the page is unloaded. // The recording stops whenever the playback pauses or the page is unloaded.
// The starting time of autoplaying muted video. // The starting time of autoplaying muted video.
int64_t muted_video_autoplay_offscreen_start_time_ms_; TimeTicks muted_video_autoplay_offscreen_start_time_;
// The duration an autoplaying muted video has been in offscreen. // The duration an autoplaying muted video has been in offscreen.
int64_t muted_video_autoplay_offscreen_duration_ms_; TimeDelta muted_video_autoplay_offscreen_duration_;
// Whether an autoplaying muted video is visible. // Whether an autoplaying muted video is visible.
bool is_visible_; bool is_visible_;
...@@ -149,7 +150,7 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener, ...@@ -149,7 +150,7 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener,
Member<ElementVisibilityObserver> Member<ElementVisibilityObserver>
muted_video_offscreen_duration_visibility_observer_; muted_video_offscreen_duration_visibility_observer_;
double load_start_time_ms_; TimeTicks load_start_time_;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment