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

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

Issue 2928433004: Add thread-checker for public methods of message center (Closed)
Patch Set: Created 3 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') | no next file » | 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 <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 373
374 if (!enable_message_center_changes_while_open) 374 if (!enable_message_center_changes_while_open)
375 notification_queue_.reset(new internal::ChangeQueue()); 375 notification_queue_.reset(new internal::ChangeQueue());
376 } 376 }
377 377
378 MessageCenterImpl::~MessageCenterImpl() { 378 MessageCenterImpl::~MessageCenterImpl() {
379 SetNotifierSettingsProvider(NULL); 379 SetNotifierSettingsProvider(NULL);
380 } 380 }
381 381
382 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) { 382 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) {
383 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
383 observer_list_.AddObserver(observer); 384 observer_list_.AddObserver(observer);
384 } 385 }
385 386
386 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) { 387 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) {
388 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
387 observer_list_.RemoveObserver(observer); 389 observer_list_.RemoveObserver(observer);
388 } 390 }
389 391
390 void MessageCenterImpl::AddNotificationBlocker(NotificationBlocker* blocker) { 392 void MessageCenterImpl::AddNotificationBlocker(NotificationBlocker* blocker) {
393 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
391 if (base::ContainsValue(blockers_, blocker)) 394 if (base::ContainsValue(blockers_, blocker))
392 return; 395 return;
393 396
394 blocker->AddObserver(this); 397 blocker->AddObserver(this);
395 blockers_.push_back(blocker); 398 blockers_.push_back(blocker);
396 } 399 }
397 400
398 void MessageCenterImpl::RemoveNotificationBlocker( 401 void MessageCenterImpl::RemoveNotificationBlocker(
399 NotificationBlocker* blocker) { 402 NotificationBlocker* blocker) {
403 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
400 std::vector<NotificationBlocker*>::iterator iter = 404 std::vector<NotificationBlocker*>::iterator iter =
401 std::find(blockers_.begin(), blockers_.end(), blocker); 405 std::find(blockers_.begin(), blockers_.end(), blocker);
402 if (iter == blockers_.end()) 406 if (iter == blockers_.end())
403 return; 407 return;
404 blocker->RemoveObserver(this); 408 blocker->RemoveObserver(this);
405 blockers_.erase(iter); 409 blockers_.erase(iter);
406 } 410 }
407 411
408 void MessageCenterImpl::OnBlockingStateChanged(NotificationBlocker* blocker) { 412 void MessageCenterImpl::OnBlockingStateChanged(NotificationBlocker* blocker) {
413 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
409 std::list<std::string> blocked_ids; 414 std::list<std::string> blocked_ids;
410 NotificationList::PopupNotifications popups = 415 NotificationList::PopupNotifications popups =
411 notification_list_->GetPopupNotifications(blockers_, &blocked_ids); 416 notification_list_->GetPopupNotifications(blockers_, &blocked_ids);
412 417
413 for (const auto& id : blocked_ids) { 418 for (const auto& id : blocked_ids) {
414 // Do not call MessageCenterImpl::MarkSinglePopupAsShown() directly here 419 // Do not call MessageCenterImpl::MarkSinglePopupAsShown() directly here
415 // just for performance reason. MessageCenterImpl::MarkSinglePopupAsShown() 420 // just for performance reason. MessageCenterImpl::MarkSinglePopupAsShown()
416 // calls NotificationList::MarkSinglePopupAsShown() and then updates the 421 // calls NotificationList::MarkSinglePopupAsShown() and then updates the
417 // unread count, but the whole cache will be recreated below. 422 // unread count, but the whole cache will be recreated below.
418 notification_list_->MarkSinglePopupAsShown(id, true); 423 notification_list_->MarkSinglePopupAsShown(id, true);
419 } 424 }
420 notification_cache_.Rebuild( 425 notification_cache_.Rebuild(
421 notification_list_->GetVisibleNotifications(blockers_)); 426 notification_list_->GetVisibleNotifications(blockers_));
422 427
423 for (const auto& id : blocked_ids) { 428 for (const auto& id : blocked_ids) {
424 for (auto& observer : observer_list_) 429 for (auto& observer : observer_list_)
425 observer.OnNotificationUpdated(id); 430 observer.OnNotificationUpdated(id);
426 } 431 }
427 for (auto& observer : observer_list_) 432 for (auto& observer : observer_list_)
428 observer.OnBlockingStateChanged(blocker); 433 observer.OnBlockingStateChanged(blocker);
429 } 434 }
430 435
431 void MessageCenterImpl::UpdateIconImage( 436 void MessageCenterImpl::UpdateIconImage(const NotifierId& notifier_id,
432 const NotifierId& notifier_id, const gfx::Image& icon) {} 437 const gfx::Image& icon) {
438 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
439 }
433 440
434 void MessageCenterImpl::NotifierGroupChanged() {} 441 void MessageCenterImpl::NotifierGroupChanged() {
442 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
443 }
435 444
436 void MessageCenterImpl::NotifierEnabledChanged( 445 void MessageCenterImpl::NotifierEnabledChanged(
437 const NotifierId& notifier_id, bool enabled) { 446 const NotifierId& notifier_id, bool enabled) {
447 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
438 if (!enabled) { 448 if (!enabled) {
439 RemoveNotificationsForNotifierId(notifier_id); 449 RemoveNotificationsForNotifierId(notifier_id);
440 } 450 }
441 } 451 }
442 452
443 void MessageCenterImpl::SetVisibility(Visibility visibility) { 453 void MessageCenterImpl::SetVisibility(Visibility visibility) {
454 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
444 visible_ = (visibility == VISIBILITY_MESSAGE_CENTER); 455 visible_ = (visibility == VISIBILITY_MESSAGE_CENTER);
445 456
446 if (visible_ && !locked_) { 457 if (visible_ && !locked_) {
447 std::set<std::string> updated_ids; 458 std::set<std::string> updated_ids;
448 notification_list_->SetNotificationsShown(blockers_, &updated_ids); 459 notification_list_->SetNotificationsShown(blockers_, &updated_ids);
449 notification_cache_.RecountUnread(); 460 notification_cache_.RecountUnread();
450 461
451 for (const auto& id : updated_ids) { 462 for (const auto& id : updated_ids) {
452 for (auto& observer : observer_list_) 463 for (auto& observer : observer_list_)
453 observer.OnNotificationUpdated(id); 464 observer.OnNotificationUpdated(id);
454 } 465 }
455 } 466 }
456 467
457 if (notification_queue_ && 468 if (notification_queue_ &&
458 visibility == VISIBILITY_TRANSIENT) { 469 visibility == VISIBILITY_TRANSIENT) {
459 notification_queue_->ApplyChanges(this); 470 notification_queue_->ApplyChanges(this);
460 } 471 }
461 472
462 for (auto& observer : observer_list_) 473 for (auto& observer : observer_list_)
463 observer.OnCenterVisibilityChanged(visibility); 474 observer.OnCenterVisibilityChanged(visibility);
464 } 475 }
465 476
466 bool MessageCenterImpl::IsMessageCenterVisible() const { 477 bool MessageCenterImpl::IsMessageCenterVisible() const {
478 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
467 return visible_; 479 return visible_;
468 } 480 }
469 481
470 size_t MessageCenterImpl::NotificationCount() const { 482 size_t MessageCenterImpl::NotificationCount() const {
483 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
471 return notification_cache_.visible_notifications.size(); 484 return notification_cache_.visible_notifications.size();
472 } 485 }
473 486
474 size_t MessageCenterImpl::UnreadNotificationCount() const { 487 size_t MessageCenterImpl::UnreadNotificationCount() const {
488 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
475 return notification_cache_.unread_count; 489 return notification_cache_.unread_count;
476 } 490 }
477 491
478 bool MessageCenterImpl::HasPopupNotifications() const { 492 bool MessageCenterImpl::HasPopupNotifications() const {
493 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
479 return !IsMessageCenterVisible() && 494 return !IsMessageCenterVisible() &&
480 notification_list_->HasPopupNotifications(blockers_); 495 notification_list_->HasPopupNotifications(blockers_);
481 } 496 }
482 497
483 bool MessageCenterImpl::IsQuietMode() const { 498 bool MessageCenterImpl::IsQuietMode() const {
499 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
484 return notification_list_->quiet_mode(); 500 return notification_list_->quiet_mode();
485 } 501 }
486 502
487 bool MessageCenterImpl::IsLockedState() const { 503 bool MessageCenterImpl::IsLockedState() const {
504 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
488 return locked_; 505 return locked_;
489 } 506 }
490 507
491 bool MessageCenterImpl::HasClickedListener(const std::string& id) { 508 bool MessageCenterImpl::HasClickedListener(const std::string& id) {
509 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
492 scoped_refptr<NotificationDelegate> delegate = 510 scoped_refptr<NotificationDelegate> delegate =
493 notification_list_->GetNotificationDelegate(id); 511 notification_list_->GetNotificationDelegate(id);
494 return delegate.get() && delegate->HasClickedListener(); 512 return delegate.get() && delegate->HasClickedListener();
495 } 513 }
496 514
497 message_center::Notification* MessageCenterImpl::FindVisibleNotificationById( 515 message_center::Notification* MessageCenterImpl::FindVisibleNotificationById(
498 const std::string& id) { 516 const std::string& id) {
517 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
499 return notification_list_->GetNotificationById(id); 518 return notification_list_->GetNotificationById(id);
500 } 519 }
501 520
502 const NotificationList::Notifications& 521 const NotificationList::Notifications&
503 MessageCenterImpl::GetVisibleNotifications() { 522 MessageCenterImpl::GetVisibleNotifications() {
523 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
504 return notification_cache_.visible_notifications; 524 return notification_cache_.visible_notifications;
505 } 525 }
506 526
507 NotificationList::PopupNotifications 527 NotificationList::PopupNotifications
508 MessageCenterImpl::GetPopupNotifications() { 528 MessageCenterImpl::GetPopupNotifications() {
529 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
509 return notification_list_->GetPopupNotifications(blockers_, NULL); 530 return notification_list_->GetPopupNotifications(blockers_, NULL);
510 } 531 }
511 532
512 void MessageCenterImpl::ForceNotificationFlush(const std::string& id) { 533 void MessageCenterImpl::ForceNotificationFlush(const std::string& id) {
534 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
513 if (notification_queue_) 535 if (notification_queue_)
514 notification_queue_->ApplyChangesForId(this, id); 536 notification_queue_->ApplyChangesForId(this, id);
515 } 537 }
516 538
517 //------------------------------------------------------------------------------ 539 //------------------------------------------------------------------------------
518 // Client code interface. 540 // Client code interface.
519 void MessageCenterImpl::AddNotification( 541 void MessageCenterImpl::AddNotification(
520 std::unique_ptr<Notification> notification) { 542 std::unique_ptr<Notification> notification) {
543 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
521 DCHECK(notification); 544 DCHECK(notification);
522 const std::string id = notification->id(); 545 const std::string id = notification->id();
523 for (size_t i = 0; i < blockers_.size(); ++i) 546 for (size_t i = 0; i < blockers_.size(); ++i)
524 blockers_[i]->CheckState(); 547 blockers_[i]->CheckState();
525 548
526 if (notification_queue_ && visible_) { 549 if (notification_queue_ && visible_) {
527 notification_queue_->AddNotification(std::move(notification)); 550 notification_queue_->AddNotification(std::move(notification));
528 return; 551 return;
529 } 552 }
530 553
531 AddNotificationImmediately(std::move(notification)); 554 AddNotificationImmediately(std::move(notification));
532 } 555 }
533 556
534 void MessageCenterImpl::AddNotificationImmediately( 557 void MessageCenterImpl::AddNotificationImmediately(
535 std::unique_ptr<Notification> notification) { 558 std::unique_ptr<Notification> notification) {
559 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
536 const std::string id = notification->id(); 560 const std::string id = notification->id();
537 561
538 // Sometimes the notification can be added with the same id and the 562 // Sometimes the notification can be added with the same id and the
539 // |notification_list| will replace the notification instead of adding new. 563 // |notification_list| will replace the notification instead of adding new.
540 // This is essentially an update rather than addition. 564 // This is essentially an update rather than addition.
541 bool already_exists = (notification_list_->GetNotificationById(id) != NULL); 565 bool already_exists = (notification_list_->GetNotificationById(id) != NULL);
542 notification_list_->AddNotification(std::move(notification)); 566 notification_list_->AddNotification(std::move(notification));
543 notification_cache_.Rebuild( 567 notification_cache_.Rebuild(
544 notification_list_->GetVisibleNotifications(blockers_)); 568 notification_list_->GetVisibleNotifications(blockers_));
545 569
546 if (already_exists) { 570 if (already_exists) {
547 for (auto& observer : observer_list_) 571 for (auto& observer : observer_list_)
548 observer.OnNotificationUpdated(id); 572 observer.OnNotificationUpdated(id);
549 } else { 573 } else {
550 for (auto& observer : observer_list_) 574 for (auto& observer : observer_list_)
551 observer.OnNotificationAdded(id); 575 observer.OnNotificationAdded(id);
552 } 576 }
553 } 577 }
554 578
555 void MessageCenterImpl::UpdateNotification( 579 void MessageCenterImpl::UpdateNotification(
556 const std::string& old_id, 580 const std::string& old_id,
557 std::unique_ptr<Notification> new_notification) { 581 std::unique_ptr<Notification> new_notification) {
582 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
558 for (size_t i = 0; i < blockers_.size(); ++i) 583 for (size_t i = 0; i < blockers_.size(); ++i)
559 blockers_[i]->CheckState(); 584 blockers_[i]->CheckState();
560 585
561 if (notification_queue_ && visible_) { 586 if (notification_queue_ && visible_) {
562 // We will allow notifications that are progress types (and stay progress 587 // 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 588 // types) to be updated even if the message center is open. There are 3
564 // requirements here: 589 // requirements here:
565 // * Notification of type PROGRESS exists with same ID in the center 590 // * Notification of type PROGRESS exists with same ID in the center
566 // * There are no queued updates for this notification (they imply a change 591 // * There are no queued updates for this notification (they imply a change
567 // that violates the PROGRESS invariant 592 // that violates the PROGRESS invariant
(...skipping 13 matching lines...) Expand all
581 return; 606 return;
582 } 607 }
583 } 608 }
584 609
585 UpdateNotificationImmediately(old_id, std::move(new_notification)); 610 UpdateNotificationImmediately(old_id, std::move(new_notification));
586 } 611 }
587 612
588 void MessageCenterImpl::UpdateNotificationImmediately( 613 void MessageCenterImpl::UpdateNotificationImmediately(
589 const std::string& old_id, 614 const std::string& old_id,
590 std::unique_ptr<Notification> new_notification) { 615 std::unique_ptr<Notification> new_notification) {
616 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
591 std::string new_id = new_notification->id(); 617 std::string new_id = new_notification->id();
592 notification_list_->UpdateNotificationMessage(old_id, 618 notification_list_->UpdateNotificationMessage(old_id,
593 std::move(new_notification)); 619 std::move(new_notification));
594 notification_cache_.Rebuild( 620 notification_cache_.Rebuild(
595 notification_list_->GetVisibleNotifications(blockers_)); 621 notification_list_->GetVisibleNotifications(blockers_));
596 if (old_id == new_id) { 622 if (old_id == new_id) {
597 for (auto& observer : observer_list_) 623 for (auto& observer : observer_list_)
598 observer.OnNotificationUpdated(new_id); 624 observer.OnNotificationUpdated(new_id);
599 } else { 625 } else {
600 for (auto& observer : observer_list_) 626 for (auto& observer : observer_list_)
601 observer.OnNotificationRemoved(old_id, false); 627 observer.OnNotificationRemoved(old_id, false);
602 for (auto& observer : observer_list_) 628 for (auto& observer : observer_list_)
603 observer.OnNotificationAdded(new_id); 629 observer.OnNotificationAdded(new_id);
604 } 630 }
605 } 631 }
606 632
607 void MessageCenterImpl::RemoveNotification(const std::string& id, 633 void MessageCenterImpl::RemoveNotification(const std::string& id,
608 bool by_user) { 634 bool by_user) {
635 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
609 if (notification_queue_ && !by_user && visible_) { 636 if (notification_queue_ && !by_user && visible_) {
610 notification_queue_->EraseNotification(id, by_user); 637 notification_queue_->EraseNotification(id, by_user);
611 return; 638 return;
612 } 639 }
613 640
614 RemoveNotificationImmediately(id, by_user); 641 RemoveNotificationImmediately(id, by_user);
615 } 642 }
616 643
617 void MessageCenterImpl::RemoveNotificationImmediately( 644 void MessageCenterImpl::RemoveNotificationImmediately(
618 const std::string& id, bool by_user) { 645 const std::string& id, bool by_user) {
646 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
619 Notification* notification = FindVisibleNotificationById(id); 647 Notification* notification = FindVisibleNotificationById(id);
620 if (notification == NULL) 648 if (notification == NULL)
621 return; 649 return;
622 650
623 if (by_user && notification->pinned()) 651 if (by_user && notification->pinned())
624 return; 652 return;
625 653
626 // In many cases |id| is a reference to an existing notification instance 654 // In many cases |id| is a reference to an existing notification instance
627 // but the instance can be destructed in this method. Hence copies the id 655 // but the instance can be destructed in this method. Hence copies the id
628 // explicitly here. 656 // explicitly here.
629 std::string copied_id(id); 657 std::string copied_id(id);
630 658
631 scoped_refptr<NotificationDelegate> delegate = 659 scoped_refptr<NotificationDelegate> delegate =
632 notification_list_->GetNotificationDelegate(copied_id); 660 notification_list_->GetNotificationDelegate(copied_id);
633 if (delegate.get()) 661 if (delegate.get())
634 delegate->Close(by_user); 662 delegate->Close(by_user);
635 663
636 notification_list_->RemoveNotification(copied_id); 664 notification_list_->RemoveNotification(copied_id);
637 notification_cache_.Rebuild( 665 notification_cache_.Rebuild(
638 notification_list_->GetVisibleNotifications(blockers_)); 666 notification_list_->GetVisibleNotifications(blockers_));
639 for (auto& observer : observer_list_) 667 for (auto& observer : observer_list_)
640 observer.OnNotificationRemoved(copied_id, by_user); 668 observer.OnNotificationRemoved(copied_id, by_user);
641 } 669 }
642 670
643 void MessageCenterImpl::RemoveNotificationsForNotifierId( 671 void MessageCenterImpl::RemoveNotificationsForNotifierId(
644 const NotifierId& notifier_id) { 672 const NotifierId& notifier_id) {
673 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
645 NotificationList::Notifications notifications = 674 NotificationList::Notifications notifications =
646 notification_list_->GetNotificationsByNotifierId(notifier_id); 675 notification_list_->GetNotificationsByNotifierId(notifier_id);
647 for (auto* notification : notifications) 676 for (auto* notification : notifications)
648 RemoveNotification(notification->id(), false); 677 RemoveNotification(notification->id(), false);
649 if (!notifications.empty()) { 678 if (!notifications.empty()) {
650 notification_cache_.Rebuild( 679 notification_cache_.Rebuild(
651 notification_list_->GetVisibleNotifications(blockers_)); 680 notification_list_->GetVisibleNotifications(blockers_));
652 } 681 }
653 } 682 }
654 683
655 void MessageCenterImpl::RemoveAllNotifications(bool by_user, RemoveType type) { 684 void MessageCenterImpl::RemoveAllNotifications(bool by_user, RemoveType type) {
685 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
656 bool remove_pinned = (type == RemoveType::ALL); 686 bool remove_pinned = (type == RemoveType::ALL);
657 687
658 const NotificationBlockers& blockers = 688 const NotificationBlockers& blockers =
659 remove_pinned ? NotificationBlockers() /* empty blockers */ 689 remove_pinned ? NotificationBlockers() /* empty blockers */
660 : blockers_; /* use default blockers */ 690 : blockers_; /* use default blockers */
661 691
662 const NotificationList::Notifications notifications = 692 const NotificationList::Notifications notifications =
663 notification_list_->GetVisibleNotifications(blockers); 693 notification_list_->GetVisibleNotifications(blockers);
664 std::set<std::string> ids; 694 std::set<std::string> ids;
665 for (auto* notification : notifications) { 695 for (auto* notification : notifications) {
(...skipping 12 matching lines...) Expand all
678 notification_list_->GetVisibleNotifications(blockers_)); 708 notification_list_->GetVisibleNotifications(blockers_));
679 } 709 }
680 for (const auto& id : ids) { 710 for (const auto& id : ids) {
681 for (auto& observer : observer_list_) 711 for (auto& observer : observer_list_)
682 observer.OnNotificationRemoved(id, by_user); 712 observer.OnNotificationRemoved(id, by_user);
683 } 713 }
684 } 714 }
685 715
686 void MessageCenterImpl::SetNotificationIcon(const std::string& notification_id, 716 void MessageCenterImpl::SetNotificationIcon(const std::string& notification_id,
687 const gfx::Image& image) { 717 const gfx::Image& image) {
718 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
688 bool updated = false; 719 bool updated = false;
689 Notification* queue_notification = 720 Notification* queue_notification =
690 notification_queue_ 721 notification_queue_
691 ? notification_queue_->GetLatestNotification(notification_id) 722 ? notification_queue_->GetLatestNotification(notification_id)
692 : NULL; 723 : NULL;
693 724
694 if (queue_notification) { 725 if (queue_notification) {
695 queue_notification->set_icon(image); 726 queue_notification->set_icon(image);
696 updated = true; 727 updated = true;
697 } else { 728 } else {
698 updated = notification_list_->SetNotificationIcon(notification_id, image); 729 updated = notification_list_->SetNotificationIcon(notification_id, image);
699 } 730 }
700 731
701 if (updated) { 732 if (updated) {
702 for (auto& observer : observer_list_) 733 for (auto& observer : observer_list_)
703 observer.OnNotificationUpdated(notification_id); 734 observer.OnNotificationUpdated(notification_id);
704 } 735 }
705 } 736 }
706 737
707 void MessageCenterImpl::SetNotificationImage(const std::string& notification_id, 738 void MessageCenterImpl::SetNotificationImage(const std::string& notification_id,
708 const gfx::Image& image) { 739 const gfx::Image& image) {
740 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
709 bool updated = false; 741 bool updated = false;
710 Notification* queue_notification = 742 Notification* queue_notification =
711 notification_queue_ 743 notification_queue_
712 ? notification_queue_->GetLatestNotification(notification_id) 744 ? notification_queue_->GetLatestNotification(notification_id)
713 : NULL; 745 : NULL;
714 746
715 if (queue_notification) { 747 if (queue_notification) {
716 queue_notification->set_image(image); 748 queue_notification->set_image(image);
717 updated = true; 749 updated = true;
718 } else { 750 } else {
719 updated = notification_list_->SetNotificationImage(notification_id, image); 751 updated = notification_list_->SetNotificationImage(notification_id, image);
720 } 752 }
721 753
722 if (updated) { 754 if (updated) {
723 for (auto& observer : observer_list_) 755 for (auto& observer : observer_list_)
724 observer.OnNotificationUpdated(notification_id); 756 observer.OnNotificationUpdated(notification_id);
725 } 757 }
726 } 758 }
727 759
728 void MessageCenterImpl::SetNotificationButtonIcon( 760 void MessageCenterImpl::SetNotificationButtonIcon(
729 const std::string& notification_id, int button_index, 761 const std::string& notification_id, int button_index,
730 const gfx::Image& image) { 762 const gfx::Image& image) {
763 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
731 bool updated = false; 764 bool updated = false;
732 Notification* queue_notification = 765 Notification* queue_notification =
733 notification_queue_ 766 notification_queue_
734 ? notification_queue_->GetLatestNotification(notification_id) 767 ? notification_queue_->GetLatestNotification(notification_id)
735 : NULL; 768 : NULL;
736 769
737 if (queue_notification) { 770 if (queue_notification) {
738 queue_notification->SetButtonIcon(button_index, image); 771 queue_notification->SetButtonIcon(button_index, image);
739 updated = true; 772 updated = true;
740 } else { 773 } else {
741 updated = notification_list_->SetNotificationButtonIcon( 774 updated = notification_list_->SetNotificationButtonIcon(
742 notification_id, button_index, image); 775 notification_id, button_index, image);
743 } 776 }
744 777
745 if (updated) { 778 if (updated) {
746 for (auto& observer : observer_list_) 779 for (auto& observer : observer_list_)
747 observer.OnNotificationUpdated(notification_id); 780 observer.OnNotificationUpdated(notification_id);
748 } 781 }
749 } 782 }
750 783
751 void MessageCenterImpl::DisableNotificationsByNotifier( 784 void MessageCenterImpl::DisableNotificationsByNotifier(
752 const NotifierId& notifier_id) { 785 const NotifierId& notifier_id) {
786 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
753 if (settings_provider_) { 787 if (settings_provider_) {
754 // TODO(mukai): SetNotifierEnabled can just accept notifier_id? 788 // TODO(mukai): SetNotifierEnabled can just accept notifier_id?
755 Notifier notifier(notifier_id, base::string16(), true); 789 Notifier notifier(notifier_id, base::string16(), true);
756 settings_provider_->SetNotifierEnabled(notifier, false); 790 settings_provider_->SetNotifierEnabled(notifier, false);
757 // The settings provider will call back to remove the notifications 791 // The settings provider will call back to remove the notifications
758 // belonging to the notifier id. 792 // belonging to the notifier id.
759 } else { 793 } else {
760 RemoveNotificationsForNotifierId(notifier_id); 794 RemoveNotificationsForNotifierId(notifier_id);
761 } 795 }
762 } 796 }
763 797
764 void MessageCenterImpl::ClickOnNotification(const std::string& id) { 798 void MessageCenterImpl::ClickOnNotification(const std::string& id) {
799 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
765 if (FindVisibleNotificationById(id) == NULL) 800 if (FindVisibleNotificationById(id) == NULL)
766 return; 801 return;
767 #if defined(OS_CHROMEOS) 802 #if defined(OS_CHROMEOS)
768 if (HasPopupNotifications()) 803 if (HasPopupNotifications())
769 MarkSinglePopupAsShown(id, true); 804 MarkSinglePopupAsShown(id, true);
770 #endif 805 #endif
771 scoped_refptr<NotificationDelegate> delegate = 806 scoped_refptr<NotificationDelegate> delegate =
772 notification_list_->GetNotificationDelegate(id); 807 notification_list_->GetNotificationDelegate(id);
773 if (delegate.get()) 808 if (delegate.get())
774 delegate->Click(); 809 delegate->Click();
775 for (auto& observer : observer_list_) 810 for (auto& observer : observer_list_)
776 observer.OnNotificationClicked(id); 811 observer.OnNotificationClicked(id);
777 } 812 }
778 813
779 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id, 814 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id,
780 int button_index) { 815 int button_index) {
816 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
781 if (FindVisibleNotificationById(id) == NULL) 817 if (FindVisibleNotificationById(id) == NULL)
782 return; 818 return;
783 #if defined(OS_CHROMEOS) 819 #if defined(OS_CHROMEOS)
784 if (HasPopupNotifications()) 820 if (HasPopupNotifications())
785 MarkSinglePopupAsShown(id, true); 821 MarkSinglePopupAsShown(id, true);
786 #endif 822 #endif
787 scoped_refptr<NotificationDelegate> delegate = 823 scoped_refptr<NotificationDelegate> delegate =
788 notification_list_->GetNotificationDelegate(id); 824 notification_list_->GetNotificationDelegate(id);
789 if (delegate.get()) 825 if (delegate.get())
790 delegate->ButtonClick(button_index); 826 delegate->ButtonClick(button_index);
791 for (auto& observer : observer_list_) 827 for (auto& observer : observer_list_)
792 observer.OnNotificationButtonClicked(id, button_index); 828 observer.OnNotificationButtonClicked(id, button_index);
793 } 829 }
794 830
795 void MessageCenterImpl::ClickOnSettingsButton(const std::string& id) { 831 void MessageCenterImpl::ClickOnSettingsButton(const std::string& id) {
832 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
796 scoped_refptr<NotificationDelegate> delegate = 833 scoped_refptr<NotificationDelegate> delegate =
797 notification_list_->GetNotificationDelegate(id); 834 notification_list_->GetNotificationDelegate(id);
798 835
799 bool handled_by_delegate = false; 836 bool handled_by_delegate = false;
800 if (delegate.get()) 837 if (delegate.get())
801 handled_by_delegate = delegate->SettingsClick(); 838 handled_by_delegate = delegate->SettingsClick();
802 839
803 for (auto& observer : observer_list_) 840 for (auto& observer : observer_list_)
804 observer.OnNotificationSettingsClicked(handled_by_delegate); 841 observer.OnNotificationSettingsClicked(handled_by_delegate);
805 } 842 }
806 843
807 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id, 844 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id,
808 bool mark_notification_as_read) { 845 bool mark_notification_as_read) {
846 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
809 if (FindVisibleNotificationById(id) == NULL) 847 if (FindVisibleNotificationById(id) == NULL)
810 return; 848 return;
811 #if !defined(OS_CHROMEOS) 849 #if !defined(OS_CHROMEOS)
812 return this->RemoveNotification(id, false); 850 return this->RemoveNotification(id, false);
813 #else 851 #else
814 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read); 852 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read);
815 notification_cache_.RecountUnread(); 853 notification_cache_.RecountUnread();
816 for (auto& observer : observer_list_) 854 for (auto& observer : observer_list_)
817 observer.OnNotificationUpdated(id); 855 observer.OnNotificationUpdated(id);
818 #endif // defined(OS_CHROMEOS) 856 #endif // defined(OS_CHROMEOS)
819 } 857 }
820 858
821 void MessageCenterImpl::DisplayedNotification( 859 void MessageCenterImpl::DisplayedNotification(
822 const std::string& id, 860 const std::string& id,
823 const DisplaySource source) { 861 const DisplaySource source) {
862 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
824 if (FindVisibleNotificationById(id) == NULL) 863 if (FindVisibleNotificationById(id) == NULL)
825 return; 864 return;
826 865
827 if (HasPopupNotifications()) 866 if (HasPopupNotifications())
828 notification_list_->MarkSinglePopupAsDisplayed(id); 867 notification_list_->MarkSinglePopupAsDisplayed(id);
829 notification_cache_.RecountUnread(); 868 notification_cache_.RecountUnread();
830 scoped_refptr<NotificationDelegate> delegate = 869 scoped_refptr<NotificationDelegate> delegate =
831 notification_list_->GetNotificationDelegate(id); 870 notification_list_->GetNotificationDelegate(id);
832 if (delegate.get()) 871 if (delegate.get())
833 delegate->Display(); 872 delegate->Display();
834 for (auto& observer : observer_list_) 873 for (auto& observer : observer_list_)
835 observer.OnNotificationDisplayed(id, source); 874 observer.OnNotificationDisplayed(id, source);
836 } 875 }
837 876
838 void MessageCenterImpl::SetNotifierSettingsProvider( 877 void MessageCenterImpl::SetNotifierSettingsProvider(
839 NotifierSettingsProvider* provider) { 878 NotifierSettingsProvider* provider) {
879 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
840 if (settings_provider_) { 880 if (settings_provider_) {
841 settings_provider_->RemoveObserver(this); 881 settings_provider_->RemoveObserver(this);
842 settings_provider_ = NULL; 882 settings_provider_ = NULL;
843 } 883 }
844 settings_provider_ = provider; 884 settings_provider_ = provider;
845 if (settings_provider_) 885 if (settings_provider_)
846 settings_provider_->AddObserver(this); 886 settings_provider_->AddObserver(this);
847 } 887 }
848 888
849 NotifierSettingsProvider* MessageCenterImpl::GetNotifierSettingsProvider() { 889 NotifierSettingsProvider* MessageCenterImpl::GetNotifierSettingsProvider() {
890 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
850 return settings_provider_; 891 return settings_provider_;
851 } 892 }
852 893
853 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { 894 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) {
895 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
854 if (in_quiet_mode != notification_list_->quiet_mode()) { 896 if (in_quiet_mode != notification_list_->quiet_mode()) {
855 notification_list_->SetQuietMode(in_quiet_mode); 897 notification_list_->SetQuietMode(in_quiet_mode);
856 for (auto& observer : observer_list_) 898 for (auto& observer : observer_list_)
857 observer.OnQuietModeChanged(in_quiet_mode); 899 observer.OnQuietModeChanged(in_quiet_mode);
858 } 900 }
859 quiet_mode_timer_.reset(); 901 quiet_mode_timer_.reset();
860 } 902 }
861 903
862 void MessageCenterImpl::SetLockedState(bool locked) { 904 void MessageCenterImpl::SetLockedState(bool locked) {
905 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
863 if (locked != locked_) { 906 if (locked != locked_) {
864 locked_ = locked; 907 locked_ = locked;
865 for (auto& observer : observer_list_) 908 for (auto& observer : observer_list_)
866 observer.OnLockedStateChanged(locked); 909 observer.OnLockedStateChanged(locked);
867 } 910 }
868 } 911 }
869 912
870 void MessageCenterImpl::EnterQuietModeWithExpire( 913 void MessageCenterImpl::EnterQuietModeWithExpire(
871 const base::TimeDelta& expires_in) { 914 const base::TimeDelta& expires_in) {
915 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
872 if (quiet_mode_timer_) { 916 if (quiet_mode_timer_) {
873 // Note that the capital Reset() is the method to restart the timer, not 917 // Note that the capital Reset() is the method to restart the timer, not
874 // scoped_ptr::reset(). 918 // scoped_ptr::reset().
875 quiet_mode_timer_->Reset(); 919 quiet_mode_timer_->Reset();
876 } else { 920 } else {
877 notification_list_->SetQuietMode(true); 921 notification_list_->SetQuietMode(true);
878 for (auto& observer : observer_list_) 922 for (auto& observer : observer_list_)
879 observer.OnQuietModeChanged(true); 923 observer.OnQuietModeChanged(true);
880 924
881 quiet_mode_timer_.reset(new base::OneShotTimer); 925 quiet_mode_timer_.reset(new base::OneShotTimer);
882 quiet_mode_timer_->Start( 926 quiet_mode_timer_->Start(
883 FROM_HERE, 927 FROM_HERE,
884 expires_in, 928 expires_in,
885 base::Bind( 929 base::Bind(
886 &MessageCenterImpl::SetQuietMode, base::Unretained(this), false)); 930 &MessageCenterImpl::SetQuietMode, base::Unretained(this), false));
887 } 931 }
888 } 932 }
889 933
890 void MessageCenterImpl::RestartPopupTimers() { 934 void MessageCenterImpl::RestartPopupTimers() {
935 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
891 if (popup_timers_controller_) 936 if (popup_timers_controller_)
892 popup_timers_controller_->StartAll(); 937 popup_timers_controller_->StartAll();
893 } 938 }
894 939
895 void MessageCenterImpl::PausePopupTimers() { 940 void MessageCenterImpl::PausePopupTimers() {
941 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
896 if (popup_timers_controller_) 942 if (popup_timers_controller_)
897 popup_timers_controller_->PauseAll(); 943 popup_timers_controller_->PauseAll();
898 } 944 }
899 945
900 void MessageCenterImpl::DisableTimersForTest() { 946 void MessageCenterImpl::DisableTimersForTest() {
901 popup_timers_controller_.reset(); 947 popup_timers_controller_.reset();
902 } 948 }
903 949
904 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) { 950 void MessageCenterImpl::EnableChangeQueueForTest(bool enable) {
905 if (enable) 951 if (enable)
906 notification_queue_.reset(new internal::ChangeQueue()); 952 notification_queue_.reset(new internal::ChangeQueue());
907 else 953 else
908 notification_queue_.reset(); 954 notification_queue_.reset();
909 } 955 }
910 956
911 } // namespace message_center 957 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698