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/system/audio/audio_controller.h" | 8 #include "ash/system/audio/audio_controller.h" |
9 #include "ash/system/brightness/brightness_controller.h" | 9 #include "ash/system/brightness/brightness_controller.h" |
10 #include "ash/system/power/power_status_controller.h" | 10 #include "ash/system/power/power_status_controller.h" |
11 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
12 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "chrome/browser/chromeos/audio/audio_handler.h" | 14 #include "chrome/browser/chromeos/audio/audio_handler.h" |
15 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 15 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
16 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 16 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
17 #include "chrome/browser/chromeos/login/user.h" | 17 #include "chrome/browser/chromeos/login/user.h" |
18 #include "chrome/browser/chromeos/login/user_manager.h" | 18 #include "chrome/browser/chromeos/login/user_manager.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_service.h" |
21 | 24 |
22 namespace chromeos { | 25 namespace chromeos { |
23 | 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 29 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
27 public AudioHandler::VolumeObserver, | 30 public AudioHandler::VolumeObserver, |
28 public PowerManagerClient::Observer { | 31 public PowerManagerClient::Observer, |
| 32 public content::NotificationObserver { |
29 public: | 33 public: |
30 explicit SystemTrayDelegate(ash::SystemTray* tray) : tray_(tray) { | 34 explicit SystemTrayDelegate(ash::SystemTray* tray) : tray_(tray) { |
31 AudioHandler::GetInstance()->AddVolumeObserver(this); | 35 AudioHandler::GetInstance()->AddVolumeObserver(this); |
32 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 36 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
33 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( | 37 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( |
34 PowerManagerClient::UPDATE_USER); | 38 PowerManagerClient::UPDATE_USER); |
| 39 |
| 40 registrar_.Add(this, |
| 41 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 42 content::NotificationService::AllSources()); |
35 } | 43 } |
36 | 44 |
37 virtual ~SystemTrayDelegate() { | 45 virtual ~SystemTrayDelegate() { |
38 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 46 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
39 if (audiohandler) | 47 if (audiohandler) |
40 audiohandler->RemoveVolumeObserver(this); | 48 audiohandler->RemoveVolumeObserver(this); |
41 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 49 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
42 } | 50 } |
43 | 51 |
44 // Overridden from ash::SystemTrayDelegate. | 52 // Overridden from ash::SystemTrayDelegate. |
45 virtual const std::string GetUserDisplayName() OVERRIDE { | 53 virtual const std::string GetUserDisplayName() OVERRIDE { |
46 return UserManager::Get()->logged_in_user().GetDisplayName(); | 54 return UserManager::Get()->logged_in_user().GetDisplayName(); |
47 } | 55 } |
48 | 56 |
49 virtual const std::string GetUserEmail() OVERRIDE { | 57 virtual const std::string GetUserEmail() OVERRIDE { |
50 return UserManager::Get()->logged_in_user().email(); | 58 return UserManager::Get()->logged_in_user().email(); |
51 } | 59 } |
52 | 60 |
53 virtual const SkBitmap& GetUserImage() OVERRIDE { | 61 virtual const SkBitmap& GetUserImage() OVERRIDE { |
54 return UserManager::Get()->logged_in_user().image(); | 62 return UserManager::Get()->logged_in_user().image(); |
55 } | 63 } |
56 | 64 |
| 65 virtual ash::user::LoginStatus GetUserLoginStatus() OVERRIDE { |
| 66 UserManager* manager = UserManager::Get(); |
| 67 if (!manager->user_is_logged_in()) |
| 68 return ash::user::LOGGED_IN_NONE; |
| 69 if (manager->current_user_is_owner()) |
| 70 return ash::user::LOGGED_IN_OWNER; |
| 71 if (manager->IsLoggedInAsGuest()) |
| 72 return ash::user::LOGGED_IN_GUEST; |
| 73 return ash::user::LOGGED_IN_USER; |
| 74 } |
| 75 |
57 virtual void ShowSettings() OVERRIDE { | 76 virtual void ShowSettings() OVERRIDE { |
58 BrowserList::GetLastActive()->OpenOptionsDialog(); | 77 BrowserList::GetLastActive()->OpenOptionsDialog(); |
59 } | 78 } |
60 | 79 |
61 virtual void ShowHelp() OVERRIDE { | 80 virtual void ShowHelp() OVERRIDE { |
62 BrowserList::GetLastActive()->ShowHelpTab(); | 81 BrowserList::GetLastActive()->ShowHelpTab(); |
63 } | 82 } |
64 | 83 |
65 virtual bool IsAudioMuted() const OVERRIDE { | 84 virtual bool IsAudioMuted() const OVERRIDE { |
66 return AudioHandler::GetInstance()->IsMuted(); | 85 return AudioHandler::GetInstance()->IsMuted(); |
(...skipping 18 matching lines...) Expand all Loading... |
85 virtual void SignOut() OVERRIDE { | 104 virtual void SignOut() OVERRIDE { |
86 BrowserList::AttemptUserExit(); | 105 BrowserList::AttemptUserExit(); |
87 } | 106 } |
88 | 107 |
89 virtual void LockScreen() OVERRIDE { | 108 virtual void LockScreen() OVERRIDE { |
90 DBusThreadManager::Get()->GetPowerManagerClient()-> | 109 DBusThreadManager::Get()->GetPowerManagerClient()-> |
91 NotifyScreenLockRequested(); | 110 NotifyScreenLockRequested(); |
92 } | 111 } |
93 | 112 |
94 private: | 113 private: |
95 ash::SystemTray* tray_; | |
96 | |
97 // Overridden from AudioHandler::VolumeObserver. | 114 // Overridden from AudioHandler::VolumeObserver. |
98 virtual void OnVolumeChanged() OVERRIDE { | 115 virtual void OnVolumeChanged() OVERRIDE { |
99 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; | 116 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; |
100 ash::Shell::GetInstance()->audio_controller()-> | 117 ash::Shell::GetInstance()->audio_controller()-> |
101 OnVolumeChanged(level); | 118 OnVolumeChanged(level); |
102 } | 119 } |
103 | 120 |
104 // Overridden from PowerManagerClient::Observer. | 121 // Overridden from PowerManagerClient::Observer. |
105 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { | 122 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { |
106 ash::Shell::GetInstance()->brightness_controller()-> | 123 ash::Shell::GetInstance()->brightness_controller()-> |
107 OnBrightnessChanged(level / 100.f, user_initiated); | 124 OnBrightnessChanged(level / 100.f, user_initiated); |
108 } | 125 } |
109 | 126 |
110 virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE { | 127 virtual void PowerChanged(const PowerSupplyStatus& power_status) OVERRIDE { |
111 ash::Shell::GetInstance()->power_status_controller()-> | 128 ash::Shell::GetInstance()->power_status_controller()-> |
112 OnPowerStatusChanged(power_status); | 129 OnPowerStatusChanged(power_status); |
113 } | 130 } |
114 | 131 |
115 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. | 132 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
116 // PowerButtonStateChanged etc.). | 133 // PowerButtonStateChanged etc.). |
117 | 134 |
| 135 // content::NotificationObserver implementation. |
| 136 virtual void Observe(int type, |
| 137 const content::NotificationSource& source, |
| 138 const content::NotificationDetails& details) OVERRIDE { |
| 139 switch (type) { |
| 140 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| 141 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); |
| 142 break; |
| 143 } |
| 144 default: |
| 145 NOTREACHED(); |
| 146 } |
| 147 } |
| 148 |
| 149 ash::SystemTray* tray_; |
| 150 content::NotificationRegistrar registrar_; |
| 151 |
118 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 152 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
119 }; | 153 }; |
120 | 154 |
121 } // namespace | 155 } // namespace |
122 | 156 |
123 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 157 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
124 return new chromeos::SystemTrayDelegate(tray); | 158 return new chromeos::SystemTrayDelegate(tray); |
125 } | 159 } |
126 | 160 |
127 } // namespace chromeos | 161 } // namespace chromeos |
OLD | NEW |