Notification: Setup NotificationScheduleService.
This CL adds NotifcationScheduleService keyed service code stack with
empty implementations.
TBR=peter@chromium.org
Bug: 930968
Change-Id: I5cd097455279ffa732375da0f53f6d33af51e1b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1469065
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637503}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 0a469eb..a53367b 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -914,6 +914,8 @@
"notifications/notification_platform_bridge.h",
"notifications/notification_platform_bridge_mac.h",
"notifications/notification_platform_bridge_mac.mm",
+ "notifications/notification_schedule_service_factory.cc",
+ "notifications/notification_schedule_service_factory.h",
"notifications/notification_ui_manager.h",
"notifications/notifier_state_tracker.cc",
"notifications/notifier_state_tracker.h",
diff --git a/chrome/browser/notifications/notification_schedule_service_factory.cc b/chrome/browser/notifications/notification_schedule_service_factory.cc
new file mode 100644
index 0000000..baa6860
--- /dev/null
+++ b/chrome/browser/notifications/notification_schedule_service_factory.cc
@@ -0,0 +1,46 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/notification_schedule_service_factory.h"
+
+#include "chrome/browser/notifications/scheduler/notification_schedule_service_impl.h"
+#include "chrome/browser/profiles/incognito_helpers.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+
+// static
+NotificationScheduleServiceFactory*
+NotificationScheduleServiceFactory::GetInstance() {
+ static base::NoDestructor<NotificationScheduleServiceFactory> instance;
+ return instance.get();
+}
+
+// static
+notifications::NotificationScheduleService*
+NotificationScheduleServiceFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return static_cast<notifications::NotificationScheduleService*>(
+ GetInstance()->GetServiceForBrowserContext(context, true /* create */));
+}
+
+NotificationScheduleServiceFactory::NotificationScheduleServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "notifications::NotificationScheduleService",
+ BrowserContextDependencyManager::GetInstance()) {}
+
+NotificationScheduleServiceFactory::~NotificationScheduleServiceFactory() =
+ default;
+
+KeyedService* NotificationScheduleServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ // TODO(xingliu): Build the actual instance here.
+ return static_cast<KeyedService*>(
+ new notifications::NotificationScheduleServiceImpl());
+}
+
+content::BrowserContext*
+NotificationScheduleServiceFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ // Separate incognito instance that does nothing.
+ return chrome::GetBrowserContextOwnInstanceInIncognito(context);
+}
diff --git a/chrome/browser/notifications/notification_schedule_service_factory.h b/chrome/browser/notifications/notification_schedule_service_factory.h
new file mode 100644
index 0000000..a6c141b
--- /dev/null
+++ b/chrome/browser/notifications/notification_schedule_service_factory.h
@@ -0,0 +1,38 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// 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_SCHEDULE_SERVICE_FACTORY_H_
+#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_SCHEDULE_SERVICE_FACTORY_H_
+
+#include "base/macros.h"
+#include "base/no_destructor.h"
+#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
+
+namespace notifications {
+class NotificationScheduleService;
+} // namespace notifications
+
+class NotificationScheduleServiceFactory
+ : public BrowserContextKeyedServiceFactory {
+ public:
+ static NotificationScheduleServiceFactory* GetInstance();
+ static notifications::NotificationScheduleService* GetForBrowserContext(
+ content::BrowserContext* context);
+
+ private:
+ friend class base::NoDestructor<NotificationScheduleServiceFactory>;
+
+ // BrowserContextKeyedServiceFactory implementation.
+ KeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* context) const override;
+ content::BrowserContext* GetBrowserContextToUse(
+ content::BrowserContext* context) const override;
+
+ NotificationScheduleServiceFactory();
+ ~NotificationScheduleServiceFactory() override;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationScheduleServiceFactory);
+};
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_SCHEDULE_SERVICE_FACTORY_H_
diff --git a/chrome/browser/notifications/proto/icon.proto b/chrome/browser/notifications/proto/icon.proto
index 6560591..9e8978c3 100644
--- a/chrome/browser/notifications/proto/icon.proto
+++ b/chrome/browser/notifications/proto/icon.proto
@@ -6,7 +6,7 @@
option optimize_for = LITE_RUNTIME;
-package notifications;
+package notifications.proto;
// Stores the icon used in a notification. The icon is in PNG format. Each time
// we should only load one icon asynchronously into memory.
diff --git a/chrome/browser/notifications/proto/notification_data.proto b/chrome/browser/notifications/proto/notification_data.proto
index 53e81fd..315a7b5 100644
--- a/chrome/browser/notifications/proto/notification_data.proto
+++ b/chrome/browser/notifications/proto/notification_data.proto
@@ -6,7 +6,7 @@
option optimize_for = LITE_RUNTIME;
-package notifications;
+package notifications.proto;
// Stores a scheduled notification which will be displayed in the future.
// Next tag: 6
diff --git a/chrome/browser/notifications/scheduler/BUILD.gn b/chrome/browser/notifications/scheduler/BUILD.gn
index 7abe741..02f3450 100644
--- a/chrome/browser/notifications/scheduler/BUILD.gn
+++ b/chrome/browser/notifications/scheduler/BUILD.gn
@@ -8,18 +8,46 @@
import("//build/config/android/rules.gni")
}
-source_set("scheduler") {
+group("scheduler") {
+ # TODO(xingliu): Change this to a source set when we have code to be used by
+ # NotificationScheduleServiceFactory.
+ deps = [
+ ":lib",
+ ]
+
+ public_deps = [
+ ":public",
+ ]
+}
+
+source_set("public") {
sources = [
"notification_background_task_scheduler.h",
"notification_data.cc",
"notification_data.h",
+ "notification_params.cc",
+ "notification_params.h",
+ "notification_schedule_service.h",
"schedule_params.cc",
"schedule_params.h",
]
deps = [
"//base",
- "//skia",
- "//ui/message_center/public/cpp",
+ "//components/keyed_service/core",
+ ]
+}
+
+# Internal library that embedders should not directly depend on.
+source_set("lib") {
+ sources = [
+ "notification_schedule_service_impl.cc",
+ "notification_schedule_service_impl.h",
+ ]
+
+ deps = [
+ ":public",
+ "//base",
+ "//components/keyed_service/core",
]
}
diff --git a/chrome/browser/notifications/scheduler/notification_data.cc b/chrome/browser/notifications/scheduler/notification_data.cc
index c2ef102..18cc897 100644
--- a/chrome/browser/notifications/scheduler/notification_data.cc
+++ b/chrome/browser/notifications/scheduler/notification_data.cc
@@ -4,14 +4,12 @@
#include "chrome/browser/notifications/scheduler/notification_data.h"
-#include "chrome/browser/notifications/scheduler/schedule_params.h"
+namespace notifications {
-NotificationData::NotificationData(
- Type type,
- std::unique_ptr<message_center::Notification> notification,
- std::unique_ptr<ScheduleParams> schedule_params)
- : type_(type),
- notification_(std::move(notification)),
- schedule_params_(std::move(schedule_params)) {}
+NotificationData::NotificationData() = default;
+
+NotificationData::NotificationData(const NotificationData& other) = default;
NotificationData::~NotificationData() = default;
+
+} // namespace notifications
diff --git a/chrome/browser/notifications/scheduler/notification_data.h b/chrome/browser/notifications/scheduler/notification_data.h
index 6372ae1..b8135dc 100644
--- a/chrome/browser/notifications/scheduler/notification_data.h
+++ b/chrome/browser/notifications/scheduler/notification_data.h
@@ -5,38 +5,38 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_DATA_H_
#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_DATA_H_
-#include <memory>
+#include <string>
-#include "base/macros.h"
-#include "ui/message_center/public/cpp/notification.h"
+namespace notifications {
-struct ScheduleParams;
-
-// Struct used to schedule a notification.
-class NotificationData {
- public:
- enum class Type {
- PLACE_HOLDER,
- };
-
- NotificationData(Type type,
- std::unique_ptr<message_center::Notification> notification,
- std::unique_ptr<ScheduleParams> schedule_params);
+// Contains data used to display a scheduled notification. All fields will be
+// persisted to disk as protobuffer NotificationData. The clients of
+// notification scheduler can optionally use the texts or icon in this struct,
+// or use hard coded assets id.
+struct NotificationData {
+ NotificationData();
+ NotificationData(const NotificationData& other);
~NotificationData();
- Type type() const { return type_; }
+ // The unique identifier of the notification. This is not used as the key for
+ // the database entry, but the id of other notification struct plumbed to
+ // the scheduler system.
+ std::string id;
- private:
- Type type_;
+ // The title of the notification.
+ std::string title;
- // Notification data that the client can optionally choose to use when showing
- // a notification. Client should only use this when the data is dynamically
- // generated, such as URL to navigate when the user clicks the notification.
- std::unique_ptr<message_center::Notification> notification_;
+ // The body text of the notification.
+ std::string message;
- std::unique_ptr<ScheduleParams> schedule_params_;
+ // The unique identifier of the icon, which must be loaded asynchronously into
+ // memory.
+ std::string icon_uuid;
- DISALLOW_COPY_AND_ASSIGN(NotificationData);
+ // URL of the web site responsible for showing the notification.
+ std::string url;
};
+} // namespace notifications
+
#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_DATA_H_
diff --git a/chrome/browser/notifications/scheduler/notification_params.cc b/chrome/browser/notifications/scheduler/notification_params.cc
new file mode 100644
index 0000000..63d1b45
--- /dev/null
+++ b/chrome/browser/notifications/scheduler/notification_params.cc
@@ -0,0 +1,22 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/scheduler/notification_params.h"
+
+#include <utility>
+
+#include "chrome/browser/notifications/scheduler/schedule_params.h"
+
+namespace notifications {
+
+NotificationParams::NotificationParams(Type type,
+ NotificationData notification,
+ ScheduleParams schedule_params)
+ : type(type),
+ notification(std::move(notification)),
+ schedule_params(std::move(schedule_params)) {}
+
+NotificationParams::~NotificationParams() = default;
+
+} // namespace notifications
diff --git a/chrome/browser/notifications/scheduler/notification_params.h b/chrome/browser/notifications/scheduler/notification_params.h
new file mode 100644
index 0000000..8ad881f
--- /dev/null
+++ b/chrome/browser/notifications/scheduler/notification_params.h
@@ -0,0 +1,39 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_PARAMS_H_
+#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_PARAMS_H_
+
+#include <memory>
+
+#include "chrome/browser/notifications/scheduler/notification_data.h"
+#include "chrome/browser/notifications/scheduler/schedule_params.h"
+
+namespace notifications {
+
+// Struct used to schedule a notification.
+struct NotificationParams {
+ enum class Type {
+ PLACE_HOLDER,
+ };
+
+ NotificationParams(Type type,
+ NotificationData notification,
+ ScheduleParams schedule_params);
+ ~NotificationParams();
+
+ // The type of notification using the scheduling system.
+ Type type;
+
+ // Data used to show the notification, such as text or title on the
+ // notification.
+ NotificationData notification;
+
+ // Scheduling details used to determine when to show the notification.
+ ScheduleParams schedule_params;
+};
+
+} // namespace notifications
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_PARAMS_H_
diff --git a/chrome/browser/notifications/scheduler/notification_schedule_service.h b/chrome/browser/notifications/scheduler/notification_schedule_service.h
new file mode 100644
index 0000000..1e6091f
--- /dev/null
+++ b/chrome/browser/notifications/scheduler/notification_schedule_service.h
@@ -0,0 +1,37 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_SCHEDULE_SERVICE_H_
+#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_SCHEDULE_SERVICE_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "components/keyed_service/core/keyed_service.h"
+
+namespace notifications {
+
+struct NotificationParams;
+
+// Service to schedule a notification to display in the future. An internal
+// throttling mechanism will be applied to limit the maximum notification shown
+// to the user. Also user's interaction with the notification will affect the
+// frequency of notification delivery.
+class NotificationScheduleService : public KeyedService {
+ public:
+ // Schedules a notification to display.
+ virtual void Schedule(
+ std::unique_ptr<NotificationParams> notification_params) = 0;
+
+ protected:
+ NotificationScheduleService() = default;
+ ~NotificationScheduleService() override = default;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NotificationScheduleService);
+};
+
+} // namespace notifications
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_SCHEDULE_SERVICE_H_
diff --git a/chrome/browser/notifications/scheduler/notification_schedule_service_impl.cc b/chrome/browser/notifications/scheduler/notification_schedule_service_impl.cc
new file mode 100644
index 0000000..4ba86c4e
--- /dev/null
+++ b/chrome/browser/notifications/scheduler/notification_schedule_service_impl.cc
@@ -0,0 +1,23 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/scheduler/notification_schedule_service_impl.h"
+
+#include <memory>
+
+#include "base/logging.h"
+#include "chrome/browser/notifications/scheduler/notification_params.h"
+
+namespace notifications {
+
+NotificationScheduleServiceImpl::NotificationScheduleServiceImpl() = default;
+
+NotificationScheduleServiceImpl::~NotificationScheduleServiceImpl() = default;
+
+void NotificationScheduleServiceImpl::Schedule(
+ std::unique_ptr<NotificationParams> notification_params) {
+ NOTIMPLEMENTED();
+}
+
+} // namespace notifications
diff --git a/chrome/browser/notifications/scheduler/notification_schedule_service_impl.h b/chrome/browser/notifications/scheduler/notification_schedule_service_impl.h
new file mode 100644
index 0000000..5b394c3
--- /dev/null
+++ b/chrome/browser/notifications/scheduler/notification_schedule_service_impl.h
@@ -0,0 +1,32 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_SCHEDULE_SERVICE_IMPL_H_
+#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_SCHEDULE_SERVICE_IMPL_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "chrome/browser/notifications/scheduler/notification_schedule_service.h"
+
+namespace notifications {
+
+struct NotificationParams;
+
+class NotificationScheduleServiceImpl : public NotificationScheduleService {
+ public:
+ NotificationScheduleServiceImpl();
+ ~NotificationScheduleServiceImpl() override;
+
+ private:
+ // NotificationScheduleService implementation.
+ void Schedule(
+ std::unique_ptr<NotificationParams> notification_params) override;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationScheduleServiceImpl);
+};
+
+} // namespace notifications
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_NOTIFICATION_SCHEDULE_SERVICE_IMPL_H_
diff --git a/chrome/browser/notifications/scheduler/schedule_params.cc b/chrome/browser/notifications/scheduler/schedule_params.cc
index ec494ade..2cf48d78 100644
--- a/chrome/browser/notifications/scheduler/schedule_params.cc
+++ b/chrome/browser/notifications/scheduler/schedule_params.cc
@@ -4,6 +4,10 @@
#include "chrome/browser/notifications/scheduler/schedule_params.h"
+namespace notifications {
+
ScheduleParams::ScheduleParams() = default;
ScheduleParams::~ScheduleParams() = default;
+
+} // namespace notifications
diff --git a/chrome/browser/notifications/scheduler/schedule_params.h b/chrome/browser/notifications/scheduler/schedule_params.h
index 9c044c7..4b51ecc9 100644
--- a/chrome/browser/notifications/scheduler/schedule_params.h
+++ b/chrome/browser/notifications/scheduler/schedule_params.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_SCHEDULE_PARAMS_H_
#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_SCHEDULE_PARAMS_H_
+namespace notifications {
+
// Specifies when to show the scheduled notification, and throttling details.
struct ScheduleParams {
enum class Priority {
@@ -26,4 +28,6 @@
Priority priority;
};
+} // namespace notifications
+
#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_SCHEDULE_PARAMS_H_