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

Side by Side Diff: ui/message_center/message_center_impl.cc

Issue 2025613002: Reland: Show message center on lock screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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_impl.h ('k') | ui/message_center/message_center_observer.h » ('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) 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
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()); 359 notification_list_.reset(new NotificationList(this));
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
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 std::set<std::string> updated_ids; 443 visible_ = (visibility == VISIBILITY_MESSAGE_CENTER);
444 notification_list_->SetMessageCenterVisible(
445 (visibility == VISIBILITY_MESSAGE_CENTER), &updated_ids);
446 notification_cache_.RecountUnread();
447 444
448 for (const auto& id : updated_ids) { 445 if (visible_ && !locked_) {
449 FOR_EACH_OBSERVER( 446 std::set<std::string> updated_ids;
450 MessageCenterObserver, observer_list_, OnNotificationUpdated(id)); 447 notification_list_->SetNotificationsShown(blockers_, &updated_ids);
448 notification_cache_.RecountUnread();
449
450 for (const auto& id : updated_ids) {
451 FOR_EACH_OBSERVER(
452 MessageCenterObserver, observer_list_, OnNotificationUpdated(id));
453 }
451 } 454 }
452 455
453 if (notification_queue_ && 456 if (notification_queue_ &&
454 visibility == VISIBILITY_TRANSIENT) { 457 visibility == VISIBILITY_TRANSIENT) {
455 notification_queue_->ApplyChanges(this); 458 notification_queue_->ApplyChanges(this);
456 } 459 }
457 460
458 FOR_EACH_OBSERVER(MessageCenterObserver, 461 FOR_EACH_OBSERVER(MessageCenterObserver,
459 observer_list_, 462 observer_list_,
460 OnCenterVisibilityChanged(visibility)); 463 OnCenterVisibilityChanged(visibility));
461 } 464 }
462 465
463 bool MessageCenterImpl::IsMessageCenterVisible() const { 466 bool MessageCenterImpl::IsMessageCenterVisible() const {
464 return notification_list_->is_message_center_visible(); 467 return visible_;
465 } 468 }
466 469
467 size_t MessageCenterImpl::NotificationCount() const { 470 size_t MessageCenterImpl::NotificationCount() const {
468 return notification_cache_.visible_notifications.size(); 471 return notification_cache_.visible_notifications.size();
469 } 472 }
470 473
471 size_t MessageCenterImpl::UnreadNotificationCount() const { 474 size_t MessageCenterImpl::UnreadNotificationCount() const {
472 return notification_cache_.unread_count; 475 return notification_cache_.unread_count;
473 } 476 }
474 477
475 bool MessageCenterImpl::HasPopupNotifications() const { 478 bool MessageCenterImpl::HasPopupNotifications() const {
476 return !IsMessageCenterVisible() && 479 return !IsMessageCenterVisible() &&
477 notification_list_->HasPopupNotifications(blockers_); 480 notification_list_->HasPopupNotifications(blockers_);
478 } 481 }
479 482
480 bool MessageCenterImpl::IsQuietMode() const { 483 bool MessageCenterImpl::IsQuietMode() const {
481 return notification_list_->quiet_mode(); 484 return notification_list_->quiet_mode();
482 } 485 }
483 486
487 bool MessageCenterImpl::IsLockedState() const {
488 return locked_;
489 }
490
484 bool MessageCenterImpl::HasClickedListener(const std::string& id) { 491 bool MessageCenterImpl::HasClickedListener(const std::string& id) {
485 scoped_refptr<NotificationDelegate> delegate = 492 scoped_refptr<NotificationDelegate> delegate =
486 notification_list_->GetNotificationDelegate(id); 493 notification_list_->GetNotificationDelegate(id);
487 return delegate.get() && delegate->HasClickedListener(); 494 return delegate.get() && delegate->HasClickedListener();
488 } 495 }
489 496
490 message_center::Notification* MessageCenterImpl::FindVisibleNotificationById( 497 message_center::Notification* MessageCenterImpl::FindVisibleNotificationById(
491 const std::string& id) { 498 const std::string& id) {
492 return notification_list_->GetNotificationById(id); 499 return notification_list_->GetNotificationById(id);
493 } 500 }
(...skipping 15 matching lines...) Expand all
509 516
510 //------------------------------------------------------------------------------ 517 //------------------------------------------------------------------------------
511 // Client code interface. 518 // Client code interface.
512 void MessageCenterImpl::AddNotification( 519 void MessageCenterImpl::AddNotification(
513 std::unique_ptr<Notification> notification) { 520 std::unique_ptr<Notification> notification) {
514 DCHECK(notification); 521 DCHECK(notification);
515 const std::string id = notification->id(); 522 const std::string id = notification->id();
516 for (size_t i = 0; i < blockers_.size(); ++i) 523 for (size_t i = 0; i < blockers_.size(); ++i)
517 blockers_[i]->CheckState(); 524 blockers_[i]->CheckState();
518 525
519 if (notification_queue_ && 526 if (notification_queue_ && visible_) {
520 notification_list_->is_message_center_visible()) {
521 notification_queue_->AddNotification(std::move(notification)); 527 notification_queue_->AddNotification(std::move(notification));
522 return; 528 return;
523 } 529 }
524 530
525 AddNotificationImmediately(std::move(notification)); 531 AddNotificationImmediately(std::move(notification));
526 } 532 }
527 533
528 void MessageCenterImpl::AddNotificationImmediately( 534 void MessageCenterImpl::AddNotificationImmediately(
529 std::unique_ptr<Notification> notification) { 535 std::unique_ptr<Notification> notification) {
530 const std::string id = notification->id(); 536 const std::string id = notification->id();
(...skipping 14 matching lines...) Expand all
545 MessageCenterObserver, observer_list_, OnNotificationAdded(id)); 551 MessageCenterObserver, observer_list_, OnNotificationAdded(id));
546 } 552 }
547 } 553 }
548 554
549 void MessageCenterImpl::UpdateNotification( 555 void MessageCenterImpl::UpdateNotification(
550 const std::string& old_id, 556 const std::string& old_id,
551 std::unique_ptr<Notification> new_notification) { 557 std::unique_ptr<Notification> new_notification) {
552 for (size_t i = 0; i < blockers_.size(); ++i) 558 for (size_t i = 0; i < blockers_.size(); ++i)
553 blockers_[i]->CheckState(); 559 blockers_[i]->CheckState();
554 560
555 if (notification_queue_ && 561 if (notification_queue_ && visible_) {
556 notification_list_->is_message_center_visible()) {
557 // We will allow notifications that are progress types (and stay progress 562 // We will allow notifications that are progress types (and stay progress
558 // types) to be updated even if the message center is open. There are 3 563 // types) to be updated even if the message center is open. There are 3
559 // requirements here: 564 // requirements here:
560 // * Notification of type PROGRESS exists with same ID in the center 565 // * Notification of type PROGRESS exists with same ID in the center
561 // * There are no queued updates for this notification (they imply a change 566 // * There are no queued updates for this notification (they imply a change
562 // that violates the PROGRESS invariant 567 // that violates the PROGRESS invariant
563 // * The new notification is type PROGRESS. 568 // * The new notification is type PROGRESS.
564 // TODO(dewittj): Ensure this works when the ID is changed by the caller. 569 // TODO(dewittj): Ensure this works when the ID is changed by the caller.
565 // This shouldn't be an issue in practice since only W3C notifications 570 // This shouldn't be an issue in practice since only W3C notifications
566 // change the ID on update, and they don't have progress type notifications. 571 // change the ID on update, and they don't have progress type notifications.
(...skipping 27 matching lines...) Expand all
594 } else { 599 } else {
595 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 600 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
596 OnNotificationRemoved(old_id, false)); 601 OnNotificationRemoved(old_id, false));
597 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 602 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
598 OnNotificationAdded(new_id)); 603 OnNotificationAdded(new_id));
599 } 604 }
600 } 605 }
601 606
602 void MessageCenterImpl::RemoveNotification(const std::string& id, 607 void MessageCenterImpl::RemoveNotification(const std::string& id,
603 bool by_user) { 608 bool by_user) {
604 if (notification_queue_ && !by_user && 609 if (notification_queue_ && !by_user && visible_) {
605 notification_list_->is_message_center_visible()) {
606 notification_queue_->EraseNotification(id, by_user); 610 notification_queue_->EraseNotification(id, by_user);
607 return; 611 return;
608 } 612 }
609 613
610 RemoveNotificationImmediately(id, by_user); 614 RemoveNotificationImmediately(id, by_user);
611 } 615 }
612 616
613 void MessageCenterImpl::RemoveNotificationImmediately( 617 void MessageCenterImpl::RemoveNotificationImmediately(
614 const std::string& id, bool by_user) { 618 const std::string& id, bool by_user) {
615 if (FindVisibleNotificationById(id) == NULL) 619 if (FindVisibleNotificationById(id) == NULL)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { 851 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) {
848 if (in_quiet_mode != notification_list_->quiet_mode()) { 852 if (in_quiet_mode != notification_list_->quiet_mode()) {
849 notification_list_->SetQuietMode(in_quiet_mode); 853 notification_list_->SetQuietMode(in_quiet_mode);
850 FOR_EACH_OBSERVER(MessageCenterObserver, 854 FOR_EACH_OBSERVER(MessageCenterObserver,
851 observer_list_, 855 observer_list_,
852 OnQuietModeChanged(in_quiet_mode)); 856 OnQuietModeChanged(in_quiet_mode));
853 } 857 }
854 quiet_mode_timer_.reset(); 858 quiet_mode_timer_.reset();
855 } 859 }
856 860
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
857 void MessageCenterImpl::EnterQuietModeWithExpire( 869 void MessageCenterImpl::EnterQuietModeWithExpire(
858 const base::TimeDelta& expires_in) { 870 const base::TimeDelta& expires_in) {
859 if (quiet_mode_timer_) { 871 if (quiet_mode_timer_) {
860 // Note that the capital Reset() is the method to restart the timer, not 872 // Note that the capital Reset() is the method to restart the timer, not
861 // scoped_ptr::reset(). 873 // scoped_ptr::reset().
862 quiet_mode_timer_->Reset(); 874 quiet_mode_timer_->Reset();
863 } else { 875 } else {
864 notification_list_->SetQuietMode(true); 876 notification_list_->SetQuietMode(true);
865 FOR_EACH_OBSERVER( 877 FOR_EACH_OBSERVER(
866 MessageCenterObserver, observer_list_, OnQuietModeChanged(true)); 878 MessageCenterObserver, observer_list_, OnQuietModeChanged(true));
(...skipping 22 matching lines...) Expand all
889 } 901 }
890 902
891 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) { 903 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) {
892 if (enable) 904 if (enable)
893 notification_queue_.reset(new internal::ChangeQueue()); 905 notification_queue_.reset(new internal::ChangeQueue());
894 else 906 else
895 notification_queue_.reset(); 907 notification_queue_.reset();
896 } 908 }
897 909
898 } // namespace message_center 910 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_impl.h ('k') | ui/message_center/message_center_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698