Commit 6b36b504 authored by Ian Wells's avatar Ian Wells Committed by Commit Bot

feedv2: Try uploading actions when Chrome enters background

Bug: 1044139
Change-Id: I9afeba55bbe9b42c47073ac1801ab2ddb5d7b6bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2348546
Commit-Queue: Ian Wells <iwells@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797095}
parent 06370fda
...@@ -61,6 +61,11 @@ void OverrideWithFinch(Config* config) { ...@@ -61,6 +61,11 @@ void OverrideWithFinch(Config* config) {
config->load_more_trigger_lookahead = base::GetFieldTrialParamByFeatureAsInt( config->load_more_trigger_lookahead = base::GetFieldTrialParamByFeatureAsInt(
kInterestFeedV2, "load_more_trigger_lookahead", kInterestFeedV2, "load_more_trigger_lookahead",
config->load_more_trigger_lookahead); config->load_more_trigger_lookahead);
config->upload_actions_on_enter_background =
base::GetFieldTrialParamByFeatureAsBool(
kInterestFeedV2, "upload_actions_on_enter_background",
config->upload_actions_on_enter_background);
} }
} // namespace } // namespace
...@@ -78,4 +83,7 @@ void SetFeedConfigForTesting(const Config& config) { ...@@ -78,4 +83,7 @@ void SetFeedConfigForTesting(const Config& config) {
g_config = config; g_config = config;
} }
Config::Config() = default;
Config::Config(const Config& other) = default;
} // namespace feed } // namespace feed
...@@ -34,6 +34,11 @@ struct Config { ...@@ -34,6 +34,11 @@ struct Config {
// How far ahead in number of items from last visible item to final item // How far ahead in number of items from last visible item to final item
// before attempting to load more content. // before attempting to load more content.
int load_more_trigger_lookahead = 5; int load_more_trigger_lookahead = 5;
// Whether to attempt uploading actions when Chrome is hidden.
bool upload_actions_on_enter_background = true;
Config();
Config(const Config& other);
}; };
// Gets the current configuration. // Gets the current configuration.
......
...@@ -213,6 +213,11 @@ void FeedStream::InitialStreamLoadComplete(LoadStreamTask::Result result) { ...@@ -213,6 +213,11 @@ void FeedStream::InitialStreamLoadComplete(LoadStreamTask::Result result) {
void FeedStream::OnEnterBackground() { void FeedStream::OnEnterBackground() {
metrics_reporter_->OnEnterBackground(); metrics_reporter_->OnEnterBackground();
if (GetFeedConfig().upload_actions_on_enter_background) {
task_queue_.AddTask(std::make_unique<UploadActionsTask>(
this, base::BindOnce(&FeedStream::UploadActionsComplete,
base::Unretained(this))));
}
} }
void FeedStream::AttachSurface(SurfaceInterface* surface) { void FeedStream::AttachSurface(SurfaceInterface* surface) {
......
...@@ -1498,6 +1498,27 @@ TEST_F(FeedStreamTest, LoadMoreUploadsActions) { ...@@ -1498,6 +1498,27 @@ TEST_F(FeedStreamTest, LoadMoreUploadsActions) {
network_.action_request_sent->feed_action(0).content_id().id()); network_.action_request_sent->feed_action(0).content_id().id());
} }
TEST_F(FeedStreamTest, BackgroundingAppUploadsActions) {
stream_->UploadAction(MakeFeedAction(1ul), false, base::DoNothing());
stream_->OnEnterBackground();
WaitForIdleTaskQueue();
EXPECT_EQ(1, network_.action_request_sent->feed_action_size());
EXPECT_EQ(1ul,
network_.action_request_sent->feed_action(0).content_id().id());
}
TEST_F(FeedStreamTest, BackgroundingAppDoesNotUploadActions) {
Config config;
config.upload_actions_on_enter_background = false;
SetFeedConfigForTesting(config);
network_.action_request_call_count = 0;
stream_->UploadAction(MakeFeedAction(1ul), false, base::DoNothing());
stream_->OnEnterBackground();
WaitForIdleTaskQueue();
EXPECT_EQ(0, network_.action_request_call_count);
}
TEST_F(FeedStreamTest, UploadActionsOneBatch) { TEST_F(FeedStreamTest, UploadActionsOneBatch) {
UploadActions( UploadActions(
{MakeFeedAction(97ul), MakeFeedAction(98ul), MakeFeedAction(99ul)}); {MakeFeedAction(97ul), MakeFeedAction(98ul), MakeFeedAction(99ul)});
......
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