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/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
11 #include "ash/system/tray/system_tray_delegate.h" | 11 #include "ash/system/tray/system_tray_delegate.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "chrome/browser/chromeos/audio/audio_handler.h" | 13 #include "chrome/browser/chromeos/audio/audio_handler.h" |
14 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 14 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
15 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 15 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| 16 #include "chrome/browser/chromeos/login/user.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" |
16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
18 | 20 |
19 namespace chromeos { | 21 namespace chromeos { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 25 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
24 public AudioHandler::VolumeObserver, | 26 public AudioHandler::VolumeObserver, |
25 public PowerManagerClient::Observer { | 27 public PowerManagerClient::Observer { |
26 public: | 28 public: |
27 explicit SystemTrayDelegate(ash::SystemTray* tray) : tray_(tray) { | 29 explicit SystemTrayDelegate(ash::SystemTray* tray) : tray_(tray) { |
28 AudioHandler::GetInstance()->AddVolumeObserver(this); | 30 AudioHandler::GetInstance()->AddVolumeObserver(this); |
29 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 31 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
30 } | 32 } |
31 | 33 |
32 virtual ~SystemTrayDelegate() { | 34 virtual ~SystemTrayDelegate() { |
33 AudioHandler::GetInstance()->RemoveVolumeObserver(this); | 35 AudioHandler::GetInstance()->RemoveVolumeObserver(this); |
34 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 36 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
35 } | 37 } |
36 | 38 |
37 // Overridden from ash::SystemTrayDelegate. | 39 // Overridden from ash::SystemTrayDelegate. |
| 40 virtual const std::string GetUserDisplayName() OVERRIDE { |
| 41 return UserManager::Get()->logged_in_user().GetDisplayName(); |
| 42 } |
| 43 |
| 44 virtual const std::string GetUserEmail() OVERRIDE { |
| 45 return UserManager::Get()->logged_in_user().email(); |
| 46 } |
| 47 |
| 48 virtual const SkBitmap& GetUserImage() OVERRIDE { |
| 49 return UserManager::Get()->logged_in_user().image(); |
| 50 } |
| 51 |
38 virtual void ShowSettings() OVERRIDE { | 52 virtual void ShowSettings() OVERRIDE { |
39 BrowserList::GetLastActive()->OpenOptionsDialog(); | 53 BrowserList::GetLastActive()->OpenOptionsDialog(); |
40 } | 54 } |
41 | 55 |
42 virtual void ShowHelp() OVERRIDE { | 56 virtual void ShowHelp() OVERRIDE { |
43 BrowserList::GetLastActive()->ShowHelpTab(); | 57 BrowserList::GetLastActive()->ShowHelpTab(); |
44 } | 58 } |
45 | 59 |
46 virtual bool IsAudioMuted() const OVERRIDE { | 60 virtual bool IsAudioMuted() const OVERRIDE { |
47 return AudioHandler::GetInstance()->IsMuted(); | 61 return AudioHandler::GetInstance()->IsMuted(); |
48 } | 62 } |
49 | 63 |
50 virtual void SetAudioMuted(bool muted) OVERRIDE { | 64 virtual void SetAudioMuted(bool muted) OVERRIDE { |
51 return AudioHandler::GetInstance()->SetMuted(muted); | 65 return AudioHandler::GetInstance()->SetMuted(muted); |
52 } | 66 } |
53 | 67 |
54 virtual float GetVolumeLevel() const OVERRIDE { | 68 virtual float GetVolumeLevel() const OVERRIDE { |
55 return AudioHandler::GetInstance()->GetVolumePercent() / 100.f; | 69 return AudioHandler::GetInstance()->GetVolumePercent() / 100.f; |
56 } | 70 } |
57 | 71 |
58 virtual void SetVolumeLevel(float level) OVERRIDE { | 72 virtual void SetVolumeLevel(float level) OVERRIDE { |
59 AudioHandler::GetInstance()->SetVolumePercent(level * 100.f); | 73 AudioHandler::GetInstance()->SetVolumePercent(level * 100.f); |
60 } | 74 } |
61 | 75 |
| 76 virtual void ShutDown() OVERRIDE { |
| 77 DBusThreadManager::Get()->GetPowerManagerClient()->RequestShutdown(); |
| 78 } |
| 79 |
| 80 virtual void SignOut() OVERRIDE { |
| 81 BrowserList::AttemptUserExit(); |
| 82 } |
| 83 |
| 84 virtual void LockScreen() OVERRIDE { |
| 85 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 86 NotifyScreenLockRequested(); |
| 87 } |
| 88 |
62 private: | 89 private: |
63 ash::SystemTray* tray_; | 90 ash::SystemTray* tray_; |
64 | 91 |
65 // Overridden from AudioHandler::VolumeObserver. | 92 // Overridden from AudioHandler::VolumeObserver. |
66 virtual void OnVolumeChanged() OVERRIDE { | 93 virtual void OnVolumeChanged() OVERRIDE { |
67 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; | 94 float level = AudioHandler::GetInstance()->GetVolumePercent() / 100.f; |
68 ash::Shell::GetInstance()->audio_controller()-> | 95 ash::Shell::GetInstance()->audio_controller()-> |
69 OnVolumeChanged(level); | 96 OnVolumeChanged(level); |
70 } | 97 } |
71 | 98 |
72 // Overridden from PowerManagerClient::Observer. | 99 // Overridden from PowerManagerClient::Observer. |
73 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { | 100 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE { |
74 ash::Shell::GetInstance()->brightness_controller()-> | 101 ash::Shell::GetInstance()->brightness_controller()-> |
75 OnBrightnessChanged(level / 100.f, user_initiated); | 102 OnBrightnessChanged(level / 100.f, user_initiated); |
76 } | 103 } |
77 | 104 |
78 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. | 105 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
79 // PowerChanged, PowerButtonStateChanged etc.). | 106 // PowerChanged, PowerButtonStateChanged etc.). |
80 | 107 |
81 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 108 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
82 }; | 109 }; |
83 | 110 |
84 } // namespace | 111 } // namespace |
85 | 112 |
86 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 113 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
87 return new chromeos::SystemTrayDelegate(tray); | 114 return new chromeos::SystemTrayDelegate(tray); |
88 } | 115 } |
89 | 116 |
90 } // namespace chromeos | 117 } // namespace chromeos |
OLD | NEW |