summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-04 02:08:30 +0000
committerdewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-04 02:08:30 +0000
commit402bbab3ab377c49254489ed11b5510139504325 (patch)
tree4a2d7af299e6d87f3d5c5f8e890e3a9ddde4dc0c /ui
parentd993b6009261f95c35a351450d5ebe401d5329b2 (diff)
downloadchromium_src-402bbab3ab377c49254489ed11b5510139504325.zip
chromium_src-402bbab3ab377c49254489ed11b5510139504325.tar.gz
chromium_src-402bbab3ab377c49254489ed11b5510139504325.tar.bz2
Allow easier cross-platform access to MessageCenter by making it a singleton object, and add it to gyp files on Windows.
TBR=sky@chromium.org R=stevenjb@chromium.org Review URL: https://chromiumcodereview.appspot.com/11684003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175081 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/message_center/message_center.cc52
-rw-r--r--ui/message_center/message_center.gyp1
-rw-r--r--ui/message_center/message_center.h33
-rw-r--r--ui/views/views.gyp2
4 files changed, 61 insertions, 27 deletions
diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc
index a5460ee..0462a03 100644
--- a/ui/message_center/message_center.cc
+++ b/ui/message_center/message_center.cc
@@ -5,23 +5,31 @@
#include "ui/message_center/message_center.h"
#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "base/observer_list.h"
namespace message_center {
//------------------------------------------------------------------------------
-MessageCenter::MessageCenter(Host* host)
- : host_(host),
- delegate_(NULL) {
- notification_list_.reset(new NotificationList(this));
+// static
+MessageCenter* MessageCenter::GetInstance() {
+ return Singleton<MessageCenter>::get();
}
MessageCenter::~MessageCenter() {
notification_list_.reset();
}
+void MessageCenter::AddObserver(Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void MessageCenter::RemoveObserver(Observer* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
void MessageCenter::SetDelegate(Delegate* delegate) {
- DCHECK(!delegate_);
delegate_ = delegate;
}
@@ -54,8 +62,7 @@ void MessageCenter::AddNotification(
const base::DictionaryValue* optional_fields) {
notification_list_->AddNotification(type, id, title, message, display_source,
extension_id, optional_fields);
- if (host_)
- host_->MessageCenterChanged(true);
+ NotifyMessageCenterChanged(true);
}
void MessageCenter::UpdateNotification(
@@ -66,27 +73,25 @@ void MessageCenter::UpdateNotification(
const base::DictionaryValue* optional_fields) {
notification_list_->UpdateNotificationMessage(
old_id, new_id, title, message, optional_fields);
- if (host_)
- host_->MessageCenterChanged(true);
+ NotifyMessageCenterChanged(true);
}
void MessageCenter::RemoveNotification(const std::string& id) {
if (!notification_list_->RemoveNotification(id))
return;
- if (host_)
- host_->MessageCenterChanged(false);
+ NotifyMessageCenterChanged(false);
}
void MessageCenter::SetNotificationPrimaryIcon(const std::string& id,
const gfx::ImageSkia& image) {
- if (notification_list_->SetNotificationPrimaryIcon(id, image) && host_)
- host_->MessageCenterChanged(true);
+ if (notification_list_->SetNotificationPrimaryIcon(id, image))
+ NotifyMessageCenterChanged(true);
}
void MessageCenter::SetNotificationSecondaryIcon(const std::string& id,
const gfx::ImageSkia& image) {
- if (notification_list_->SetNotificationSecondaryIcon(id, image) && host_)
- host_->MessageCenterChanged(true);
+ if (notification_list_->SetNotificationSecondaryIcon(id, image))
+ NotifyMessageCenterChanged(true);
}
//------------------------------------------------------------------------------
@@ -138,7 +143,7 @@ void MessageCenter::OnNotificationClicked(const std::string& id) {
}
void MessageCenter::OnQuietModeChanged(bool quiet_mode) {
- host_->MessageCenterChanged(true);
+ NotifyMessageCenterChanged(true);
}
void MessageCenter::OnButtonClicked(const std::string& id, int button_index) {
@@ -154,4 +159,19 @@ void MessageCenter::Delegate::OnButtonClicked(const std::string& id,
int button_index) {
}
+//------------------------------------------------------------------------------
+// Private.
+
+MessageCenter::MessageCenter()
+ : delegate_(NULL) {
+ notification_list_.reset(new NotificationList(this));
+}
+
+void MessageCenter::NotifyMessageCenterChanged(bool new_notification) {
+ FOR_EACH_OBSERVER(Observer,
+ observer_list_,
+ OnMessageCenterChanged(new_notification));
+}
+
+
} // namespace message_center
diff --git a/ui/message_center/message_center.gyp b/ui/message_center/message_center.gyp
index 28e86fd..1157f38 100644
--- a/ui/message_center/message_center.gyp
+++ b/ui/message_center/message_center.gyp
@@ -13,6 +13,7 @@
'dependencies': [
'../../base/base.gyp:base',
'../../base/base.gyp:base_i18n',
+ '../../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../../skia/skia.gyp:skia',
'../base/strings/ui_strings.gyp:ui_strings',
'../compositor/compositor.gyp:compositor',
diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h
index 6aa5f96..0815501 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. Generally called only once, except in tests.
+ // Changing the delegate does not affect notifications in its
+ // NotificationList.
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);
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 6b4055c..dd0fa93 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -490,8 +490,6 @@
['exclude', 'widget/desktop_aura'],
],
'sources!': [
- 'bubble/tray_bubble_view.cc',
- 'bubble/tray_bubble_view.h',
'widget/native_widget_aura_window_observer.cc',
'widget/native_widget_aura_window_observer.h',
'widget/widget_aura_utils.cc',