| 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 #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" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "ui/message_center/notification.h" | 10 #include "ui/message_center/notification.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 void MessageCenter::Shutdown() { | 32 void MessageCenter::Shutdown() { |
| 33 DCHECK(g_message_center); | 33 DCHECK(g_message_center); |
| 34 delete g_message_center; | 34 delete g_message_center; |
| 35 g_message_center = NULL; | 35 g_message_center = NULL; |
| 36 } | 36 } |
| 37 | 37 |
| 38 //------------------------------------------------------------------------------ | 38 //------------------------------------------------------------------------------ |
| 39 |
| 40 MessageCenter::Delegate::~Delegate() { |
| 41 } |
| 42 |
| 43 //------------------------------------------------------------------------------ |
| 44 |
| 39 MessageCenter::MessageCenter() | 45 MessageCenter::MessageCenter() |
| 40 : delegate_(NULL) { | 46 : delegate_(NULL) { |
| 41 notification_list_.reset(new NotificationList(this)); | 47 notification_list_.reset(new NotificationList(this)); |
| 42 } | 48 } |
| 43 | 49 |
| 44 MessageCenter::~MessageCenter() { | 50 MessageCenter::~MessageCenter() { |
| 45 notification_list_.reset(); | 51 notification_list_.reset(); |
| 46 } | 52 } |
| 47 | 53 |
| 48 void MessageCenter::AddObserver(Observer* observer) { | 54 void MessageCenter::AddObserver(Observer* observer) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 125 |
| 120 void MessageCenter::SetNotificationButtonIcon( | 126 void MessageCenter::SetNotificationButtonIcon( |
| 121 const std::string& notification_id, int button_index, | 127 const std::string& notification_id, int button_index, |
| 122 const gfx::Image& image) { | 128 const gfx::Image& image) { |
| 123 if (notification_list_->SetNotificationButtonIcon(notification_id, | 129 if (notification_list_->SetNotificationButtonIcon(notification_id, |
| 124 button_index, image)) | 130 button_index, image)) |
| 125 NotifyMessageCenterChanged(true); | 131 NotifyMessageCenterChanged(true); |
| 126 } | 132 } |
| 127 | 133 |
| 128 //------------------------------------------------------------------------------ | 134 //------------------------------------------------------------------------------ |
| 129 // Overridden from NotificationList::Delegate. | 135 // Overridden from NotificationChangeObserver: |
| 130 | 136 |
| 131 void MessageCenter::SendRemoveNotification(const std::string& id, | 137 void MessageCenter::OnRemoveNotification(const std::string& id, bool by_user) { |
| 132 bool by_user) { | |
| 133 if (delegate_) | 138 if (delegate_) |
| 134 delegate_->NotificationRemoved(id, by_user); | 139 delegate_->NotificationRemoved(id, by_user); |
| 135 } | 140 } |
| 136 | 141 |
| 137 void MessageCenter::SendRemoveAllNotifications(bool by_user) { | 142 void MessageCenter::OnRemoveAllNotifications(bool by_user) { |
| 138 if (delegate_) { | 143 if (delegate_) { |
| 139 const NotificationList::Notifications& notifications = | 144 const NotificationList::Notifications& notifications = |
| 140 notification_list_->GetNotifications(); | 145 notification_list_->GetNotifications(); |
| 141 for (NotificationList::Notifications::const_iterator loopiter = | 146 for (NotificationList::Notifications::const_iterator loopiter = |
| 142 notifications.begin(); | 147 notifications.begin(); |
| 143 loopiter != notifications.end(); ) { | 148 loopiter != notifications.end(); ) { |
| 144 NotificationList::Notifications::const_iterator curiter = loopiter++; | 149 NotificationList::Notifications::const_iterator curiter = loopiter++; |
| 145 std::string notification_id = (*curiter)->id(); | 150 std::string notification_id = (*curiter)->id(); |
| 146 // May call RemoveNotification and erase curiter. | 151 // May call RemoveNotification and erase curiter. |
| 147 delegate_->NotificationRemoved(notification_id, by_user); | 152 delegate_->NotificationRemoved(notification_id, by_user); |
| 148 } | 153 } |
| 149 } | 154 } |
| 150 } | 155 } |
| 151 | 156 |
| 152 void MessageCenter::DisableNotificationByExtension( | 157 void MessageCenter::OnDisableNotificationsByExtension( |
| 153 const std::string& id) { | 158 const std::string& id) { |
| 154 if (delegate_) | 159 if (delegate_) |
| 155 delegate_->DisableExtension(id); | 160 delegate_->DisableExtension(id); |
| 156 // When we disable notifications, we remove any existing matching | 161 // When we disable notifications, we remove any existing matching |
| 157 // notifications to avoid adding complicated UI to re-enable the source. | 162 // notifications to avoid adding complicated UI to re-enable the source. |
| 158 notification_list_->SendRemoveNotificationsByExtension(id); | 163 notification_list_->SendRemoveNotificationsByExtension(id); |
| 159 } | 164 } |
| 160 | 165 |
| 161 void MessageCenter::DisableNotificationByUrl(const std::string& id) { | 166 void MessageCenter::OnDisableNotificationsByUrl(const std::string& id) { |
| 162 if (delegate_) | 167 if (delegate_) |
| 163 delegate_->DisableNotificationsFromSource(id); | 168 delegate_->DisableNotificationsFromSource(id); |
| 164 notification_list_->SendRemoveNotificationsBySource(id); | 169 notification_list_->SendRemoveNotificationsBySource(id); |
| 165 } | 170 } |
| 166 | 171 |
| 167 void MessageCenter::ShowNotificationSettings(const std::string& id) { | 172 void MessageCenter::OnShowNotificationSettings(const std::string& id) { |
| 168 if (delegate_) | 173 if (delegate_) |
| 169 delegate_->ShowSettings(id); | 174 delegate_->ShowSettings(id); |
| 170 } | 175 } |
| 171 | 176 |
| 172 void MessageCenter::ShowNotificationSettingsDialog(gfx::NativeView context) { | 177 void MessageCenter::OnShowNotificationSettingsDialog(gfx::NativeView context) { |
| 173 if (delegate_) | 178 if (delegate_) |
| 174 delegate_->ShowSettingsDialog(context); | 179 delegate_->ShowSettingsDialog(context); |
| 175 } | 180 } |
| 176 | 181 |
| 177 void MessageCenter::OnNotificationClicked(const std::string& id) { | 182 void MessageCenter::OnExpanded(const std::string& id) { |
| 183 notification_list_->MarkNotificationAsExpanded(id); |
| 184 } |
| 185 |
| 186 void MessageCenter::OnClicked(const std::string& id) { |
| 178 if (delegate_) | 187 if (delegate_) |
| 179 delegate_->OnClicked(id); | 188 delegate_->OnClicked(id); |
| 180 if (HasPopupNotifications()) { | 189 if (HasPopupNotifications()) { |
| 181 notification_list_->MarkSinglePopupAsShown(id, true); | 190 notification_list_->MarkSinglePopupAsShown(id, true); |
| 182 NotifyMessageCenterChanged(false); | 191 NotifyMessageCenterChanged(false); |
| 183 } | 192 } |
| 184 } | 193 } |
| 185 | 194 |
| 186 void MessageCenter::OnQuietModeChanged(bool quiet_mode) { | |
| 187 NotifyMessageCenterChanged(true); | |
| 188 } | |
| 189 | |
| 190 void MessageCenter::OnButtonClicked(const std::string& id, int button_index) { | 195 void MessageCenter::OnButtonClicked(const std::string& id, int button_index) { |
| 191 if (delegate_) | 196 if (delegate_) |
| 192 delegate_->OnButtonClicked(id, button_index); | 197 delegate_->OnButtonClicked(id, button_index); |
| 193 if (HasPopupNotifications()) { | 198 if (HasPopupNotifications()) { |
| 194 notification_list_->MarkSinglePopupAsShown(id, true); | 199 notification_list_->MarkSinglePopupAsShown(id, true); |
| 195 NotifyMessageCenterChanged(false); | 200 NotifyMessageCenterChanged(false); |
| 196 } | 201 } |
| 197 } | 202 } |
| 198 | 203 |
| 199 NotificationList* MessageCenter::GetNotificationList() { | 204 //------------------------------------------------------------------------------ |
| 200 return notification_list_.get(); | 205 // Overridden from NotificationList::Delegate: |
| 206 |
| 207 void MessageCenter::SendRemoveNotification(const std::string& id, |
| 208 bool by_user) { |
| 209 if (delegate_) |
| 210 delegate_->NotificationRemoved(id, by_user); |
| 201 } | 211 } |
| 202 | 212 |
| 203 void MessageCenter::Delegate::OnButtonClicked(const std::string& id, | 213 void MessageCenter::OnQuietModeChanged(bool quiet_mode) { |
| 204 int button_index) { | 214 NotifyMessageCenterChanged(true); |
| 205 } | 215 } |
| 206 | 216 |
| 207 //------------------------------------------------------------------------------ | 217 //------------------------------------------------------------------------------ |
| 208 // Private. | 218 // Private. |
| 209 | 219 |
| 210 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) { | 220 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) { |
| 211 FOR_EACH_OBSERVER(Observer, | 221 FOR_EACH_OBSERVER(Observer, |
| 212 observer_list_, | 222 observer_list_, |
| 213 OnMessageCenterChanged(new_notification)); | 223 OnMessageCenterChanged(new_notification)); |
| 214 } | 224 } |
| 215 | 225 |
| 216 | 226 |
| 217 } // namespace message_center | 227 } // namespace message_center |
| OLD | NEW |