Commit 6f17cf1e authored by Becca Hughes's avatar Becca Hughes Committed by Chromium LUCI CQ

Add a method to get new Media Feeds and store the user consent

Adds a method which will get newly discovered Media Feeds which
will then be displayed to the user. When the user gives their
consent then this will be stored.

Change-Id: I70cc391e394d7c21334c3722526a33e30cf9c45e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568290Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834430}
parent 27d288e5
......@@ -324,6 +324,15 @@ std::vector<media_feeds::mojom::MediaFeedPtr> MediaHistoryFeedsTable::GetRows(
statement.BindInt64(
0, static_cast<int>(media_feeds::mojom::FeedUserStatus::kEnabled));
} else if (request.type ==
MediaHistoryKeyedService::GetMediaFeedsRequest::Type::kNewFeeds) {
sql.push_back("FROM mediaFeed WHERE user_status = ?");
statement.Assign(DB()->GetCachedStatement(
SQL_FROM_HERE, base::JoinString(sql, " ").c_str()));
statement.BindInt64(
0, static_cast<int>(media_feeds::mojom::FeedUserStatus::kAuto));
} else {
sql.push_back("FROM mediaFeed");
......
......@@ -433,6 +433,13 @@ MediaHistoryKeyedService::GetMediaFeedsRequest::CreateSelectedFeedsForFetch() {
return request;
}
MediaHistoryKeyedService::GetMediaFeedsRequest
MediaHistoryKeyedService::GetMediaFeedsRequest::CreateNewFeeds() {
GetMediaFeedsRequest request;
request.type = Type::kNewFeeds;
return request;
}
MediaHistoryKeyedService::GetMediaFeedsRequest::GetMediaFeedsRequest() =
default;
......
......@@ -250,8 +250,11 @@ class MediaHistoryKeyedService : public KeyedService,
// |origin_audio_video_watchtime_percentile| field in |MediaFeedPtr|.
kTopFeedsForDisplay,
// Returns the feeeds that have been selected by the user to be fetched.
// Returns the feeds that have been selected by the user to be fetched.
kSelectedFeedsForFetch,
// Returns the feeds that have been newly discovered.
kNewFeeds,
};
static GetMediaFeedsRequest CreateTopFeedsForFetch(
......@@ -266,6 +269,8 @@ class MediaHistoryKeyedService : public KeyedService,
static GetMediaFeedsRequest CreateSelectedFeedsForFetch();
static GetMediaFeedsRequest CreateNewFeeds();
GetMediaFeedsRequest();
GetMediaFeedsRequest(const GetMediaFeedsRequest& t);
......
......@@ -3078,6 +3078,41 @@ TEST_P(MediaHistoryStoreFeedsTest, GetSelectedFeedsForFetch) {
}
}
TEST_P(MediaHistoryStoreFeedsTest, GetNewFeeds) {
const GURL feed_url_a("https://www.google.com/feed");
const GURL feed_url_b("https://www.google.co.uk/feed");
const GURL feed_url_c("https://www.google.co.tv/feed");
DiscoverMediaFeed(feed_url_a);
DiscoverMediaFeed(feed_url_b);
DiscoverMediaFeed(feed_url_c);
WaitForDB();
// If we are read only we should use -1 as a placeholder feed id because the
// feed will not have been stored. This is so we can run the rest of the test
// to ensure a no-op.
const int feed_id_a = IsReadOnly() ? -1 : GetMediaFeedsSync(service())[0]->id;
const int feed_id_b = IsReadOnly() ? -1 : GetMediaFeedsSync(service())[1]->id;
const int feed_id_c = IsReadOnly() ? -1 : GetMediaFeedsSync(service())[2]->id;
service()->UpdateFeedUserStatus(
feed_id_a, media_feeds::mojom::FeedUserStatus::kDisabled);
service()->UpdateFeedUserStatus(feed_id_b,
media_feeds::mojom::FeedUserStatus::kEnabled);
WaitForDB();
auto feeds = GetMediaFeedsSync(
service(),
MediaHistoryKeyedService::GetMediaFeedsRequest::CreateNewFeeds());
if (IsReadOnly()) {
EXPECT_TRUE(feeds.empty());
} else {
ASSERT_EQ(1u, feeds.size());
EXPECT_EQ(feed_id_c, feeds[0]->id);
}
}
#endif // !defined(OS_ANDROID)
} // namespace media_history
......@@ -266,6 +266,31 @@ void KaleidoscopeDataProviderImpl::RecordDialogClosedHistogram(bool value) {
base::UmaHistogramBoolean("Media.Kaleidoscope.DialogClosed", value);
}
void KaleidoscopeDataProviderImpl::GetNewMediaFeeds(
GetNewMediaFeedsCallback cb) {
auto* prefs = profile_->GetPrefs();
DCHECK(prefs);
const bool auto_enabled =
prefs->GetBoolean(kaleidoscope::prefs::kKaleidoscopeAutoSelectMediaFeeds);
GetMediaHistoryService()->GetMediaFeeds(
media_history::MediaHistoryKeyedService::GetMediaFeedsRequest::
CreateNewFeeds(),
base::BindOnce(
[](GetNewMediaFeedsCallback cb, bool auto_enabled,
std::vector<media_feeds::mojom::MediaFeedPtr> feeds) {
std::move(cb).Run(std::move(feeds), auto_enabled);
},
std::move(cb), auto_enabled));
}
void KaleidoscopeDataProviderImpl::UpdateFeedUserStatus(
int64_t feed_id,
media_feeds::mojom::FeedUserStatus status) {
GetMediaHistoryService()->UpdateFeedUserStatus(feed_id, status);
}
media_history::MediaHistoryKeyedService*
KaleidoscopeDataProviderImpl::GetMediaHistoryService() {
return media_history::MediaHistoryKeyedServiceFactory::GetForProfile(
......
......@@ -69,6 +69,9 @@ class KaleidoscopeDataProviderImpl
const std::vector<std::string>& providers) override;
void RecordTimeTakenToStartWatchHistogram(base::TimeDelta time) override;
void RecordDialogClosedHistogram(bool value) override;
void GetNewMediaFeeds(GetNewMediaFeedsCallback cb) override;
void UpdateFeedUserStatus(int64_t feed_id,
media_feeds::mojom::FeedUserStatus status) override;
private:
media_history::MediaHistoryKeyedService* GetMediaHistoryService();
......
......@@ -112,6 +112,16 @@ interface KaleidoscopeDataProvider {
// Records a histogram when the dialog was closed of whether the user selected
// a link from the dialog.
RecordDialogClosedHistogram(bool value);
// Returns Media Feeds that are "new" and should be displayed to the user so
// that they know this Media Feed is now being fetched.
GetNewMediaFeeds() => (
array<media_feeds.mojom.MediaFeed> feeds,
bool automatic_selection_enabled);
// Update the selection the user made as to whether they want this Media Feed
// displayed in Kaleidoscope.
UpdateFeedUserStatus(int64 feed_id, media_feeds.mojom.FeedUserStatus status);
};
// Handles identity related tasks.
......
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