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

Side by Side Diff: chrome/browser/chromeos/system/ash_system_tray_delegate.cc

Issue 9968101: Close notification windows while message loop is still active (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chromeos/system/ash_system_tray_delegate.h" 5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/system/audio/audio_observer.h" 9 #include "ash/system/audio/audio_observer.h"
10 #include "ash/system/bluetooth/bluetooth_observer.h" 10 #include "ash/system/bluetooth/bluetooth_observer.h"
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 603
604 virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE { 604 virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE {
605 GetAppropriateBrowser()->ShowSingletonTab(GURL(topup_url)); 605 GetAppropriateBrowser()->ShowSingletonTab(GURL(topup_url));
606 } 606 }
607 607
608 virtual void ChangeProxySettings() OVERRIDE { 608 virtual void ChangeProxySettings() OVERRIDE {
609 CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE); 609 CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE);
610 BaseLoginDisplayHost::default_host()->OpenProxySettings(); 610 BaseLoginDisplayHost::default_host()->OpenProxySettings();
611 } 611 }
612 612
613 virtual void OnTrayDestroyed() OVERRIDE {
614 tray_ = NULL;
615 }
616
613 private: 617 private:
614 // Returns the last active browser. If there is no such browser, creates a new 618 // Returns the last active browser. If there is no such browser, creates a new
615 // browser window with an empty tab and returns it. 619 // browser window with an empty tab and returns it.
616 Browser* GetAppropriateBrowser() { 620 Browser* GetAppropriateBrowser() {
617 return Browser::GetOrCreateTabbedBrowser( 621 return Browser::GetOrCreateTabbedBrowser(
618 ProfileManager::GetDefaultProfileOrOffTheRecord()); 622 ProfileManager::GetDefaultProfileOrOffTheRecord());
619 } 623 }
620 624
621 void SetProfile(Profile* profile) { 625 void SetProfile(Profile* profile) {
622 pref_registrar_.reset(new PrefChangeRegistrar); 626 pref_registrar_.reset(new PrefChangeRegistrar);
623 pref_registrar_->Init(profile->GetPrefs()); 627 pref_registrar_->Init(profile->GetPrefs());
624 pref_registrar_->Add(prefs::kUse24HourClock, this); 628 pref_registrar_->Add(prefs::kUse24HourClock, this);
625 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); 629 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this);
626 UpdateClockType(profile->GetPrefs()); 630 UpdateClockType(profile->GetPrefs());
627 search_key_mapped_to_ = 631 search_key_mapped_to_ =
628 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); 632 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo);
629 } 633 }
630 634
631 void UpdateClockType(PrefService* service) { 635 void UpdateClockType(PrefService* service) {
632 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? 636 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ?
633 base::k24HourClock : base::k12HourClock; 637 base::k24HourClock : base::k12HourClock;
634 ash::ClockObserver* observer = 638 ash::ClockObserver* observer = tray_ ? tray_->clock_observer() : NULL;
635 ash::Shell::GetInstance()->tray()->clock_observer();
636 if (observer) 639 if (observer)
637 observer->OnDateFormatChanged(); 640 observer->OnDateFormatChanged();
638 } 641 }
639 642
640 void NotifyRefreshClock() { 643 void NotifyRefreshClock() {
641 ash::ClockObserver* observer = 644 ash::ClockObserver* observer = tray_ ? tray_->clock_observer() : NULL;
642 ash::Shell::GetInstance()->tray()->clock_observer();
643 if (observer) 645 if (observer)
644 observer->Refresh(); 646 observer->Refresh();
645 } 647 }
646 648
647 void NotifyRefreshNetwork() { 649 void NotifyRefreshNetwork() {
648 ash::NetworkObserver* observer = 650 ash::NetworkObserver* observer = tray_ ? tray_->network_observer() : NULL;
649 ash::Shell::GetInstance()->tray()->network_observer();
650 if (observer) { 651 if (observer) {
651 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); 652 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
652 ash::NetworkIconInfo info; 653 ash::NetworkIconInfo info;
653 info.image = network_icon_->GetIconAndText(&info.description); 654 info.image = network_icon_->GetIconAndText(&info.description);
654 info.tray_icon_visible = 655 info.tray_icon_visible =
655 ShouldShowNetworkIconInTray(crosnet->connected_network()); 656 ShouldShowNetworkIconInTray(crosnet->connected_network());
656 observer->OnNetworkRefresh(info); 657 observer->OnNetworkRefresh(info);
657 } 658 }
658 } 659 }
659 660
660 void NotifyRefreshBluetooth() { 661 void NotifyRefreshBluetooth() {
661 ash::BluetoothObserver* observer = 662 ash::BluetoothObserver* observer =
662 ash::Shell::GetInstance()->tray()->bluetooth_observer(); 663 tray_ ? tray_->bluetooth_observer() : NULL;
663 if (observer) 664 if (observer)
664 observer->OnBluetoothRefresh(); 665 observer->OnBluetoothRefresh();
665 } 666 }
666 667
667 void NotifyRefreshIME() { 668 void NotifyRefreshIME() {
668 ash::IMEObserver* observer = 669 ash::IMEObserver* observer = tray_ ? tray_->ime_observer() : NULL;
669 ash::Shell::GetInstance()->tray()->ime_observer();
670 if (observer) 670 if (observer)
671 observer->OnIMERefresh(); 671 observer->OnIMERefresh();
672 } 672 }
673 673
674 void RefreshNetworkObserver(NetworkLibrary* crosnet) { 674 void RefreshNetworkObserver(NetworkLibrary* crosnet) {
675 const Network* network = crosnet->active_network(); 675 const Network* network = crosnet->active_network();
676 std::string new_path = network ? network->service_path() : std::string(); 676 std::string new_path = network ? network->service_path() : std::string();
677 if (active_network_path_ != new_path) { 677 if (active_network_path_ != new_path) {
678 if (!active_network_path_.empty()) 678 if (!active_network_path_.empty())
679 crosnet->RemoveNetworkObserver(active_network_path_, this); 679 crosnet->RemoveNetworkObserver(active_network_path_, this);
680 if (!new_path.empty()) 680 if (!new_path.empty())
681 crosnet->AddNetworkObserver(new_path, this); 681 crosnet->AddNetworkObserver(new_path, this);
682 active_network_path_ = new_path; 682 active_network_path_ = new_path;
683 } 683 }
684 } 684 }
685 685
686 void RefreshNetworkDeviceObserver(NetworkLibrary* crosnet) { 686 void RefreshNetworkDeviceObserver(NetworkLibrary* crosnet) {
687 const NetworkDevice* cellular = crosnet->FindCellularDevice(); 687 const NetworkDevice* cellular = crosnet->FindCellularDevice();
688 std::string new_cellular_device_path = cellular ? 688 std::string new_cellular_device_path = cellular ?
689 cellular->device_path() : std::string(); 689 cellular->device_path() : std::string();
690 if (cellular_device_path_ != new_cellular_device_path) 690 if (cellular_device_path_ != new_cellular_device_path)
691 cellular_device_path_ = new_cellular_device_path; 691 cellular_device_path_ = new_cellular_device_path;
692 } 692 }
693 693
694 // Overridden from AudioHandler::VolumeObserver. 694 // Overridden from AudioHandler::VolumeObserver.
695 virtual void OnVolumeChanged() OVERRIDE { 695 virtual void OnVolumeChanged() OVERRIDE {
696 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; 696 if (tray_) {
697 ash::Shell::GetInstance()->tray()->audio_observer()-> 697 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f;
698 OnVolumeChanged(level); 698 tray_->audio_observer()->OnVolumeChanged(level);
699 }
699 } 700 }
700 701
701 // Overridden from PowerManagerClient::Observer. 702 // Overridden from PowerManagerClient::Observer.
702 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { 703 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE {
703 ash::Shell::GetInstance()->tray()->brightness_observer()-> 704 if (tray_) {
704 OnBrightnessChanged(static_cast<double>(level), user_initiated); 705 tray_->brightness_observer()->
706 OnBrightnessChanged(static_cast<double>(level), user_initiated);
707 }
705 } 708 }
706 709
707 virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE { 710 virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE {
708 power_supply_status_ = power_status; 711 power_supply_status_ = power_status;
709 ash::PowerStatusObserver* observer = 712 ash::PowerStatusObserver* observer =
710 ash::Shell::GetInstance()->tray()->power_status_observer(); 713 tray_ ? tray_->power_status_observer() : NULL;
711 if (observer) 714 if (observer)
712 observer->OnPowerStatusChanged(power_status); 715 observer->OnPowerStatusChanged(power_status);
713 } 716 }
714 717
715 virtual void SystemResumed() OVERRIDE { 718 virtual void SystemResumed() OVERRIDE {
716 NotifyRefreshClock(); 719 NotifyRefreshClock();
717 } 720 }
718 721
719 virtual void LockScreen() OVERRIDE { 722 virtual void LockScreen() OVERRIDE {
720 screen_locked_ = true; 723 screen_locked_ = true;
721 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); 724 if (tray_)
725 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus());
722 } 726 }
723 727
724 virtual void UnlockScreen() OVERRIDE { 728 virtual void UnlockScreen() OVERRIDE {
725 screen_locked_ = false; 729 screen_locked_ = false;
726 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); 730 if (tray_)
731 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus());
727 } 732 }
728 733
729 virtual void UnlockScreenFailed() OVERRIDE { 734 virtual void UnlockScreenFailed() OVERRIDE {
730 } 735 }
731 736
732 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. 737 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g.
733 // PowerButtonStateChanged etc.). 738 // PowerButtonStateChanged etc.).
734 739
735 // Overridden from NetworkMenuIcon::Delegate. 740 // Overridden from NetworkMenuIcon::Delegate.
736 virtual void NetworkMenuIconChanged() OVERRIDE { 741 virtual void NetworkMenuIconChanged() OVERRIDE {
(...skipping 16 matching lines...) Expand all
753 } 758 }
754 759
755 virtual bool ShouldOpenButtonOptions() const OVERRIDE { 760 virtual bool ShouldOpenButtonOptions() const OVERRIDE {
756 return false; 761 return false;
757 } 762 }
758 763
759 // Overridden from NetworkLibrary::NetworkManagerObserver. 764 // Overridden from NetworkLibrary::NetworkManagerObserver.
760 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { 765 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE {
761 RefreshNetworkObserver(crosnet); 766 RefreshNetworkObserver(crosnet);
762 RefreshNetworkDeviceObserver(crosnet); 767 RefreshNetworkDeviceObserver(crosnet);
763 data_promo_notification_->ShowOptionalMobileDataPromoNotification(crosnet, 768 if (tray_) {
764 tray_, this); 769 data_promo_notification_->ShowOptionalMobileDataPromoNotification(
770 crosnet, tray_, this);
771 }
765 772
766 NotifyRefreshNetwork(); 773 NotifyRefreshNetwork();
767 } 774 }
768 775
769 // Overridden from NetworkLibrary::NetworkObserver. 776 // Overridden from NetworkLibrary::NetworkObserver.
770 virtual void OnNetworkChanged(NetworkLibrary* crosnet, 777 virtual void OnNetworkChanged(NetworkLibrary* crosnet,
771 const Network* network) OVERRIDE { 778 const Network* network) OVERRIDE {
772 NotifyRefreshNetwork(); 779 NotifyRefreshNetwork();
773 } 780 }
774 781
775 // Overridden from NetworkLibrary::CellularDataPlanObserver. 782 // Overridden from NetworkLibrary::CellularDataPlanObserver.
776 virtual void OnCellularDataPlanChanged(NetworkLibrary* crosnet) OVERRIDE { 783 virtual void OnCellularDataPlanChanged(NetworkLibrary* crosnet) OVERRIDE {
777 NotifyRefreshNetwork(); 784 NotifyRefreshNetwork();
778 } 785 }
779 786
780 // content::NotificationObserver implementation. 787 // content::NotificationObserver implementation.
781 virtual void Observe(int type, 788 virtual void Observe(int type,
782 const content::NotificationSource& source, 789 const content::NotificationSource& source,
783 const content::NotificationDetails& details) OVERRIDE { 790 const content::NotificationDetails& details) OVERRIDE {
784 switch (type) { 791 switch (type) {
785 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 792 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
786 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); 793 if (tray_)
794 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus());
787 break; 795 break;
788 } 796 }
789 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { 797 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
790 ash::UpdateObserver* observer = 798 ash::UpdateObserver* observer = tray_ ? tray_->update_observer() : NULL;
791 ash::Shell::GetInstance()->tray()->update_observer();
792 if (observer) 799 if (observer)
793 observer->OnUpdateRecommended(); 800 observer->OnUpdateRecommended();
794 break; 801 break;
795 } 802 }
796 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { 803 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
797 // This notification is also sent on login screen when user avatar 804 // This notification is also sent on login screen when user avatar
798 // is loaded from file. 805 // is loaded from file.
799 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { 806 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) {
800 ash::UserObserver* observer = 807 ash::UserObserver* observer = tray_ ? tray_->user_observer() : NULL;
801 ash::Shell::GetInstance()->tray()->user_observer();
802 if (observer) 808 if (observer)
803 observer->OnUserUpdate(); 809 observer->OnUserUpdate();
804 } 810 }
805 break; 811 break;
806 } 812 }
807 case chrome::NOTIFICATION_PREF_CHANGED: { 813 case chrome::NOTIFICATION_PREF_CHANGED: {
808 std::string pref = *content::Details<std::string>(details).ptr(); 814 std::string pref = *content::Details<std::string>(details).ptr();
809 PrefService* service = content::Source<PrefService>(source).ptr(); 815 PrefService* service = content::Source<PrefService>(source).ptr();
810 if (pref == prefs::kUse24HourClock) { 816 if (pref == prefs::kUse24HourClock) {
811 UpdateClockType(service); 817 UpdateClockType(service);
812 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { 818 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) {
813 search_key_mapped_to_ = 819 search_key_mapped_to_ =
814 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); 820 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo);
815 } else if (pref == prefs::kSpokenFeedbackEnabled) { 821 } else if (pref == prefs::kSpokenFeedbackEnabled) {
816 ash::AccessibilityObserver* observer = 822 ash::AccessibilityObserver* observer =
817 ash::Shell::GetInstance()->tray()->accessibility_observer(); 823 tray_ ? tray_->accessibility_observer() : NULL;
818 if (observer) { 824 if (observer) {
819 observer->OnAccessibilityModeChanged( 825 observer->OnAccessibilityModeChanged(
820 service->GetBoolean(prefs::kSpokenFeedbackEnabled), 826 service->GetBoolean(prefs::kSpokenFeedbackEnabled),
821 IDS_STATUSBAR_ACCESSIBILITY_TURNED_ON_BUBBLE); 827 IDS_STATUSBAR_ACCESSIBILITY_TURNED_ON_BUBBLE);
822 } 828 }
823 } else { 829 } else {
824 NOTREACHED(); 830 NOTREACHED();
825 } 831 }
826 break; 832 break;
827 } 833 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 } 906 }
901 907
902 // Overridden from SystemKeyEventListener::CapsLockObserver. 908 // Overridden from SystemKeyEventListener::CapsLockObserver.
903 virtual void OnCapsLockChange(bool enabled) OVERRIDE { 909 virtual void OnCapsLockChange(bool enabled) OVERRIDE {
904 int id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SHIFT_AND_SEARCH_KEYS; 910 int id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SHIFT_AND_SEARCH_KEYS;
905 if (!base::chromeos::IsRunningOnChromeOS() || 911 if (!base::chromeos::IsRunningOnChromeOS() ||
906 search_key_mapped_to_ == input_method::kCapsLockKey) 912 search_key_mapped_to_ == input_method::kCapsLockKey)
907 id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SEARCH; 913 id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SEARCH;
908 914
909 ash::CapsLockObserver* observer = 915 ash::CapsLockObserver* observer =
910 ash::Shell::GetInstance()->tray()->caps_lock_observer(); 916 tray_ ? tray_->caps_lock_observer() : NULL;
911 if (observer) 917 if (observer)
912 observer->OnCapsLockChanged(enabled, id); 918 observer->OnCapsLockChanged(enabled, id);
913 } 919 }
914 920
915 // Overridden from MessageBubbleLinkListener 921 // Overridden from MessageBubbleLinkListener
916 virtual void OnLinkActivated(size_t index) OVERRIDE { 922 virtual void OnLinkActivated(size_t index) OVERRIDE {
917 // If we have deal info URL defined that means that there're 923 // If we have deal info URL defined that means that there're
918 // 2 links in bubble. Let the user close it manually then thus giving 924 // 2 links in bubble. Let the user close it manually then thus giving
919 // ability to navigate to second link. 925 // ability to navigate to second link.
920 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback. 926 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); 975 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate);
970 }; 976 };
971 977
972 } // namespace 978 } // namespace
973 979
974 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { 980 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) {
975 return new chromeos::SystemTrayDelegate(tray); 981 return new chromeos::SystemTrayDelegate(tray);
976 } 982 }
977 983
978 } // namespace chromeos 984 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698