#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"
// 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_)
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());
}
}
+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;
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());
+}