Commit 3871928e authored by tbarzic@chromium.org's avatar tbarzic@chromium.org

Fixing gdata updates in the system tray.

BUG=141826
TEST=Manual test, suite: smoke on amd64-generic vm

original (by serya)
https://chromiumcodereview.appspot.com/10854160

the original cl was reverted for busting cros_amd64

the problem was we were calling GetDefaultProfile on 
NOTIFICATION_LOGIN_USER_CHANGED which is before default profile is 
registerred, so we ended up synchronously creating profile while
NOTIFICATION_LOGIN_USER_CHANGED was dispatched.

Review URL: https://chromiumcodereview.appspot.com/10919233

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156429 0039d316-1c4b-4281-b951-d872f2087c98
parent 72e1eb94
...@@ -208,6 +208,9 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -208,6 +208,9 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
registrar_.Add(this, registrar_.Add(this,
chrome::NOTIFICATION_PROFILE_CREATED, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled,
g_browser_process->local_state(), this); g_browser_process->local_state(), this);
...@@ -237,14 +240,10 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -237,14 +240,10 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
bluetooth_adapter_->RemoveObserver(this); bluetooth_adapter_->RemoveObserver(this);
// Stop observing gdata operations. // Stop observing gdata operations.
Profile* profile = ProfileManager::GetDefaultProfile(); DriveSystemService* system_service = FindDriveSystemService();
if (gdata::util::IsGDataAvailable(profile)) { if (system_service) {
DriveSystemService* system_service = system_service->drive_service()->operation_registry()->
DriveSystemServiceFactory::FindForProfile(profile); RemoveObserver(this);
if (system_service) {
system_service->drive_service()->operation_registry()->
RemoveObserver(this);
}
} }
} }
...@@ -446,12 +445,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -446,12 +445,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
} }
virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE {
Profile* profile = ProfileManager::GetDefaultProfile(); DriveSystemService* system_service = FindDriveSystemService();
if (!gdata::util::IsGDataAvailable(profile))
return;
DriveSystemService* system_service =
DriveSystemServiceFactory::FindForProfile(profile);
if (!system_service) if (!system_service)
return; return;
...@@ -461,12 +455,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -461,12 +455,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
virtual void GetDriveOperationStatusList( virtual void GetDriveOperationStatusList(
ash::DriveOperationStatusList* list) OVERRIDE { ash::DriveOperationStatusList* list) OVERRIDE {
Profile* profile = ProfileManager::GetDefaultProfile(); DriveSystemService* system_service = FindDriveSystemService();
if (!gdata::util::IsGDataAvailable(profile))
return;
DriveSystemService* system_service =
DriveSystemServiceFactory::FindForProfile(profile);
if (!system_service) if (!system_service)
return; return;
...@@ -729,15 +718,14 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -729,15 +718,14 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
UpdateClockType(profile->GetPrefs()); UpdateClockType(profile->GetPrefs());
search_key_mapped_to_ = search_key_mapped_to_ =
profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo);
}
if (gdata::util::IsGDataAvailable(profile)) { void ObserveGDataUpdates() {
DriveSystemService* system_service = DriveSystemService* system_service = FindDriveSystemService();
DriveSystemServiceFactory::FindForProfile(profile); if (!system_service)
if (!system_service) return;
return;
system_service->drive_service()->operation_registry()->AddObserver(this); system_service->drive_service()->operation_registry()->AddObserver(this);
}
} }
void UpdateClockType(PrefService* service) { void UpdateClockType(PrefService* service) {
...@@ -1054,6 +1042,11 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -1054,6 +1042,11 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
} }
break; break;
} }
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
// GData system service exists by the time if enabled.
ObserveGDataUpdates();
break;
}
case chrome::NOTIFICATION_PREF_CHANGED: { case chrome::NOTIFICATION_PREF_CHANGED: {
std::string pref = *content::Details<std::string>(details).ptr(); std::string pref = *content::Details<std::string>(details).ptr();
PrefService* service = content::Source<PrefService>(source).ptr(); PrefService* service = content::Source<PrefService>(source).ptr();
...@@ -1145,12 +1138,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -1145,12 +1138,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
// status in UI in cases when there are no new changes coming (i.e. when the // status in UI in cases when there are no new changes coming (i.e. when the
// last set of transfer operations completed). // last set of transfer operations completed).
void RecheckGDataOperations() { void RecheckGDataOperations() {
Profile* profile = ProfileManager::GetDefaultProfile(); DriveSystemService* system_service = FindDriveSystemService();
if (!gdata::util::IsGDataAvailable(profile))
return;
DriveSystemService* system_service =
DriveSystemServiceFactory::FindForProfile(profile);
if (!system_service) if (!system_service)
return; return;
...@@ -1158,6 +1146,13 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -1158,6 +1146,13 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
GetProgressStatusList()); GetProgressStatusList());
} }
DriveSystemService* FindDriveSystemService() {
Profile* profile = ProfileManager::GetDefaultProfile();
if (!gdata::util::IsGDataAvailable(profile))
return NULL;
return DriveSystemServiceFactory::FindForProfile(profile);
}
// Overridden from system::TimezoneSettings::Observer. // Overridden from system::TimezoneSettings::Observer.
virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE {
NotifyRefreshClock(); NotifyRefreshClock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment