Commit ec686dc0 authored by Pavel Beloborodov's avatar Pavel Beloborodov Committed by Commit Bot

Restore avatar after user logs out from sync.

BUG=863008

Change-Id: If083bc0703e251fb6e9c597fe5b7f842e37875c9

R=bauerb@chromium.org,sky@chromium.org

Change-Id: If083bc0703e251fb6e9c597fe5b7f842e37875c9
Reviewed-on: https://chromium-review.googlesource.com/1135137
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582541}
parent dbcb1e96
...@@ -164,6 +164,12 @@ void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) { ...@@ -164,6 +164,12 @@ void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) {
entry->SetGAIAPicture(nullptr); entry->SetGAIAPicture(nullptr);
// Unset the cached URL. // Unset the cached URL.
profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL); profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL);
if (profile_->GetPrefs()->GetInteger(prefs::kProfileLocalAvatarIndex) !=
-1) {
// Restore avatar from the local prefs.
entry->SetAvatarIconIndex(
profile_->GetPrefs()->GetInteger(prefs::kProfileLocalAvatarIndex));
}
} else { } else {
// Update the new user's GAIA info. // Update the new user's GAIA info.
Update(); Update();
......
...@@ -338,4 +338,27 @@ TEST_F(GAIAInfoUpdateServiceTest, LogIn) { ...@@ -338,4 +338,27 @@ TEST_F(GAIAInfoUpdateServiceTest, LogIn) {
"pat@example.com"); "pat@example.com");
} }
TEST_F(GAIAInfoUpdateServiceTest, RestoreAvatarIndexOnLogout) {
identity::SetPrimaryAccount(SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()),
"pat@example.com");
const size_t kLocalAvatarIndex = 10;
const size_t kRemoteAvatarIndex = 5;
profile()->GetPrefs()->SetInteger(prefs::kProfileLocalAvatarIndex,
kLocalAvatarIndex);
ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
ProfileAttributesEntry* entry = storage()->GetAllProfilesAttributes().front();
entry->SetAvatarIconIndex(kRemoteAvatarIndex);
EXPECT_EQ(kRemoteAvatarIndex, entry->GetAvatarIconIndex());
// Log out.
identity::ClearPrimaryAccount(
SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()));
EXPECT_EQ(kLocalAvatarIndex, entry->GetAvatarIconIndex());
}
#endif #endif
...@@ -396,6 +396,7 @@ void ProfileImpl::RegisterProfilePrefs( ...@@ -396,6 +396,7 @@ void ProfileImpl::RegisterProfilePrefs(
registry->RegisterStringPref(prefs::kProfileName, std::string(), registry->RegisterStringPref(prefs::kProfileName, std::string(),
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
#endif #endif
registry->RegisterIntegerPref(prefs::kProfileLocalAvatarIndex, -1);
registry->RegisterStringPref(prefs::kSupervisedUserId, std::string()); registry->RegisterStringPref(prefs::kSupervisedUserId, std::string());
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -1055,6 +1055,11 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) { ...@@ -1055,6 +1055,11 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex))
profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index);
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileLocalAvatarIndex)) {
profile->GetPrefs()->SetInteger(prefs::kProfileLocalAvatarIndex,
avatar_index);
}
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName))
profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); profile->GetPrefs()->SetString(prefs::kProfileName, profile_name);
......
...@@ -192,6 +192,7 @@ void ManageProfileHandler::HandleSetProfileIconToDefaultAvatar( ...@@ -192,6 +192,7 @@ void ManageProfileHandler::HandleSetProfileIconToDefaultAvatar(
PrefService* pref_service = profile_->GetPrefs(); PrefService* pref_service = profile_->GetPrefs();
pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index);
pref_service->SetInteger(prefs::kProfileLocalAvatarIndex, new_icon_index);
pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false);
pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false); pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false);
......
...@@ -1082,6 +1082,7 @@ const char kImportDialogSearchEngine[] = "import_dialog_search_engine"; ...@@ -1082,6 +1082,7 @@ const char kImportDialogSearchEngine[] = "import_dialog_search_engine";
// Profile avatar and name // Profile avatar and name
const char kProfileAvatarIndex[] = "profile.avatar_index"; const char kProfileAvatarIndex[] = "profile.avatar_index";
const char kProfileLocalAvatarIndex[] = "profile.local_avatar_index";
const char kProfileName[] = "profile.name"; const char kProfileName[] = "profile.name";
// Whether a profile is using a default avatar name (eg. Pickles or Person 1) // Whether a profile is using a default avatar name (eg. Pickles or Person 1)
// because it was randomly assigned at profile creation time. // because it was randomly assigned at profile creation time.
......
...@@ -360,6 +360,7 @@ extern const char kImportDialogSavedPasswords[]; ...@@ -360,6 +360,7 @@ extern const char kImportDialogSavedPasswords[];
extern const char kImportDialogSearchEngine[]; extern const char kImportDialogSearchEngine[];
extern const char kProfileAvatarIndex[]; extern const char kProfileAvatarIndex[];
extern const char kProfileLocalAvatarIndex[];
extern const char kProfileUsingDefaultName[]; extern const char kProfileUsingDefaultName[];
extern const char kProfileName[]; extern const char kProfileName[];
extern const char kProfileUsingDefaultAvatar[]; extern const char kProfileUsingDefaultAvatar[];
......
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