X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fprofiles%2Fgaia_info_update_service.cc;h=b7fd973769a81b5249d9c93210a80d701145aae8;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=9585110d5637372a89b3ccf6ab795facf100178b;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/profiles/gaia_info_update_service.cc b/src/chrome/browser/profiles/gaia_info_update_service.cc index 9585110..b7fd973 100644 --- a/src/chrome/browser/profiles/gaia_info_update_service.cc +++ b/src/chrome/browser/profiles/gaia_info_update_service.cc @@ -10,9 +10,10 @@ #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" +#include "components/signin/core/common/profile_management_switches.h" #include "content/public/browser/notification_details.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/image/image.h" @@ -26,28 +27,29 @@ const int kUpdateIntervalHours = 24; // before starting an update. This avoids slowdown during startup. const int kMinUpdateIntervalSeconds = 5; -} // namespace +} // namespace 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()); +}