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_PROFILE_PREPARED, |
| 213 content::NotificationService::AllSources()); |
211 | 214 |
212 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, | 215 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, |
213 g_browser_process->local_state(), this); | 216 g_browser_process->local_state(), this); |
214 | 217 |
215 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); | 218 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); |
216 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); | 219 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); |
217 | 220 |
218 bluetooth_adapter_ = BluetoothAdapter::DefaultAdapter(); | 221 bluetooth_adapter_ = BluetoothAdapter::DefaultAdapter(); |
219 bluetooth_adapter_->AddObserver(this); | 222 bluetooth_adapter_->AddObserver(this); |
220 } | 223 } |
221 | 224 |
222 virtual ~SystemTrayDelegate() { | 225 virtual ~SystemTrayDelegate() { |
223 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 226 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
224 if (audiohandler) | 227 if (audiohandler) |
225 audiohandler->RemoveVolumeObserver(this); | 228 audiohandler->RemoveVolumeObserver(this); |
226 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); | 229 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); |
227 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 230 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
228 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 231 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
229 if (crosnet) { | 232 if (crosnet) { |
230 crosnet->RemoveNetworkManagerObserver(this); | 233 crosnet->RemoveNetworkManagerObserver(this); |
231 crosnet->RemoveCellularDataPlanObserver(this); | 234 crosnet->RemoveCellularDataPlanObserver(this); |
232 } | 235 } |
233 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); | 236 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); |
234 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 237 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
235 if (SystemKeyEventListener::GetInstance()) | 238 if (SystemKeyEventListener::GetInstance()) |
236 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); | 239 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); |
237 bluetooth_adapter_->RemoveObserver(this); | 240 bluetooth_adapter_->RemoveObserver(this); |
238 | 241 |
239 // Stop observing gdata operations. | 242 // Stop observing gdata operations. |
240 Profile* profile = ProfileManager::GetDefaultProfile(); | 243 DriveSystemService* system_service = FindDriveSystemService(); |
241 if (gdata::util::IsGDataAvailable(profile)) { | 244 if (system_service) { |
242 DriveSystemService* system_service = | 245 system_service->drive_service()->operation_registry()-> |
243 DriveSystemServiceFactory::FindForProfile(profile); | 246 RemoveObserver(this); |
244 if (system_service) { | |
245 system_service->drive_service()->operation_registry()-> | |
246 RemoveObserver(this); | |
247 } | |
248 } | 247 } |
249 } | 248 } |
250 | 249 |
251 // Overridden from ash::SystemTrayDelegate: | 250 // Overridden from ash::SystemTrayDelegate: |
252 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { | 251 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { |
253 // In case of OOBE / sign in screen tray will be shown later. | 252 // In case of OOBE / sign in screen tray will be shown later. |
254 return UserManager::Get()->IsUserLoggedIn(); | 253 return UserManager::Get()->IsUserLoggedIn(); |
255 } | 254 } |
256 | 255 |
257 virtual const string16 GetUserDisplayName() const OVERRIDE { | 256 virtual const string16 GetUserDisplayName() const OVERRIDE { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { | 433 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { |
435 input_method::InputMethodManager::GetInstance()->ChangeInputMethod(ime_id); | 434 input_method::InputMethodManager::GetInstance()->ChangeInputMethod(ime_id); |
436 } | 435 } |
437 | 436 |
438 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { | 437 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { |
439 input_method::InputMethodManager::GetInstance()-> | 438 input_method::InputMethodManager::GetInstance()-> |
440 ActivateInputMethodProperty(key); | 439 ActivateInputMethodProperty(key); |
441 } | 440 } |
442 | 441 |
443 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { | 442 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { |
444 Profile* profile = ProfileManager::GetDefaultProfile(); | 443 DriveSystemService* system_service = FindDriveSystemService(); |
445 if (!gdata::util::IsGDataAvailable(profile)) | |
446 return; | |
447 | |
448 DriveSystemService* system_service = | |
449 DriveSystemServiceFactory::FindForProfile(profile); | |
450 if (!system_service) | 444 if (!system_service) |
451 return; | 445 return; |
452 | 446 |
453 system_service->drive_service()->operation_registry()->CancelForFilePath( | 447 system_service->drive_service()->operation_registry()->CancelForFilePath( |
454 file_path); | 448 file_path); |
455 } | 449 } |
456 | 450 |
457 virtual void GetDriveOperationStatusList( | 451 virtual void GetDriveOperationStatusList( |
458 ash::DriveOperationStatusList* list) OVERRIDE { | 452 ash::DriveOperationStatusList* list) OVERRIDE { |
459 Profile* profile = ProfileManager::GetDefaultProfile(); | 453 DriveSystemService* system_service = FindDriveSystemService(); |
460 if (!gdata::util::IsGDataAvailable(profile)) | |
461 return; | |
462 | |
463 DriveSystemService* system_service = | |
464 DriveSystemServiceFactory::FindForProfile(profile); | |
465 if (!system_service) | 454 if (!system_service) |
466 return; | 455 return; |
467 | 456 |
468 *list = GetDriveStatusList( | 457 *list = GetDriveStatusList( |
469 system_service->drive_service()->operation_registry()-> | 458 system_service->drive_service()->operation_registry()-> |
470 GetProgressStatusList()); | 459 GetProgressStatusList()); |
471 } | 460 } |
472 | 461 |
473 | 462 |
474 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, | 463 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 } | 706 } |
718 | 707 |
719 void SetProfile(Profile* profile) { | 708 void SetProfile(Profile* profile) { |
720 pref_registrar_.reset(new PrefChangeRegistrar); | 709 pref_registrar_.reset(new PrefChangeRegistrar); |
721 pref_registrar_->Init(profile->GetPrefs()); | 710 pref_registrar_->Init(profile->GetPrefs()); |
722 pref_registrar_->Add(prefs::kUse24HourClock, this); | 711 pref_registrar_->Add(prefs::kUse24HourClock, this); |
723 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); | 712 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); |
724 UpdateClockType(profile->GetPrefs()); | 713 UpdateClockType(profile->GetPrefs()); |
725 search_key_mapped_to_ = | 714 search_key_mapped_to_ = |
726 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 715 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
| 716 } |
727 | 717 |
728 if (gdata::util::IsGDataAvailable(profile)) { | 718 void ObserveGDataUpdates() { |
729 DriveSystemService* system_service = | 719 DriveSystemService* system_service = FindDriveSystemService(); |
730 DriveSystemServiceFactory::FindForProfile(profile); | 720 if (!system_service) |
731 if (!system_service) | 721 return; |
732 return; | |
733 | 722 |
734 system_service->drive_service()->operation_registry()->AddObserver(this); | 723 system_service->drive_service()->operation_registry()->AddObserver(this); |
735 } | |
736 } | 724 } |
737 | 725 |
738 void UpdateClockType(PrefService* service) { | 726 void UpdateClockType(PrefService* service) { |
739 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? | 727 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? |
740 base::k24HourClock : base::k12HourClock; | 728 base::k24HourClock : base::k12HourClock; |
741 ash::ClockObserver* observer = tray_->clock_observer(); | 729 ash::ClockObserver* observer = tray_->clock_observer(); |
742 if (observer) | 730 if (observer) |
743 observer->OnDateFormatChanged(); | 731 observer->OnDateFormatChanged(); |
744 } | 732 } |
745 | 733 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { | 1008 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { |
1021 // This notification is also sent on login screen when user avatar | 1009 // This notification is also sent on login screen when user avatar |
1022 // is loaded from file. | 1010 // is loaded from file. |
1023 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { | 1011 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { |
1024 ash::UserObserver* observer = tray_->user_observer(); | 1012 ash::UserObserver* observer = tray_->user_observer(); |
1025 if (observer) | 1013 if (observer) |
1026 observer->OnUserUpdate(); | 1014 observer->OnUserUpdate(); |
1027 } | 1015 } |
1028 break; | 1016 break; |
1029 } | 1017 } |
| 1018 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: { |
| 1019 // GData system service exists by the time if enabled. |
| 1020 ObserveGDataUpdates(); |
| 1021 break; |
| 1022 } |
1030 case chrome::NOTIFICATION_PREF_CHANGED: { | 1023 case chrome::NOTIFICATION_PREF_CHANGED: { |
1031 std::string pref = *content::Details<std::string>(details).ptr(); | 1024 std::string pref = *content::Details<std::string>(details).ptr(); |
1032 PrefService* service = content::Source<PrefService>(source).ptr(); | 1025 PrefService* service = content::Source<PrefService>(source).ptr(); |
1033 if (pref == prefs::kUse24HourClock) { | 1026 if (pref == prefs::kUse24HourClock) { |
1034 UpdateClockType(service); | 1027 UpdateClockType(service); |
1035 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { | 1028 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { |
1036 search_key_mapped_to_ = | 1029 search_key_mapped_to_ = |
1037 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 1030 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
1038 } else if (pref == prefs::kSpokenFeedbackEnabled) { | 1031 } else if (pref == prefs::kSpokenFeedbackEnabled) { |
1039 ash::AccessibilityObserver* observer = | 1032 ash::AccessibilityObserver* observer = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 } | 1104 } |
1112 } | 1105 } |
1113 | 1106 |
1114 } | 1107 } |
1115 | 1108 |
1116 // Pulls the list of ongoing drive operations and initiates status update. | 1109 // Pulls the list of ongoing drive operations and initiates status update. |
1117 // This method is needed to ensure delayed cleanup of the latest reported | 1110 // This method is needed to ensure delayed cleanup of the latest reported |
1118 // status in UI in cases when there are no new changes coming (i.e. when the | 1111 // status in UI in cases when there are no new changes coming (i.e. when the |
1119 // last set of transfer operations completed). | 1112 // last set of transfer operations completed). |
1120 void RecheckGDataOperations() { | 1113 void RecheckGDataOperations() { |
1121 Profile* profile = ProfileManager::GetDefaultProfile(); | 1114 DriveSystemService* system_service = FindDriveSystemService(); |
1122 if (!gdata::util::IsGDataAvailable(profile)) | |
1123 return; | |
1124 | |
1125 DriveSystemService* system_service = | |
1126 DriveSystemServiceFactory::FindForProfile(profile); | |
1127 if (!system_service) | 1115 if (!system_service) |
1128 return; | 1116 return; |
1129 | 1117 |
1130 OnProgressUpdate(system_service->drive_service()->operation_registry()-> | 1118 OnProgressUpdate(system_service->drive_service()->operation_registry()-> |
1131 GetProgressStatusList()); | 1119 GetProgressStatusList()); |
1132 } | 1120 } |
1133 | 1121 |
| 1122 DriveSystemService* FindDriveSystemService() { |
| 1123 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 1124 if (!gdata::util::IsGDataAvailable(profile)) |
| 1125 return NULL; |
| 1126 return DriveSystemServiceFactory::FindForProfile(profile); |
| 1127 } |
| 1128 |
1134 // Overridden from system::TimezoneSettings::Observer. | 1129 // Overridden from system::TimezoneSettings::Observer. |
1135 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { | 1130 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { |
1136 NotifyRefreshClock(); | 1131 NotifyRefreshClock(); |
1137 } | 1132 } |
1138 | 1133 |
1139 // Overridden from BluetoothAdapter::Observer. | 1134 // Overridden from BluetoothAdapter::Observer. |
1140 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | 1135 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, |
1141 bool present) OVERRIDE { | 1136 bool present) OVERRIDE { |
1142 NotifyRefreshBluetooth(); | 1137 NotifyRefreshBluetooth(); |
1143 } | 1138 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 1237 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
1243 }; | 1238 }; |
1244 | 1239 |
1245 } // namespace | 1240 } // namespace |
1246 | 1241 |
1247 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 1242 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
1248 return new chromeos::SystemTrayDelegate(tray); | 1243 return new chromeos::SystemTrayDelegate(tray); |
1249 } | 1244 } |
1250 | 1245 |
1251 } // namespace chromeos | 1246 } // namespace chromeos |
OLD | NEW |