diff options
Diffstat (limited to 'ash')
22 files changed, 188 insertions, 73 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index a6e4ee0..dbf94c2 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -258,14 +258,13 @@ Shell::~Shell() { // Destroy SystemTrayDelegate before destroying the status area(s). system_tray_delegate_.reset(); - // Destroy SystemTrayNotifier immediately after destroying SystemTrayDelegate - // so that it is still available when shutting down the UI, but not after - // the notifier observers have been destroyed. - system_tray_notifier_.reset(); - // Destroy all child windows including widgets. display_controller_->CloseChildWindows(); + // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems + // needs to remove observers from it. + system_tray_notifier_.reset(); + // These need a valid Shell instance to clean up properly, so explicitly // delete them before invalidating the instance. // Alphabetical. diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc index 1551b60..672ddeb 100644 --- a/ash/system/audio/tray_volume.cc +++ b/ash/system/audio/tray_volume.cc @@ -9,6 +9,7 @@ #include "ash/ash_constants.h" #include "ash/shell.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_views.h" #include "ash/volume_control_delegate.h" @@ -217,9 +218,11 @@ TrayVolume::TrayVolume(SystemTray* system_tray) : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE), volume_view_(NULL), is_default_view_(false) { + Shell::GetInstance()->system_tray_notifier()->AddAudioObserver(this); } TrayVolume::~TrayVolume() { + Shell::GetInstance()->system_tray_notifier()->RemoveAudioObserver(this); } bool TrayVolume::GetInitialVisibility() { diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc index de93f8b..f61af58 100644 --- a/ash/system/bluetooth/tray_bluetooth.cc +++ b/ash/system/bluetooth/tray_bluetooth.cc @@ -7,6 +7,7 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_item_more.h" @@ -262,9 +263,11 @@ TrayBluetooth::TrayBluetooth(SystemTray* system_tray) : SystemTrayItem(system_tray), default_(NULL), detailed_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddBluetoothObserver(this); } TrayBluetooth::~TrayBluetooth() { + Shell::GetInstance()->system_tray_notifier()->RemoveBluetoothObserver(this); } views::View* TrayBluetooth::CreateTrayView(user::LoginStatus status) { diff --git a/ash/system/brightness/tray_brightness.cc b/ash/system/brightness/tray_brightness.cc index bc9977a..907798f 100644 --- a/ash/system/brightness/tray_brightness.cc +++ b/ash/system/brightness/tray_brightness.cc @@ -9,6 +9,7 @@ #include "ash/shell.h" #include "ash/system/brightness/brightness_control_delegate.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_views.h" #include "base/bind.h" @@ -137,9 +138,12 @@ TrayBrightness::TrayBrightness(SystemTray* system_tray) FROM_HERE, base::Bind(&TrayBrightness::GetInitialBrightness, weak_ptr_factory_.GetWeakPtr())); + Shell::GetInstance()->system_tray_notifier()->AddBrightnessObserver(this); } -TrayBrightness::~TrayBrightness() {} +TrayBrightness::~TrayBrightness() { + Shell::GetInstance()->system_tray_notifier()->RemoveBrightnessObserver(this); +} void TrayBrightness::GetInitialBrightness() { BrightnessControlDelegate* delegate = diff --git a/ash/system/chromeos/network/tray_network.cc b/ash/system/chromeos/network/tray_network.cc index e2721bf..663fd2d 100644 --- a/ash/system/chromeos/network/tray_network.cc +++ b/ash/system/chromeos/network/tray_network.cc @@ -10,6 +10,7 @@ #include "ash/system/chromeos/network/tray_network_state_observer.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_item_more.h" #include "ash/system/tray/tray_item_view.h" @@ -567,9 +568,11 @@ TrayNetwork::TrayNetwork(SystemTray* system_tray) chromeos::switches::kEnableNewNetworkHandlers)) { network_state_observer_.reset(new TrayNetworkStateObserver(this)); } + Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); } TrayNetwork::~TrayNetwork() { + Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); } views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { diff --git a/ash/system/chromeos/network/tray_sms.cc b/ash/system/chromeos/network/tray_sms.cc index 7b794ff..a57e195 100644 --- a/ash/system/chromeos/network/tray_sms.cc +++ b/ash/system/chromeos/network/tray_sms.cc @@ -5,8 +5,10 @@ #include "ash/system/chromeos/network/tray_sms.h" #include "ash/ash_switches.h" +#include "ash/shell.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_bubble.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_item_more.h" @@ -281,9 +283,11 @@ TraySms::TraySms(SystemTray* system_tray) default_(NULL), detailed_(NULL), notification_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddSmsObserver(this); } TraySms::~TraySms() { + Shell::GetInstance()->system_tray_notifier()->RemoveSmsObserver(this); } views::View* TraySms::CreateDefaultView(user::LoginStatus status) { diff --git a/ash/system/chromeos/network/tray_vpn.cc b/ash/system/chromeos/network/tray_vpn.cc index 66810c7..7733390 100644 --- a/ash/system/chromeos/network/tray_vpn.cc +++ b/ash/system/chromeos/network/tray_vpn.cc @@ -7,6 +7,7 @@ #include "ash/shell.h" #include "ash/system/chromeos/network/network_list_detailed_view_base.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_item_more.h" #include "grit/ash_strings.h" @@ -122,9 +123,11 @@ TrayVPN::TrayVPN(SystemTray* system_tray) : SystemTrayItem(system_tray), default_(NULL), detailed_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddVpnObserver(this); } TrayVPN::~TrayVPN() { + Shell::GetInstance()->system_tray_notifier()->RemoveVpnObserver(this); } views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { diff --git a/ash/system/date/tray_date.cc b/ash/system/date/tray_date.cc index 928b36e..1c7aa1c 100644 --- a/ash/system/date/tray_date.cc +++ b/ash/system/date/tray_date.cc @@ -8,6 +8,7 @@ #include "ash/system/date/date_view.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_item_view.h" #include "ash/system/tray/tray_views.h" @@ -133,9 +134,11 @@ namespace internal { TrayDate::TrayDate(SystemTray* system_tray) : SystemTrayItem(system_tray), time_tray_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddClockObserver(this); } TrayDate::~TrayDate() { + Shell::GetInstance()->system_tray_notifier()->RemoveClockObserver(this); } views::View* TrayDate::CreateTrayView(user::LoginStatus status) { diff --git a/ash/system/drive/tray_drive.cc b/ash/system/drive/tray_drive.cc index a4460b8..0c26584 100644 --- a/ash/system/drive/tray_drive.cc +++ b/ash/system/drive/tray_drive.cc @@ -9,6 +9,7 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_item_more.h" @@ -378,9 +379,11 @@ TrayDrive::TrayDrive(SystemTray* system_tray) : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_DRIVE_LIGHT), default_(NULL), detailed_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddDriveObserver(this); } TrayDrive::~TrayDrive() { + Shell::GetInstance()->system_tray_notifier()->RemoveDriveObserver(this); } bool TrayDrive::GetInitialVisibility() { diff --git a/ash/system/ime/tray_ime.cc b/ash/system/ime/tray_ime.cc index 7c258f8..ee05452 100644 --- a/ash/system/ime/tray_ime.cc +++ b/ash/system/ime/tray_ime.cc @@ -10,6 +10,7 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_item_more.h" @@ -244,9 +245,11 @@ TrayIME::TrayIME(SystemTray* system_tray) detailed_(NULL), notification_(NULL), message_shown_(false) { + Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); } TrayIME::~TrayIME() { + Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); } void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { diff --git a/ash/system/locale/tray_locale.cc b/ash/system/locale/tray_locale.cc index 88adab9..0e25216 100644 --- a/ash/system/locale/tray_locale.cc +++ b/ash/system/locale/tray_locale.cc @@ -4,6 +4,8 @@ #include "ash/system/locale/tray_locale.h" +#include "ash/shell.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_notification_view.h" #include "ash/system/tray/tray_views.h" @@ -113,9 +115,11 @@ TrayLocale::TrayLocale(SystemTray* system_tray) : SystemTrayItem(system_tray), notification_(NULL), delegate_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddLocaleObserver(this); } TrayLocale::~TrayLocale() { + Shell::GetInstance()->system_tray_notifier()->RemoveLocaleObserver(this); } views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) { diff --git a/ash/system/logout_button/tray_logout_button.cc b/ash/system/logout_button/tray_logout_button.cc index 4821099..252df96 100644 --- a/ash/system/logout_button/tray_logout_button.cc +++ b/ash/system/logout_button/tray_logout_button.cc @@ -8,6 +8,7 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/user/login_status.h" #include "base/logging.h" @@ -135,6 +136,12 @@ class LogoutButton : public views::View, TrayLogoutButton::TrayLogoutButton(SystemTray* system_tray) : SystemTrayItem(system_tray), logout_button_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); +} + +TrayLogoutButton::~TrayLogoutButton() { + Shell::GetInstance()->system_tray_notifier()-> + RemoveLogoutButtonObserver(this); } views::View* TrayLogoutButton::CreateTrayView(user::LoginStatus status) { diff --git a/ash/system/logout_button/tray_logout_button.h b/ash/system/logout_button/tray_logout_button.h index a2d01c7..50ca9f9 100644 --- a/ash/system/logout_button/tray_logout_button.h +++ b/ash/system/logout_button/tray_logout_button.h @@ -22,6 +22,7 @@ class LogoutButton; class TrayLogoutButton : public SystemTrayItem, public LogoutButtonObserver { public: explicit TrayLogoutButton(SystemTray* system_tray); + virtual ~TrayLogoutButton(); // Overridden from SystemTrayItem. virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; diff --git a/ash/system/power/tray_power.cc b/ash/system/power/tray_power.cc index ff1a95f..10f1722 100644 --- a/ash/system/power/tray_power.cc +++ b/ash/system/power/tray_power.cc @@ -10,6 +10,7 @@ #include "ash/system/power/power_status_view.h" #include "ash/system/power/power_supply_status.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_notification_view.h" #include "ash/system/tray/tray_views.h" @@ -138,9 +139,11 @@ TrayPower::TrayPower(SystemTray* system_tray) power_tray_(NULL), notification_view_(NULL), notification_state_(NOTIFICATION_NONE) { + Shell::GetInstance()->system_tray_notifier()->AddPowerStatusObserver(this); } TrayPower::~TrayPower() { + Shell::GetInstance()->system_tray_notifier()->RemovePowerStatusObserver(this); } // static diff --git a/ash/system/settings/tray_settings.cc b/ash/system/settings/tray_settings.cc index 3be2386..ad81ca6 100644 --- a/ash/system/settings/tray_settings.cc +++ b/ash/system/settings/tray_settings.cc @@ -7,6 +7,7 @@ #include "ash/shell.h" #include "ash/system/power/power_status_view.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_views.h" #include "base/logging.h" @@ -123,9 +124,12 @@ class SettingsDefaultView : public ash::internal::ActionableView { TraySettings::TraySettings(SystemTray* system_tray) : SystemTrayItem(system_tray), default_view_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddPowerStatusObserver(this); } -TraySettings::~TraySettings() {} +TraySettings::~TraySettings() { + Shell::GetInstance()->system_tray_notifier()->RemovePowerStatusObserver(this); +} views::View* TraySettings::CreateTrayView(user::LoginStatus status) { return NULL; diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index d671f55..8b09994 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -23,7 +23,6 @@ #include "ash/system/settings/tray_settings.h" #include "ash/system/status_area_widget.h" #include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/system_tray_item.h" #include "ash/system/tray/tray_bubble_wrapper.h" #include "ash/system/tray/tray_constants.h" @@ -129,73 +128,28 @@ void SystemTray::InitializeTrayItems(SystemTrayDelegate* delegate) { } void SystemTray::CreateItems(SystemTrayDelegate* delegate) { - internal::TrayVolume* tray_volume = new internal::TrayVolume(this); - internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(this); - internal::TrayBrightness* tray_brightness = - new internal::TrayBrightness(this); - internal::TrayDate* tray_date = new internal::TrayDate(this); - internal::TrayPower* tray_power = new internal::TrayPower(this); - internal::TrayIME* tray_ime = new internal::TrayIME(this); - internal::TrayUser* tray_user = new internal::TrayUser(this); - internal::TrayAccessibility* tray_accessibility = - new internal::TrayAccessibility(this); - internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock(this); - internal::TrayDrive* tray_drive = new internal::TrayDrive(this); - internal::TrayLocale* tray_locale = new internal::TrayLocale(this); - internal::TrayLogoutButton* tray_logout_button = - new internal::TrayLogoutButton(this); - internal::TrayUpdate* tray_update = new internal::TrayUpdate(this); - internal::TraySettings* tray_settings = new internal::TraySettings(this); + AddTrayItem(new internal::TrayLogoutButton(this)); + AddTrayItem(new internal::TrayUser(this)); + AddTrayItem(new internal::TrayIME(this)); + AddTrayItem(new internal::TrayAccessibility(this)); + AddTrayItem(new internal::TrayPower(this)); #if defined(OS_CHROMEOS) - internal::TrayDisplay* tray_display = new internal::TrayDisplay(this); - internal::TrayNetwork* tray_network = new internal::TrayNetwork(this); - internal::TrayVPN* tray_vpn = new internal::TrayVPN(this); - internal::TraySms* tray_sms = new internal::TraySms(this); + AddTrayItem(new internal::TrayNetwork(this)); + AddTrayItem(new internal::TrayVPN(this)); + AddTrayItem(new internal::TraySms(this)); #endif - - SystemTrayNotifier* notifier = Shell::GetInstance()->system_tray_notifier(); - notifier->AddAccessibilityObserver(tray_accessibility); - notifier->AddAudioObserver(tray_volume); - notifier->AddBluetoothObserver(tray_bluetooth); - notifier->AddBrightnessObserver(tray_brightness); - notifier->AddCapsLockObserver(tray_caps_lock); - notifier->AddClockObserver(tray_date); - notifier->AddDriveObserver(tray_drive); - notifier->AddIMEObserver(tray_ime); - notifier->AddLocaleObserver(tray_locale); - notifier->AddLogoutButtonObserver(tray_logout_button); - notifier->AddPowerStatusObserver(tray_power); - notifier->AddPowerStatusObserver(tray_settings); - notifier->AddUpdateObserver(tray_update); - notifier->AddUserObserver(tray_user); -#if defined(OS_CHROMEOS) - notifier->AddNetworkObserver(tray_network); - notifier->AddVpnObserver(tray_vpn); - notifier->AddSmsObserver(tray_sms); -#endif - - AddTrayItem(tray_logout_button); - AddTrayItem(tray_user); - AddTrayItem(tray_ime); - AddTrayItem(tray_accessibility); - AddTrayItem(tray_power); -#if defined(OS_CHROMEOS) - AddTrayItem(tray_network); - AddTrayItem(tray_vpn); - AddTrayItem(tray_sms); -#endif - AddTrayItem(tray_bluetooth); - AddTrayItem(tray_drive); - AddTrayItem(tray_locale); + AddTrayItem(new internal::TrayBluetooth(this)); + AddTrayItem(new internal::TrayDrive(this)); + AddTrayItem(new internal::TrayLocale(this)); #if defined(OS_CHROMEOS) - AddTrayItem(tray_display); + AddTrayItem(new internal::TrayDisplay(this)); #endif - AddTrayItem(tray_volume); - AddTrayItem(tray_brightness); - AddTrayItem(tray_update); - AddTrayItem(tray_caps_lock); - AddTrayItem(tray_settings); - AddTrayItem(tray_date); + AddTrayItem(new internal::TrayVolume(this)); + AddTrayItem(new internal::TrayBrightness(this)); + AddTrayItem(new internal::TrayUpdate(this)); + AddTrayItem(new internal::TrayCapsLock(this)); + AddTrayItem(new internal::TraySettings(this)); + AddTrayItem(new internal::TrayDate(this)); #if defined(OS_LINUX) // Add memory monitor if enabled. diff --git a/ash/system/tray/system_tray_notifier.cc b/ash/system/tray/system_tray_notifier.cc index 17d6fd2..09704c8 100644 --- a/ash/system/tray/system_tray_notifier.cc +++ b/ash/system/tray/system_tray_notifier.cc @@ -17,68 +17,136 @@ void SystemTrayNotifier::AddAccessibilityObserver( accessibility_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveAccessibilityObserver( + AccessibilityObserver* observer) { + accessibility_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddAudioObserver(AudioObserver* observer) { audio_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveAudioObserver(AudioObserver* observer) { + audio_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddBluetoothObserver(BluetoothObserver* observer) { bluetooth_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveBluetoothObserver(BluetoothObserver* observer) { + bluetooth_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddBrightnessObserver(BrightnessObserver* observer) { brightness_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveBrightnessObserver( + BrightnessObserver* observer) { + brightness_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddCapsLockObserver(CapsLockObserver* observer) { caps_lock_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveCapsLockObserver(CapsLockObserver* observer) { + caps_lock_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddClockObserver(ClockObserver* observer) { clock_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveClockObserver(ClockObserver* observer) { + clock_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddDriveObserver(DriveObserver* observer) { drive_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveDriveObserver(DriveObserver* observer) { + drive_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddIMEObserver(IMEObserver* observer) { ime_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveIMEObserver(IMEObserver* observer) { + ime_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddLocaleObserver(LocaleObserver* observer) { locale_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveLocaleObserver(LocaleObserver* observer) { + locale_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddLogoutButtonObserver( LogoutButtonObserver* observer) { logout_button_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveLogoutButtonObserver( + LogoutButtonObserver* observer) { + logout_button_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddPowerStatusObserver( PowerStatusObserver* observer) { power_status_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemovePowerStatusObserver( + PowerStatusObserver* observer) { + power_status_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddUpdateObserver(UpdateObserver* observer) { update_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveUpdateObserver(UpdateObserver* observer) { + update_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddUserObserver(UserObserver* observer) { user_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveUserObserver(UserObserver* observer) { + user_observers_.RemoveObserver(observer); +} + #if defined(OS_CHROMEOS) void SystemTrayNotifier::AddNetworkObserver(NetworkObserver* observer) { network_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveNetworkObserver(NetworkObserver* observer) { + network_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddVpnObserver(NetworkObserver* observer) { vpn_observers_.AddObserver(observer); } +void SystemTrayNotifier::RemoveVpnObserver(NetworkObserver* observer) { + vpn_observers_.RemoveObserver(observer); +} + void SystemTrayNotifier::AddSmsObserver(SmsObserver* observer) { sms_observers_.AddObserver(observer); } + +void SystemTrayNotifier::RemoveSmsObserver(SmsObserver* observer) { + sms_observers_.RemoveObserver(observer); +} #endif void SystemTrayNotifier::NotifyAccessibilityModeChanged() { diff --git a/ash/system/tray/system_tray_notifier.h b/ash/system/tray/system_tray_notifier.h index 9ef149d..9cfddd2 100644 --- a/ash/system/tray/system_tray_notifier.h +++ b/ash/system/tray/system_tray_notifier.h @@ -39,22 +39,53 @@ public: ~SystemTrayNotifier(); void AddAccessibilityObserver(AccessibilityObserver* observer); + void RemoveAccessibilityObserver(AccessibilityObserver* observer); + void AddAudioObserver(AudioObserver* observer); + void RemoveAudioObserver(AudioObserver* observer); + void AddBluetoothObserver(BluetoothObserver* observer); + void RemoveBluetoothObserver(BluetoothObserver* observer); + void AddBrightnessObserver(BrightnessObserver* observer); + void RemoveBrightnessObserver(BrightnessObserver* observer); + void AddCapsLockObserver(CapsLockObserver* observer); + void RemoveCapsLockObserver(CapsLockObserver* observer); + void AddClockObserver(ClockObserver* observer); + void RemoveClockObserver(ClockObserver* observer); + void AddDriveObserver(DriveObserver* observer); + void RemoveDriveObserver(DriveObserver* observer); + void AddIMEObserver(IMEObserver* observer); + void RemoveIMEObserver(IMEObserver* observer); + void AddLocaleObserver(LocaleObserver* observer); + void RemoveLocaleObserver(LocaleObserver* observer); + void AddLogoutButtonObserver(LogoutButtonObserver* observer); + void RemoveLogoutButtonObserver(LogoutButtonObserver* observer); + void AddPowerStatusObserver(PowerStatusObserver* observer); + void RemovePowerStatusObserver(PowerStatusObserver* observer); + void AddUpdateObserver(UpdateObserver* observer); + void RemoveUpdateObserver(UpdateObserver* observer); + void AddUserObserver(UserObserver* observer); + void RemoveUserObserver(UserObserver* observer); + #if defined(OS_CHROMEOS) void AddNetworkObserver(NetworkObserver* observer); + void RemoveNetworkObserver(NetworkObserver* observer); + void AddVpnObserver(NetworkObserver* observer); + void RemoveVpnObserver(NetworkObserver* observer); + void AddSmsObserver(SmsObserver* observer); + void RemoveSmsObserver(SmsObserver* observer); #endif void NotifyAccessibilityModeChanged(); diff --git a/ash/system/tray_accessibility.cc b/ash/system/tray_accessibility.cc index 6bb88d6..644e7eb 100644 --- a/ash/system/tray_accessibility.cc +++ b/ash/system/tray_accessibility.cc @@ -8,6 +8,7 @@ #include "ash/shell_delegate.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_item_more.h" @@ -227,9 +228,12 @@ TrayAccessibility::TrayAccessibility(SystemTray* system_tray) login_(GetCurrentLoginStatus()) { DCHECK(Shell::GetInstance()->delegate()); DCHECK(system_tray); + Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); } TrayAccessibility::~TrayAccessibility() { + Shell::GetInstance()->system_tray_notifier()-> + RemoveAccessibilityObserver(this); } bool TrayAccessibility::GetInitialVisibility() { diff --git a/ash/system/tray_caps_lock.cc b/ash/system/tray_caps_lock.cc index e355317..6985533 100644 --- a/ash/system/tray_caps_lock.cc +++ b/ash/system/tray_caps_lock.cc @@ -6,6 +6,7 @@ #include "ash/caps_lock_delegate.h" #include "ash/shell.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_views.h" #include "grit/ash_resources.h" @@ -110,9 +111,12 @@ TrayCapsLock::TrayCapsLock(SystemTray* system_tray) caps_lock_enabled_( Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled()), message_shown_(false) { + Shell::GetInstance()->system_tray_notifier()->AddCapsLockObserver(this); } -TrayCapsLock::~TrayCapsLock() {} +TrayCapsLock::~TrayCapsLock() { + Shell::GetInstance()->system_tray_notifier()->RemoveCapsLockObserver(this); +} bool TrayCapsLock::GetInitialVisibility() { return Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled(); diff --git a/ash/system/tray_update.cc b/ash/system/tray_update.cc index 67aa2b3..5be9d49 100644 --- a/ash/system/tray_update.cc +++ b/ash/system/tray_update.cc @@ -9,6 +9,7 @@ #include "ash/system/status_area_widget.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_views.h" #include "ash/wm/shelf_layout_manager.h" @@ -156,9 +157,12 @@ class UpdateNagger : public ui::LayerAnimationObserver { TrayUpdate::TrayUpdate(SystemTray* system_tray) : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE), severity_(UpdateObserver::UPDATE_NORMAL) { + Shell::GetInstance()->system_tray_notifier()->AddUpdateObserver(this); } -TrayUpdate::~TrayUpdate() {} +TrayUpdate::~TrayUpdate() { + Shell::GetInstance()->system_tray_notifier()->RemoveUpdateObserver(this); +} bool TrayUpdate::GetInitialVisibility() { return Shell::GetInstance()->tray_delegate()->SystemShouldUpgrade(); diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc index 728ffa1..4403136 100644 --- a/ash/system/user/tray_user.cc +++ b/ash/system/user/tray_user.cc @@ -11,6 +11,7 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_item_view.h" #include "ash/system/tray/tray_views.h" @@ -534,9 +535,11 @@ TrayUser::TrayUser(SystemTray* system_tray) user_(NULL), avatar_(NULL), label_(NULL) { + Shell::GetInstance()->system_tray_notifier()->AddUserObserver(this); } TrayUser::~TrayUser() { + Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); } views::View* TrayUser::CreateTrayView(user::LoginStatus status) { |