[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 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_UI_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_ |
| 7 | |
[email protected] | 33286c9 | 2013-05-29 23:13:37 | [diff] [blame] | 8 | #include <set> |
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 9 | #include <string> |
[email protected] | 6ffdb900 | 2011-11-15 00:09:24 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 11 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 12 | #include "base/macros.h" |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 13 | #include "chrome/browser/notifications/notification_common.h" |
[email protected] | 1218f33 | 2012-04-17 19:04:40 | [diff] [blame] | 14 | |
juyik | 048931af | 2014-10-06 17:56:30 | [diff] [blame] | 15 | typedef void* ProfileID; |
| 16 | |
[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 17 | class GURL; |
[email protected] | 1218f33 | 2012-04-17 19:04:40 | [diff] [blame] | 18 | class Profile; |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 19 | |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 20 | namespace message_center { |
| 21 | class Notification; |
| 22 | } |
| 23 | |
Evan Stade | 4d8df16 | 2018-06-07 16:59:25 | [diff] [blame] | 24 | // This interface is used to manage the UI surfaces for non-native desktop |
| 25 | // notifications (hence, this is not used by Chrome OS and is not used for |
| 26 | // Windows Action Center notifications). There is just one instance for all |
| 27 | // profiles. This represents the middle layer of notification and it's aware of |
| 28 | // profile. It identifies a notification by the id string and a profile, hence |
| 29 | // two notifications from two different profiles, even though they may have |
| 30 | // identical ids, will not be considered the same notification. This interface |
| 31 | // will generate a new id behind the scene based on the id string and the |
| 32 | // profile's characteristics for each notification and use this new id to call |
| 33 | // lower layer MessageCenter interface which is profile agnostic. Therefore the |
| 34 | // ids passed into this interface are not the same as those passed into the |
| 35 | // MessageCenter interface. |
[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 36 | class NotificationUIManager { |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 37 | public: |
juyik | 048931af | 2014-10-06 17:56:30 | [diff] [blame] | 38 | // Convert a profile pointer into an opaque profile id, which can be safely |
| 39 | // used by FindById() and CancelById() even after a profile may have been |
| 40 | // destroyed. |
| 41 | static ProfileID GetProfileID(Profile* profile) { |
| 42 | return static_cast<ProfileID>(profile); |
| 43 | } |
| 44 | |
[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 45 | virtual ~NotificationUIManager() {} |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 46 | |
[email protected] | a93e63f5 | 2012-12-18 04:26:40 | [diff] [blame] | 47 | // Creates an initialized UI manager. |
a-v-y | 76c3abb | 2016-08-01 18:34:40 | [diff] [blame] | 48 | static NotificationUIManager* Create(); |
[email protected] | b0b2a3dd | 2011-01-06 00:30:05 | [diff] [blame] | 49 | |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 50 | // Adds a notification to be displayed. |
| 51 | virtual void Add(const message_center::Notification& notification, |
| 52 | Profile* profile) = 0; |
[email protected] | 702790b | 2013-08-02 04:50:39 | [diff] [blame] | 53 | |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 54 | // Updates the given notification, if it already exists.Returns true for |
| 55 | // update and false to report a no-op. |
| 56 | virtual bool Update(const message_center::Notification& notification, |
| 57 | Profile* profile) = 0; |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 58 | |
[email protected] | 12d9b9ea | 2013-07-26 13:40:47 | [diff] [blame] | 59 | // Returns the pointer to a notification if it match the supplied ID, either |
| 60 | // currently displayed or in the queue. |
juyik | 048931af | 2014-10-06 17:56:30 | [diff] [blame] | 61 | // This function can be bound for delayed execution, where a profile pointer |
| 62 | // may not be valid. Hence caller needs to call the static GetProfileID(...) |
| 63 | // function to turn a profile pointer into a profile id and pass that in. |
Evan Stade | 4755cf2 | 2017-10-17 18:35:43 | [diff] [blame] | 64 | virtual const message_center::Notification* FindById( |
| 65 | const std::string& delegate_id, |
| 66 | ProfileID profile_id) const = 0; |
[email protected] | 48dfce7 | 2013-01-28 06:32:19 | [diff] [blame] | 67 | |
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 68 | // Removes any notifications matching the supplied ID, either currently |
| 69 | // displayed or in the queue. Returns true if anything was removed. |
juyik | 048931af | 2014-10-06 17:56:30 | [diff] [blame] | 70 | // This function can be bound for delayed execution, where a profile pointer |
| 71 | // may not be valid. Hence caller needs to call the static GetProfileID(...) |
| 72 | // function to turn a profile pointer into a profile id and pass that in. |
| 73 | virtual bool CancelById(const std::string& delegate_id, |
| 74 | ProfileID profile_id) = 0; |
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 75 | |
deepak.m1 | 909d4de | 2015-06-02 03:38:26 | [diff] [blame] | 76 | // Returns the set of all delegate IDs for notifications from |profile_id|. |
| 77 | virtual std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) = 0; |
peter | 5b494b3 | 2015-05-19 19:35:09 | [diff] [blame] | 78 | |
[email protected] | 704adb6 | 2012-11-30 17:29:52 | [diff] [blame] | 79 | // Removes notifications matching the |source_origin| (which could be an |
| 80 | // extension ID). Returns true if anything was removed. |
[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 81 | virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0; |
[email protected] | b52448bb | 2009-11-04 21:29:11 | [diff] [blame] | 82 | |
juyik | 048931af | 2014-10-06 17:56:30 | [diff] [blame] | 83 | // Removes notifications matching |profile_id|. Returns true if any were |
| 84 | // removed. |
| 85 | virtual bool CancelAllByProfile(ProfileID profile_id) = 0; |
[email protected] | 704adb6 | 2012-11-30 17:29:52 | [diff] [blame] | 86 | |
[email protected] | ad085262 | 2010-12-01 19:12:08 | [diff] [blame] | 87 | // Cancels all pending notifications and closes anything currently showing. |
| 88 | // Used when the app is terminating. |
[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 89 | virtual void CancelAll() = 0; |
[email protected] | ad085262 | 2010-12-01 19:12:08 | [diff] [blame] | 90 | |
sammiequon | ee04538 | 2017-03-30 16:24:06 | [diff] [blame] | 91 | // Cancels all pending notifications and closes anything currently showing. |
| 92 | // After this is called, no new notifications can be added. Used when the app |
| 93 | // is terminating. |
| 94 | virtual void StartShutdown() = 0; |
| 95 | |
[email protected] | 1272b1e6 | 2012-04-04 14:42:45 | [diff] [blame] | 96 | protected: |
| 97 | NotificationUIManager() {} |
[email protected] | 0fb286e | 2011-10-18 19:34:40 | [diff] [blame] | 98 | |
[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 99 | private: |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(NotificationUIManager); |
| 101 | }; |
| 102 | |
| 103 | #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_ |