Commit a06b143a authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Notification scheduler: Rewrite BackgroundTaskCoordinator.

This CL rewrites the logic to schedule background task in
BackgroundTaskCoordinator. Now it's based on deliver time window.

The old unit tests are deleted, new unit tests will be added in
following CL.

Bug: 991010
Change-Id: I8a05e8178d94b1daadf87d8abc8f9e0bac783e37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1756439
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689105}
parent 3bcd14d3
......@@ -39,15 +39,13 @@ class BackgroundTaskCoordinator {
static std::unique_ptr<BackgroundTaskCoordinator> Create(
std::unique_ptr<NotificationBackgroundTaskScheduler> background_task,
const SchedulerConfig* config,
TimeRandomizer time_randomizer,
base::Clock* clock);
virtual ~BackgroundTaskCoordinator();
// Schedule background task based on current notification in the storage.
virtual void ScheduleBackgroundTask(Notifications notifications,
ClientStates client_states,
SchedulerTaskTime task_start_time) = 0;
ClientStates client_states) = 0;
};
} // namespace notifications
......
......@@ -6,6 +6,7 @@
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/strings/stringprintf.h"
......@@ -75,8 +76,6 @@ class DisplayDeciderTest : public testing::Test {
void SetUp() override {
// Setup configuration used by this test.
config_.morning_task_hour = 7;
config_.evening_task_hour = 18;
config_.max_daily_shown_all_type = 3;
}
......
......@@ -267,7 +267,7 @@ class NotificationSchedulerImpl : public NotificationScheduler,
context_->impression_tracker()->GetClientStates(&client_states);
context_->background_task_coordinator()->ScheduleBackgroundTask(
std::move(notifications), std::move(client_states), task_start_time_);
std::move(notifications), std::move(client_states));
}
void OnUserAction(const UserActionData& action_data) override {
......
......@@ -207,7 +207,7 @@ TEST_F(NotificationSchedulerTest, Schedule) {
auto param = std::unique_ptr<NotificationParams>();
EXPECT_CALL(*notification_manager(), ScheduleNotification(_));
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _, _));
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _));
scheduler()->Schedule(std::move(param));
}
......@@ -217,7 +217,7 @@ TEST_F(NotificationSchedulerTest, DeleteAllNotifications) {
// Currently we don't reschedule background task even if all the notifications
// are deleted.
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _, _)).Times(0);
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _)).Times(0);
EXPECT_CALL(*notification_manager(),
DeleteNotifications(SchedulerClientType::kTest1));
scheduler()->DeleteAllNotifications(SchedulerClientType::kTest1);
......@@ -260,7 +260,7 @@ TEST_F(NotificationSchedulerTest, BackgroundTaskStartShowNothing) {
EXPECT_CALL(*display_agent(), ShowNotification(_, _)).Times(0);
EXPECT_CALL(*notification_manager(), DisplayNotification(_)).Times(0);
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _, _));
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _));
scheduler()->OnStartTask(SchedulerTaskTime::kMorning, base::DoNothing());
}
......@@ -308,7 +308,7 @@ TEST_F(NotificationSchedulerTest, BackgroundTaskStartShowNotification) {
notification_manager_delegate()->DisplayNotification(std::move(entry));
}));
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _, _));
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _));
scheduler()->OnStartTask(SchedulerTaskTime::kMorning, base::DoNothing());
loop.Run();
......@@ -317,7 +317,7 @@ TEST_F(NotificationSchedulerTest, BackgroundTaskStartShowNotification) {
// Test to simulate a background task stopped by the OS.
TEST_F(NotificationSchedulerTest, BackgroundTaskStop) {
Init();
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _, _));
EXPECT_CALL(*task_coordinator(), ScheduleBackgroundTask(_, _));
scheduler()->OnStopTask(SchedulerTaskTime::kMorning);
}
......
......@@ -18,12 +18,6 @@ constexpr base::TimeDelta kDefaultImpressionExpiration =
constexpr base::TimeDelta kDefaultSuppressionDuration =
base::TimeDelta::FromDays(56);
// The morning task by default will run at 7am.
constexpr int kDefaultMorningTaskHour = 7;
// The evening task by default will run at 6pm.
constexpr int kDefaultEveningTaskHour = 18;
// Check consecutive notification dismisses in this duration to generate a
// dismiss event.
constexpr base::TimeDelta kDefaultDimissDuration = base::TimeDelta::FromDays(7);
......@@ -33,8 +27,8 @@ constexpr base::TimeDelta kDefaultBackgroundTaskWindowDuration =
base::TimeDelta::FromHours(1);
// Default randomized time window to distribute load from user actions.
constexpr base::TimeDelta kDefaultBackgroundTaskRandomTimeWindow =
base::TimeDelta::FromHours(1);
constexpr base::TimeDelta kDefaultBackgroundTaskMinInterval =
base::TimeDelta::FromMinutes(10);
// static
std::unique_ptr<SchedulerConfig> SchedulerConfig::Create() {
......@@ -50,11 +44,8 @@ SchedulerConfig::SchedulerConfig()
suppression_duration(kDefaultSuppressionDuration),
dismiss_count(3),
dismiss_duration(kDefaultDimissDuration),
morning_task_hour(kDefaultMorningTaskHour),
evening_task_hour(kDefaultEveningTaskHour),
background_task_window_duration(kDefaultBackgroundTaskWindowDuration),
background_task_random_time_window(
kDefaultBackgroundTaskRandomTimeWindow) {
background_task_min_interval(kDefaultBackgroundTaskMinInterval) {
// TODO(xingliu): Add constructor using finch data.
}
......
......@@ -49,19 +49,11 @@ struct SchedulerConfig {
// in this duration, to generate a dismiss event.
base::TimeDelta dismiss_duration;
// The hour (from 0 to 23) to run the morning background task for notification
// scheduler.
int morning_task_hour;
// The hour (from 0 to 23) to run the evening background task for notification
// scheduler.
int evening_task_hour;
// The time window to launch the background task.
base::TimeDelta background_task_window_duration;
// A random time delta to distribute the user clicks to a time window.
base::TimeDelta background_task_random_time_window;
// The minimum interval between background tasks.
base::TimeDelta background_task_min_interval;
private:
DISALLOW_COPY_AND_ASSIGN(SchedulerConfig);
......
......@@ -97,8 +97,6 @@ KeyedService* CreateNotificationScheduleService(
auto background_task_coordinator = BackgroundTaskCoordinator::Create(
std::move(background_task_scheduler), config.get(),
base::BindRepeating(&BackgroundTaskCoordinator::DefaultTimeRandomizer,
config->background_task_random_time_window),
base::DefaultClock::GetInstance());
auto display_decider = DisplayDecider::Create(
......
......@@ -15,10 +15,9 @@ class MockBackgroundTaskCoordinator : public BackgroundTaskCoordinator {
public:
MockBackgroundTaskCoordinator();
~MockBackgroundTaskCoordinator() override;
MOCK_METHOD3(ScheduleBackgroundTask,
MOCK_METHOD2(ScheduleBackgroundTask,
void(BackgroundTaskCoordinator::Notifications notifications,
BackgroundTaskCoordinator::ClientStates client_states,
SchedulerTaskTime task_start_time));
BackgroundTaskCoordinator::ClientStates client_states));
};
} // namespace test
......
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