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 <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 //////////////////////////////////////////////////////////////////////////////// | 352 //////////////////////////////////////////////////////////////////////////////// |
353 // MessageCenterImpl | 353 // MessageCenterImpl |
354 | 354 |
355 MessageCenterImpl::MessageCenterImpl() | 355 MessageCenterImpl::MessageCenterImpl() |
356 : MessageCenter(), | 356 : MessageCenter(), |
357 popup_timers_controller_(new PopupTimersController(this)), | 357 popup_timers_controller_(new PopupTimersController(this)), |
358 settings_provider_(NULL) { | 358 settings_provider_(NULL) { |
359 notification_list_.reset(new NotificationList(this)); | 359 notification_list_.reset(new NotificationList()); |
360 | 360 |
361 bool enable_message_center_changes_while_open = true; // enable by default | 361 bool enable_message_center_changes_while_open = true; // enable by default |
362 std::string arg = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 362 std::string arg = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
363 switches::kMessageCenterChangesWhileOpen); | 363 switches::kMessageCenterChangesWhileOpen); |
364 if (!arg.empty()) { | 364 if (!arg.empty()) { |
365 if (arg == "enabled") | 365 if (arg == "enabled") |
366 enable_message_center_changes_while_open = true; | 366 enable_message_center_changes_while_open = true; |
367 else if (arg == "disabled") | 367 else if (arg == "disabled") |
368 enable_message_center_changes_while_open = false; | 368 enable_message_center_changes_while_open = false; |
369 } | 369 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 void MessageCenterImpl::NotifierGroupChanged() {} | 433 void MessageCenterImpl::NotifierGroupChanged() {} |
434 | 434 |
435 void MessageCenterImpl::NotifierEnabledChanged( | 435 void MessageCenterImpl::NotifierEnabledChanged( |
436 const NotifierId& notifier_id, bool enabled) { | 436 const NotifierId& notifier_id, bool enabled) { |
437 if (!enabled) { | 437 if (!enabled) { |
438 RemoveNotificationsForNotifierId(notifier_id); | 438 RemoveNotificationsForNotifierId(notifier_id); |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 void MessageCenterImpl::SetVisibility(Visibility visibility) { | 442 void MessageCenterImpl::SetVisibility(Visibility visibility) { |
443 visible_ = (visibility == VISIBILITY_MESSAGE_CENTER); | 443 std::set<std::string> updated_ids; |
| 444 notification_list_->SetMessageCenterVisible( |
| 445 (visibility == VISIBILITY_MESSAGE_CENTER), &updated_ids); |
| 446 notification_cache_.RecountUnread(); |
444 | 447 |
445 if (visible_ && !locked_) { | 448 for (const auto& id : updated_ids) { |
446 std::set<std::string> updated_ids; | 449 FOR_EACH_OBSERVER( |
447 notification_list_->SetNotificationsShown(blockers_, &updated_ids); | 450 MessageCenterObserver, observer_list_, OnNotificationUpdated(id)); |
448 notification_cache_.RecountUnread(); | |
449 | |
450 for (const auto& id : updated_ids) { | |
451 FOR_EACH_OBSERVER( | |
452 MessageCenterObserver, observer_list_, OnNotificationUpdated(id)); | |
453 } | |
454 } | 451 } |
455 | 452 |
456 if (notification_queue_ && | 453 if (notification_queue_ && |
457 visibility == VISIBILITY_TRANSIENT) { | 454 visibility == VISIBILITY_TRANSIENT) { |
458 notification_queue_->ApplyChanges(this); | 455 notification_queue_->ApplyChanges(this); |
459 } | 456 } |
460 | 457 |
461 FOR_EACH_OBSERVER(MessageCenterObserver, | 458 FOR_EACH_OBSERVER(MessageCenterObserver, |
462 observer_list_, | 459 observer_list_, |
463 OnCenterVisibilityChanged(visibility)); | 460 OnCenterVisibilityChanged(visibility)); |
464 } | 461 } |
465 | 462 |
466 bool MessageCenterImpl::IsMessageCenterVisible() const { | 463 bool MessageCenterImpl::IsMessageCenterVisible() const { |
467 return visible_; | 464 return notification_list_->is_message_center_visible(); |
468 } | 465 } |
469 | 466 |
470 size_t MessageCenterImpl::NotificationCount() const { | 467 size_t MessageCenterImpl::NotificationCount() const { |
471 return notification_cache_.visible_notifications.size(); | 468 return notification_cache_.visible_notifications.size(); |
472 } | 469 } |
473 | 470 |
474 size_t MessageCenterImpl::UnreadNotificationCount() const { | 471 size_t MessageCenterImpl::UnreadNotificationCount() const { |
475 return notification_cache_.unread_count; | 472 return notification_cache_.unread_count; |
476 } | 473 } |
477 | 474 |
478 bool MessageCenterImpl::HasPopupNotifications() const { | 475 bool MessageCenterImpl::HasPopupNotifications() const { |
479 return !IsMessageCenterVisible() && | 476 return !IsMessageCenterVisible() && |
480 notification_list_->HasPopupNotifications(blockers_); | 477 notification_list_->HasPopupNotifications(blockers_); |
481 } | 478 } |
482 | 479 |
483 bool MessageCenterImpl::IsQuietMode() const { | 480 bool MessageCenterImpl::IsQuietMode() const { |
484 return notification_list_->quiet_mode(); | 481 return notification_list_->quiet_mode(); |
485 } | 482 } |
486 | 483 |
487 bool MessageCenterImpl::IsLockedState() const { | |
488 return locked_; | |
489 } | |
490 | |
491 bool MessageCenterImpl::HasClickedListener(const std::string& id) { | 484 bool MessageCenterImpl::HasClickedListener(const std::string& id) { |
492 scoped_refptr<NotificationDelegate> delegate = | 485 scoped_refptr<NotificationDelegate> delegate = |
493 notification_list_->GetNotificationDelegate(id); | 486 notification_list_->GetNotificationDelegate(id); |
494 return delegate.get() && delegate->HasClickedListener(); | 487 return delegate.get() && delegate->HasClickedListener(); |
495 } | 488 } |
496 | 489 |
497 message_center::Notification* MessageCenterImpl::FindVisibleNotificationById( | 490 message_center::Notification* MessageCenterImpl::FindVisibleNotificationById( |
498 const std::string& id) { | 491 const std::string& id) { |
499 return notification_list_->GetNotificationById(id); | 492 return notification_list_->GetNotificationById(id); |
500 } | 493 } |
(...skipping 15 matching lines...) Expand all Loading... |
516 | 509 |
517 //------------------------------------------------------------------------------ | 510 //------------------------------------------------------------------------------ |
518 // Client code interface. | 511 // Client code interface. |
519 void MessageCenterImpl::AddNotification( | 512 void MessageCenterImpl::AddNotification( |
520 std::unique_ptr<Notification> notification) { | 513 std::unique_ptr<Notification> notification) { |
521 DCHECK(notification); | 514 DCHECK(notification); |
522 const std::string id = notification->id(); | 515 const std::string id = notification->id(); |
523 for (size_t i = 0; i < blockers_.size(); ++i) | 516 for (size_t i = 0; i < blockers_.size(); ++i) |
524 blockers_[i]->CheckState(); | 517 blockers_[i]->CheckState(); |
525 | 518 |
526 if (notification_queue_ && visible_) { | 519 if (notification_queue_ && |
| 520 notification_list_->is_message_center_visible()) { |
527 notification_queue_->AddNotification(std::move(notification)); | 521 notification_queue_->AddNotification(std::move(notification)); |
528 return; | 522 return; |
529 } | 523 } |
530 | 524 |
531 AddNotificationImmediately(std::move(notification)); | 525 AddNotificationImmediately(std::move(notification)); |
532 } | 526 } |
533 | 527 |
534 void MessageCenterImpl::AddNotificationImmediately( | 528 void MessageCenterImpl::AddNotificationImmediately( |
535 std::unique_ptr<Notification> notification) { | 529 std::unique_ptr<Notification> notification) { |
536 const std::string id = notification->id(); | 530 const std::string id = notification->id(); |
(...skipping 14 matching lines...) Expand all Loading... |
551 MessageCenterObserver, observer_list_, OnNotificationAdded(id)); | 545 MessageCenterObserver, observer_list_, OnNotificationAdded(id)); |
552 } | 546 } |
553 } | 547 } |
554 | 548 |
555 void MessageCenterImpl::UpdateNotification( | 549 void MessageCenterImpl::UpdateNotification( |
556 const std::string& old_id, | 550 const std::string& old_id, |
557 std::unique_ptr<Notification> new_notification) { | 551 std::unique_ptr<Notification> new_notification) { |
558 for (size_t i = 0; i < blockers_.size(); ++i) | 552 for (size_t i = 0; i < blockers_.size(); ++i) |
559 blockers_[i]->CheckState(); | 553 blockers_[i]->CheckState(); |
560 | 554 |
561 if (notification_queue_ && visible_) { | 555 if (notification_queue_ && |
| 556 notification_list_->is_message_center_visible()) { |
562 // We will allow notifications that are progress types (and stay progress | 557 // We will allow notifications that are progress types (and stay progress |
563 // types) to be updated even if the message center is open. There are 3 | 558 // types) to be updated even if the message center is open. There are 3 |
564 // requirements here: | 559 // requirements here: |
565 // * Notification of type PROGRESS exists with same ID in the center | 560 // * Notification of type PROGRESS exists with same ID in the center |
566 // * There are no queued updates for this notification (they imply a change | 561 // * There are no queued updates for this notification (they imply a change |
567 // that violates the PROGRESS invariant | 562 // that violates the PROGRESS invariant |
568 // * The new notification is type PROGRESS. | 563 // * The new notification is type PROGRESS. |
569 // TODO(dewittj): Ensure this works when the ID is changed by the caller. | 564 // TODO(dewittj): Ensure this works when the ID is changed by the caller. |
570 // This shouldn't be an issue in practice since only W3C notifications | 565 // This shouldn't be an issue in practice since only W3C notifications |
571 // change the ID on update, and they don't have progress type notifications. | 566 // change the ID on update, and they don't have progress type notifications. |
(...skipping 27 matching lines...) Expand all Loading... |
599 } else { | 594 } else { |
600 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 595 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
601 OnNotificationRemoved(old_id, false)); | 596 OnNotificationRemoved(old_id, false)); |
602 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 597 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
603 OnNotificationAdded(new_id)); | 598 OnNotificationAdded(new_id)); |
604 } | 599 } |
605 } | 600 } |
606 | 601 |
607 void MessageCenterImpl::RemoveNotification(const std::string& id, | 602 void MessageCenterImpl::RemoveNotification(const std::string& id, |
608 bool by_user) { | 603 bool by_user) { |
609 if (notification_queue_ && !by_user && visible_) { | 604 if (notification_queue_ && !by_user && |
| 605 notification_list_->is_message_center_visible()) { |
610 notification_queue_->EraseNotification(id, by_user); | 606 notification_queue_->EraseNotification(id, by_user); |
611 return; | 607 return; |
612 } | 608 } |
613 | 609 |
614 RemoveNotificationImmediately(id, by_user); | 610 RemoveNotificationImmediately(id, by_user); |
615 } | 611 } |
616 | 612 |
617 void MessageCenterImpl::RemoveNotificationImmediately( | 613 void MessageCenterImpl::RemoveNotificationImmediately( |
618 const std::string& id, bool by_user) { | 614 const std::string& id, bool by_user) { |
619 if (FindVisibleNotificationById(id) == NULL) | 615 if (FindVisibleNotificationById(id) == NULL) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { | 847 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { |
852 if (in_quiet_mode != notification_list_->quiet_mode()) { | 848 if (in_quiet_mode != notification_list_->quiet_mode()) { |
853 notification_list_->SetQuietMode(in_quiet_mode); | 849 notification_list_->SetQuietMode(in_quiet_mode); |
854 FOR_EACH_OBSERVER(MessageCenterObserver, | 850 FOR_EACH_OBSERVER(MessageCenterObserver, |
855 observer_list_, | 851 observer_list_, |
856 OnQuietModeChanged(in_quiet_mode)); | 852 OnQuietModeChanged(in_quiet_mode)); |
857 } | 853 } |
858 quiet_mode_timer_.reset(); | 854 quiet_mode_timer_.reset(); |
859 } | 855 } |
860 | 856 |
861 void MessageCenterImpl::SetLockedState(bool locked) { | |
862 if (locked != locked_) { | |
863 locked_ = locked; | |
864 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | |
865 OnLockedStateChanged(locked)); | |
866 } | |
867 } | |
868 | |
869 void MessageCenterImpl::EnterQuietModeWithExpire( | 857 void MessageCenterImpl::EnterQuietModeWithExpire( |
870 const base::TimeDelta& expires_in) { | 858 const base::TimeDelta& expires_in) { |
871 if (quiet_mode_timer_) { | 859 if (quiet_mode_timer_) { |
872 // Note that the capital Reset() is the method to restart the timer, not | 860 // Note that the capital Reset() is the method to restart the timer, not |
873 // scoped_ptr::reset(). | 861 // scoped_ptr::reset(). |
874 quiet_mode_timer_->Reset(); | 862 quiet_mode_timer_->Reset(); |
875 } else { | 863 } else { |
876 notification_list_->SetQuietMode(true); | 864 notification_list_->SetQuietMode(true); |
877 FOR_EACH_OBSERVER( | 865 FOR_EACH_OBSERVER( |
878 MessageCenterObserver, observer_list_, OnQuietModeChanged(true)); | 866 MessageCenterObserver, observer_list_, OnQuietModeChanged(true)); |
(...skipping 22 matching lines...) Expand all Loading... |
901 } | 889 } |
902 | 890 |
903 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) { | 891 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) { |
904 if (enable) | 892 if (enable) |
905 notification_queue_.reset(new internal::ChangeQueue()); | 893 notification_queue_.reset(new internal::ChangeQueue()); |
906 else | 894 else |
907 notification_queue_.reset(); | 895 notification_queue_.reset(); |
908 } | 896 } |
909 | 897 |
910 } // namespace message_center | 898 } // namespace message_center |
OLD | NEW |