blob: da82dd7d35cc8ab92a1aff0ef14f1feb6b791e13 [file] [log] [blame]
[email protected]1272b1e62012-04-04 14:42:451// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]29672ab2009-10-30 03:44:032// 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]33286c92013-05-29 23:13:378#include <set>
[email protected]24c5013f2010-11-19 22:21:089#include <string>
[email protected]6ffdb9002011-11-15 00:09:2410#include <vector>
[email protected]29672ab2009-10-30 03:44:0311
avi6846aef2015-12-26 01:09:3812#include "base/macros.h"
Evan Stade4755cf22017-10-17 18:35:4313#include "chrome/browser/notifications/notification_common.h"
[email protected]1218f332012-04-17 19:04:4014
juyik048931af2014-10-06 17:56:3015typedef void* ProfileID;
16
[email protected]1272b1e62012-04-04 14:42:4517class GURL;
[email protected]1218f332012-04-17 19:04:4018class Profile;
[email protected]29672ab2009-10-30 03:44:0319
Evan Stade4755cf22017-10-17 18:35:4320namespace message_center {
21class Notification;
22}
23
Evan Stade4d8df162018-06-07 16:59:2524// 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]1272b1e62012-04-04 14:42:4536class NotificationUIManager {
[email protected]29672ab2009-10-30 03:44:0337 public:
juyik048931af2014-10-06 17:56:3038 // 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]1272b1e62012-04-04 14:42:4545 virtual ~NotificationUIManager() {}
[email protected]29672ab2009-10-30 03:44:0346
[email protected]a93e63f52012-12-18 04:26:4047 // Creates an initialized UI manager.
a-v-y76c3abb2016-08-01 18:34:4048 static NotificationUIManager* Create();
[email protected]b0b2a3dd2011-01-06 00:30:0549
Evan Stade4755cf22017-10-17 18:35:4350 // Adds a notification to be displayed.
51 virtual void Add(const message_center::Notification& notification,
52 Profile* profile) = 0;
[email protected]702790b2013-08-02 04:50:3953
Evan Stade4755cf22017-10-17 18:35:4354 // 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]29672ab2009-10-30 03:44:0358
[email protected]12d9b9ea2013-07-26 13:40:4759 // Returns the pointer to a notification if it match the supplied ID, either
60 // currently displayed or in the queue.
juyik048931af2014-10-06 17:56:3061 // 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 Stade4755cf22017-10-17 18:35:4364 virtual const message_center::Notification* FindById(
65 const std::string& delegate_id,
66 ProfileID profile_id) const = 0;
[email protected]48dfce72013-01-28 06:32:1967
[email protected]24c5013f2010-11-19 22:21:0868 // Removes any notifications matching the supplied ID, either currently
69 // displayed or in the queue. Returns true if anything was removed.
juyik048931af2014-10-06 17:56:3070 // 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]24c5013f2010-11-19 22:21:0875
deepak.m1909d4de2015-06-02 03:38:2676 // Returns the set of all delegate IDs for notifications from |profile_id|.
77 virtual std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) = 0;
peter5b494b32015-05-19 19:35:0978
[email protected]704adb62012-11-30 17:29:5279 // Removes notifications matching the |source_origin| (which could be an
80 // extension ID). Returns true if anything was removed.
[email protected]1272b1e62012-04-04 14:42:4581 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0;
[email protected]b52448bb2009-11-04 21:29:1182
juyik048931af2014-10-06 17:56:3083 // Removes notifications matching |profile_id|. Returns true if any were
84 // removed.
85 virtual bool CancelAllByProfile(ProfileID profile_id) = 0;
[email protected]704adb62012-11-30 17:29:5286
[email protected]ad0852622010-12-01 19:12:0887 // Cancels all pending notifications and closes anything currently showing.
88 // Used when the app is terminating.
[email protected]1272b1e62012-04-04 14:42:4589 virtual void CancelAll() = 0;
[email protected]ad0852622010-12-01 19:12:0890
sammiequonee045382017-03-30 16:24:0691 // 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]1272b1e62012-04-04 14:42:4596 protected:
97 NotificationUIManager() {}
[email protected]0fb286e2011-10-18 19:34:4098
[email protected]61d68ef12011-01-13 14:02:5699 private:
[email protected]29672ab2009-10-30 03:44:03100 DISALLOW_COPY_AND_ASSIGN(NotificationUIManager);
101};
102
103#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_