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

Unified Diff: ui/message_center/message_center.cc

Issue 11684003: Make MessageCenter a singleton object and build on Windows. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update comment. 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 | « ui/message_center/message_center.h ('k') | ui/message_center/message_center.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/message_center.cc
diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc
index a5460ee89f424a57417277f9c91e2db8d5a32f4b..0462a03563e61ac78938614b40fc1fcaac5d483e 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
« no previous file with comments | « ui/message_center/message_center.h ('k') | ui/message_center/message_center.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698