Commit 6ce98927 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Handle kInfiniteDuration start times in WatchTimeReporter.

These should not start the reporter but are possible. Due to the
statefulness of WTR this means we need a new "has valid start time"
flag which controls when reporting is running.

BUG=965820,967103
TEST=new unittest
R=sandersd

Change-Id: Ieeb125472609f2a0c3b027c9c43ab4ded7cb669a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1632893
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663930}
parent 8fba5045
......@@ -350,14 +350,20 @@ bool WatchTimeReporter::ShouldReportingTimerRun() const {
// TODO(dalecurtis): We should only consider |volume_| when there is actually
// an audio track; requires updating lots of tests to fix.
return ShouldReportWatchTime() && is_playing_ && volume_ && is_visible_ &&
!in_shutdown_ && !is_seeking_;
!in_shutdown_ && !is_seeking_ && has_valid_start_timestamp_;
}
void WatchTimeReporter::MaybeStartReportingTimer(
base::TimeDelta start_timestamp) {
DCHECK_NE(start_timestamp, kInfiniteDuration);
DCHECK_GE(start_timestamp, base::TimeDelta());
// It's possible for |current_time| to be kInfiniteDuration here if the page
// seeks to kInfiniteDuration (2**64 - 1) when Duration() is infinite. There
// is no possible elapsed watch time when this occurs, so don't start the
// WatchTimeReporter at this time. If a later seek puts us earlier in the
// stream this method will be called again after OnSeeking().
has_valid_start_timestamp_ = start_timestamp != kInfiniteDuration;
// Don't start the timer if our state indicates we shouldn't; this check is
// important since the various event handlers do not have to care about the
// state of other events.
......
......@@ -213,6 +213,7 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
bool is_visible_ = true;
bool is_seeking_ = false;
bool in_shutdown_ = false;
bool has_valid_start_timestamp_ = false;
double volume_ = 1.0;
// Updated by UpdateSecondaryProperties(); controls timer state when
......
......@@ -659,6 +659,14 @@ TEST_P(WatchTimeReporterTest, WatchTimeReporter) {
wtr_.reset();
}
TEST_P(WatchTimeReporterTest, WatchTimeReporterInfiniteStartTime) {
EXPECT_CALL(*this, GetCurrentMediaTime())
.WillRepeatedly(testing::Return(kInfiniteDuration));
Initialize(false, false, kSizeJustRight);
wtr_->OnPlaying();
EXPECT_FALSE(IsMonitoring());
}
TEST_P(WatchTimeReporterTest, WatchTimeReporterBasic) {
constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5);
constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10);
......
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