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