miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |
| 7 | |
miguelg | abf610a | 2017-06-02 17:31:43 | [diff] [blame] | 8 | #include <map> |
miguelg | bfe76835 | 2017-03-20 15:34:31 | [diff] [blame] | 9 | #include <memory> |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 10 | #include <set> |
| 11 | #include <string> |
miguelg | 87e986d | 2016-07-08 18:04:44 | [diff] [blame] | 12 | |
miguelg | bfe76835 | 2017-03-20 15:34:31 | [diff] [blame] | 13 | #include "base/callback_forward.h" |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 14 | #include "base/macros.h" |
miguelg | 87e986d | 2016-07-08 18:04:44 | [diff] [blame] | 15 | #include "chrome/browser/notifications/notification_common.h" |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 16 | #include "chrome/browser/notifications/notification_handler.h" |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 17 | #include "components/keyed_service/core/keyed_service.h" |
| 18 | |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 19 | class Profile; |
| 20 | |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 21 | namespace message_center { |
| 22 | class Notification; |
| 23 | } |
| 24 | |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 25 | // Profile-bound service that enables user-visible notifications to be displayed |
| 26 | // and managed. Notifications may either be presented using a notification |
| 27 | // center provided by the platform, or by Chrome's Message Center. |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 28 | class NotificationDisplayService : public KeyedService { |
| 29 | public: |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 30 | ~NotificationDisplayService() override; |
| 31 | |
| 32 | // Callback to be used with the GetDisplayed() method. Includes the set of |
| 33 | // notification ids that is being displayed to the user. The |
| 34 | // |supports_synchronization| callback indicates whether the platform has the |
| 35 | // ability to query which notifications are still being displayed. |
| 36 | // |
| 37 | // TODO(peter): Rename |supports_synchronization| to |supported|. |
| 38 | // TODO(peter): Change this to be a base::OnceCallback, remove use of the |
| 39 | // std::unique_ptr<> in favor of move semantics. |
miguelg | bfe76835 | 2017-03-20 15:34:31 | [diff] [blame] | 40 | using DisplayedNotificationsCallback = |
| 41 | base::Callback<void(std::unique_ptr<std::set<std::string>>, |
| 42 | bool /* supports_synchronization */)>; |
Evan Stade | 6e15415 | 2017-11-10 01:58:25 | [diff] [blame] | 43 | |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 44 | // Returns an instance of the display service for the given |profile|. |
Evan Stade | 6e15415 | 2017-11-10 01:58:25 | [diff] [blame] | 45 | static NotificationDisplayService* GetForProfile(Profile* profile); |
| 46 | |
Evan Stade | 5d6e469 | 2017-12-08 17:43:52 | [diff] [blame] | 47 | // Returns the NDS for system notifications which aren't tied to a particular |
| 48 | // user. Currently only implemented on Chrome OS. TODO(estade): implement |
| 49 | // elsewhere as needed. |
| 50 | static NotificationDisplayService* GetForSystemNotifications(); |
| 51 | |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 52 | // Displays the |notification| of type |notification_type|. The |metadata| |
| 53 | // may be provided for certain notification types that require additional |
| 54 | // information for the notification to be displayed. |
Evan Stade | 4ebefdf4 | 2017-09-21 23:50:18 | [diff] [blame] | 55 | virtual void Display( |
Peter Beverloo | 6dba2e10 | 2017-11-23 17:46:33 | [diff] [blame] | 56 | NotificationHandler::Type notification_type, |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 57 | const message_center::Notification& notification, |
Evan Stade | 4ebefdf4 | 2017-09-21 23:50:18 | [diff] [blame] | 58 | std::unique_ptr<NotificationCommon::Metadata> metadata = nullptr) = 0; |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 59 | |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 60 | // Closes the notification having |notification_id| of |notification_type|. |
Peter Beverloo | 6dba2e10 | 2017-11-23 17:46:33 | [diff] [blame] | 61 | virtual void Close(NotificationHandler::Type notification_type, |
miguelg | 87e986d | 2016-07-08 18:04:44 | [diff] [blame] | 62 | const std::string& notification_id) = 0; |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 63 | |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 64 | // Gets the IDs of currently displaying notifications and invokes |callback| |
| 65 | // once available. Not all backends support retrieving this information. |
peter | b5298ae | 2017-04-11 21:52:51 | [diff] [blame] | 66 | virtual void GetDisplayed(const DisplayedNotificationsCallback& callback) = 0; |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 67 | |
Peter Beverloo | 7426194d | 2017-12-11 17:39:38 | [diff] [blame^] | 68 | protected: |
| 69 | NotificationDisplayService() = default; |
Evan Stade | 0bf465e5 | 2017-10-03 18:12:00 | [diff] [blame] | 70 | |
Evan Stade | cc63b18 | 2017-09-26 16:05:12 | [diff] [blame] | 71 | private: |
miguelg | 23cd2dd7 | 2016-04-21 15:24:03 | [diff] [blame] | 72 | DISALLOW_COPY_AND_ASSIGN(NotificationDisplayService); |
| 73 | }; |
| 74 | |
| 75 | #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_ |