Commit b7d9656d authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media History] Do not record background or muted watchtime

Adds a fix so that Media History does not record
background or muted watchtime since they are not
useful to us (we only want foreground unmuted).

BUG=1086511

Change-Id: I175c20ad88c136f291b72ae021b3cc22729bc5f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216375
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771995}
parent cdb5b523
......@@ -29,6 +29,7 @@
#include "components/history/core/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/context_menu_params.h"
#include "content/public/browser/media_session.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browsing_data_remover_test_util.h"
......@@ -1253,4 +1254,55 @@ IN_PROC_BROWSER_TEST_P(MediaHistoryBrowserTest,
}
}
IN_PROC_BROWSER_TEST_P(MediaHistoryBrowserTest,
DoNotRecordWatchtime_Background) {
auto* browser = CreateBrowserFromParam();
auto* service = GetMediaHistoryService(browser);
// Setup the test page.
auto* web_contents = browser->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(SetupPageAndStartPlaying(browser, GetTestURL()));
// Hide the web contents.
web_contents->WasHidden();
// Wait for significant playback in the background tab.
WaitForSignificantPlayback(browser);
// Close all the tabs to trigger any saving.
browser->tab_strip_model()->CloseAllTabs();
// Wait until the session has finished saving.
WaitForDB(service);
// No playbacks should have been saved since we were in the background.
auto playbacks = GetPlaybacksSync(service);
EXPECT_TRUE(playbacks.empty());
}
IN_PROC_BROWSER_TEST_P(MediaHistoryBrowserTest, DoNotRecordWatchtime_Muted) {
auto* browser = CreateBrowserFromParam();
auto* service = GetMediaHistoryService(browser);
// Setup the test page.
auto* web_contents = browser->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(SetupPageAndStartPlaying(browser, GetTestURL()));
// Mute the video.
ASSERT_TRUE(content::ExecuteScript(web_contents, "mute();"));
// Wait for significant playback in the muted tab.
WaitForSignificantPlayback(browser);
// Close all the tabs to trigger any saving.
browser->tab_strip_model()->CloseAllTabs();
// Wait until the session has finished saving.
WaitForDB(service);
// No playbacks should have been saved since we were muted.
auto playbacks = GetPlaybacksSync(service);
EXPECT_TRUE(playbacks.empty());
}
} // namespace media_history
......@@ -19,6 +19,11 @@ function attemptPlayVideoOnly() {
attemptPlay('video-only.webm');
}
function mute() {
const video = document.querySelector('video');
video.muted = true;
}
function attemptPlay(src) {
const video = document.querySelector('video');
video.src = src;
......
......@@ -421,7 +421,7 @@ void WatchTimeRecorder::RecordUkmPlaybackData() {
base::flat_set<AudioCodecProfile> aac_profiles;
base::TimeDelta total_watch_time;
base::TimeDelta total_foreground_audible_watch_time;
for (auto& ukm_record : ukm_records_) {
ukm::builders::Media_BasicPlayback builder(source_id_);
......@@ -446,7 +446,11 @@ void WatchTimeRecorder::RecordUkmPlaybackData() {
// Only one of these keys should be present.
DCHECK(!recorded_all_metric);
recorded_all_metric = true;
total_watch_time += kv.second;
// We should only add to the total watchtime if we were not in the
// background and not muted.
if (!properties_->is_muted && !properties_->is_background)
total_foreground_audible_watch_time += kv.second;
builder.SetWatchTime(kv.second.InMilliseconds());
if (ukm_record.total_underflow_count) {
......@@ -554,10 +558,10 @@ void WatchTimeRecorder::RecordUkmPlaybackData() {
base::UmaHistogramEnumeration("Media.AudioCodecProfile.AAC", profile);
}
if (total_watch_time > base::TimeDelta()) {
if (total_foreground_audible_watch_time > base::TimeDelta()) {
std::move(record_playback_cb_)
.Run(total_watch_time, last_timestamp_, properties_->has_video,
properties_->has_audio);
.Run(total_foreground_audible_watch_time, last_timestamp_,
properties_->has_video, properties_->has_audio);
}
ukm_records_.clear();
......
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