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/network/network_controller.h" | 10 #include "ash/system/network/network_controller.h" |
| 11 #include "ash/system/power/date_format_observer.h" |
11 #include "ash/system/power/power_status_controller.h" | 12 #include "ash/system/power/power_status_controller.h" |
12 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
13 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
14 #include "ash/system/user/update_controller.h" | 15 #include "ash/system/user/update_controller.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "chrome/browser/chromeos/audio/audio_handler.h" | 17 #include "chrome/browser/chromeos/audio/audio_handler.h" |
17 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
18 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 20 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 21 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
21 #include "chrome/browser/chromeos/login/user.h" | 22 #include "chrome/browser/chromeos/login/user.h" |
22 #include "chrome/browser/chromeos/login/user_manager.h" | 23 #include "chrome/browser/chromeos/login/user_manager.h" |
23 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 24 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/upgrade_detector.h" | 29 #include "chrome/browser/upgrade_detector.h" |
| 30 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
28 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
30 | 34 |
31 namespace chromeos { | 35 namespace chromeos { |
32 | 36 |
33 namespace { | 37 namespace { |
34 | 38 |
35 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 39 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
36 public AudioHandler::VolumeObserver, | 40 public AudioHandler::VolumeObserver, |
(...skipping 17 matching lines...) Expand all Loading... |
54 crosnet->AddNetworkManagerObserver(this); | 58 crosnet->AddNetworkManagerObserver(this); |
55 OnNetworkManagerChanged(crosnet); | 59 OnNetworkManagerChanged(crosnet); |
56 crosnet->AddCellularDataPlanObserver(this); | 60 crosnet->AddCellularDataPlanObserver(this); |
57 | 61 |
58 registrar_.Add(this, | 62 registrar_.Add(this, |
59 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 63 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
60 content::NotificationService::AllSources()); | 64 content::NotificationService::AllSources()); |
61 registrar_.Add(this, | 65 registrar_.Add(this, |
62 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 66 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
63 content::NotificationService::AllSources()); | 67 content::NotificationService::AllSources()); |
| 68 |
| 69 InitializePrefChangeRegistrar(); |
64 } | 70 } |
65 | 71 |
66 virtual ~SystemTrayDelegate() { | 72 virtual ~SystemTrayDelegate() { |
67 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 73 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
68 if (audiohandler) | 74 if (audiohandler) |
69 audiohandler->RemoveVolumeObserver(this); | 75 audiohandler->RemoveVolumeObserver(this); |
70 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 76 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
71 } | 77 } |
72 | 78 |
73 // Overridden from ash::SystemTrayDelegate: | 79 // Overridden from ash::SystemTrayDelegate: |
(...skipping 22 matching lines...) Expand all Loading... |
96 | 102 |
97 virtual bool SystemShouldUpgrade() const OVERRIDE { | 103 virtual bool SystemShouldUpgrade() const OVERRIDE { |
98 return UpgradeDetector::GetInstance()->notify_upgrade(); | 104 return UpgradeDetector::GetInstance()->notify_upgrade(); |
99 } | 105 } |
100 | 106 |
101 virtual int GetSystemUpdateIconResource() const OVERRIDE { | 107 virtual int GetSystemUpdateIconResource() const OVERRIDE { |
102 return UpgradeDetector::GetInstance()->GetIconResourceID( | 108 return UpgradeDetector::GetInstance()->GetIconResourceID( |
103 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); | 109 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); |
104 } | 110 } |
105 | 111 |
| 112 virtual base::HourClockType GetHourClockType() const OVERRIDE { |
| 113 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 114 return !profile || profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock) ? |
| 115 base::k24HourClock : base::k12HourClock; |
| 116 } |
| 117 |
106 virtual void ShowSettings() OVERRIDE { | 118 virtual void ShowSettings() OVERRIDE { |
107 BrowserList::GetLastActive()->OpenOptionsDialog(); | 119 BrowserList::GetLastActive()->OpenOptionsDialog(); |
108 } | 120 } |
109 | 121 |
110 virtual void ShowDateSettings() OVERRIDE { | 122 virtual void ShowDateSettings() OVERRIDE { |
111 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); | 123 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); |
112 } | 124 } |
113 | 125 |
114 virtual void ShowHelp() OVERRIDE { | 126 virtual void ShowHelp() OVERRIDE { |
115 BrowserList::GetLastActive()->ShowHelpTab(); | 127 BrowserList::GetLastActive()->ShowHelpTab(); |
(...skipping 28 matching lines...) Expand all Loading... |
144 NotifyScreenLockRequested(); | 156 NotifyScreenLockRequested(); |
145 } | 157 } |
146 | 158 |
147 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { | 159 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { |
148 ash::NetworkIconInfo info; | 160 ash::NetworkIconInfo info; |
149 info.image = network_icon_->GetIconAndText(&info.description); | 161 info.image = network_icon_->GetIconAndText(&info.description); |
150 return info; | 162 return info; |
151 } | 163 } |
152 | 164 |
153 private: | 165 private: |
| 166 void InitializePrefChangeRegistrar() { |
| 167 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 168 pref_registrar_.reset(new PrefChangeRegistrar); |
| 169 pref_registrar_->Init(profile->GetPrefs()); |
| 170 pref_registrar_->Add(prefs::kUse24HourClock, this); |
| 171 } |
| 172 |
154 void NotifyRefreshNetwork() { | 173 void NotifyRefreshNetwork() { |
155 ash::NetworkController* controller = | 174 ash::NetworkController* controller = |
156 ash::Shell::GetInstance()->network_controller(); | 175 ash::Shell::GetInstance()->network_controller(); |
157 if (controller) { | 176 if (controller) { |
158 ash::NetworkIconInfo info; | 177 ash::NetworkIconInfo info; |
159 info.image = network_icon_->GetIconAndText(&info.description); | 178 info.image = network_icon_->GetIconAndText(&info.description); |
160 controller->OnNetworkRefresh(info); | 179 controller->OnNetworkRefresh(info); |
161 } | 180 } |
162 } | 181 } |
163 | 182 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 virtual void OnCellularDataPlanChanged(NetworkLibrary* crosnet) OVERRIDE { | 255 virtual void OnCellularDataPlanChanged(NetworkLibrary* crosnet) OVERRIDE { |
237 NotifyRefreshNetwork(); | 256 NotifyRefreshNetwork(); |
238 } | 257 } |
239 | 258 |
240 // content::NotificationObserver implementation. | 259 // content::NotificationObserver implementation. |
241 virtual void Observe(int type, | 260 virtual void Observe(int type, |
242 const content::NotificationSource& source, | 261 const content::NotificationSource& source, |
243 const content::NotificationDetails& details) OVERRIDE { | 262 const content::NotificationDetails& details) OVERRIDE { |
244 switch (type) { | 263 switch (type) { |
245 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 264 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| 265 // Profile may have changed after login. So re-initialize the |
| 266 // pref-change registrar. |
| 267 InitializePrefChangeRegistrar(); |
246 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); | 268 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); |
247 break; | 269 break; |
248 } | 270 } |
249 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { | 271 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { |
250 ash::UpdateController* controller = | 272 ash::UpdateController* controller = |
251 ash::Shell::GetInstance()->update_controller(); | 273 ash::Shell::GetInstance()->update_controller(); |
252 if (controller) | 274 if (controller) |
253 controller->OnUpdateRecommended(); | 275 controller->OnUpdateRecommended(); |
254 break; | 276 break; |
255 } | 277 } |
| 278 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 279 DCHECK_EQ(*content::Details<std::string>(details).ptr(), |
| 280 prefs::kUse24HourClock); |
| 281 ash::DateFormatObserver* observer = |
| 282 ash::Shell::GetInstance()->date_format_observer(); |
| 283 if (observer) |
| 284 observer->OnDateFormatChanged(); |
| 285 break; |
| 286 } |
256 default: | 287 default: |
257 NOTREACHED(); | 288 NOTREACHED(); |
258 } | 289 } |
259 } | 290 } |
260 | 291 |
261 ash::SystemTray* tray_; | 292 ash::SystemTray* tray_; |
262 scoped_ptr<NetworkMenuIcon> network_icon_; | 293 scoped_ptr<NetworkMenuIcon> network_icon_; |
263 content::NotificationRegistrar registrar_; | 294 content::NotificationRegistrar registrar_; |
| 295 scoped_ptr<PrefChangeRegistrar> pref_registrar_; |
264 std::string cellular_device_path_; | 296 std::string cellular_device_path_; |
265 std::string active_network_path_; | 297 std::string active_network_path_; |
266 | 298 |
267 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 299 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
268 }; | 300 }; |
269 | 301 |
270 } // namespace | 302 } // namespace |
271 | 303 |
272 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 304 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
273 return new chromeos::SystemTrayDelegate(tray); | 305 return new chromeos::SystemTrayDelegate(tray); |
274 } | 306 } |
275 | 307 |
276 } // namespace chromeos | 308 } // namespace chromeos |
OLD | NEW |