diff options
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/shell.cc | 9 | ||||
-rw-r--r-- | ash/shell.h | 6 | ||||
-rw-r--r-- | ash/system/status_area_widget.cc | 9 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 91 | ||||
-rw-r--r-- | ash/system/tray/system_tray.h | 81 | ||||
-rw-r--r-- | ash/system/tray/system_tray_notifier.cc | 237 | ||||
-rw-r--r-- | ash/system/tray/system_tray_notifier.h | 117 | ||||
-rw-r--r-- | chrome/browser/chromeos/locale_change_guard.cc | 7 | ||||
-rw-r--r-- | chrome/browser/chromeos/network_message_observer.cc | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/sms_observer.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/data_promo_notification.cc | 17 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/ash_system_tray_delegate.cc | 128 |
13 files changed, 474 insertions, 243 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 649062c4..ac60ac8 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -213,6 +213,8 @@ 'system/tray/system_tray_delegate.h', 'system/tray/system_tray_item.cc', 'system/tray/system_tray_item.h', + 'system/tray/system_tray_notifier.cc', + 'system/tray/system_tray_notifier.h', 'system/tray/test_system_tray_delegate.cc', 'system/tray/test_system_tray_delegate.h', 'system/tray/tray_background_view.cc', diff --git a/ash/shell.cc b/ash/shell.cc index bac0bb6..45dc886 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -29,6 +29,7 @@ #include "ash/shell_window_ids.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/tooltips/tooltip_controller.h" #include "ash/touch/touch_observer_hud.h" #include "ash/wm/activation_controller.h" @@ -257,6 +258,11 @@ 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(); @@ -495,6 +501,9 @@ void Shell::Init() { shadow_controller_.reset(new internal::ShadowController()); } + // Create system_tray_notifier_ before the delegate. + system_tray_notifier_.reset(new ash::SystemTrayNotifier()); + // Initialize system_tray_delegate_ before initializing StatusAreaWidget. system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate()); if (!system_tray_delegate_.get()) diff --git a/ash/shell.h b/ash/shell.h index 8e27380..72073dc 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -75,6 +75,7 @@ class ShellDelegate; class ShellObserver; class SystemTray; class SystemTrayDelegate; +class SystemTrayNotifier; class UserActivityDetector; class UserWallpaperDelegate; class VideoDetector; @@ -372,6 +373,10 @@ class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate, return system_tray_delegate_.get(); } + SystemTrayNotifier* system_tray_notifier() { + return system_tray_notifier_.get(); + } + static void set_initially_hide_cursor(bool hide) { initially_hide_cursor_ = hide; } @@ -460,6 +465,7 @@ class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate, scoped_ptr<ShellDelegate> delegate_; scoped_ptr<SystemTrayDelegate> system_tray_delegate_; + scoped_ptr<SystemTrayNotifier> system_tray_notifier_; scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_; scoped_ptr<CapsLockDelegate> caps_lock_delegate_; diff --git a/ash/system/status_area_widget.cc b/ash/system/status_area_widget.cc index b487de5..c1b165f 100644 --- a/ash/system/status_area_widget.cc +++ b/ash/system/status_area_widget.cc @@ -46,13 +46,14 @@ StatusAreaWidget::~StatusAreaWidget() { void StatusAreaWidget::CreateTrayViews() { AddSystemTray(); AddWebNotificationTray(); - // Initialize() must be called after all trays have been created. + SystemTrayDelegate* delegate = ash::Shell::GetInstance()->tray_delegate(); + DCHECK(delegate); + // Initialize after all trays have been created. if (system_tray_) - system_tray_->Initialize(); + system_tray_->InitializeTrayItems(delegate); if (web_notification_tray_) web_notification_tray_->Initialize(); - UpdateAfterLoginStatusChange( - ash::Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); + UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); } void StatusAreaWidget::Shutdown() { diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index e7d8385..9ba7800 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -18,12 +18,12 @@ #include "ash/system/locale/tray_locale.h" #include "ash/system/logout_button/tray_logout_button.h" #include "ash/system/monitor/tray_monitor.h" -#include "ash/system/power/power_status_observer.h" #include "ash/system/power/power_supply_status.h" #include "ash/system/power/tray_power.h" #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" @@ -107,23 +107,6 @@ using internal::SystemTrayBubble; SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) : internal::TrayBackgroundView(status_area_widget), items_(), - accessibility_observer_(NULL), - audio_observer_(NULL), - bluetooth_observer_(NULL), - brightness_observer_(NULL), - caps_lock_observer_(NULL), - clock_observer_(NULL), - drive_observer_(NULL), - ime_observer_(NULL), - locale_observer_(NULL), - logout_button_observer_(NULL), -#if defined(OS_CHROMEOS) - network_observer_(NULL), - vpn_observer_(NULL), - sms_observer_(NULL), -#endif - update_observer_(NULL), - user_observer_(NULL), default_bubble_height_(0), hide_notifications_(false) { SetContentsBackground(); @@ -140,47 +123,54 @@ SystemTray::~SystemTray() { } } -void SystemTray::CreateItems() { +void SystemTray::InitializeTrayItems(SystemTrayDelegate* delegate) { + internal::TrayBackgroundView::Initialize(); + CreateItems(delegate); +} + +void SystemTray::CreateItems(SystemTrayDelegate* delegate) { internal::TrayVolume* tray_volume = new internal::TrayVolume(); internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); internal::TrayDate* tray_date = new internal::TrayDate(); internal::TrayPower* tray_power = new internal::TrayPower(); - internal::TrayIME* tray_ime = new internal::TrayIME; - internal::TrayUser* tray_user = new internal::TrayUser; + internal::TrayIME* tray_ime = new internal::TrayIME(); + internal::TrayUser* tray_user = new internal::TrayUser(); internal::TrayAccessibility* tray_accessibility = - new internal::TrayAccessibility; - internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock; - internal::TrayDrive* tray_drive = new internal::TrayDrive; - internal::TrayLocale* tray_locale = new internal::TrayLocale; + new internal::TrayAccessibility(); + internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock(); + internal::TrayDrive* tray_drive = new internal::TrayDrive(); + internal::TrayLocale* tray_locale = new internal::TrayLocale(); internal::TrayLogoutButton* tray_logout_button = new internal::TrayLogoutButton(); - internal::TrayUpdate* tray_update = new internal::TrayUpdate; + internal::TrayUpdate* tray_update = new internal::TrayUpdate(); internal::TraySettings* tray_settings = new internal::TraySettings(); - - accessibility_observer_ = tray_accessibility; - audio_observer_ = tray_volume; - bluetooth_observer_ = tray_bluetooth; - brightness_observer_ = tray_brightness; - caps_lock_observer_ = tray_caps_lock; - clock_observer_ = tray_date; - drive_observer_ = tray_drive; - ime_observer_ = tray_ime; - locale_observer_ = tray_locale; - logout_button_observer_ = tray_logout_button; - power_status_observers_.AddObserver(tray_power); - power_status_observers_.AddObserver(tray_settings); - update_observer_ = tray_update; - user_observer_ = tray_user; - #if defined(OS_CHROMEOS) - internal::TrayDisplay* tray_display = new internal::TrayDisplay; - internal::TrayNetwork* tray_network = new internal::TrayNetwork; - internal::TrayVPN* tray_vpn = new internal::TrayVPN; + internal::TrayDisplay* tray_display = new internal::TrayDisplay(); + internal::TrayNetwork* tray_network = new internal::TrayNetwork(); + internal::TrayVPN* tray_vpn = new internal::TrayVPN(); internal::TraySms* tray_sms = new internal::TraySms(); - network_observer_ = tray_network; - vpn_observer_ = tray_vpn; - sms_observer_ = tray_sms; +#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); @@ -498,11 +488,6 @@ void SystemTray::UpdateNotificationBubble() { status_area_widget()->SetHideWebNotifications(true); } -void SystemTray::Initialize() { - internal::TrayBackgroundView::Initialize(); - CreateItems(); -} - void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { if (alignment == shelf_alignment()) return; diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h index a42632f..57cc2e7 100644 --- a/ash/system/tray/system_tray.h +++ b/ash/system/tray/system_tray.h @@ -34,6 +34,7 @@ class IMEObserver; class LocaleObserver; class LogoutButtonObserver; class PowerStatusObserver; +class SystemTrayDelegate; class UpdateObserver; class UserObserver; #if defined(OS_CHROMEOS) @@ -61,8 +62,9 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, explicit SystemTray(internal::StatusAreaWidget* status_area_widget); virtual ~SystemTray(); - // Creates the default set of items for the sytem tray. - void CreateItems(); + // Calls TrayBackgroundView::Initialize(), creates the tray items, and + // adds them to SystemTrayNotifier. + void InitializeTrayItems(SystemTrayDelegate* delegate); // Adds a new item in the tray. void AddTrayItem(SystemTrayItem* item); @@ -118,64 +120,12 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, // Returns true if the mouse is inside the notification bubble. bool IsMouseInNotificationBubble() const; - AccessibilityObserver* accessibility_observer() { - return accessibility_observer_; - } - AudioObserver* audio_observer() { - return audio_observer_; - } - BluetoothObserver* bluetooth_observer() { - return bluetooth_observer_; - } - BrightnessObserver* brightness_observer() { - return brightness_observer_; - } - CapsLockObserver* caps_lock_observer() { - return caps_lock_observer_; - } - ClockObserver* clock_observer() { - return clock_observer_; - } - DriveObserver* drive_observer() { - return drive_observer_; - } - IMEObserver* ime_observer() { - return ime_observer_; - } - LocaleObserver* locale_observer() { - return locale_observer_; - } - LogoutButtonObserver* logout_button_observer() { - return logout_button_observer_; - } -#if defined(OS_CHROMEOS) - NetworkObserver* network_observer() { - return network_observer_; - } - NetworkObserver* vpn_observer() { - return vpn_observer_; - } - SmsObserver* sms_observer() { - return sms_observer_; - } -#endif - ObserverList<PowerStatusObserver>& power_status_observers() { - return power_status_observers_; - } - UpdateObserver* update_observer() { - return update_observer_; - } - UserObserver* user_observer() { - return user_observer_; - } - // Accessors for testing. // Returns true if the bubble exists. bool CloseBubbleForTest() const; // Overridden from TrayBackgroundView. - virtual void Initialize() OVERRIDE; virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; virtual void AnchorUpdated() OVERRIDE; virtual string16 GetAccessibleNameForTray() OVERRIDE; @@ -194,6 +144,9 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; private: + // Creates the default set of items for the sytem tray. + void CreateItems(SystemTrayDelegate* delegate); + // Returns true if the system_bubble_ exists and is of type |type|. bool HasSystemBubbleType(internal::SystemTrayBubble::BubbleType type); @@ -237,26 +190,6 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, // Mappings of system tray item and it's view in the tray. std::map<SystemTrayItem*, views::View*> tray_item_map_; - // These observers are not owned by the tray. - AccessibilityObserver* accessibility_observer_; - AudioObserver* audio_observer_; - BluetoothObserver* bluetooth_observer_; - BrightnessObserver* brightness_observer_; - CapsLockObserver* caps_lock_observer_; - ClockObserver* clock_observer_; - DriveObserver* drive_observer_; - IMEObserver* ime_observer_; - LocaleObserver* locale_observer_; - LogoutButtonObserver* logout_button_observer_; -#if defined(OS_CHROMEOS) - NetworkObserver* network_observer_; - NetworkObserver* vpn_observer_; - SmsObserver* sms_observer_; -#endif - ObserverList<PowerStatusObserver> power_status_observers_; - UpdateObserver* update_observer_; - UserObserver* user_observer_; - // Bubble for default and detailed views. scoped_ptr<internal::SystemBubbleWrapper> system_bubble_; diff --git a/ash/system/tray/system_tray_notifier.cc b/ash/system/tray/system_tray_notifier.cc new file mode 100644 index 0000000..66d490d --- /dev/null +++ b/ash/system/tray/system_tray_notifier.cc @@ -0,0 +1,237 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/tray/system_tray_notifier.h" + +namespace ash { + +SystemTrayNotifier::SystemTrayNotifier() { +} + +SystemTrayNotifier::~SystemTrayNotifier() { +} + +void SystemTrayNotifier::AddAccessibilityObserver( + AccessibilityObserver* observer) { + accessibility_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddAudioObserver(AudioObserver* observer) { + audio_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddBluetoothObserver(BluetoothObserver* observer) { + bluetooth_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddBrightnessObserver(BrightnessObserver* observer) { + brightness_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddCapsLockObserver(CapsLockObserver* observer) { + caps_lock_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddClockObserver(ClockObserver* observer) { + clock_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddDriveObserver(DriveObserver* observer) { + drive_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddIMEObserver(IMEObserver* observer) { + ime_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddLocaleObserver(LocaleObserver* observer) { + locale_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddLogoutButtonObserver( + LogoutButtonObserver* observer) { + logout_button_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddPowerStatusObserver( + PowerStatusObserver* observer) { + power_status_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddUpdateObserver(UpdateObserver* observer) { + update_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddUserObserver(UserObserver* observer) { + user_observers_.AddObserver(observer); +} + +#if defined(OS_CHROMEOS) +void SystemTrayNotifier::AddNetworkObserver(NetworkObserver* observer) { + network_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddVpnObserver(NetworkObserver* observer) { + vpn_observers_.AddObserver(observer); +} + +void SystemTrayNotifier::AddSmsObserver(SmsObserver* observer) { + sms_observers_.AddObserver(observer); +} +#endif + +void SystemTrayNotifier::NotifyAccessibilityModeChanged( + bool spoken_feedback_enabled) { + FOR_EACH_OBSERVER( + AccessibilityObserver, + accessibility_observers_, + OnAccessibilityModeChanged(spoken_feedback_enabled)); +} + +void SystemTrayNotifier::NotifyVolumeChanged(float level) { + FOR_EACH_OBSERVER(AudioObserver, + audio_observers_, + OnVolumeChanged(level)); +} + +void SystemTrayNotifier::NotifyMuteToggled() { + FOR_EACH_OBSERVER(AudioObserver, + audio_observers_, + OnMuteToggled()); +} + +void SystemTrayNotifier::NotifyRefreshBluetooth() { + FOR_EACH_OBSERVER(BluetoothObserver, + bluetooth_observers_, + OnBluetoothRefresh()); +} + +void SystemTrayNotifier::NotifyBluetoothDiscoveringChanged() { + FOR_EACH_OBSERVER(BluetoothObserver, + bluetooth_observers_, + OnBluetoothDiscoveringChanged()); +} + +void SystemTrayNotifier::NotifyBrightnessChanged(double level, + bool user_initiated) { + FOR_EACH_OBSERVER( + BrightnessObserver, + brightness_observers_, + OnBrightnessChanged(level, user_initiated)); +} + +void SystemTrayNotifier::NotifyCapsLockChanged( + bool enabled, + bool search_mapped_to_caps_lock) { + FOR_EACH_OBSERVER(CapsLockObserver, + caps_lock_observers_, + OnCapsLockChanged(enabled, search_mapped_to_caps_lock)); +} + +void SystemTrayNotifier::NotifyRefreshClock() { + FOR_EACH_OBSERVER(ClockObserver, clock_observers_, Refresh()); +} + +void SystemTrayNotifier::NotifyDateFormatChanged() { + FOR_EACH_OBSERVER(ClockObserver, + clock_observers_, + OnDateFormatChanged()); +} + +void SystemTrayNotifier::NotifyRefreshDrive(DriveOperationStatusList& list) { + FOR_EACH_OBSERVER(DriveObserver, + drive_observers_, + OnDriveRefresh(list)); +} + +void SystemTrayNotifier::NotifyRefreshIME(bool show_message) { + FOR_EACH_OBSERVER(IMEObserver, + ime_observers_, + OnIMERefresh(show_message)); +} + +void SystemTrayNotifier::NotifyShowLoginButtonChanged(bool show_login_button) { + FOR_EACH_OBSERVER(LogoutButtonObserver, + logout_button_observers_, + OnShowLogoutButtonInTrayChanged(show_login_button)); +} + +void SystemTrayNotifier::NotifyLocaleChanged( + LocaleObserver::Delegate* delegate, + const std::string& cur_locale, + const std::string& from_locale, + const std::string& to_locale) { + FOR_EACH_OBSERVER( + LocaleObserver, + locale_observers_, + OnLocaleChanged(delegate, cur_locale, from_locale, to_locale)); +} + +void SystemTrayNotifier::NotifyPowerStatusChanged( + const PowerSupplyStatus& power_status) { + FOR_EACH_OBSERVER(PowerStatusObserver, + power_status_observers_, + OnPowerStatusChanged(power_status)); +} + +void SystemTrayNotifier::NotifyUpdateRecommended( + UpdateObserver::UpdateSeverity severity) { + FOR_EACH_OBSERVER(UpdateObserver, + update_observers_, + OnUpdateRecommended(severity)); +} + +void SystemTrayNotifier::NotifyUserUpdate() { + FOR_EACH_OBSERVER(UserObserver, + user_observers_, + OnUserUpdate()); +} + +#if defined(OS_CHROMEOS) + +void SystemTrayNotifier::NotifyRefreshNetwork(const NetworkIconInfo &info) { + FOR_EACH_OBSERVER(NetworkObserver, + network_observers_, + OnNetworkRefresh(info)); +} + +void SystemTrayNotifier::NotifySetNetworkMessage( + NetworkTrayDelegate* delegate, + NetworkObserver::MessageType message_type, + const string16& title, + const string16& message, + const std::vector<string16>& links) { + FOR_EACH_OBSERVER(NetworkObserver, + network_observers_, + SetNetworkMessage( + delegate, message_type, title, message, links)); +} + +void SystemTrayNotifier::NotifyClearNetworkMessage( + NetworkObserver::MessageType message_type) { + FOR_EACH_OBSERVER(NetworkObserver, + network_observers_, + ClearNetworkMessage(message_type)); +} + +void SystemTrayNotifier::NotifyVpnRefreshNetwork(const NetworkIconInfo &info) { + FOR_EACH_OBSERVER(NetworkObserver, + vpn_observers_, + OnNetworkRefresh(info)); +} + +void SystemTrayNotifier::NotifyWillToggleWifi() { + FOR_EACH_OBSERVER(NetworkObserver, + network_observers_, + OnWillToggleWifi()); +} + +void SystemTrayNotifier::NotifyAddSmsMessage( + const base::DictionaryValue& message) { + FOR_EACH_OBSERVER(SmsObserver, sms_observers_, AddMessage(message)); +} + +#endif // OS_CHROMEOS + +} // namespace ash diff --git a/ash/system/tray/system_tray_notifier.h b/ash/system/tray/system_tray_notifier.h new file mode 100644 index 0000000..b755167 --- /dev/null +++ b/ash/system/tray/system_tray_notifier.h @@ -0,0 +1,117 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_NOTIFIER_H_ +#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_NOTIFIER_H_ + +#include <string> +#include <vector> + +#include "ash/ash_export.h" +#include "ash/system/audio/audio_observer.h" +#include "ash/system/bluetooth/bluetooth_observer.h" +#include "ash/system/brightness/brightness_observer.h" +#include "ash/system/chromeos/network/network_observer.h" +#include "ash/system/chromeos/network/sms_observer.h" +#include "ash/system/date/clock_observer.h" +#include "ash/system/drive/drive_observer.h" +#include "ash/system/ime/ime_observer.h" +#include "ash/system/locale/locale_observer.h" +#include "ash/system/logout_button/logout_button_observer.h" +#include "ash/system/power/power_status_observer.h" +#include "ash/system/tray_accessibility.h" +#include "ash/system/tray_caps_lock.h" +#include "ash/system/user/update_observer.h" +#include "ash/system/user/user_observer.h" +#include "base/observer_list.h" + +#if defined(OS_CHROMEOS) +#include "ash/system/chromeos/network/network_observer.h" +#include "ash/system/chromeos/network/sms_observer.h" +#endif + +namespace ash { + +class ASH_EXPORT SystemTrayNotifier { +public: + SystemTrayNotifier(); + ~SystemTrayNotifier(); + + void AddAccessibilityObserver(AccessibilityObserver* observer); + void AddAudioObserver(AudioObserver* observer); + void AddBluetoothObserver(BluetoothObserver* observer); + void AddBrightnessObserver(BrightnessObserver* observer); + void AddCapsLockObserver(CapsLockObserver* observer); + void AddClockObserver(ClockObserver* observer); + void AddDriveObserver(DriveObserver* observer); + void AddIMEObserver(IMEObserver* observer); + void AddLocaleObserver(LocaleObserver* observer); + void AddLogoutButtonObserver(LogoutButtonObserver* observer); + void AddPowerStatusObserver(PowerStatusObserver* observer); + void AddUpdateObserver(UpdateObserver* observer); + void AddUserObserver(UserObserver* observer); +#if defined(OS_CHROMEOS) + void AddNetworkObserver(NetworkObserver* observer); + void AddVpnObserver(NetworkObserver* observer); + void AddSmsObserver(SmsObserver* observer); +#endif + + void NotifyAccessibilityModeChanged(bool spoken_feedback_enabled); + void NotifyVolumeChanged(float level); + void NotifyMuteToggled(); + void NotifyRefreshBluetooth(); + void NotifyBluetoothDiscoveringChanged(); + void NotifyBrightnessChanged(double level, bool user_initialted); + void NotifyCapsLockChanged(bool enabled, bool search_mapped_to_caps_lock); + void NotifyRefreshClock(); + void NotifyDateFormatChanged(); + void NotifyRefreshDrive(DriveOperationStatusList& list); + void NotifyRefreshIME(bool show_message); + void NotifyShowLoginButtonChanged(bool show_login_button); + void NotifyLocaleChanged(LocaleObserver::Delegate* delegate, + const std::string& cur_locale, + const std::string& from_locale, + const std::string& to_locale); + void NotifyPowerStatusChanged(const PowerSupplyStatus& power_status); + void NotifyUpdateRecommended(UpdateObserver::UpdateSeverity severity); + void NotifyUserUpdate(); +#if defined(OS_CHROMEOS) + void NotifyRefreshNetwork(const NetworkIconInfo &info); + void NotifySetNetworkMessage(NetworkTrayDelegate* delegate, + NetworkObserver::MessageType message_type, + const string16& title, + const string16& message, + const std::vector<string16>& links); + void NotifyClearNetworkMessage(NetworkObserver::MessageType message_type); + void NotifyVpnRefreshNetwork(const NetworkIconInfo &info); + void NotifyWillToggleWifi(); + void NotifyAddSmsMessage(const base::DictionaryValue& message); +#endif + + private: + ObserverList<AccessibilityObserver> accessibility_observers_; + ObserverList<AudioObserver> audio_observers_; + ObserverList<BluetoothObserver> bluetooth_observers_; + ObserverList<BrightnessObserver> brightness_observers_; + ObserverList<CapsLockObserver> caps_lock_observers_; + ObserverList<ClockObserver> clock_observers_; + ObserverList<DriveObserver> drive_observers_; + ObserverList<IMEObserver> ime_observers_; + ObserverList<LocaleObserver> locale_observers_; + ObserverList<LogoutButtonObserver> logout_button_observers_; + ObserverList<PowerStatusObserver> power_status_observers_; + ObserverList<UpdateObserver> update_observers_; + ObserverList<UserObserver> user_observers_; +#if defined(OS_CHROMEOS) + ObserverList<NetworkObserver> network_observers_; + ObserverList<NetworkObserver> vpn_observers_; + ObserverList<SmsObserver> sms_observers_; +#endif + + DISALLOW_COPY_AND_ASSIGN(SystemTrayNotifier); +}; + +} // namespace ash + +#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_NOTIFIER_H_ diff --git a/chrome/browser/chromeos/locale_change_guard.cc b/chrome/browser/chromeos/locale_change_guard.cc index 606bfb4..80108ab 100644 --- a/chrome/browser/chromeos/locale_change_guard.cc +++ b/chrome/browser/chromeos/locale_change_guard.cc @@ -6,6 +6,7 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray.h" +#include "ash/system/tray/system_tray_notifier.h" #include "base/bind.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" @@ -171,10 +172,8 @@ void LocaleChangeGuard::Check() { PrepareChangingLocale(from_locale, to_locale); } - if (ash::Shell::GetInstance()->status_area_widget()) { - ash::Shell::GetInstance()->system_tray()->locale_observer()-> - OnLocaleChanged(this, cur_locale, from_locale_, to_locale_); - } + ash::Shell::GetInstance()->system_tray_notifier()->NotifyLocaleChanged( + this, cur_locale, from_locale_, to_locale_); } void LocaleChangeGuard::AcceptLocaleChange() { diff --git a/chrome/browser/chromeos/network_message_observer.cc b/chrome/browser/chromeos/network_message_observer.cc index 5e24899..5501d76 100644 --- a/chrome/browser/chromeos/network_message_observer.cc +++ b/chrome/browser/chromeos/network_message_observer.cc @@ -8,6 +8,7 @@ #include "ash/shell_delegate.h" #include "ash/system/chromeos/network/network_observer.h" #include "ash/system/tray/system_tray.h" +#include "ash/system/tray/system_tray_notifier.h" #include "base/bind.h" #include "base/callback.h" #include "base/stl_util.h" @@ -71,8 +72,8 @@ class NetworkMessageNotification : public ash::NetworkTrayDelegate { } void Hide() { - ash::Shell::GetInstance()->system_tray()->network_observer()-> - ClearNetworkMessage(error_type_); + ash::Shell::GetInstance()->system_tray_notifier()-> + NotifyClearNetworkMessage(error_type_); } void SetTitle(const string16& title) { @@ -86,8 +87,8 @@ class NetworkMessageNotification : public ash::NetworkTrayDelegate { callback_ = callback; std::vector<string16> links; links.push_back(link_text); - ash::Shell::GetInstance()->system_tray()->network_observer()-> - SetNetworkMessage(this, error_type_, title_, message, links); + ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( + this, error_type_, title_, message, links); } void ShowAlways(const string16& message, diff --git a/chrome/browser/chromeos/sms_observer.cc b/chrome/browser/chromeos/sms_observer.cc index 866568f..431fc87 100644 --- a/chrome/browser/chromeos/sms_observer.cc +++ b/chrome/browser/chromeos/sms_observer.cc @@ -7,6 +7,7 @@ #include "ash/shell.h" #include "ash/system/chromeos/network/sms_observer.h" #include "ash/system/tray/system_tray.h" +#include "ash/system/tray/system_tray_notifier.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "grit/generated_resources.h" @@ -111,8 +112,7 @@ void SmsObserver::OnNewMessage(const std::string& modem_device_path, base::DictionaryValue dict; dict.SetString(ash::kSmsNumberKey, message.number); dict.SetString(ash::kSmsTextKey, message.text); - if (ash::Shell::GetInstance()->status_area_widget()) - ash::Shell::GetInstance()->system_tray()->sms_observer()->AddMessage(dict); + ash::Shell::GetInstance()->system_tray_notifier()->NotifyAddSmsMessage(dict); } } // namespace chromeos diff --git a/chrome/browser/chromeos/status/data_promo_notification.cc b/chrome/browser/chromeos/status/data_promo_notification.cc index 6d1cfcf..2acb823 100644 --- a/chrome/browser/chromeos/status/data_promo_notification.cc +++ b/chrome/browser/chromeos/status/data_promo_notification.cc @@ -8,6 +8,7 @@ #include "ash/shell_window_ids.h" #include "ash/system/chromeos/network/network_observer.h" #include "ash/system/tray/system_tray.h" +#include "ash/system/tray/system_tray_notifier.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/cros/cros_library.h" @@ -202,12 +203,9 @@ void DataPromoNotification::ShowOptionalMobileDataPromoNotification( links.push_back(l10n_util::GetStringUTF16(link_message_id)); if (!deal_info_url_.empty()) links.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); - if (ash::Shell::GetInstance()->system_tray()->network_observer()) { - ash::Shell::GetInstance()->system_tray()->network_observer()-> - SetNetworkMessage(listener, ash::NetworkObserver::MESSAGE_DATA_PROMO, - string16(), message, links); - } - + ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( + listener, ash::NetworkObserver::MESSAGE_DATA_PROMO, + string16(), message, links); check_for_promo_ = false; SetShow3gPromoNotification(false); if (carrier_deal_promo_pref != kNotificationCountPrefDefault) @@ -216,11 +214,8 @@ void DataPromoNotification::ShowOptionalMobileDataPromoNotification( } void DataPromoNotification::CloseNotification() { - if (ash::Shell::GetInstance()->status_area_widget() && - ash::Shell::GetInstance()->system_tray()->network_observer()) { - ash::Shell::GetInstance()->system_tray()->network_observer()-> - ClearNetworkMessage(ash::NetworkObserver::MESSAGE_DATA_PROMO); - } + ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( + ash::NetworkObserver::MESSAGE_DATA_PROMO); } } // namespace chromeos diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index ee421bd..e3f0389 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -17,6 +17,7 @@ #include "ash/system/power/power_status_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_accessibility.h" #include "ash/system/tray_caps_lock.h" #include "ash/system/user/update_observer.h" @@ -176,8 +177,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, screen_locked_(false), connected_network_state_(STATE_UNKNOWN), data_promo_notification_(new DataPromoNotification()), - volume_control_delegate_(ALLOW_THIS_IN_INITIALIZER_LIST( - new VolumeController)) { + volume_control_delegate_(new VolumeController()) { // Register notifications on construction so that events such as // PROFILE_CREATED do not get missed if they happen before Initialize(). registrar_.Add(this, @@ -625,7 +625,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } virtual void ToggleWifi() OVERRIDE { - GetSystemTray()->network_observer()->OnWillToggleWifi(); + GetSystemTrayNotifier()->NotifyWillToggleWifi(); network_menu_->ToggleWifi(); } @@ -739,6 +739,10 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, return ash::Shell::GetInstance()->system_tray(); } + ash::SystemTrayNotifier* GetSystemTrayNotifier() { + return ash::Shell::GetInstance()->system_tray_notifier(); + } + // Returns the last active browser. If there is no such browser, creates a new // browser window with an empty tab and returns it. Browser* GetAppropriateBrowser() { @@ -771,44 +775,22 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, void UpdateClockType(PrefServiceBase* service) { clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? base::k24HourClock : base::k12HourClock; - ash::ClockObserver* observer = GetSystemTray()->clock_observer(); - if (observer) - observer->OnDateFormatChanged(); + GetSystemTrayNotifier()->NotifyDateFormatChanged(); } void UpdateShowLogoutButtonInTray(PrefServiceBase* service) { - ash::LogoutButtonObserver* observer = - GetSystemTray()->logout_button_observer(); - if (observer) { - observer->OnShowLogoutButtonInTrayChanged( - service->GetBoolean(prefs::kShowLogoutButtonInTray)); - } - } - - void NotifyRefreshClock() { - ash::ClockObserver* observer = GetSystemTray()->clock_observer(); - if (observer) - observer->Refresh(); + GetSystemTrayNotifier()->NotifyShowLoginButtonChanged( + service->GetBoolean(prefs::kShowLogoutButtonInTray)); } void NotifyRefreshNetwork() { - ash::NetworkObserver* observer = GetSystemTray()->network_observer(); chromeos::NetworkLibrary* crosnet = chromeos::CrosLibrary::Get()->GetNetworkLibrary(); - if (observer) { - ash::NetworkIconInfo info; - info.image = network_icon_->GetIconAndText(&info.description); - info.tray_icon_visible = network_icon_->ShouldShowIconInTray(); - observer->OnNetworkRefresh(info); - } - - ash::NetworkObserver* vpn_observer = GetSystemTray()->vpn_observer(); - if (vpn_observer) { - ash::NetworkIconInfo info; - info.image = network_icon_->GetIconAndText(&info.description); - info.tray_icon_visible = network_icon_->ShouldShowIconInTray(); - vpn_observer->OnNetworkRefresh(info); - } + ash::NetworkIconInfo info; + info.image = network_icon_->GetIconAndText(&info.description); + info.tray_icon_visible = network_icon_->ShouldShowIconInTray(); + GetSystemTrayNotifier()->NotifyRefreshNetwork(info); + GetSystemTrayNotifier()->NotifyVpnRefreshNetwork(info); // Update Accessibility. @@ -838,30 +820,6 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, connected_network_state_ = connected_network_state; } - void NotifyRefreshBluetooth() { - ash::BluetoothObserver* observer = GetSystemTray()->bluetooth_observer(); - if (observer) - observer->OnBluetoothRefresh(); - } - - void NotifyBluetoothDiscoveringChanged() { - ash::BluetoothObserver* observer = GetSystemTray()->bluetooth_observer(); - if (observer) - observer->OnBluetoothDiscoveringChanged(); - } - - void NotifyRefreshIME(bool show_message) { - ash::IMEObserver* observer = GetSystemTray()->ime_observer(); - if (observer) - observer->OnIMERefresh(show_message); - } - - void NotifyRefreshDrive(ash::DriveOperationStatusList& list) { - ash::DriveObserver* observer = GetSystemTray()->drive_observer(); - if (observer) - observer->OnDriveRefresh(list); - } - void RefreshNetworkObserver(NetworkLibrary* crosnet) { const Network* network = crosnet->active_network(); std::string new_path = network ? network->service_path() : std::string(); @@ -983,29 +941,27 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, // Overridden from AudioHandler::VolumeObserver. virtual void OnVolumeChanged() OVERRIDE { float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; - GetSystemTray()->audio_observer()->OnVolumeChanged(level); + GetSystemTrayNotifier()->NotifyVolumeChanged(level); } // Overridden from AudioHandler::VolumeObserver. virtual void OnMuteToggled() OVERRIDE { - GetSystemTray()->audio_observer()->OnMuteToggled(); + GetSystemTrayNotifier()->NotifyMuteToggled(); } // Overridden from PowerManagerClient::Observer. virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { - GetSystemTray()->brightness_observer()-> - OnBrightnessChanged(static_cast<double>(level), user_initiated); + double leveld = static_cast<double>(level); + GetSystemTrayNotifier()->NotifyBrightnessChanged(leveld, user_initiated); } virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE { power_supply_status_ = power_status; - FOR_EACH_OBSERVER(ash::PowerStatusObserver, - GetSystemTray()->power_status_observers(), - OnPowerStatusChanged(power_status)); + GetSystemTrayNotifier()->NotifyPowerStatusChanged(power_status); } virtual void SystemResumed() OVERRIDE { - NotifyRefreshClock(); + GetSystemTrayNotifier()->NotifyRefreshClock(); } // Overridden from SessionManagerClient::Observer. @@ -1094,18 +1050,14 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, severity = ash::UpdateObserver::UPDATE_NORMAL; break; } - ash::UpdateObserver* observer = GetSystemTray()->update_observer(); - if (observer) - observer->OnUpdateRecommended(severity); + GetSystemTrayNotifier()->NotifyUpdateRecommended(severity); break; } case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { // This notification is also sent on login screen when user avatar // is loaded from file. if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { - ash::UserObserver* observer = GetSystemTray()->user_observer(); - if (observer) - observer->OnUserUpdate(); + GetSystemTrayNotifier()->NotifyUserUpdate(); } break; } @@ -1140,12 +1092,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, search_key_mapped_to_ = service->GetInteger(prefs::kLanguageRemapSearchKeyTo); } else if (pref == prefs::kSpokenFeedbackEnabled) { - ash::AccessibilityObserver* observer = - GetSystemTray()->accessibility_observer(); - if (observer) { - observer->OnAccessibilityModeChanged( - service->GetBoolean(prefs::kSpokenFeedbackEnabled)); - } + GetSystemTrayNotifier()->NotifyAccessibilityModeChanged( + service->GetBoolean(prefs::kSpokenFeedbackEnabled)); } else if (pref == prefs::kShowLogoutButtonInTray) { UpdateShowLogoutButtonInTray(service); } else { @@ -1156,19 +1104,19 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, // Overridden from InputMethodManager::Observer. virtual void InputMethodChanged( input_method::InputMethodManager* manager, bool show_message) OVERRIDE { - NotifyRefreshIME(show_message); + GetSystemTrayNotifier()->NotifyRefreshIME(show_message); } virtual void InputMethodPropertyChanged( input_method::InputMethodManager* manager) OVERRIDE { - NotifyRefreshIME(false); + GetSystemTrayNotifier()->NotifyRefreshIME(false); } // google_apis::DriveServiceObserver overrides. virtual void OnProgressUpdate( const google_apis::OperationProgressStatusList& list) OVERRIDE { std::vector<ash::DriveOperationStatus> ui_list = GetDriveStatusList(list); - NotifyRefreshDrive(ui_list); + GetSystemTrayNotifier()->NotifyRefreshDrive(ui_list); // If we have something to report right now (i.e. completion status only), // we need to delayed re-check the status in few seconds to ensure we @@ -1217,38 +1165,38 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, // Overridden from system::TimezoneSettings::Observer. virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { - NotifyRefreshClock(); + GetSystemTrayNotifier()->NotifyRefreshClock(); } // Overridden from BluetoothAdapter::Observer. virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, bool present) OVERRIDE { - NotifyRefreshBluetooth(); + GetSystemTrayNotifier()->NotifyRefreshBluetooth(); } virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, bool powered) OVERRIDE { - NotifyRefreshBluetooth(); + GetSystemTrayNotifier()->NotifyRefreshBluetooth(); } virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, bool discovering) OVERRIDE { - NotifyBluetoothDiscoveringChanged(); + GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged(); } virtual void DeviceAdded(device::BluetoothAdapter* adapter, device::BluetoothDevice* device) OVERRIDE { - NotifyRefreshBluetooth(); + GetSystemTrayNotifier()->NotifyRefreshBluetooth(); } virtual void DeviceChanged(device::BluetoothAdapter* adapter, device::BluetoothDevice* device) OVERRIDE { - NotifyRefreshBluetooth(); + GetSystemTrayNotifier()->NotifyRefreshBluetooth(); } virtual void DeviceRemoved(device::BluetoothAdapter* adapter, device::BluetoothDevice* device) OVERRIDE { - NotifyRefreshBluetooth(); + GetSystemTrayNotifier()->NotifyRefreshBluetooth(); } // Overridden from SystemKeyEventListener::CapsLockObserver. @@ -1257,10 +1205,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, if (!base::chromeos::IsRunningOnChromeOS() || search_key_mapped_to_ == input_method::kCapsLockKey) search_mapped_to_caps_lock = true; - - ash::CapsLockObserver* observer = GetSystemTray()->caps_lock_observer(); - if (observer) - observer->OnCapsLockChanged(enabled, search_mapped_to_caps_lock); + GetSystemTrayNotifier()->NotifyCapsLockChanged( + enabled, search_mapped_to_caps_lock); } // Overridden from ash::NetworkTrayDelegate |