OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ | 5 #ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ |
6 #define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ | 6 #define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
13 #include "ui/message_center/message_center_export.h" | 13 #include "ui/message_center/message_center_export.h" |
| 14 #include "ui/message_center/notification_change_observer.h" |
14 #include "ui/message_center/notification_list.h" | 15 #include "ui/message_center/notification_list.h" |
15 #include "ui/message_center/notification_types.h" | 16 #include "ui/message_center/notification_types.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class DictionaryValue; | 19 class DictionaryValue; |
19 } | 20 } |
20 | 21 |
21 // Class for managing the NotificationList. The client (e.g. Chrome) calls | 22 // Class for managing the NotificationList. The client (e.g. Chrome) calls |
22 // [Add|Remove|Update]Notification to create and update notifications in the | 23 // [Add|Remove|Update]Notification to create and update notifications in the |
23 // list. It can also implement Delegate to receive callbacks when a | 24 // list. It can also implement Delegate to receive callbacks when a |
24 // notification is removed (closed), or clicked on. | 25 // notification is removed (closed), or clicked on. |
25 // If an Observer is provided, it will be informed when the notification list | 26 // If an Observer is provided, it will be informed when the notification list |
26 // changes, and is expected to handle creating, showing, and hiding of any | 27 // changes, and is expected to handle creating, showing, and hiding of any |
27 // bubbles. | 28 // bubbles. |
28 | 29 |
29 namespace message_center { | 30 namespace message_center { |
30 | 31 |
31 class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { | 32 class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationChangeObserver, |
| 33 public NotificationList::Delegate { |
32 public: | 34 public: |
33 // Creates the global message center object. | 35 // Creates the global message center object. |
34 static void Initialize(); | 36 static void Initialize(); |
35 | 37 |
36 // Returns the global message center object. Initialize must be called first. | 38 // Returns the global message center object. Initialize must be called first. |
37 static MessageCenter* Get(); | 39 static MessageCenter* Get(); |
38 | 40 |
39 // Destroys the global message_center object. | 41 // Destroys the global message_center object. |
40 static void Shutdown(); | 42 static void Shutdown(); |
41 | 43 |
42 // Class that hosts the message center. | 44 // Class that hosts the message center. |
43 class MESSAGE_CENTER_EXPORT Observer { | 45 class MESSAGE_CENTER_EXPORT Observer { |
44 public: | 46 public: |
45 // Called when the notification list has changed. |new_notification| will | 47 // Called when the notification list has changed. |new_notification| will |
46 // be true if a notification was added or updated. | 48 // be true if a notification was added or updated. |
47 virtual void OnMessageCenterChanged(bool new_notification) = 0; | 49 virtual void OnMessageCenterChanged(bool new_notification) = 0; |
48 protected: | 50 protected: |
49 virtual ~Observer() {} | 51 virtual ~Observer() {} |
50 }; | 52 }; |
51 | 53 |
52 class MESSAGE_CENTER_EXPORT Delegate { | 54 class MESSAGE_CENTER_EXPORT Delegate { |
53 public: | 55 public: |
| 56 virtual ~Delegate(); |
| 57 |
54 // Called when the notification associated with |notification_id| is | 58 // Called when the notification associated with |notification_id| is |
55 // removed (i.e. closed by the user). | 59 // removed (i.e. closed by the user). |
56 virtual void NotificationRemoved(const std::string& notification_id, | 60 virtual void NotificationRemoved(const std::string& notification_id, |
57 bool by_user) = 0; | 61 bool by_user) = 0; |
58 | 62 |
59 // Request to disable the extension associated with |notification_id|. | 63 // Request to disable the extension associated with |notification_id|. |
60 virtual void DisableExtension(const std::string& notification_id) = 0; | 64 virtual void DisableExtension(const std::string& notification_id) = 0; |
61 | 65 |
62 // Request to disable notifications from the source of |notification_id|. | 66 // Request to disable notifications from the source of |notification_id|. |
63 virtual void DisableNotificationsFromSource( | 67 virtual void DisableNotificationsFromSource( |
(...skipping 10 matching lines...) Expand all Loading... |
74 // Called when the notification body is clicked on. | 78 // Called when the notification body is clicked on. |
75 virtual void OnClicked(const std::string& notification_id) = 0; | 79 virtual void OnClicked(const std::string& notification_id) = 0; |
76 | 80 |
77 // Called when a button in a notification is clicked. |button_index| | 81 // Called when a button in a notification is clicked. |button_index| |
78 // indicates which button was clicked, zero-indexed (button one is 0, | 82 // indicates which button was clicked, zero-indexed (button one is 0, |
79 // button two is 1). | 83 // button two is 1). |
80 // | 84 // |
81 // TODO(miket): consider providing default implementations for the pure | 85 // TODO(miket): consider providing default implementations for the pure |
82 // virtuals above, to avoid changing so many files in disparate parts of | 86 // virtuals above, to avoid changing so many files in disparate parts of |
83 // the codebase each time we enhance this interface. | 87 // the codebase each time we enhance this interface. |
84 virtual void OnButtonClicked(const std::string& id, int button_index); | 88 virtual void OnButtonClicked(const std::string& id, int button_index) = 0; |
85 | |
86 protected: | |
87 virtual ~Delegate() {} | |
88 }; | 89 }; |
89 | 90 |
90 // Called to set the delegate. Generally called only once, except in tests. | 91 // Called to set the delegate. Generally called only once, except in tests. |
91 // Changing the delegate does not affect notifications in its | 92 // Changing the delegate does not affect notifications in its |
92 // NotificationList. | 93 // NotificationList. |
93 void SetDelegate(Delegate* delegate); | 94 void SetDelegate(Delegate* delegate); |
94 | 95 |
95 // Management of the observer list. | 96 // Management of the observer list. |
96 void AddObserver(Observer* observer); | 97 void AddObserver(Observer* observer); |
97 void RemoveObserver(Observer* observer); | 98 void RemoveObserver(Observer* observer); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 void SetNotificationImage(const std::string& notification_id, | 139 void SetNotificationImage(const std::string& notification_id, |
139 const gfx::Image& image); | 140 const gfx::Image& image); |
140 | 141 |
141 void SetNotificationButtonIcon(const std::string& notification_id, | 142 void SetNotificationButtonIcon(const std::string& notification_id, |
142 int button_index, | 143 int button_index, |
143 const gfx::Image& image); | 144 const gfx::Image& image); |
144 | 145 |
145 NotificationList* notification_list() { return notification_list_.get(); } | 146 NotificationList* notification_list() { return notification_list_.get(); } |
146 bool quiet_mode() const { return notification_list_->quiet_mode(); } | 147 bool quiet_mode() const { return notification_list_->quiet_mode(); } |
147 | 148 |
148 // Overridden from NotificationList::Delegate. | 149 // Overridden from NotificationChangeObserver: |
| 150 virtual void OnRemoveNotification(const std::string& id, bool by_user) |
| 151 OVERRIDE; |
| 152 virtual void OnRemoveAllNotifications(bool by_user) OVERRIDE; |
| 153 virtual void OnDisableNotificationsByExtension(const std::string& id) |
| 154 OVERRIDE; |
| 155 virtual void OnDisableNotificationsByUrl(const std::string& id) OVERRIDE; |
| 156 virtual void OnShowNotificationSettings(const std::string& id) OVERRIDE; |
| 157 virtual void OnShowNotificationSettingsDialog(gfx::NativeView context) |
| 158 OVERRIDE; |
| 159 virtual void OnExpanded(const std::string& id) OVERRIDE; |
| 160 virtual void OnClicked(const std::string& id) OVERRIDE; |
| 161 virtual void OnButtonClicked(const std::string& id, int button_index) |
| 162 OVERRIDE; |
| 163 |
| 164 // Overridden from NotificationList::Delegate: |
149 virtual void SendRemoveNotification(const std::string& id, | 165 virtual void SendRemoveNotification(const std::string& id, |
150 bool by_user) OVERRIDE; | 166 bool by_user) OVERRIDE; |
151 virtual void SendRemoveAllNotifications(bool by_user) OVERRIDE; | |
152 virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; | |
153 virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE; | |
154 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; | |
155 virtual void ShowNotificationSettingsDialog(gfx::NativeView context) OVERRIDE; | |
156 virtual void OnNotificationClicked(const std::string& id) OVERRIDE; | |
157 virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE; | 167 virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE; |
158 virtual void OnButtonClicked(const std::string& id, int button_index) | |
159 OVERRIDE; | |
160 virtual NotificationList* GetNotificationList() OVERRIDE; | |
161 | 168 |
162 protected: | 169 protected: |
163 MessageCenter(); | 170 MessageCenter(); |
164 virtual ~MessageCenter(); | 171 virtual ~MessageCenter(); |
165 | 172 |
166 private: | 173 private: |
167 // Calls OnMessageCenterChanged on each observer. | 174 // Calls OnMessageCenterChanged on each observer. |
168 void NotifyMessageCenterChanged(bool new_notification); | 175 void NotifyMessageCenterChanged(bool new_notification); |
169 | 176 |
170 scoped_ptr<NotificationList> notification_list_; | 177 scoped_ptr<NotificationList> notification_list_; |
171 ObserverList<Observer> observer_list_; | 178 ObserverList<Observer> observer_list_; |
172 Delegate* delegate_; | 179 Delegate* delegate_; |
173 | 180 |
174 DISALLOW_COPY_AND_ASSIGN(MessageCenter); | 181 DISALLOW_COPY_AND_ASSIGN(MessageCenter); |
175 }; | 182 }; |
176 | 183 |
177 } // namespace message_center | 184 } // namespace message_center |
178 | 185 |
179 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ | 186 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ |
OLD | NEW |