| 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..31d489bf16c25b57ba72d1da110a2bac3aa8b3df 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,19 @@ void GAIAInfoUpdateService::OnUsernameChanged() {
|
| }
|
| }
|
|
|
| +void GAIAInfoUpdateService::Shutdown() {
|
| + timer_.Stop();
|
| + profile_image_downloader_.reset();
|
| + SigninManagerBase* signin_manager =
|
| + SigninManagerFactory::GetForProfile(profile_);
|
| + signin_manager->RemoveObserver(this);
|
| +
|
| + // OK to reset |profile_| pointer here because GAIAInfoUpdateService will not
|
| + // access it again. This pointer is also used to implement the delegate for
|
| + // |profile_image_downloader_|. However that object was destroyed above.
|
| + profile_ = NULL;
|
| +}
|
| +
|
| void GAIAInfoUpdateService::ScheduleNextUpdate() {
|
| if (timer_.IsRunning())
|
| return;
|
| @@ -192,3 +205,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());
|
| +}
|
|
|