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/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/audio/audio_observer.h" | 9 #include "ash/system/audio/audio_observer.h" |
10 #include "ash/system/bluetooth/bluetooth_observer.h" | 10 #include "ash/system/bluetooth/bluetooth_observer.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 201 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
202 content::NotificationService::AllSources()); | 202 content::NotificationService::AllSources()); |
203 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) { | 203 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) { |
204 registrar_.Add(this, | 204 registrar_.Add(this, |
205 chrome::NOTIFICATION_SESSION_STARTED, | 205 chrome::NOTIFICATION_SESSION_STARTED, |
206 content::NotificationService::AllSources()); | 206 content::NotificationService::AllSources()); |
207 } | 207 } |
208 registrar_.Add(this, | 208 registrar_.Add(this, |
209 chrome::NOTIFICATION_PROFILE_CREATED, | 209 chrome::NOTIFICATION_PROFILE_CREATED, |
210 content::NotificationService::AllSources()); | 210 content::NotificationService::AllSources()); |
211 registrar_.Add(this, | |
212 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
213 content::NotificationService::AllSources()); | |
214 | 211 |
215 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, | 212 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, |
216 g_browser_process->local_state(), this); | 213 g_browser_process->local_state(), this); |
217 | 214 |
218 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); | 215 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); |
219 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); | 216 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); |
220 | 217 |
221 bluetooth_adapter_ = BluetoothAdapter::DefaultAdapter(); | 218 bluetooth_adapter_ = BluetoothAdapter::DefaultAdapter(); |
222 bluetooth_adapter_->AddObserver(this); | 219 bluetooth_adapter_->AddObserver(this); |
223 } | 220 } |
224 | 221 |
225 virtual ~SystemTrayDelegate() { | 222 virtual ~SystemTrayDelegate() { |
226 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 223 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
227 if (audiohandler) | 224 if (audiohandler) |
228 audiohandler->RemoveVolumeObserver(this); | 225 audiohandler->RemoveVolumeObserver(this); |
229 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); | 226 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); |
230 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 227 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
231 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 228 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
232 if (crosnet) { | 229 if (crosnet) { |
233 crosnet->RemoveNetworkManagerObserver(this); | 230 crosnet->RemoveNetworkManagerObserver(this); |
234 crosnet->RemoveCellularDataPlanObserver(this); | 231 crosnet->RemoveCellularDataPlanObserver(this); |
235 } | 232 } |
236 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); | 233 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); |
237 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 234 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
238 if (SystemKeyEventListener::GetInstance()) | 235 if (SystemKeyEventListener::GetInstance()) |
239 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); | 236 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); |
240 bluetooth_adapter_->RemoveObserver(this); | 237 bluetooth_adapter_->RemoveObserver(this); |
241 | 238 |
242 // Stop observing gdata operations. | 239 // Stop observing gdata operations. |
243 GDataSystemService* system_service = FindGDataSystemService(); | 240 Profile* profile = ProfileManager::GetDefaultProfile(); |
244 if (system_service) { | 241 if (gdata::util::IsGDataAvailable(profile)) { |
245 system_service->docs_service()->operation_registry()-> | 242 GDataSystemService* system_service = |
246 RemoveObserver(this); | 243 GDataSystemServiceFactory::FindForProfile(profile); |
| 244 if (system_service) { |
| 245 system_service->docs_service()->operation_registry()-> |
| 246 RemoveObserver(this); |
| 247 } |
247 } | 248 } |
248 } | 249 } |
249 | 250 |
250 // Overridden from ash::SystemTrayDelegate: | 251 // Overridden from ash::SystemTrayDelegate: |
251 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { | 252 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { |
252 // In case of OOBE / sign in screen tray will be shown later. | 253 // In case of OOBE / sign in screen tray will be shown later. |
253 return UserManager::Get()->IsUserLoggedIn(); | 254 return UserManager::Get()->IsUserLoggedIn(); |
254 } | 255 } |
255 | 256 |
256 virtual const string16 GetUserDisplayName() const OVERRIDE { | 257 virtual const string16 GetUserDisplayName() const OVERRIDE { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { | 446 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { |
446 input_method::InputMethodManager::GetInstance()->ChangeInputMethod(ime_id); | 447 input_method::InputMethodManager::GetInstance()->ChangeInputMethod(ime_id); |
447 } | 448 } |
448 | 449 |
449 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { | 450 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { |
450 input_method::InputMethodManager::GetInstance()-> | 451 input_method::InputMethodManager::GetInstance()-> |
451 ActivateInputMethodProperty(key); | 452 ActivateInputMethodProperty(key); |
452 } | 453 } |
453 | 454 |
454 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { | 455 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { |
455 GDataSystemService* system_service = FindGDataSystemService(); | 456 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 457 if (!gdata::util::IsGDataAvailable(profile)) |
| 458 return; |
| 459 |
| 460 GDataSystemService* system_service = |
| 461 GDataSystemServiceFactory::FindForProfile(profile); |
456 if (!system_service) | 462 if (!system_service) |
457 return; | 463 return; |
458 | 464 |
459 system_service->docs_service()->operation_registry()->CancelForFilePath( | 465 system_service->docs_service()->operation_registry()->CancelForFilePath( |
460 file_path); | 466 file_path); |
461 } | 467 } |
462 | 468 |
463 virtual void GetDriveOperationStatusList( | 469 virtual void GetDriveOperationStatusList( |
464 ash::DriveOperationStatusList* list) OVERRIDE { | 470 ash::DriveOperationStatusList* list) OVERRIDE { |
465 GDataSystemService* system_service = FindGDataSystemService(); | 471 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 472 if (!gdata::util::IsGDataAvailable(profile)) |
| 473 return; |
| 474 |
| 475 GDataSystemService* system_service = |
| 476 GDataSystemServiceFactory::FindForProfile(profile); |
466 if (!system_service) | 477 if (!system_service) |
467 return; | 478 return; |
468 | 479 |
469 *list = GetDriveStatusList( | 480 *list = GetDriveStatusList( |
470 system_service->docs_service()->operation_registry()-> | 481 system_service->docs_service()->operation_registry()-> |
471 GetProgressStatusList()); | 482 GetProgressStatusList()); |
472 } | 483 } |
473 | 484 |
474 | 485 |
475 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, | 486 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 } | 729 } |
719 | 730 |
720 void SetProfile(Profile* profile) { | 731 void SetProfile(Profile* profile) { |
721 pref_registrar_.reset(new PrefChangeRegistrar); | 732 pref_registrar_.reset(new PrefChangeRegistrar); |
722 pref_registrar_->Init(profile->GetPrefs()); | 733 pref_registrar_->Init(profile->GetPrefs()); |
723 pref_registrar_->Add(prefs::kUse24HourClock, this); | 734 pref_registrar_->Add(prefs::kUse24HourClock, this); |
724 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); | 735 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); |
725 UpdateClockType(profile->GetPrefs()); | 736 UpdateClockType(profile->GetPrefs()); |
726 search_key_mapped_to_ = | 737 search_key_mapped_to_ = |
727 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 738 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
728 } | |
729 | 739 |
730 void ObserveGDataUpdates() { | 740 if (gdata::util::IsGDataAvailable(profile)) { |
731 GDataSystemService* system_service = FindGDataSystemService(); | 741 GDataSystemService* system_service = |
732 if (!system_service) | 742 GDataSystemServiceFactory::FindForProfile(profile); |
733 return; | 743 if (!system_service) |
| 744 return; |
734 | 745 |
735 system_service->docs_service()->operation_registry()->AddObserver(this); | 746 system_service->docs_service()->operation_registry()->AddObserver(this); |
| 747 } |
736 } | 748 } |
737 | 749 |
738 void UpdateClockType(PrefService* service) { | 750 void UpdateClockType(PrefService* service) { |
739 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? | 751 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? |
740 base::k24HourClock : base::k12HourClock; | 752 base::k24HourClock : base::k12HourClock; |
741 ash::ClockObserver* observer = tray_->clock_observer(); | 753 ash::ClockObserver* observer = tray_->clock_observer(); |
742 if (observer) | 754 if (observer) |
743 observer->OnDateFormatChanged(); | 755 observer->OnDateFormatChanged(); |
744 } | 756 } |
745 | 757 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { | 1032 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { |
1021 // This notification is also sent on login screen when user avatar | 1033 // This notification is also sent on login screen when user avatar |
1022 // is loaded from file. | 1034 // is loaded from file. |
1023 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { | 1035 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { |
1024 ash::UserObserver* observer = tray_->user_observer(); | 1036 ash::UserObserver* observer = tray_->user_observer(); |
1025 if (observer) | 1037 if (observer) |
1026 observer->OnUserUpdate(); | 1038 observer->OnUserUpdate(); |
1027 } | 1039 } |
1028 break; | 1040 break; |
1029 } | 1041 } |
1030 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | |
1031 // GData system service exists by the time if enabled. | |
1032 ObserveGDataUpdates(); | |
1033 break; | |
1034 } | |
1035 case chrome::NOTIFICATION_PREF_CHANGED: { | 1042 case chrome::NOTIFICATION_PREF_CHANGED: { |
1036 std::string pref = *content::Details<std::string>(details).ptr(); | 1043 std::string pref = *content::Details<std::string>(details).ptr(); |
1037 PrefService* service = content::Source<PrefService>(source).ptr(); | 1044 PrefService* service = content::Source<PrefService>(source).ptr(); |
1038 if (pref == prefs::kUse24HourClock) { | 1045 if (pref == prefs::kUse24HourClock) { |
1039 UpdateClockType(service); | 1046 UpdateClockType(service); |
1040 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { | 1047 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { |
1041 search_key_mapped_to_ = | 1048 search_key_mapped_to_ = |
1042 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 1049 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
1043 } else if (pref == prefs::kSpokenFeedbackEnabled) { | 1050 } else if (pref == prefs::kSpokenFeedbackEnabled) { |
1044 ash::AccessibilityObserver* observer = | 1051 ash::AccessibilityObserver* observer = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 } | 1123 } |
1117 } | 1124 } |
1118 | 1125 |
1119 } | 1126 } |
1120 | 1127 |
1121 // Pulls the list of ongoing drive operations and initiates status update. | 1128 // Pulls the list of ongoing drive operations and initiates status update. |
1122 // This method is needed to ensure delayed cleanup of the latest reported | 1129 // This method is needed to ensure delayed cleanup of the latest reported |
1123 // status in UI in cases when there are no new changes coming (i.e. when the | 1130 // status in UI in cases when there are no new changes coming (i.e. when the |
1124 // last set of transfer operations completed). | 1131 // last set of transfer operations completed). |
1125 void RecheckGDataOperations() { | 1132 void RecheckGDataOperations() { |
1126 GDataSystemService* system_service = FindGDataSystemService(); | 1133 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 1134 if (!gdata::util::IsGDataAvailable(profile)) |
| 1135 return; |
| 1136 |
| 1137 GDataSystemService* system_service = |
| 1138 GDataSystemServiceFactory::FindForProfile(profile); |
1127 if (!system_service) | 1139 if (!system_service) |
1128 return; | 1140 return; |
1129 | 1141 |
1130 OnProgressUpdate(system_service->docs_service()->operation_registry()-> | 1142 OnProgressUpdate(system_service->docs_service()->operation_registry()-> |
1131 GetProgressStatusList()); | 1143 GetProgressStatusList()); |
1132 } | 1144 } |
1133 | 1145 |
1134 GDataSystemService* FindGDataSystemService() { | |
1135 Profile* profile = ProfileManager::GetDefaultProfile(); | |
1136 if (!gdata::util::IsGDataAvailable(profile)) | |
1137 return NULL; | |
1138 return GDataSystemServiceFactory::FindForProfile(profile); | |
1139 } | |
1140 | |
1141 // Overridden from system::TimezoneSettings::Observer. | 1146 // Overridden from system::TimezoneSettings::Observer. |
1142 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { | 1147 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { |
1143 NotifyRefreshClock(); | 1148 NotifyRefreshClock(); |
1144 } | 1149 } |
1145 | 1150 |
1146 // Overridden from BluetoothAdapter::Observer. | 1151 // Overridden from BluetoothAdapter::Observer. |
1147 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | 1152 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, |
1148 bool present) OVERRIDE { | 1153 bool present) OVERRIDE { |
1149 NotifyRefreshBluetooth(); | 1154 NotifyRefreshBluetooth(); |
1150 } | 1155 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 1254 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
1250 }; | 1255 }; |
1251 | 1256 |
1252 } // namespace | 1257 } // namespace |
1253 | 1258 |
1254 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 1259 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
1255 return new chromeos::SystemTrayDelegate(tray); | 1260 return new chromeos::SystemTrayDelegate(tray); |
1256 } | 1261 } |
1257 | 1262 |
1258 } // namespace chromeos | 1263 } // namespace chromeos |
OLD | NEW |