| Index: media/blink/watch_time_reporter.h
|
| diff --git a/media/blink/watch_time_reporter.h b/media/blink/watch_time_reporter.h
|
| index 81ea7bd6200d4b9022057c46acd072f40f6b03fb..8290bdc1b04807003620dbae5eb903040d40a69d 100644
|
| --- a/media/blink/watch_time_reporter.h
|
| +++ b/media/blink/watch_time_reporter.h
|
| @@ -21,16 +21,21 @@ namespace media {
|
| // playbacks as well as audio+video playbacks of sufficient size.
|
| //
|
| // Watch time for our purposes is defined as the amount of elapsed media time
|
| -// for audio only or audio+video media. A minimum of 7 seconds of unmuted,
|
| -// foreground (where this is video) media must be watched to start watch time
|
| -// monitoring. Watch time is checked every 5 seconds from then on and reported
|
| -// to multiple buckets: All, MSE, SRC, EME, AC, and battery.
|
| +// for audio only or audio+video media. A minimum of 7 seconds of unmuted media
|
| +// must be watched to start watch time monitoring. Watch time is checked every 5
|
| +// seconds from then on and reported to multiple buckets: All, MSE, SRC, EME,
|
| +// AC, and battery.
|
| //
|
| // Any one of paused, hidden (where this is video), or muted is sufficient to
|
| // stop watch time metric reports. Each of these has a hysteresis where if the
|
| // state change is undone within 5 seconds, the watch time will be counted as
|
| // uninterrupted.
|
| //
|
| +// If the media is audio+video, foreground watch time is logged to the normal
|
| +// AudioVideo bucket, while background watch time goes to the specific
|
| +// AudioVideo.Background bucket. As with other events, there is hysteresis on
|
| +// change between the foreground and background.
|
| +//
|
| // Power events (on/off battery power) have a similar hysteresis, but unlike
|
| // the aforementioned properties, will not stop metric collection.
|
| //
|
| @@ -68,7 +73,8 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
|
|
|
| // These methods are used to ensure that watch time is only reported for
|
| // media that is actually playing. They should be called whenever the media
|
| - // starts or stops playing for any reason.
|
| + // starts or stops playing for any reason. If the media is audio+video and
|
| + // currently hidden, OnPlaying() will start background watch time reporting.
|
| void OnPlaying();
|
| void OnPaused();
|
|
|
| @@ -87,7 +93,8 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
|
|
|
| // These methods are used to ensure that watch time is only reported for
|
| // videos that are actually visible to the user. They should be called when
|
| - // the video is shown or hidden respectively.
|
| + // the video is shown or hidden respectively. OnHidden() will start background
|
| + // watch time reporting if the media is audio+video.
|
| //
|
| // TODO(dalecurtis): At present, this is only called when the entire content
|
| // window goes into the foreground or background respectively; i.e. it does
|
| @@ -96,9 +103,34 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
|
| void OnShown();
|
| void OnHidden();
|
|
|
| + // Setup the reporting interval to be immediate to avoid spinning real time
|
| + // within the unit test.
|
| + void set_reporting_interval_for_testing() {
|
| + reporting_interval_ = base::TimeDelta();
|
| + }
|
| +
|
| + void set_is_on_battery_power_for_testing(bool on_battery_power) {
|
| + is_on_battery_power_ = on_battery_power;
|
| + }
|
| +
|
| + void OnPowerStateChangeForTesting(bool on_battery_power) {
|
| + OnPowerStateChange(on_battery_power);
|
| + }
|
| +
|
| private:
|
| friend class WatchTimeReporterTest;
|
|
|
| + // Internal constructor for marking background status.
|
| + WatchTimeReporter(bool has_audio,
|
| + bool has_video,
|
| + bool is_mse,
|
| + bool is_encrypted,
|
| + bool is_embedded_media_experience_enabled,
|
| + scoped_refptr<MediaLog> media_log,
|
| + const gfx::Size& initial_video_size,
|
| + const GetMediaTimeCB& get_media_time_cb,
|
| + bool is_background);
|
| +
|
| // base::PowerObserver implementation.
|
| //
|
| // We only observe power source changes. We don't need to observe suspend and
|
| @@ -121,6 +153,7 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
|
| scoped_refptr<MediaLog> media_log_;
|
| const gfx::Size initial_video_size_;
|
| const GetMediaTimeCB get_media_time_cb_;
|
| + const bool is_background_;
|
|
|
| // The amount of time between each UpdateWatchTime(); this is the frequency by
|
| // which the watch times are updated. In the event of a process crash or kill
|
| @@ -137,6 +170,7 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
|
|
|
| // The last media timestamp seen by UpdateWatchTime().
|
| base::TimeDelta last_media_timestamp_ = kNoTimestamp;
|
| + base::TimeDelta last_media_power_timestamp_ = kNoTimestamp;
|
|
|
| // The starting and ending timestamps used for reporting watch time.
|
| base::TimeDelta start_timestamp_;
|
| @@ -147,6 +181,10 @@ class MEDIA_BLINK_EXPORT WatchTimeReporter : base::PowerObserver {
|
| base::TimeDelta start_timestamp_for_power_;
|
| base::TimeDelta end_timestamp_for_power_ = kNoTimestamp;
|
|
|
| + // Special case reporter for handling background video watch time. Configured
|
| + // as an audio only WatchTimeReporter with |is_background_| set to true.
|
| + std::unique_ptr<WatchTimeReporter> background_reporter_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(WatchTimeReporter);
|
| };
|
|
|
|
|