Commit 0f3ae247 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media History] Refactor store class

Since we have MHKS, MHS didn't really do anything
apart from proxy to MHSI. This replaces MHS with
MHSI.

BUG=1024351

Change-Id: Ifb6e6c6d33d428dbfd415e3e81a63a22858835c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2138553
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757631}
parent 309e1e97
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/media/history/media_history_images_table.h" #include "chrome/browser/media/history/media_history_images_table.h"
#include "chrome/browser/media/history/media_history_keyed_service.h" #include "chrome/browser/media/history/media_history_keyed_service.h"
#include "chrome/browser/media/history/media_history_keyed_service_factory.h" #include "chrome/browser/media/history/media_history_keyed_service_factory.h"
#include "chrome/browser/media/history/media_history_origin_table.h"
#include "chrome/browser/media/history/media_history_session_images_table.h" #include "chrome/browser/media/history/media_history_session_images_table.h"
#include "chrome/browser/media/history/media_history_session_table.h" #include "chrome/browser/media/history/media_history_session_table.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
......
...@@ -50,7 +50,7 @@ class MediaHistoryFeedItemsTable : public MediaHistoryTableBase { ...@@ -50,7 +50,7 @@ class MediaHistoryFeedItemsTable : public MediaHistoryTableBase {
delete; delete;
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistoryFeedItemsTable( explicit MediaHistoryFeedItemsTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/updateable_sequenced_task_runner.h" #include "base/updateable_sequenced_task_runner.h"
#include "chrome/browser/media/feeds/media_feeds.pb.h" #include "chrome/browser/media/feeds/media_feeds.pb.h"
#include "chrome/browser/media/feeds/media_feeds_utils.h" #include "chrome/browser/media/feeds/media_feeds_utils.h"
#include "chrome/browser/media/history/media_history_origin_table.h"
#include "chrome/browser/media/history/media_history_store.h" #include "chrome/browser/media/history/media_history_store.h"
#include "services/media_session/public/cpp/media_image.h" #include "services/media_session/public/cpp/media_image.h"
#include "sql/statement.h" #include "sql/statement.h"
......
...@@ -37,7 +37,7 @@ class MediaHistoryFeedsTable : public MediaHistoryTableBase { ...@@ -37,7 +37,7 @@ class MediaHistoryFeedsTable : public MediaHistoryTableBase {
}; };
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistoryFeedsTable( explicit MediaHistoryFeedsTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/updateable_sequenced_task_runner.h" #include "base/updateable_sequenced_task_runner.h"
#include "chrome/browser/media/history/media_history_origin_table.h"
#include "chrome/browser/media/history/media_history_store.h" #include "chrome/browser/media/history/media_history_store.h"
#include "sql/statement.h" #include "sql/statement.h"
......
...@@ -24,7 +24,7 @@ class MediaHistoryImagesTable : public MediaHistoryTableBase { ...@@ -24,7 +24,7 @@ class MediaHistoryImagesTable : public MediaHistoryTableBase {
static const char kTableName[]; static const char kTableName[];
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistoryImagesTable( explicit MediaHistoryImagesTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "chrome/browser/media/history/media_history_feed_items_table.h" #include "chrome/browser/media/history/media_history_feed_items_table.h"
#include "chrome/browser/media/history/media_history_feeds_table.h" #include "chrome/browser/media/history/media_history_feeds_table.h"
#include "chrome/browser/media/history/media_history_images_table.h" #include "chrome/browser/media/history/media_history_images_table.h"
#include "chrome/browser/media/history/media_history_origin_table.h"
#include "chrome/browser/media/history/media_history_playback_table.h"
#include "chrome/browser/media/history/media_history_session_images_table.h" #include "chrome/browser/media/history/media_history_session_images_table.h"
#include "chrome/browser/media/history/media_history_session_table.h" #include "chrome/browser/media/history/media_history_session_table.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
......
...@@ -25,7 +25,7 @@ class MediaHistoryOriginTable : public MediaHistoryTableBase { ...@@ -25,7 +25,7 @@ class MediaHistoryOriginTable : public MediaHistoryTableBase {
static std::string GetOriginForStorage(const url::Origin& origin); static std::string GetOriginForStorage(const url::Origin& origin);
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistoryOriginTable( explicit MediaHistoryOriginTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -39,7 +39,7 @@ class MediaHistoryPlaybackTable : public MediaHistoryTableBase { ...@@ -39,7 +39,7 @@ class MediaHistoryPlaybackTable : public MediaHistoryTableBase {
bool DeleteURL(const GURL& url) override; bool DeleteURL(const GURL& url) override;
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistoryPlaybackTable( explicit MediaHistoryPlaybackTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -30,7 +30,7 @@ class MediaHistorySessionImagesTable : public MediaHistoryTableBase { ...@@ -30,7 +30,7 @@ class MediaHistorySessionImagesTable : public MediaHistoryTableBase {
static const char kTableName[]; static const char kTableName[];
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistorySessionImagesTable( explicit MediaHistorySessionImagesTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -33,7 +33,7 @@ class MediaHistorySessionTable : public MediaHistoryTableBase { ...@@ -33,7 +33,7 @@ class MediaHistorySessionTable : public MediaHistoryTableBase {
bool DeleteURL(const GURL& url) override; bool DeleteURL(const GURL& url) override;
private: private:
friend class MediaHistoryStoreInternal; friend class MediaHistoryStore;
explicit MediaHistorySessionTable( explicit MediaHistorySessionTable(
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_MEDIA_HISTORY_MEDIA_HISTORY_STORE_H_ #ifndef CHROME_BROWSER_MEDIA_HISTORY_MEDIA_HISTORY_STORE_H_
#define CHROME_BROWSER_MEDIA_HISTORY_MEDIA_HISTORY_STORE_H_ #define CHROME_BROWSER_MEDIA_HISTORY_MEDIA_HISTORY_STORE_H_
#include <memory>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -16,13 +15,9 @@ ...@@ -16,13 +15,9 @@
#include "base/updateable_sequenced_task_runner.h" #include "base/updateable_sequenced_task_runner.h"
#include "chrome/browser/media/feeds/media_feeds_store.mojom.h" #include "chrome/browser/media/feeds/media_feeds_store.mojom.h"
#include "chrome/browser/media/history/media_history_keyed_service.h" #include "chrome/browser/media/history/media_history_keyed_service.h"
#include "chrome/browser/media/history/media_history_origin_table.h"
#include "chrome/browser/media/history/media_history_playback_table.h"
#include "chrome/browser/media/history/media_history_store.mojom.h" #include "chrome/browser/media/history/media_history_store.mojom.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "content/public/browser/media_player_watch_time.h" #include "content/public/browser/media_player_watch_time.h"
#include "services/media_session/public/cpp/media_metadata.h"
#include "sql/database.h"
#include "sql/init_status.h" #include "sql/init_status.h"
#include "sql/meta_table.h" #include "sql/meta_table.h"
...@@ -42,14 +37,22 @@ class Origin; ...@@ -42,14 +37,22 @@ class Origin;
namespace media_history { namespace media_history {
class MediaHistoryStoreInternal; class MediaHistoryOriginTable;
class MediaHistoryPlaybackTable;
class MediaHistoryStore { class MediaHistorySessionTable;
class MediaHistorySessionImagesTable;
class MediaHistoryImagesTable;
class MediaHistoryFeedsTable;
class MediaHistoryFeedItemsTable;
// Refcounted as it is created, initialized and destroyed on a different thread
// from the DB sequence provided to the constructor of this class that is
// required for all methods performing database access.
class MediaHistoryStore : public base::RefCountedThreadSafe<MediaHistoryStore> {
public: public:
MediaHistoryStore( MediaHistoryStore(
Profile* profile, Profile* profile,
scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner); scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner);
~MediaHistoryStore();
MediaHistoryStore(const MediaHistoryStore& t) = delete; MediaHistoryStore(const MediaHistoryStore& t) = delete;
MediaHistoryStore& operator=(const MediaHistoryStore&) = delete; MediaHistoryStore& operator=(const MediaHistoryStore&) = delete;
...@@ -100,48 +103,46 @@ class MediaHistoryStore { ...@@ -100,48 +103,46 @@ class MediaHistoryStore {
protected: protected:
friend class MediaHistoryKeyedService; friend class MediaHistoryKeyedService;
// Saves a playback from a single player in the media history store. // Opens the database file from the |db_path|. Separated from the
// constructor to ease construction/destruction of this object on one thread
// and database access on the DB sequence of |db_task_runner_|.
void Initialize();
sql::InitStatus CreateOrUpgradeIfNeeded();
sql::InitStatus InitializeTables();
sql::Database* DB();
// Returns a flag indicating whether the origin id was created successfully.
bool CreateOriginId(const url::Origin& origin);
void SavePlayback(const content::MediaPlayerWatchTime& watch_time); void SavePlayback(const content::MediaPlayerWatchTime& watch_time);
void GetMediaHistoryStats( mojom::MediaHistoryStatsPtr GetMediaHistoryStats();
base::OnceCallback<void(mojom::MediaHistoryStatsPtr)> callback); int GetTableRowCount(const std::string& table_name);
// Returns all the rows in the origin table. This should only be used for std::vector<mojom::MediaHistoryOriginRowPtr> GetOriginRowsForDebug();
// debugging because it is very slow.
void GetOriginRowsForDebug( std::vector<mojom::MediaHistoryPlaybackRowPtr>
base::OnceCallback<void(std::vector<mojom::MediaHistoryOriginRowPtr>)> GetMediaHistoryPlaybackRowsForDebug();
callback);
std::vector<media_feeds::mojom::MediaFeedPtr> GetMediaFeedsForDebug();
// Returns all the rows in the playback table. This is only used for
// debugging because it loads all rows in the table.
void GetMediaHistoryPlaybackRowsForDebug(
base::OnceCallback<void(std::vector<mojom::MediaHistoryPlaybackRowPtr>)>
callback);
// Returns all the rows in the media feeds table. This is only used for
// debugging because it loads all rows in the table.
void GetMediaFeedsForDebug(
base::OnceCallback<void(std::vector<media_feeds::mojom::MediaFeedPtr>)>
callback);
// Gets the playback sessions from the media history store. The results will
// be ordered by most recent first and be limited to the first |num_sessions|.
// For each session it calls |filter| and if that returns |true| then that
// session will be included in the results.
void GetPlaybackSessions(
base::Optional<unsigned int> num_sessions,
base::Optional<GetPlaybackSessionsFilter> filter,
base::OnceCallback<void(
std::vector<mojom::MediaHistoryPlaybackSessionRowPtr>)> callback);
// Saves a playback session in the media history store.
void SavePlaybackSession( void SavePlaybackSession(
const GURL& url, const GURL& url,
const media_session::MediaMetadata& metadata, const media_session::MediaMetadata& metadata,
const base::Optional<media_session::MediaPosition>& position, const base::Optional<media_session::MediaPosition>& position,
const std::vector<media_session::MediaImage>& artwork); const std::vector<media_session::MediaImage>& artwork);
// Saves a newly discovered media feed in the media history store. std::vector<mojom::MediaHistoryPlaybackSessionRowPtr> GetPlaybackSessions(
base::Optional<unsigned int> num_sessions,
base::Optional<MediaHistoryStore::GetPlaybackSessionsFilter> filter);
void RazeAndClose();
void DeleteAllOriginData(const std::set<url::Origin>& origins);
void DeleteAllURLData(const std::set<GURL>& urls);
std::set<GURL> GetURLsInTableForTest(const std::string& table);
void DiscoverMediaFeed(const GURL& url); void DiscoverMediaFeed(const GURL& url);
void StoreMediaFeedFetchResult( void StoreMediaFeedFetchResult(
...@@ -152,33 +153,32 @@ class MediaHistoryStore { ...@@ -152,33 +153,32 @@ class MediaHistoryStore {
const std::vector<media_session::MediaImage>& logos, const std::vector<media_session::MediaImage>& logos,
const std::string& display_name); const std::string& display_name);
// Gets all the feed items for |feed_id|. std::vector<media_feeds::mojom::MediaFeedItemPtr>
void GetItemsForMediaFeedForDebug( GetItemsForMediaFeedForDebug(const int64_t feed_id);
const int64_t feed_id,
base::OnceCallback<
void(std::vector<media_feeds::mojom::MediaFeedItemPtr>)> callback);
void GetPendingSafeSearchCheckMediaFeedItems( MediaHistoryKeyedService::PendingSafeSearchCheckList
base::OnceCallback< GetPendingSafeSearchCheckMediaFeedItems();
void(MediaHistoryKeyedService::PendingSafeSearchCheckList)> callback);
void StoreMediaFeedItemSafeSearchResults( void StoreMediaFeedItemSafeSearchResults(
std::map<int64_t, media_feeds::mojom::SafeSearchResult> results); std::map<int64_t, media_feeds::mojom::SafeSearchResult> results);
scoped_refptr<base::UpdateableSequencedTaskRunner> GetDBTaskRunnerForTest();
void GetURLsInTableForTest(const std::string& table,
base::OnceCallback<void(std::set<GURL>)> callback);
void PostTaskToDBForTest(base::OnceClosure callback);
void EraseDatabaseAndCreateNew();
void DeleteAllOriginData(const std::set<url::Origin>& origins);
void DeleteAllURLData(const std::set<GURL>& urls);
private: private:
scoped_refptr<MediaHistoryStoreInternal> db_; friend class base::RefCountedThreadSafe<MediaHistoryStore>;
~MediaHistoryStore();
Profile* const profile_; scoped_refptr<base::UpdateableSequencedTaskRunner> db_task_runner_;
const base::FilePath db_path_;
std::unique_ptr<sql::Database> db_;
sql::MetaTable meta_table_;
scoped_refptr<MediaHistoryOriginTable> origin_table_;
scoped_refptr<MediaHistoryPlaybackTable> playback_table_;
scoped_refptr<MediaHistorySessionTable> session_table_;
scoped_refptr<MediaHistorySessionImagesTable> session_images_table_;
scoped_refptr<MediaHistoryImagesTable> images_table_;
scoped_refptr<MediaHistoryFeedsTable> feeds_table_;
scoped_refptr<MediaHistoryFeedItemsTable> feed_items_table_;
bool initialization_successful_;
}; };
} // namespace media_history } // namespace media_history
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
#include "chrome/browser/media/history/media_history_feed_items_table.h" #include "chrome/browser/media/history/media_history_feed_items_table.h"
#include "chrome/browser/media/history/media_history_feeds_table.h" #include "chrome/browser/media/history/media_history_feeds_table.h"
#include "chrome/browser/media/history/media_history_images_table.h" #include "chrome/browser/media/history/media_history_images_table.h"
#include "chrome/browser/media/history/media_history_keyed_service.h" #include "chrome/browser/media/history/media_history_origin_table.h"
#include "chrome/browser/media/history/media_history_playback_table.h"
#include "chrome/browser/media/history/media_history_session_images_table.h" #include "chrome/browser/media/history/media_history_session_images_table.h"
#include "chrome/browser/media/history/media_history_session_table.h" #include "chrome/browser/media/history/media_history_session_table.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
......
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