OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <memory> | 9 #include <memory> |
9 #include <set> | 10 #include <set> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "chrome/browser/notifications/notification_common.h" | 15 #include "chrome/browser/notifications/notification_common.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
16 | 17 |
| 18 namespace base { |
| 19 class NullableString16; |
| 20 } |
| 21 |
17 class Notification; | 22 class Notification; |
| 23 class NotificationHandler; |
18 class Profile; | 24 class Profile; |
19 | 25 |
20 // Profile-bound service that enables notifications to be displayed and | 26 // Profile-bound service that enables notifications to be displayed and |
21 // interacted with on the user's screen, orthogonal of whether this | 27 // interacted with on the user's screen, orthogonal of whether this |
22 // functionality is provided by the browser or by the operating system. An | 28 // functionality is provided by the browser or by the operating system. An |
23 // instance can be retrieved through the NotificationDisplayServiceFactory. | 29 // instance can be retrieved through the NotificationDisplayServiceFactory. |
24 // | 30 // |
25 // TODO(peter): Add a NotificationHandler mechanism for registering listeners. | 31 // TODO(peter): Add a NotificationHandler mechanism for registering listeners. |
26 class NotificationDisplayService : public KeyedService { | 32 class NotificationDisplayService : public KeyedService { |
27 public: | 33 public: |
28 using DisplayedNotificationsCallback = | 34 using DisplayedNotificationsCallback = |
29 base::Callback<void(std::unique_ptr<std::set<std::string>>, | 35 base::Callback<void(std::unique_ptr<std::set<std::string>>, |
30 bool /* supports_synchronization */)>; | 36 bool /* supports_synchronization */)>; |
31 NotificationDisplayService() {} | 37 explicit NotificationDisplayService(Profile* profile); |
32 ~NotificationDisplayService() override {} | 38 ~NotificationDisplayService() override; |
33 | 39 |
34 // Displays the |notification| identified by |notification_id|. | 40 // Displays the |notification| identified by |notification_id|. |
35 virtual void Display(NotificationCommon::Type notification_type, | 41 virtual void Display(NotificationCommon::Type notification_type, |
36 const std::string& notification_id, | 42 const std::string& notification_id, |
37 const Notification& notification) = 0; | 43 const Notification& notification) = 0; |
38 | 44 |
39 // Closes the notification identified by |notification_id|. | 45 // Closes the notification identified by |notification_id|. |
40 virtual void Close(NotificationCommon::Type notification_type, | 46 virtual void Close(NotificationCommon::Type notification_type, |
41 const std::string& notification_id) = 0; | 47 const std::string& notification_id) = 0; |
42 | 48 |
43 // Writes the ids of all currently displaying notifications and | 49 // Writes the ids of all currently displaying notifications and |
44 // invokes |callback| with the result once known. | 50 // invokes |callback| with the result once known. |
45 virtual void GetDisplayed(const DisplayedNotificationsCallback& callback) = 0; | 51 virtual void GetDisplayed(const DisplayedNotificationsCallback& callback) = 0; |
46 | 52 |
| 53 // Used to propagate back events originate from the user (click, close...). |
| 54 // The events are received and dispatched to the right consumer depending on |
| 55 // the type of notification. Consumers include, service workers, pages, |
| 56 // extensions... |
| 57 void ProcessNotificationOperation(NotificationCommon::Operation operation, |
| 58 NotificationCommon::Type notification_type, |
| 59 const std::string& origin, |
| 60 const std::string& notification_id, |
| 61 int action_index, |
| 62 const base::NullableString16& reply); |
| 63 |
| 64 protected: |
| 65 NotificationHandler* GetNotificationHandler( |
| 66 NotificationCommon::Type notification_type); |
| 67 |
47 private: | 68 private: |
| 69 // Registers an implementation object to handle notification operations |
| 70 // for |notification_type|. |
| 71 void AddNotificationHandler(NotificationCommon::Type notification_type, |
| 72 std::unique_ptr<NotificationHandler> handler); |
| 73 |
| 74 std::map<NotificationCommon::Type, std::unique_ptr<NotificationHandler>> |
| 75 notification_handlers_; |
| 76 Profile* profile_; |
| 77 |
48 DISALLOW_COPY_AND_ASSIGN(NotificationDisplayService); | 78 DISALLOW_COPY_AND_ASSIGN(NotificationDisplayService); |
49 }; | 79 }; |
50 | 80 |
51 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ | 81 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |
OLD | NEW |