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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 pref_registrar_->Add(prefs::kUse24HourClock, this); | 618 pref_registrar_->Add(prefs::kUse24HourClock, this); |
619 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); | 619 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); |
620 UpdateClockType(profile->GetPrefs()); | 620 UpdateClockType(profile->GetPrefs()); |
621 search_key_mapped_to_ = | 621 search_key_mapped_to_ = |
622 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 622 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
623 } | 623 } |
624 | 624 |
625 void UpdateClockType(PrefService* service) { | 625 void UpdateClockType(PrefService* service) { |
626 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? | 626 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? |
627 base::k24HourClock : base::k12HourClock; | 627 base::k24HourClock : base::k12HourClock; |
628 ash::ClockObserver* observer = | 628 ash::ClockObserver* observer = tray_->clock_observer(); |
629 ash::Shell::GetInstance()->tray()->clock_observer(); | |
630 if (observer) | 629 if (observer) |
631 observer->OnDateFormatChanged(); | 630 observer->OnDateFormatChanged(); |
632 } | 631 } |
633 | 632 |
634 void NotifyRefreshClock() { | 633 void NotifyRefreshClock() { |
635 ash::ClockObserver* observer = | 634 ash::ClockObserver* observer = tray_->clock_observer(); |
636 ash::Shell::GetInstance()->tray()->clock_observer(); | |
637 if (observer) | 635 if (observer) |
638 observer->Refresh(); | 636 observer->Refresh(); |
639 } | 637 } |
640 | 638 |
641 void NotifyRefreshNetwork() { | 639 void NotifyRefreshNetwork() { |
642 ash::NetworkObserver* observer = | 640 ash::NetworkObserver* observer = tray_->network_observer(); |
643 ash::Shell::GetInstance()->tray()->network_observer(); | |
644 if (observer) { | 641 if (observer) { |
645 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 642 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
646 ash::NetworkIconInfo info; | 643 ash::NetworkIconInfo info; |
647 info.image = network_icon_->GetIconAndText(&info.description); | 644 info.image = network_icon_->GetIconAndText(&info.description); |
648 info.tray_icon_visible = | 645 info.tray_icon_visible = |
649 ShouldShowNetworkIconInTray(crosnet->connected_network()); | 646 ShouldShowNetworkIconInTray(crosnet->connected_network()); |
650 observer->OnNetworkRefresh(info); | 647 observer->OnNetworkRefresh(info); |
651 } | 648 } |
652 } | 649 } |
653 | 650 |
654 void NotifyRefreshBluetooth() { | 651 void NotifyRefreshBluetooth() { |
655 ash::BluetoothObserver* observer = | 652 ash::BluetoothObserver* observer = tray_->bluetooth_observer(); |
656 ash::Shell::GetInstance()->tray()->bluetooth_observer(); | |
657 if (observer) | 653 if (observer) |
658 observer->OnBluetoothRefresh(); | 654 observer->OnBluetoothRefresh(); |
659 } | 655 } |
660 | 656 |
661 void NotifyRefreshIME() { | 657 void NotifyRefreshIME() { |
662 ash::IMEObserver* observer = | 658 ash::IMEObserver* observer = tray_->ime_observer(); |
663 ash::Shell::GetInstance()->tray()->ime_observer(); | |
664 if (observer) | 659 if (observer) |
665 observer->OnIMERefresh(); | 660 observer->OnIMERefresh(); |
666 } | 661 } |
667 | 662 |
668 void RefreshNetworkObserver(NetworkLibrary* crosnet) { | 663 void RefreshNetworkObserver(NetworkLibrary* crosnet) { |
669 const Network* network = crosnet->active_network(); | 664 const Network* network = crosnet->active_network(); |
670 std::string new_path = network ? network->service_path() : std::string(); | 665 std::string new_path = network ? network->service_path() : std::string(); |
671 if (active_network_path_ != new_path) { | 666 if (active_network_path_ != new_path) { |
672 if (!active_network_path_.empty()) | 667 if (!active_network_path_.empty()) |
673 crosnet->RemoveNetworkObserver(active_network_path_, this); | 668 crosnet->RemoveNetworkObserver(active_network_path_, this); |
674 if (!new_path.empty()) | 669 if (!new_path.empty()) |
675 crosnet->AddNetworkObserver(new_path, this); | 670 crosnet->AddNetworkObserver(new_path, this); |
676 active_network_path_ = new_path; | 671 active_network_path_ = new_path; |
677 } | 672 } |
678 } | 673 } |
679 | 674 |
680 void RefreshNetworkDeviceObserver(NetworkLibrary* crosnet) { | 675 void RefreshNetworkDeviceObserver(NetworkLibrary* crosnet) { |
681 const NetworkDevice* cellular = crosnet->FindCellularDevice(); | 676 const NetworkDevice* cellular = crosnet->FindCellularDevice(); |
682 std::string new_cellular_device_path = cellular ? | 677 std::string new_cellular_device_path = cellular ? |
683 cellular->device_path() : std::string(); | 678 cellular->device_path() : std::string(); |
684 if (cellular_device_path_ != new_cellular_device_path) | 679 if (cellular_device_path_ != new_cellular_device_path) |
685 cellular_device_path_ = new_cellular_device_path; | 680 cellular_device_path_ = new_cellular_device_path; |
686 } | 681 } |
687 | 682 |
688 // Overridden from AudioHandler::VolumeObserver. | 683 // Overridden from AudioHandler::VolumeObserver. |
689 virtual void OnVolumeChanged() OVERRIDE { | 684 virtual void OnVolumeChanged() OVERRIDE { |
690 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; | 685 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; |
691 ash::Shell::GetInstance()->tray()->audio_observer()-> | 686 tray_->audio_observer()->OnVolumeChanged(level); |
692 OnVolumeChanged(level); | |
693 } | 687 } |
694 | 688 |
695 // Overridden from PowerManagerClient::Observer. | 689 // Overridden from PowerManagerClient::Observer. |
696 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { | 690 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { |
697 ash::Shell::GetInstance()->tray()->brightness_observer()-> | 691 tray_->brightness_observer()-> |
698 OnBrightnessChanged(static_cast<double>(level), user_initiated); | 692 OnBrightnessChanged(static_cast<double>(level), user_initiated); |
699 } | 693 } |
700 | 694 |
701 virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE { | 695 virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE { |
702 power_supply_status_ = power_status; | 696 power_supply_status_ = power_status; |
703 ash::PowerStatusObserver* observer = | 697 ash::PowerStatusObserver* observer = tray_->power_status_observer(); |
704 ash::Shell::GetInstance()->tray()->power_status_observer(); | |
705 if (observer) | 698 if (observer) |
706 observer->OnPowerStatusChanged(power_status); | 699 observer->OnPowerStatusChanged(power_status); |
707 } | 700 } |
708 | 701 |
709 virtual void SystemResumed() OVERRIDE { | 702 virtual void SystemResumed() OVERRIDE { |
710 NotifyRefreshClock(); | 703 NotifyRefreshClock(); |
711 } | 704 } |
712 | 705 |
713 virtual void LockScreen() OVERRIDE { | 706 virtual void LockScreen() OVERRIDE { |
714 screen_locked_ = true; | 707 screen_locked_ = true; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 740 } |
748 | 741 |
749 virtual bool ShouldOpenButtonOptions() const OVERRIDE { | 742 virtual bool ShouldOpenButtonOptions() const OVERRIDE { |
750 return false; | 743 return false; |
751 } | 744 } |
752 | 745 |
753 // Overridden from NetworkLibrary::NetworkManagerObserver. | 746 // Overridden from NetworkLibrary::NetworkManagerObserver. |
754 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { | 747 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { |
755 RefreshNetworkObserver(crosnet); | 748 RefreshNetworkObserver(crosnet); |
756 RefreshNetworkDeviceObserver(crosnet); | 749 RefreshNetworkDeviceObserver(crosnet); |
757 data_promo_notification_->ShowOptionalMobileDataPromoNotification(crosnet, | 750 data_promo_notification_->ShowOptionalMobileDataPromoNotification( |
758 tray_, this); | 751 crosnet, tray_, this); |
759 | 752 |
760 NotifyRefreshNetwork(); | 753 NotifyRefreshNetwork(); |
761 } | 754 } |
762 | 755 |
763 // Overridden from NetworkLibrary::NetworkObserver. | 756 // Overridden from NetworkLibrary::NetworkObserver. |
764 virtual void OnNetworkChanged(NetworkLibrary* crosnet, | 757 virtual void OnNetworkChanged(NetworkLibrary* crosnet, |
765 const Network* network) OVERRIDE { | 758 const Network* network) OVERRIDE { |
766 NotifyRefreshNetwork(); | 759 NotifyRefreshNetwork(); |
767 } | 760 } |
768 | 761 |
769 // Overridden from NetworkLibrary::CellularDataPlanObserver. | 762 // Overridden from NetworkLibrary::CellularDataPlanObserver. |
770 virtual void OnCellularDataPlanChanged(NetworkLibrary* crosnet) OVERRIDE { | 763 virtual void OnCellularDataPlanChanged(NetworkLibrary* crosnet) OVERRIDE { |
771 NotifyRefreshNetwork(); | 764 NotifyRefreshNetwork(); |
772 } | 765 } |
773 | 766 |
774 // content::NotificationObserver implementation. | 767 // content::NotificationObserver implementation. |
775 virtual void Observe(int type, | 768 virtual void Observe(int type, |
776 const content::NotificationSource& source, | 769 const content::NotificationSource& source, |
777 const content::NotificationDetails& details) OVERRIDE { | 770 const content::NotificationDetails& details) OVERRIDE { |
778 switch (type) { | 771 switch (type) { |
779 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 772 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
780 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); | 773 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); |
781 break; | 774 break; |
782 } | 775 } |
783 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { | 776 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { |
784 ash::UpdateObserver* observer = | 777 ash::UpdateObserver* observer = tray_->update_observer(); |
785 ash::Shell::GetInstance()->tray()->update_observer(); | |
786 if (observer) | 778 if (observer) |
787 observer->OnUpdateRecommended(); | 779 observer->OnUpdateRecommended(); |
788 break; | 780 break; |
789 } | 781 } |
790 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { | 782 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { |
791 // This notification is also sent on login screen when user avatar | 783 // This notification is also sent on login screen when user avatar |
792 // is loaded from file. | 784 // is loaded from file. |
793 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { | 785 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { |
794 ash::UserObserver* observer = | 786 ash::UserObserver* observer = tray_->user_observer(); |
795 ash::Shell::GetInstance()->tray()->user_observer(); | |
796 if (observer) | 787 if (observer) |
797 observer->OnUserUpdate(); | 788 observer->OnUserUpdate(); |
798 } | 789 } |
799 break; | 790 break; |
800 } | 791 } |
801 case chrome::NOTIFICATION_PREF_CHANGED: { | 792 case chrome::NOTIFICATION_PREF_CHANGED: { |
802 std::string pref = *content::Details<std::string>(details).ptr(); | 793 std::string pref = *content::Details<std::string>(details).ptr(); |
803 PrefService* service = content::Source<PrefService>(source).ptr(); | 794 PrefService* service = content::Source<PrefService>(source).ptr(); |
804 if (pref == prefs::kUse24HourClock) { | 795 if (pref == prefs::kUse24HourClock) { |
805 UpdateClockType(service); | 796 UpdateClockType(service); |
806 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { | 797 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { |
807 search_key_mapped_to_ = | 798 search_key_mapped_to_ = |
808 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 799 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
809 } else if (pref == prefs::kSpokenFeedbackEnabled) { | 800 } else if (pref == prefs::kSpokenFeedbackEnabled) { |
810 ash::AccessibilityObserver* observer = | 801 ash::AccessibilityObserver* observer = |
811 ash::Shell::GetInstance()->tray()->accessibility_observer(); | 802 tray_->accessibility_observer(); |
812 if (observer) { | 803 if (observer) { |
813 observer->OnAccessibilityModeChanged( | 804 observer->OnAccessibilityModeChanged( |
814 service->GetBoolean(prefs::kSpokenFeedbackEnabled), | 805 service->GetBoolean(prefs::kSpokenFeedbackEnabled), |
815 IDS_STATUSBAR_ACCESSIBILITY_TURNED_ON_BUBBLE); | 806 IDS_STATUSBAR_ACCESSIBILITY_TURNED_ON_BUBBLE); |
816 } | 807 } |
817 } else { | 808 } else { |
818 NOTREACHED(); | 809 NOTREACHED(); |
819 } | 810 } |
820 break; | 811 break; |
821 } | 812 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 NotifyRefreshBluetooth(); | 884 NotifyRefreshBluetooth(); |
894 } | 885 } |
895 | 886 |
896 // Overridden from SystemKeyEventListener::CapsLockObserver. | 887 // Overridden from SystemKeyEventListener::CapsLockObserver. |
897 virtual void OnCapsLockChange(bool enabled) OVERRIDE { | 888 virtual void OnCapsLockChange(bool enabled) OVERRIDE { |
898 int id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SHIFT_AND_SEARCH_KEYS; | 889 int id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SHIFT_AND_SEARCH_KEYS; |
899 if (!base::chromeos::IsRunningOnChromeOS() || | 890 if (!base::chromeos::IsRunningOnChromeOS() || |
900 search_key_mapped_to_ == input_method::kCapsLockKey) | 891 search_key_mapped_to_ == input_method::kCapsLockKey) |
901 id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SEARCH; | 892 id = IDS_STATUSBAR_CAPS_LOCK_ENABLED_PRESS_SEARCH; |
902 | 893 |
903 ash::CapsLockObserver* observer = | 894 ash::CapsLockObserver* observer = tray_->caps_lock_observer(); |
904 ash::Shell::GetInstance()->tray()->caps_lock_observer(); | |
905 if (observer) | 895 if (observer) |
906 observer->OnCapsLockChanged(enabled, id); | 896 observer->OnCapsLockChanged(enabled, id); |
907 } | 897 } |
908 | 898 |
909 // Overridden from MessageBubbleLinkListener | 899 // Overridden from MessageBubbleLinkListener |
910 virtual void OnLinkActivated(size_t index) OVERRIDE { | 900 virtual void OnLinkActivated(size_t index) OVERRIDE { |
911 // If we have deal info URL defined that means that there're | 901 // 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 | 902 // 2 links in bubble. Let the user close it manually then thus giving |
913 // ability to navigate to second link. | 903 // ability to navigate to second link. |
914 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback. | 904 // 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); | 953 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
964 }; | 954 }; |
965 | 955 |
966 } // namespace | 956 } // namespace |
967 | 957 |
968 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 958 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
969 return new chromeos::SystemTrayDelegate(tray); | 959 return new chromeos::SystemTrayDelegate(tray); |
970 } | 960 } |
971 | 961 |
972 } // namespace chromeos | 962 } // namespace chromeos |
OLD | NEW |