| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
| 6 | 6 |
| 7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
| 8 #include "ui/message_center/message_center_style.h" | 8 #include "ui/message_center/message_center_style.h" |
| 9 #include "ui/message_center/message_center_types.h" |
| 9 #include "ui/message_center/notification.h" | 10 #include "ui/message_center/notification.h" |
| 10 #include "ui/message_center/notification_list.h" | 11 #include "ui/message_center/notification_list.h" |
| 11 #include "ui/message_center/notification_types.h" | 12 #include "ui/message_center/notification_types.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 base::TimeDelta GetTimeoutForPriority(int priority) { | 16 base::TimeDelta GetTimeoutForPriority(int priority) { |
| 16 if (priority > message_center::DEFAULT_PRIORITY) { | 17 if (priority > message_center::DEFAULT_PRIORITY) { |
| 17 return base::TimeDelta::FromSeconds( | 18 return base::TimeDelta::FromSeconds( |
| 18 message_center::kAutocloseHighPriorityDelaySeconds); | 19 message_center::kAutocloseHighPriorityDelaySeconds); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 188 } |
| 188 | 189 |
| 189 } // namespace internal | 190 } // namespace internal |
| 190 | 191 |
| 191 //////////////////////////////////////////////////////////////////////////////// | 192 //////////////////////////////////////////////////////////////////////////////// |
| 192 // MessageCenterImpl | 193 // MessageCenterImpl |
| 193 | 194 |
| 194 MessageCenterImpl::MessageCenterImpl() | 195 MessageCenterImpl::MessageCenterImpl() |
| 195 : MessageCenter(), | 196 : MessageCenter(), |
| 196 popup_timers_controller_(new internal::PopupTimersController(this)), | 197 popup_timers_controller_(new internal::PopupTimersController(this)), |
| 197 delegate_(NULL), | |
| 198 settings_provider_(NULL) { | 198 settings_provider_(NULL) { |
| 199 notification_list_.reset(new NotificationList()); | 199 notification_list_.reset(new NotificationList()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 MessageCenterImpl::~MessageCenterImpl() { | 202 MessageCenterImpl::~MessageCenterImpl() { |
| 203 notification_list_.reset(); | 203 notification_list_.reset(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) { | 206 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) { |
| 207 observer_list_.AddObserver(observer); | 207 observer_list_.AddObserver(observer); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) { | 210 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) { |
| 211 observer_list_.RemoveObserver(observer); | 211 observer_list_.RemoveObserver(observer); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void MessageCenterImpl::SetDelegate(Delegate* delegate) { | 214 void MessageCenterImpl::SetVisibility(Visibility visibility) { |
| 215 delegate_ = delegate; | 215 std::set<std::string> updated_ids; |
| 216 } | 216 notification_list_->SetMessageCenterVisible( |
| 217 (visibility == VISIBILITY_MESSAGE_CENTER), &updated_ids); |
| 217 | 218 |
| 218 void MessageCenterImpl::SetMessageCenterVisible(bool visible) { | |
| 219 std::set<std::string> updated_ids; | |
| 220 notification_list_->SetMessageCenterVisible(visible, &updated_ids); | |
| 221 for (std::set<std::string>::const_iterator iter = updated_ids.begin(); | 219 for (std::set<std::string>::const_iterator iter = updated_ids.begin(); |
| 222 iter != updated_ids.end(); | 220 iter != updated_ids.end(); |
| 223 ++iter) { | 221 ++iter) { |
| 224 FOR_EACH_OBSERVER( | 222 FOR_EACH_OBSERVER( |
| 225 MessageCenterObserver, observer_list_, OnNotificationUpdated(*iter)); | 223 MessageCenterObserver, observer_list_, OnNotificationUpdated(*iter)); |
| 226 } | 224 } |
| 227 | 225 |
| 228 if (!visible) { | 226 FOR_EACH_OBSERVER(MessageCenterObserver, |
| 229 FOR_EACH_OBSERVER( | 227 observer_list_, |
| 230 MessageCenterObserver, observer_list_, OnNotificationCenterClosed()); | 228 OnCenterVisibilityChanged(visibility)); |
| 231 } | |
| 232 } | 229 } |
| 233 | 230 |
| 234 bool MessageCenterImpl::IsMessageCenterVisible() { | 231 bool MessageCenterImpl::IsMessageCenterVisible() { |
| 235 return notification_list_->is_message_center_visible(); | 232 return notification_list_->is_message_center_visible(); |
| 236 } | 233 } |
| 237 | 234 |
| 238 size_t MessageCenterImpl::NotificationCount() const { | 235 size_t MessageCenterImpl::NotificationCount() const { |
| 239 return notification_list_->NotificationCount(); | 236 return notification_list_->NotificationCount(); |
| 240 } | 237 } |
| 241 | 238 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 NotificationList::Notifications notifications = | 385 NotificationList::Notifications notifications = |
| 389 notification_list_->GetNotificationsByNotifierId(notifier_id); | 386 notification_list_->GetNotificationsByNotifierId(notifier_id); |
| 390 for (NotificationList::Notifications::const_iterator iter = | 387 for (NotificationList::Notifications::const_iterator iter = |
| 391 notifications.begin(); iter != notifications.end();) { | 388 notifications.begin(); iter != notifications.end();) { |
| 392 std::string id = (*iter)->id(); | 389 std::string id = (*iter)->id(); |
| 393 iter++; | 390 iter++; |
| 394 RemoveNotification(id, false); | 391 RemoveNotification(id, false); |
| 395 } | 392 } |
| 396 } | 393 } |
| 397 | 394 |
| 398 void MessageCenterImpl::ShowNotificationSettings(const std::string& id) { | |
| 399 if (delegate_) | |
| 400 delegate_->ShowSettings(id); | |
| 401 } | |
| 402 | |
| 403 void MessageCenterImpl::ExpandNotification(const std::string& id) { | 395 void MessageCenterImpl::ExpandNotification(const std::string& id) { |
| 404 if (!HasNotification(id)) | 396 if (!HasNotification(id)) |
| 405 return; | 397 return; |
| 406 notification_list_->MarkNotificationAsExpanded(id); | 398 notification_list_->MarkNotificationAsExpanded(id); |
| 407 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 399 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
| 408 OnNotificationUpdated(id)); | 400 OnNotificationUpdated(id)); |
| 409 } | 401 } |
| 410 | 402 |
| 411 void MessageCenterImpl::ClickOnNotification(const std::string& id) { | 403 void MessageCenterImpl::ClickOnNotification(const std::string& id) { |
| 412 if (!HasNotification(id)) | 404 if (!HasNotification(id)) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 void MessageCenterImpl::PausePopupTimers() { | 498 void MessageCenterImpl::PausePopupTimers() { |
| 507 if (popup_timers_controller_.get()) | 499 if (popup_timers_controller_.get()) |
| 508 popup_timers_controller_->PauseAll(); | 500 popup_timers_controller_->PauseAll(); |
| 509 } | 501 } |
| 510 | 502 |
| 511 void MessageCenterImpl::DisableTimersForTest() { | 503 void MessageCenterImpl::DisableTimersForTest() { |
| 512 popup_timers_controller_.reset(); | 504 popup_timers_controller_.reset(); |
| 513 } | 505 } |
| 514 | 506 |
| 515 } // namespace message_center | 507 } // namespace message_center |
| OLD | NEW |