Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: ui/message_center/message_center.h

Issue 11684003: Make MessageCenter a singleton object and build on Windows. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use Observer model instead of Host model. Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/chrome_browser_ui.gypi ('k') | ui/message_center/message_center.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/message_center.h
diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h
index 6aa5f96117be63b2d2317d1809a87744f6caebfc..58a3272b6b66ffadaf57b227cd56eb0d2175785d 100644
--- a/ui/message_center/message_center.h
+++ b/ui/message_center/message_center.h
@@ -5,11 +5,16 @@
#ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
#define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
+#include <string>
+
#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
#include "ui/message_center/message_center_export.h"
#include "ui/message_center/notification_list.h"
#include "ui/notifications/notification_types.h"
+template <typename T> struct DefaultSingletonTraits;
+
namespace base {
class DictionaryValue;
}
@@ -18,7 +23,7 @@ class DictionaryValue;
// [Add|Remove|Update]Notification to create and update notifications in the
// list. It can also implement Delegate to receive callbacks when a
// notification is removed (closed), or clicked on.
-// If a Host is provided, it will be informed when the notification list
+// If an Observer is provided, it will be informed when the notification list
// changes, and is expected to handle creating, showing, and hiding of any
// bubbles.
@@ -27,14 +32,13 @@ namespace message_center {
class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
public:
// Class that hosts the message center.
- class MESSAGE_CENTER_EXPORT Host {
+ class MESSAGE_CENTER_EXPORT Observer {
public:
// Called when the notification list has changed. |new_notification| will
// be true if a notification was added or updated.
- virtual void MessageCenterChanged(bool new_notification) = 0;
-
+ virtual void OnMessageCenterChanged(bool new_notification) = 0;
protected:
- virtual ~Host() {}
+ virtual ~Observer() {}
};
class MESSAGE_CENTER_EXPORT Delegate {
@@ -70,14 +74,19 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
virtual ~Delegate() {}
};
- // |host| is expected to manage any notification bubbles. It may be NULL.
- explicit MessageCenter(Host* host);
+ static MessageCenter* GetInstance();
virtual ~MessageCenter();
- // Called once to set the delegate.
+ // Called to set the delegate. Note that since the MessageCenter is a
+ // singleton object, it may already be created and have notifications in its
+ // NotificationList.
stevenjb 2013/01/03 22:32:45 I would change this to something like: // Called t
dewittj 2013/01/04 00:18:14 Done.
void SetDelegate(Delegate* delegate);
+ // Management of the observer list.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
// Informs the notification list whether the message center is visible.
// This affects whether or not a message has been "read".
void SetMessageCenterVisible(bool visible);
@@ -135,8 +144,14 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
virtual NotificationList* GetNotificationList() OVERRIDE;
private:
+ friend struct DefaultSingletonTraits<MessageCenter>;
+ MessageCenter();
+
+ // Calls OnMessageCenterChanged on each observer.
+ void NotifyMessageCenterChanged(bool new_notification);
+
scoped_ptr<NotificationList> notification_list_;
- Host* host_;
+ ObserverList<Observer> observer_list_;
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(MessageCenter);
« no previous file with comments | « chrome/chrome_browser_ui.gypi ('k') | ui/message_center/message_center.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698