Commit 09cb0ade authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Notification scheduler: Use BackgroundTaskCoordinator.

This CL uses the BackgroundTaskCoordinator to scedule background task
with platform API.

Bug: 963283,930968
Change-Id: I9d6af682cdc456f66dcab88997eee08acab11320
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1639560
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666112}
parent 9e213600
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/notifications/scheduler/internal/background_task_coordinator.h"
#include "chrome/browser/notifications/scheduler/internal/display_decider.h" #include "chrome/browser/notifications/scheduler/internal/display_decider.h"
#include "chrome/browser/notifications/scheduler/internal/distribution_policy.h" #include "chrome/browser/notifications/scheduler/internal/distribution_policy.h"
#include "chrome/browser/notifications/scheduler/internal/icon_store.h" #include "chrome/browser/notifications/scheduler/internal/icon_store.h"
...@@ -187,9 +188,15 @@ class NotificationSchedulerImpl ...@@ -187,9 +188,15 @@ class NotificationSchedulerImpl
} }
void ScheduleBackgroundTask() { void ScheduleBackgroundTask() {
// TODO(xingliu): Implements a class to determine the next background task BackgroundTaskCoordinator::Notifications notifications;
// based on scheduled notification data. context_->notification_manager()->GetAllNotifications(&notifications);
NOTIMPLEMENTED(); BackgroundTaskCoordinator::ClientStates client_states;
context_->impression_tracker()->GetClientStates(&client_states);
// TODO(xingliu): Pass SchedulerTaskTime from background task.
context_->background_task_coordinator()->ScheduleBackgroundTask(
std::move(notifications), std::move(client_states),
SchedulerTaskTime::kMorning);
} }
void OnClick(const std::string& notification_id) override { void OnClick(const std::string& notification_id) override {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <utility> #include <utility>
#include "base/time/default_clock.h"
#include "chrome/browser/notifications/scheduler/internal/background_task_coordinator.h"
#include "chrome/browser/notifications/scheduler/internal/display_decider.h" #include "chrome/browser/notifications/scheduler/internal/display_decider.h"
#include "chrome/browser/notifications/scheduler/internal/icon_store.h" #include "chrome/browser/notifications/scheduler/internal/icon_store.h"
#include "chrome/browser/notifications/scheduler/internal/impression_history_tracker.h" #include "chrome/browser/notifications/scheduler/internal/impression_history_tracker.h"
...@@ -18,18 +20,21 @@ namespace notifications { ...@@ -18,18 +20,21 @@ namespace notifications {
NotificationSchedulerContext::NotificationSchedulerContext( NotificationSchedulerContext::NotificationSchedulerContext(
std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar, std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar,
std::unique_ptr<NotificationBackgroundTaskScheduler> scheduler, std::unique_ptr<NotificationBackgroundTaskScheduler> background_task,
std::unique_ptr<IconStore> icon_store, std::unique_ptr<IconStore> icon_store,
std::unique_ptr<ImpressionHistoryTracker> impression_tracker, std::unique_ptr<ImpressionHistoryTracker> impression_tracker,
std::unique_ptr<ScheduledNotificationManager> notification_manager, std::unique_ptr<ScheduledNotificationManager> notification_manager,
std::unique_ptr<DisplayDecider> display_decider, std::unique_ptr<DisplayDecider> display_decider,
std::unique_ptr<SchedulerConfig> config) std::unique_ptr<SchedulerConfig> config)
: client_registrar_(std::move(client_registrar)), : client_registrar_(std::move(client_registrar)),
background_task_scheduler_(std::move(scheduler)),
impression_tracker_(std::move(impression_tracker)), impression_tracker_(std::move(impression_tracker)),
notification_manager_(std::move(notification_manager)), notification_manager_(std::move(notification_manager)),
display_decider_(std::move(display_decider)), display_decider_(std::move(display_decider)),
config_(std::move(config)) {} config_(std::move(config)),
background_task_coordinator_(std::make_unique<BackgroundTaskCoordinator>(
std::move(background_task),
config_.get(),
base::DefaultClock::GetInstance())) {}
NotificationSchedulerContext::~NotificationSchedulerContext() = default; NotificationSchedulerContext::~NotificationSchedulerContext() = default;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
namespace notifications { namespace notifications {
class BackgroundTaskCoordinator;
class DisplayDecider; class DisplayDecider;
class IconStore; class IconStore;
class ImpressionHistoryTracker; class ImpressionHistoryTracker;
...@@ -27,7 +28,7 @@ class NotificationSchedulerContext { ...@@ -27,7 +28,7 @@ class NotificationSchedulerContext {
public: public:
NotificationSchedulerContext( NotificationSchedulerContext(
std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar, std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar,
std::unique_ptr<NotificationBackgroundTaskScheduler> scheduler, std::unique_ptr<NotificationBackgroundTaskScheduler> background_task,
std::unique_ptr<IconStore> icon_store, std::unique_ptr<IconStore> icon_store,
std::unique_ptr<ImpressionHistoryTracker> impression_tracker, std::unique_ptr<ImpressionHistoryTracker> impression_tracker,
std::unique_ptr<ScheduledNotificationManager> notification_manager, std::unique_ptr<ScheduledNotificationManager> notification_manager,
...@@ -39,8 +40,8 @@ class NotificationSchedulerContext { ...@@ -39,8 +40,8 @@ class NotificationSchedulerContext {
return client_registrar_.get(); return client_registrar_.get();
} }
NotificationBackgroundTaskScheduler* background_task_scheduler() { BackgroundTaskCoordinator* background_task_coordinator() {
return background_task_scheduler_.get(); return background_task_coordinator_.get();
} }
IconStore* icon_store() { return icon_store_.get(); } IconStore* icon_store() { return icon_store_.get(); }
...@@ -61,10 +62,6 @@ class NotificationSchedulerContext { ...@@ -61,10 +62,6 @@ class NotificationSchedulerContext {
// Holds a list of clients using the notification scheduler system. // Holds a list of clients using the notification scheduler system.
std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar_; std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar_;
// Used to schedule background task in OS level.
std::unique_ptr<NotificationBackgroundTaskScheduler>
background_task_scheduler_;
// Stores notification icons. // Stores notification icons.
std::unique_ptr<IconStore> icon_store_; std::unique_ptr<IconStore> icon_store_;
...@@ -80,6 +77,9 @@ class NotificationSchedulerContext { ...@@ -80,6 +77,9 @@ class NotificationSchedulerContext {
// System configuration. // System configuration.
std::unique_ptr<SchedulerConfig> config_; std::unique_ptr<SchedulerConfig> config_;
// Used to schedule background task in OS level.
std::unique_ptr<BackgroundTaskCoordinator> background_task_coordinator_;
DISALLOW_COPY_AND_ASSIGN(NotificationSchedulerContext); DISALLOW_COPY_AND_ASSIGN(NotificationSchedulerContext);
}; };
......
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