Commit 88764eb9 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media History] Store watchtime in seconds

Since we have the aggregate watchtime in seconds
it will be easier if we store the watchtime in
seconds, especially since we don't need millisecond
level accuracy.

BUG=1024351

Change-Id: I985d6f9d42c1d7ccf3eb9ba88c0dba1bc14e93e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037633
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738332}
parent 211e3f60
......@@ -28,7 +28,7 @@ sql::InitStatus MediaHistoryPlaybackTable::CreateTableIfNonExistent() {
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"origin_id INTEGER NOT NULL,"
"url TEXT,"
"watch_time_ms INTEGER,"
"watch_time_s INTEGER,"
"has_video INTEGER,"
"has_audio INTEGER,"
"last_updated_time_s BIGINT NOT NULL,"
......@@ -65,17 +65,16 @@ bool MediaHistoryPlaybackTable::SavePlayback(
sql::Statement statement(DB()->GetCachedStatement(
SQL_FROM_HERE,
base::StringPrintf(
"INSERT INTO %s "
"(origin_id, url, watch_time_ms, has_video, has_audio, "
"last_updated_time_s) "
"VALUES ((SELECT id FROM origin WHERE origin = ?), "
"?, ?, ?, ?, ?)",
kTableName)
base::StringPrintf("INSERT INTO %s "
"(origin_id, url, watch_time_s, has_video, has_audio, "
"last_updated_time_s) "
"VALUES ((SELECT id FROM origin WHERE origin = ?), "
"?, ?, ?, ?, ?)",
kTableName)
.c_str()));
statement.BindString(0, watch_time.origin.spec());
statement.BindString(1, watch_time.url.spec());
statement.BindInt64(2, watch_time.cumulative_watch_time.InMilliseconds());
statement.BindInt64(2, watch_time.cumulative_watch_time.InSeconds());
statement.BindInt(3, watch_time.has_video);
statement.BindInt(4, watch_time.has_audio);
statement.BindInt64(5,
......
......@@ -94,9 +94,9 @@ TEST_F(MediaHistoryStoreUnitTest, CreateDatabaseTables) {
TEST_F(MediaHistoryStoreUnitTest, SavePlayback) {
// Create a media player watch time and save it to the playbacks table.
GURL url("http://google.com/test");
content::MediaPlayerWatchTime watch_time(
url, url.GetOrigin(), base::TimeDelta::FromMilliseconds(123),
base::TimeDelta::FromMilliseconds(321), true, false);
content::MediaPlayerWatchTime watch_time(url, url.GetOrigin(),
base::TimeDelta::FromSeconds(60),
base::TimeDelta(), true, false);
GetMediaHistoryStore()->SavePlayback(watch_time);
int64_t now_in_seconds_before =
base::Time::Now().ToDeltaSinceWindowsEpoch().InSeconds();
......@@ -112,7 +112,7 @@ TEST_F(MediaHistoryStoreUnitTest, SavePlayback) {
// Verify that the playback table contains the expected number of items
sql::Statement select_from_playback_statement(GetDB().GetUniqueStatement(
"SELECT id, url, origin_id, watch_time_ms, has_video, has_audio, "
"SELECT id, url, origin_id, watch_time_s, has_video, has_audio, "
"last_updated_time_s FROM playback"));
ASSERT_TRUE(select_from_playback_statement.is_valid());
int playback_row_count = 0;
......@@ -122,7 +122,7 @@ TEST_F(MediaHistoryStoreUnitTest, SavePlayback) {
EXPECT_EQ("http://google.com/test",
select_from_playback_statement.ColumnString(1));
EXPECT_EQ(1, select_from_playback_statement.ColumnInt(2));
EXPECT_EQ(123, select_from_playback_statement.ColumnInt(3));
EXPECT_EQ(60, select_from_playback_statement.ColumnInt(3));
EXPECT_EQ(1, select_from_playback_statement.ColumnInt(4));
EXPECT_EQ(0, select_from_playback_statement.ColumnInt(5));
EXPECT_LE(now_in_seconds_before,
......
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