Index: chrome/browser/profiles/gaia_info_update_service.cc |
diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc |
index 9585110d5637372a89b3ccf6ab795facf100178b..d953cf211acd06bcd1ba2dd93900c11e41d8cf44 100644 |
--- a/chrome/browser/profiles/gaia_info_update_service.cc |
+++ b/chrome/browser/profiles/gaia_info_update_service.cc |
@@ -10,6 +10,7 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
#include "chrome/browser/sync/profile_sync_service.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/profile_management_switches.h" |
@@ -30,24 +31,25 @@ const int kMinUpdateIntervalSeconds = 5; |
GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile) |
: profile_(profile) { |
- PrefService* prefs = profile_->GetPrefs(); |
- username_pref_.Init(prefs::kGoogleServicesUsername, prefs, |
- base::Bind(&GAIAInfoUpdateService::OnUsernameChanged, |
- base::Unretained(this))); |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(profile_); |
+ signin_manager->AddObserver(this); |
+ PrefService* prefs = profile_->GetPrefs(); |
last_updated_ = base::Time::FromInternalValue( |
prefs->GetInt64(prefs::kProfileGAIAInfoUpdateTime)); |
ScheduleNextUpdate(); |
} |
GAIAInfoUpdateService::~GAIAInfoUpdateService() { |
+ DCHECK(!profile_) << "Shutdown not called before dtor"; |
} |
void GAIAInfoUpdateService::Update() { |
// The user must be logged in. |
- std::string username = profile_->GetPrefs()->GetString( |
- prefs::kGoogleServicesUsername); |
- if (username.empty()) |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(profile_); |
+ if (signin_manager->GetAuthenticatedAccountId().empty()) |
return; |
if (profile_image_downloader_) |
@@ -151,15 +153,13 @@ void GAIAInfoUpdateService::OnProfileDownloadFailure( |
ScheduleNextUpdate(); |
} |
-void GAIAInfoUpdateService::OnUsernameChanged() { |
+void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) { |
ProfileInfoCache& cache = |
g_browser_process->profile_manager()->GetProfileInfoCache(); |
size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
if (profile_index == std::string::npos) |
return; |
- std::string username = profile_->GetPrefs()->GetString( |
- prefs::kGoogleServicesUsername); |
if (username.empty()) { |
// Unset the old user's GAIA info. |
cache.SetGAIANameOfProfileAtIndex(profile_index, base::string16()); |
@@ -176,6 +176,14 @@ void GAIAInfoUpdateService::OnUsernameChanged() { |
} |
} |
+void GAIAInfoUpdateService::Shutdown() { |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(profile_); |
+ profile_image_downloader_.reset(); |
+ signin_manager->RemoveObserver(this); |
+ profile_ = NULL; |
noms (inactive)
2014/03/24 13:35:25
Can you maybe add a comment as yo why it's ok to n
Roger Tawa OOO till Jul 10th
2014/03/24 17:49:30
Done.
|
+} |
+ |
void GAIAInfoUpdateService::ScheduleNextUpdate() { |
if (timer_.IsRunning()) |
return; |
@@ -192,3 +200,13 @@ void GAIAInfoUpdateService::ScheduleNextUpdate() { |
timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); |
} |
+ |
+void GAIAInfoUpdateService::GoogleSigninSucceeded( |
+ const std::string& username, |
+ const std::string& password) { |
+ OnUsernameChanged(username); |
+} |
+ |
+void GAIAInfoUpdateService::GoogleSignedOut(const std::string& username) { |
+ OnUsernameChanged(std::string()); |
+} |