blob: f89829638e977eab10e4dbf5037d277c5d23b4ca [file] [log] [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TRIGGER_SCHEDULER_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TRIGGER_SCHEDULER_H_
#include <memory>
#include "base/time/time.h"
#include "base/timer/timer.h"
namespace content {
class StoragePartition;
} // namespace content
class Profile;
class NotificationTriggerScheduler {
public:
static std::unique_ptr<NotificationTriggerScheduler> Create();
// Triggers pending notifications for all loaded profiles.
static void TriggerNotifications();
NotificationTriggerScheduler(const NotificationTriggerScheduler&) = delete;
NotificationTriggerScheduler& operator=(const NotificationTriggerScheduler&) =
delete;
virtual ~NotificationTriggerScheduler();
// Schedules a trigger at |timestamp| that calls TriggerNotifications on each
// StoragePartition of profiles that have pending notifications at that time.
// If there is an existing earlier trigger set, this is a nop. Otherwise this
// overwrites the existing trigger so only the earliest is set at any time.
virtual void ScheduleTrigger(base::Time timestamp);
protected:
// Use NotificationTriggerScheduler::Create() to get an instance of this.
NotificationTriggerScheduler();
// Triggers pending notifications for |partition|. Virtual so we can observe
// PlatformNotificationContextImpl::TriggerNotifications() calls in tests.
virtual void TriggerNotificationsForStoragePartition(
content::StoragePartition* partition);
private:
// Triggers pending notifications for |profile|.
static void TriggerNotificationsForProfile(Profile* profile);
base::OneShotTimer trigger_timer_;
};
#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TRIGGER_SCHEDULER_H_