Chromium Code Reviews| 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 (click, close...). | |
|
Peter Beverloo
2017/06/01 11:32:46
Used by who? Now that the service has two categori
Miguel Garcia
2017/06/02 15:02:55
Done.
| |
| 54 virtual void ProcessNotificationOperation( | |
|
Peter Beverloo
2017/06/01 11:32:46
Drop "virtual"?
Miguel Garcia
2017/06/02 15:02:55
Done.
| |
| 55 NotificationCommon::Operation operation, | |
| 56 NotificationCommon::Type notification_type, | |
| 57 const std::string& origin, | |
| 58 const std::string& notification_id, | |
| 59 int action_index, | |
| 60 const base::NullableString16& reply); | |
| 61 | |
| 62 protected: | |
| 63 NotificationHandler* GetNotificationHandler( | |
| 64 NotificationCommon::Type notification_type); | |
| 65 | |
| 47 private: | 66 private: |
| 67 // Registers an implementation object to handle notification operations | |
| 68 // for |notification_type|. | |
| 69 void AddNotificationHandler(NotificationCommon::Type notification_type, | |
| 70 std::unique_ptr<NotificationHandler> handler); | |
|
Peter Beverloo
2017/06/01 11:32:46
We'd move this to the factory, right? That'd requi
Miguel Garcia
2017/06/02 15:02:55
Yeah right now we are still adding the handlers in
| |
| 71 | |
| 72 std::map<NotificationCommon::Type, std::unique_ptr<NotificationHandler>> | |
| 73 notification_handlers_; | |
| 74 Profile* profile_; | |
| 75 | |
| 48 DISALLOW_COPY_AND_ASSIGN(NotificationDisplayService); | 76 DISALLOW_COPY_AND_ASSIGN(NotificationDisplayService); |
| 49 }; | 77 }; |
| 50 | 78 |
| 51 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ | 79 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |
| OLD | NEW |