Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/chromeos/system/ash_system_tray_delegate.cc

Issue 10854160: Fixing gdata updates in the system tray. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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());
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 GDataSystemService* system_service = FindGDataSystemService();
241 if (gdata::util::IsGDataAvailable(profile)) { 244 if (system_service) {
242 GDataSystemService* system_service = 245 system_service->docs_service()->operation_registry()->
243 GDataSystemServiceFactory::FindForProfile(profile); 246 RemoveObserver(this);
244 if (system_service) {
245 system_service->docs_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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { 443 virtual void SwitchIME(const std::string& ime_id) OVERRIDE {
445 input_method::InputMethodManager::GetInstance()->ChangeInputMethod(ime_id); 444 input_method::InputMethodManager::GetInstance()->ChangeInputMethod(ime_id);
446 } 445 }
447 446
448 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { 447 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE {
449 input_method::InputMethodManager::GetInstance()-> 448 input_method::InputMethodManager::GetInstance()->
450 ActivateInputMethodProperty(key); 449 ActivateInputMethodProperty(key);
451 } 450 }
452 451
453 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { 452 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE {
454 Profile* profile = ProfileManager::GetDefaultProfile(); 453 GDataSystemService* system_service = FindGDataSystemService();
455 if (!gdata::util::IsGDataAvailable(profile))
456 return;
457
458 GDataSystemService* system_service =
459 GDataSystemServiceFactory::FindForProfile(profile);
460 if (!system_service) 454 if (!system_service)
461 return; 455 return;
462 456
463 system_service->docs_service()->operation_registry()->CancelForFilePath( 457 system_service->docs_service()->operation_registry()->CancelForFilePath(
464 file_path); 458 file_path);
465 } 459 }
466 460
467 virtual void GetDriveOperationStatusList( 461 virtual void GetDriveOperationStatusList(
468 ash::DriveOperationStatusList* list) OVERRIDE { 462 ash::DriveOperationStatusList* list) OVERRIDE {
469 Profile* profile = ProfileManager::GetDefaultProfile(); 463 GDataSystemService* system_service = FindGDataSystemService();
470 if (!gdata::util::IsGDataAvailable(profile))
471 return;
472
473 GDataSystemService* system_service =
474 GDataSystemServiceFactory::FindForProfile(profile);
475 if (!system_service) 464 if (!system_service)
476 return; 465 return;
477 466
478 *list = GetDriveStatusList( 467 *list = GetDriveStatusList(
479 system_service->docs_service()->operation_registry()-> 468 system_service->docs_service()->operation_registry()->
480 GetProgressStatusList()); 469 GetProgressStatusList());
481 } 470 }
482 471
483 472
484 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, 473 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 } 716 }
728 717
729 void SetProfile(Profile* profile) { 718 void SetProfile(Profile* profile) {
730 pref_registrar_.reset(new PrefChangeRegistrar); 719 pref_registrar_.reset(new PrefChangeRegistrar);
731 pref_registrar_->Init(profile->GetPrefs()); 720 pref_registrar_->Init(profile->GetPrefs());
732 pref_registrar_->Add(prefs::kUse24HourClock, this); 721 pref_registrar_->Add(prefs::kUse24HourClock, this);
733 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this); 722 pref_registrar_->Add(prefs::kLanguageXkbRemapSearchKeyTo, this);
734 UpdateClockType(profile->GetPrefs()); 723 UpdateClockType(profile->GetPrefs());
735 search_key_mapped_to_ = 724 search_key_mapped_to_ =
736 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); 725 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo);
726 }
737 727
738 if (gdata::util::IsGDataAvailable(profile)) { 728 void ObserveGDataUpdates() {
739 GDataSystemService* system_service = 729 GDataSystemService* system_service = FindGDataSystemService();
740 GDataSystemServiceFactory::FindForProfile(profile); 730 if (!system_service)
741 if (!system_service) 731 return;
742 return;
743 732
744 system_service->docs_service()->operation_registry()->AddObserver(this); 733 system_service->docs_service()->operation_registry()->AddObserver(this);
745 }
746 } 734 }
747 735
748 void UpdateClockType(PrefService* service) { 736 void UpdateClockType(PrefService* service) {
749 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? 737 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ?
750 base::k24HourClock : base::k12HourClock; 738 base::k24HourClock : base::k12HourClock;
751 ash::ClockObserver* observer = tray_->clock_observer(); 739 ash::ClockObserver* observer = tray_->clock_observer();
752 if (observer) 740 if (observer)
753 observer->OnDateFormatChanged(); 741 observer->OnDateFormatChanged();
754 } 742 }
755 743
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { 1018 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
1031 // This notification is also sent on login screen when user avatar 1019 // This notification is also sent on login screen when user avatar
1032 // is loaded from file. 1020 // is loaded from file.
1033 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) { 1021 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) {
1034 ash::UserObserver* observer = tray_->user_observer(); 1022 ash::UserObserver* observer = tray_->user_observer();
1035 if (observer) 1023 if (observer)
1036 observer->OnUserUpdate(); 1024 observer->OnUserUpdate();
1037 } 1025 }
1038 break; 1026 break;
1039 } 1027 }
1028 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
1029 // GData system service exists by the time if enabled.
1030 ObserveGDataUpdates();
1031 break;
1032 }
1040 case chrome::NOTIFICATION_PREF_CHANGED: { 1033 case chrome::NOTIFICATION_PREF_CHANGED: {
1041 std::string pref = *content::Details<std::string>(details).ptr(); 1034 std::string pref = *content::Details<std::string>(details).ptr();
1042 PrefService* service = content::Source<PrefService>(source).ptr(); 1035 PrefService* service = content::Source<PrefService>(source).ptr();
1043 if (pref == prefs::kUse24HourClock) { 1036 if (pref == prefs::kUse24HourClock) {
1044 UpdateClockType(service); 1037 UpdateClockType(service);
1045 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) { 1038 } else if (pref == prefs::kLanguageXkbRemapSearchKeyTo) {
1046 search_key_mapped_to_ = 1039 search_key_mapped_to_ =
1047 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); 1040 service->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo);
1048 } else if (pref == prefs::kSpokenFeedbackEnabled) { 1041 } else if (pref == prefs::kSpokenFeedbackEnabled) {
1049 ash::AccessibilityObserver* observer = 1042 ash::AccessibilityObserver* observer =
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 } 1114 }
1122 } 1115 }
1123 1116
1124 } 1117 }
1125 1118
1126 // Pulls the list of ongoing drive operations and initiates status update. 1119 // Pulls the list of ongoing drive operations and initiates status update.
1127 // This method is needed to ensure delayed cleanup of the latest reported 1120 // This method is needed to ensure delayed cleanup of the latest reported
1128 // status in UI in cases when there are no new changes coming (i.e. when the 1121 // status in UI in cases when there are no new changes coming (i.e. when the
1129 // last set of transfer operations completed). 1122 // last set of transfer operations completed).
1130 void RecheckGDataOperations() { 1123 void RecheckGDataOperations() {
1131 Profile* profile = ProfileManager::GetDefaultProfile(); 1124 GDataSystemService* system_service = FindGDataSystemService();
1132 if (!gdata::util::IsGDataAvailable(profile))
1133 return;
1134
1135 GDataSystemService* system_service =
1136 GDataSystemServiceFactory::FindForProfile(profile);
1137 if (!system_service) 1125 if (!system_service)
1138 return; 1126 return;
1139 1127
1140 OnProgressUpdate(system_service->docs_service()->operation_registry()-> 1128 OnProgressUpdate(system_service->docs_service()->operation_registry()->
1141 GetProgressStatusList()); 1129 GetProgressStatusList());
1142 } 1130 }
1143 1131
1132 GDataSystemService* FindGDataSystemService() {
1133 Profile* profile = ProfileManager::GetDefaultProfile();
1134 if (!gdata::util::IsGDataAvailable(profile))
1135 return NULL;
1136 return GDataSystemServiceFactory::FindForProfile(profile);
1137 }
1138
1144 // Overridden from system::TimezoneSettings::Observer. 1139 // Overridden from system::TimezoneSettings::Observer.
1145 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { 1140 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE {
1146 NotifyRefreshClock(); 1141 NotifyRefreshClock();
1147 } 1142 }
1148 1143
1149 // Overridden from BluetoothAdapter::Observer. 1144 // Overridden from BluetoothAdapter::Observer.
1150 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, 1145 virtual void AdapterPresentChanged(BluetoothAdapter* adapter,
1151 bool present) OVERRIDE { 1146 bool present) OVERRIDE {
1152 NotifyRefreshBluetooth(); 1147 NotifyRefreshBluetooth();
1153 } 1148 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); 1247 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate);
1253 }; 1248 };
1254 1249
1255 } // namespace 1250 } // namespace
1256 1251
1257 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { 1252 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) {
1258 return new chromeos::SystemTrayDelegate(tray); 1253 return new chromeos::SystemTrayDelegate(tray);
1259 } 1254 }
1260 1255
1261 } // namespace chromeos 1256 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698