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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // list. It can also implement Delegate to receive callbacks when a | 23 // list. It can also implement Delegate to receive callbacks when a |
24 // notification is removed (closed), or clicked on. | 24 // notification is removed (closed), or clicked on. |
25 // If an Observer is provided, it will be informed when the notification list | 25 // 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 | 26 // changes, and is expected to handle creating, showing, and hiding of any |
27 // bubbles. | 27 // bubbles. |
28 | 28 |
29 namespace message_center { | 29 namespace message_center { |
30 | 30 |
31 class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { | 31 class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { |
32 public: | 32 public: |
| 33 // Creates the global message center object. |
| 34 static void Initialize(); |
| 35 |
| 36 // Returns the global message center object. Initialize must be called first. |
| 37 static MessageCenter* Get(); |
| 38 |
| 39 // Destroys the global message_center object. |
| 40 static void Shutdown(); |
| 41 |
33 // Class that hosts the message center. | 42 // Class that hosts the message center. |
34 class MESSAGE_CENTER_EXPORT Observer { | 43 class MESSAGE_CENTER_EXPORT Observer { |
35 public: | 44 public: |
36 // Called when the notification list has changed. |new_notification| will | 45 // Called when the notification list has changed. |new_notification| will |
37 // be true if a notification was added or updated. | 46 // be true if a notification was added or updated. |
38 virtual void OnMessageCenterChanged(bool new_notification) = 0; | 47 virtual void OnMessageCenterChanged(bool new_notification) = 0; |
39 protected: | 48 protected: |
40 virtual ~Observer() {} | 49 virtual ~Observer() {} |
41 }; | 50 }; |
42 | 51 |
(...skipping 28 matching lines...) Expand all Loading... |
71 // | 80 // |
72 // TODO(miket): consider providing default implementations for the pure | 81 // TODO(miket): consider providing default implementations for the pure |
73 // virtuals above, to avoid changing so many files in disparate parts of | 82 // virtuals above, to avoid changing so many files in disparate parts of |
74 // the codebase each time we enhance this interface. | 83 // the codebase each time we enhance this interface. |
75 virtual void OnButtonClicked(const std::string& id, int button_index); | 84 virtual void OnButtonClicked(const std::string& id, int button_index); |
76 | 85 |
77 protected: | 86 protected: |
78 virtual ~Delegate() {} | 87 virtual ~Delegate() {} |
79 }; | 88 }; |
80 | 89 |
81 MessageCenter(); | |
82 virtual ~MessageCenter(); | |
83 | |
84 // Called to set the delegate. Generally called only once, except in tests. | 90 // Called to set the delegate. Generally called only once, except in tests. |
85 // Changing the delegate does not affect notifications in its | 91 // Changing the delegate does not affect notifications in its |
86 // NotificationList. | 92 // NotificationList. |
87 void SetDelegate(Delegate* delegate); | 93 void SetDelegate(Delegate* delegate); |
88 | 94 |
89 // Management of the observer list. | 95 // Management of the observer list. |
90 void AddObserver(Observer* observer); | 96 void AddObserver(Observer* observer); |
91 void RemoveObserver(Observer* observer); | 97 void RemoveObserver(Observer* observer); |
92 | 98 |
93 // Informs the notification list whether the message center is visible. | 99 // Informs the notification list whether the message center is visible. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; | 152 virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; |
147 virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE; | 153 virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE; |
148 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; | 154 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; |
149 virtual void ShowNotificationSettingsDialog(gfx::NativeView context) OVERRIDE; | 155 virtual void ShowNotificationSettingsDialog(gfx::NativeView context) OVERRIDE; |
150 virtual void OnNotificationClicked(const std::string& id) OVERRIDE; | 156 virtual void OnNotificationClicked(const std::string& id) OVERRIDE; |
151 virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE; | 157 virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE; |
152 virtual void OnButtonClicked(const std::string& id, int button_index) | 158 virtual void OnButtonClicked(const std::string& id, int button_index) |
153 OVERRIDE; | 159 OVERRIDE; |
154 virtual NotificationList* GetNotificationList() OVERRIDE; | 160 virtual NotificationList* GetNotificationList() OVERRIDE; |
155 | 161 |
| 162 protected: |
| 163 MessageCenter(); |
| 164 virtual ~MessageCenter(); |
| 165 |
156 private: | 166 private: |
157 // Calls OnMessageCenterChanged on each observer. | 167 // Calls OnMessageCenterChanged on each observer. |
158 void NotifyMessageCenterChanged(bool new_notification); | 168 void NotifyMessageCenterChanged(bool new_notification); |
159 | 169 |
160 scoped_ptr<NotificationList> notification_list_; | 170 scoped_ptr<NotificationList> notification_list_; |
161 ObserverList<Observer> observer_list_; | 171 ObserverList<Observer> observer_list_; |
162 Delegate* delegate_; | 172 Delegate* delegate_; |
163 | 173 |
164 DISALLOW_COPY_AND_ASSIGN(MessageCenter); | 174 DISALLOW_COPY_AND_ASSIGN(MessageCenter); |
165 }; | 175 }; |
166 | 176 |
167 } // namespace message_center | 177 } // namespace message_center |
168 | 178 |
169 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ | 179 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ |
OLD | NEW |