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

Side by Side 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, 11 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/message_center/message_center.h" 5 #include "ui/message_center/message_center.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include "base/observer_list.h"
8 10
9 namespace message_center { 11 namespace message_center {
10 12
11 //------------------------------------------------------------------------------ 13 //------------------------------------------------------------------------------
12 14
13 MessageCenter::MessageCenter(Host* host) 15 // static
14 : host_(host), 16 MessageCenter* MessageCenter::GetInstance() {
15 delegate_(NULL) { 17 return Singleton<MessageCenter>::get();
16 notification_list_.reset(new NotificationList(this));
17 } 18 }
18 19
19 MessageCenter::~MessageCenter() { 20 MessageCenter::~MessageCenter() {
20 notification_list_.reset(); 21 notification_list_.reset();
21 } 22 }
22 23
24 void MessageCenter::AddObserver(Observer* observer) {
25 observer_list_.AddObserver(observer);
26 }
27
28 void MessageCenter::RemoveObserver(Observer* observer) {
29 observer_list_.RemoveObserver(observer);
30 }
31
23 void MessageCenter::SetDelegate(Delegate* delegate) { 32 void MessageCenter::SetDelegate(Delegate* delegate) {
24 DCHECK(!delegate_);
25 delegate_ = delegate; 33 delegate_ = delegate;
26 } 34 }
27 35
28 void MessageCenter::SetMessageCenterVisible(bool visible) { 36 void MessageCenter::SetMessageCenterVisible(bool visible) {
29 notification_list_->SetMessageCenterVisible(visible); 37 notification_list_->SetMessageCenterVisible(visible);
30 } 38 }
31 39
32 size_t MessageCenter::NotificationCount() const { 40 size_t MessageCenter::NotificationCount() const {
33 return notification_list_->NotificationCount(); 41 return notification_list_->NotificationCount();
34 } 42 }
(...skipping 12 matching lines...) Expand all
47 void MessageCenter::AddNotification( 55 void MessageCenter::AddNotification(
48 ui::notifications::NotificationType type, 56 ui::notifications::NotificationType type,
49 const std::string& id, 57 const std::string& id,
50 const string16& title, 58 const string16& title,
51 const string16& message, 59 const string16& message,
52 const string16& display_source, 60 const string16& display_source,
53 const std::string& extension_id, 61 const std::string& extension_id,
54 const base::DictionaryValue* optional_fields) { 62 const base::DictionaryValue* optional_fields) {
55 notification_list_->AddNotification(type, id, title, message, display_source, 63 notification_list_->AddNotification(type, id, title, message, display_source,
56 extension_id, optional_fields); 64 extension_id, optional_fields);
57 if (host_) 65 NotifyMessageCenterChanged(true);
58 host_->MessageCenterChanged(true);
59 } 66 }
60 67
61 void MessageCenter::UpdateNotification( 68 void MessageCenter::UpdateNotification(
62 const std::string& old_id, 69 const std::string& old_id,
63 const std::string& new_id, 70 const std::string& new_id,
64 const string16& title, 71 const string16& title,
65 const string16& message, 72 const string16& message,
66 const base::DictionaryValue* optional_fields) { 73 const base::DictionaryValue* optional_fields) {
67 notification_list_->UpdateNotificationMessage( 74 notification_list_->UpdateNotificationMessage(
68 old_id, new_id, title, message, optional_fields); 75 old_id, new_id, title, message, optional_fields);
69 if (host_) 76 NotifyMessageCenterChanged(true);
70 host_->MessageCenterChanged(true);
71 } 77 }
72 78
73 void MessageCenter::RemoveNotification(const std::string& id) { 79 void MessageCenter::RemoveNotification(const std::string& id) {
74 if (!notification_list_->RemoveNotification(id)) 80 if (!notification_list_->RemoveNotification(id))
75 return; 81 return;
76 if (host_) 82 NotifyMessageCenterChanged(false);
77 host_->MessageCenterChanged(false);
78 } 83 }
79 84
80 void MessageCenter::SetNotificationPrimaryIcon(const std::string& id, 85 void MessageCenter::SetNotificationPrimaryIcon(const std::string& id,
81 const gfx::ImageSkia& image) { 86 const gfx::ImageSkia& image) {
82 if (notification_list_->SetNotificationPrimaryIcon(id, image) && host_) 87 if (notification_list_->SetNotificationPrimaryIcon(id, image))
83 host_->MessageCenterChanged(true); 88 NotifyMessageCenterChanged(true);
84 } 89 }
85 90
86 void MessageCenter::SetNotificationSecondaryIcon(const std::string& id, 91 void MessageCenter::SetNotificationSecondaryIcon(const std::string& id,
87 const gfx::ImageSkia& image) { 92 const gfx::ImageSkia& image) {
88 if (notification_list_->SetNotificationSecondaryIcon(id, image) && host_) 93 if (notification_list_->SetNotificationSecondaryIcon(id, image))
89 host_->MessageCenterChanged(true); 94 NotifyMessageCenterChanged(true);
90 } 95 }
91 96
92 //------------------------------------------------------------------------------ 97 //------------------------------------------------------------------------------
93 // Overridden from NotificationList::Delegate. 98 // Overridden from NotificationList::Delegate.
94 99
95 void MessageCenter::SendRemoveNotification(const std::string& id) { 100 void MessageCenter::SendRemoveNotification(const std::string& id) {
96 if (delegate_) 101 if (delegate_)
97 delegate_->NotificationRemoved(id); 102 delegate_->NotificationRemoved(id);
98 } 103 }
99 104
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (delegate_) 136 if (delegate_)
132 delegate_->ShowSettings(id); 137 delegate_->ShowSettings(id);
133 } 138 }
134 139
135 void MessageCenter::OnNotificationClicked(const std::string& id) { 140 void MessageCenter::OnNotificationClicked(const std::string& id) {
136 if (delegate_) 141 if (delegate_)
137 delegate_->OnClicked(id); 142 delegate_->OnClicked(id);
138 } 143 }
139 144
140 void MessageCenter::OnQuietModeChanged(bool quiet_mode) { 145 void MessageCenter::OnQuietModeChanged(bool quiet_mode) {
141 host_->MessageCenterChanged(true); 146 NotifyMessageCenterChanged(true);
142 } 147 }
143 148
144 void MessageCenter::OnButtonClicked(const std::string& id, int button_index) { 149 void MessageCenter::OnButtonClicked(const std::string& id, int button_index) {
145 if (delegate_) 150 if (delegate_)
146 delegate_->OnButtonClicked(id, button_index); 151 delegate_->OnButtonClicked(id, button_index);
147 } 152 }
148 153
149 NotificationList* MessageCenter::GetNotificationList() { 154 NotificationList* MessageCenter::GetNotificationList() {
150 return notification_list_.get(); 155 return notification_list_.get();
151 } 156 }
152 157
153 void MessageCenter::Delegate::OnButtonClicked(const std::string& id, 158 void MessageCenter::Delegate::OnButtonClicked(const std::string& id,
154 int button_index) { 159 int button_index) {
155 } 160 }
156 161
162 //------------------------------------------------------------------------------
163 // Private.
164
165 MessageCenter::MessageCenter()
166 : delegate_(NULL) {
167 notification_list_.reset(new NotificationList(this));
168 }
169
170 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) {
171 FOR_EACH_OBSERVER(Observer,
172 observer_list_,
173 OnMessageCenterChanged(new_notification));
174 }
175
176
157 } // namespace message_center 177 } // namespace message_center
OLDNEW
« 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