summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornoms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-25 05:59:39 +0000
committernoms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-25 05:59:39 +0000
commit425d6ab548e2c0225fbcee1ec79784fafc91186b (patch)
tree19a5c31f854bb65ce220a46dbd12ecf7139ab869
parent1d96e0315b34e2d0668f71ae01f0d3382710df8a (diff)
downloadchromium_src-425d6ab548e2c0225fbcee1ec79784fafc91186b.zip
chromium_src-425d6ab548e2c0225fbcee1ec79784fafc91186b.tar.gz
chromium_src-425d6ab548e2c0225fbcee1ec79784fafc91186b.tar.bz2
[Profiles] Don't treat GAIA names differently than regular profile names.
This also half-enables the ability to use the Gaia profile pictures as the profile avatar on the main truck if you had previously used the --new-profile-management or --gaia-profile-info flags before. (Because the chrome://settings doesn't enable setting it outside the flag). There was special, ancient logic that treated profiles using a Gaia names as "special", which didn't mix well with syncing of the profile name. Basically, you could either use a synced profile name, or a Gaia name, but not both (i.e. download the synced name and then be able to rename the profile back to its Gaia name). I think this fixes it. and shouldn't really break a lot of other things, as the two functions that I've deleted weren't really used anywhere. BUG=352090 TEST=Be able to rename a local profile. Be able to sign in to a profile, and if this is the first time you're doing it, the profile name should be the user's Gaia first name. Be able to rename this profile to a custom name, and back to the Gaia name. Finally, if you're signing in with this account on a different profile, the name that you last left off should be the one that is synced/used. Review URL: https://codereview.chromium.org/196473015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259161 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/profiles/gaia_info_update_service.cc20
-rw-r--r--chrome/browser/profiles/gaia_info_update_service_unittest.cc35
-rw-r--r--chrome/browser/profiles/profile_info_cache.cc50
-rw-r--r--chrome/browser/profiles/profile_info_cache.h12
-rw-r--r--chrome/browser/profiles/profile_info_cache_unittest.cc49
-rw-r--r--chrome/browser/profiles/profile_info_interface.h3
-rw-r--r--chrome/browser/profiles/profiles_state.cc31
7 files changed, 19 insertions, 181 deletions
diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc
index 9733fe4..9585110 100644
--- a/chrome/browser/profiles/gaia_info_update_service.cc
+++ b/chrome/browser/profiles/gaia_info_update_service.cc
@@ -131,20 +131,12 @@ void GAIAInfoUpdateService::OnProfileDownloadSuccess(
cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL);
}
- // If this profile hasn't switched to using GAIA information for the profile
- // name and picture then switch it now. Once the profile has switched this
- // preference guards against clobbering the user's custom settings.
- if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) {
- cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true);
- // Order matters here for shortcut management, like in
- // ProfileShortcutManagerWin::OnProfileAdded, as the picture update does not
- // allow us to change the target, so we have to apply any renaming first. We
- // also need to re-fetch the index, as SetIsUsingGAIANameOfProfileAtIndex
- // may alter it.
- cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true);
- profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
- cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true);
- }
+ // Order matters here for shortcut management, like in
+ // ProfileShortcutManagerWin::OnProfileAdded, as the picture update does not
+ // allow us to change the target, so we have to apply any renaming first. We
+ // also need to re-fetch the index, as changing the profile name may alter it.
+ profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
+ cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true);
}
void GAIAInfoUpdateService::OnProfileDownloadFailure(
diff --git a/chrome/browser/profiles/gaia_info_update_service_unittest.cc b/chrome/browser/profiles/gaia_info_update_service_unittest.cc
index 5aa1d7e..1eacf5b 100644
--- a/chrome/browser/profiles/gaia_info_update_service_unittest.cc
+++ b/chrome/browser/profiles/gaia_info_update_service_unittest.cc
@@ -95,8 +95,6 @@ TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) {
// On success both the profile info and GAIA info should be updated.
size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
- EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index));
- EXPECT_TRUE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index));
EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index));
EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index));
EXPECT_TRUE(gfx::test::IsEqual(
@@ -119,7 +117,6 @@ TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) {
ProfileDownloaderDelegate::SERVICE_ERROR);
// On failure nothing should be updated.
- EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index));
EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index));
EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index));
EXPECT_TRUE(gfx::test::IsEqual(
@@ -128,38 +125,6 @@ TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) {
EXPECT_EQ(std::string(), service.GetCachedPictureURL());
}
-TEST_F(GAIAInfoUpdateServiceTest, NoMigration) {
- size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
- base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index);
- gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index);
-
- // Mark the profile as migrated.
- GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(index, true);
-
- GAIAInfoUpdateService service(profile());
- NiceMock<ProfileDownloaderMock> downloader(&service);
- base::string16 new_name = base::ASCIIToUTF16("Pat Smith");
- EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(new_name));
- gfx::Image new_image = gfx::test::CreateImage();
- const SkBitmap* new_bmp = new_image.ToSkBitmap();
- EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*new_bmp));
- EXPECT_CALL(downloader, GetProfilePictureStatus()).
- WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS));
- EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(""));
-
- service.OnProfileDownloadSuccess(&downloader);
-
- // On success with no migration the profile info should not be updated but
- // the GAIA info should be updated.
- EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index));
- EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index));
- EXPECT_EQ(new_name, GetCache()->GetGAIANameOfProfileAtIndex(index));
- EXPECT_TRUE(gfx::test::IsEqual(
- old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index)));
- EXPECT_TRUE(gfx::test::IsEqual(
- new_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index)));
-}
-
TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) {
#if defined(OS_CHROMEOS)
// This feature should never be enabled on ChromeOS.
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
index 8055c96..9338c39e 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -42,14 +42,12 @@ const char kNameKey[] = "name";
const char kShortcutNameKey[] = "shortcut_name";
const char kGAIANameKey[] = "gaia_name";
const char kGAIAGivenNameKey[] = "gaia_given_name";
-const char kUseGAIANameKey[] = "use_gaia_name";
const char kUserNameKey[] = "user_name";
const char kIsUsingDefaultName[] = "is_using_default_name";
const char kAvatarIconKey[] = "avatar_icon";
const char kAuthCredentialsKey[] = "local_auth_credentials";
const char kUseGAIAPictureKey[] = "use_gaia_picture";
const char kBackgroundAppsKey[] = "background_apps";
-const char kHasMigratedToGAIAInfoKey[] = "has_migrated_to_gaia_info";
const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name";
const char kIsManagedKey[] = "is_managed";
const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list";
@@ -318,8 +316,7 @@ base::string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const {
base::string16 name;
// Unless the user has customized the profile name, we should use the
// profile's Gaia given name, if it's available.
- if (IsUsingGAIANameOfProfileAtIndex(index) &&
- ProfileIsUsingDefaultNameAtIndex(index)) {
+ if (ProfileIsUsingDefaultNameAtIndex(index)) {
base::string16 given_name = GetGAIAGivenNameOfProfileAtIndex(index);
name = given_name.empty() ? GetGAIANameOfProfileAtIndex(index) : given_name;
}
@@ -400,12 +397,6 @@ base::string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex(
return name;
}
-bool ProfileInfoCache::IsUsingGAIANameOfProfileAtIndex(size_t index) const {
- bool value = false;
- GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value);
- return value;
-}
-
const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex(
size_t index) const {
base::FilePath path = GetPathOfProfileAtIndex(index);
@@ -677,28 +668,6 @@ void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex(
SetInfoForProfileAtIndex(index, info.release());
}
-void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index,
- bool value) {
- if (value == IsUsingGAIANameOfProfileAtIndex(index))
- return;
-
- base::string16 old_display_name = GetNameOfProfileAtIndex(index);
- scoped_ptr<base::DictionaryValue> info(
- GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kUseGAIANameKey, value);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
- base::string16 new_display_name = GetNameOfProfileAtIndex(index);
- base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- UpdateSortForProfileIndex(index);
-
- if (old_display_name != new_display_name) {
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileNameChanged(profile_path, old_display_name));
- }
-}
-
void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
const gfx::Image* image) {
base::FilePath path = GetPathOfProfileAtIndex(index);
@@ -839,23 +808,6 @@ base::string16 ProfileInfoCache::ChooseNameForNewProfile(
}
}
-bool ProfileInfoCache::GetHasMigratedToGAIAInfoOfProfileAtIndex(
- size_t index) const {
- bool value = false;
- GetInfoForProfileAtIndex(index)->GetBoolean(
- kHasMigratedToGAIAInfoKey, &value);
- return value;
-}
-
-void ProfileInfoCache::SetHasMigratedToGAIAInfoOfProfileAtIndex(
- size_t index, bool value) {
- scoped_ptr<base::DictionaryValue> info(
- GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kHasMigratedToGAIAInfoKey, value);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
-
bool ProfileInfoCache::IconIndexIsUnique(size_t icon_index) const {
for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index)
diff --git a/chrome/browser/profiles/profile_info_cache.h b/chrome/browser/profiles/profile_info_cache.h
index 42a0222..28251f0 100644
--- a/chrome/browser/profiles/profile_info_cache.h
+++ b/chrome/browser/profiles/profile_info_cache.h
@@ -77,7 +77,6 @@ class ProfileInfoCache : public ProfileInfoInterface,
size_t index) const OVERRIDE;
virtual base::string16 GetGAIAGivenNameOfProfileAtIndex(
size_t index) const OVERRIDE;
- virtual bool IsUsingGAIANameOfProfileAtIndex(size_t index) const OVERRIDE;
// Returns the GAIA picture for the given profile. This may return NULL
// if the profile does not have a GAIA picture or if the picture must be
// loaded from disk.
@@ -111,7 +110,6 @@ class ProfileInfoCache : public ProfileInfoInterface,
void SetGAIANameOfProfileAtIndex(size_t index, const base::string16& name);
void SetGAIAGivenNameOfProfileAtIndex(size_t index,
const base::string16& name);
- void SetIsUsingGAIANameOfProfileAtIndex(size_t index, bool value);
void SetGAIAPictureOfProfileAtIndex(size_t index, const gfx::Image* image);
void SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, bool value);
void SetProfileSigninRequiredAtIndex(size_t index, bool value);
@@ -121,16 +119,6 @@ class ProfileInfoCache : public ProfileInfoInterface,
// Returns unique name that can be assigned to a newly created profile.
base::string16 ChooseNameForNewProfile(size_t icon_index) const;
- // Checks if the given profile has switched to using GAIA information
- // for the profile name and picture. This pref is used to switch over
- // to GAIA info the first time it is available. Afterwards this pref is
- // checked to prevent clobbering the user's custom settings.
- bool GetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index) const;
-
- // Marks the given profile as having switched to using GAIA information
- // for the profile name and picture.
- void SetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index, bool value);
-
// Returns an avatar icon index that can be assigned to a newly created
// profile. Note that the icon may not be unique since there are a limited
// set of default icons.
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc
index 972d8ef..3f9b1e4 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.cc
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -281,34 +281,6 @@ TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) {
EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
}
-TEST_F(ProfileInfoCacheTest, HasMigrated) {
- GetCache()->AddProfileToCache(
- GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
- base::string16(), 0, std::string());
- GetCache()->AddProfileToCache(
- GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
- base::string16(), 0, std::string());
-
- // Sanity check.
- EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
- EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
-
- // Set migrated state for 2nd profile.
- GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true);
- EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
- EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
-
- // Set migrated state for 1st profile.
- GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true);
- EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
- EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
-
- // Unset migrated state for 2nd profile.
- GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false);
- EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
- EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
-}
-
TEST_F(ProfileInfoCacheTest, ProfileActiveTime) {
GetCache()->AddProfileToCache(
GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
@@ -342,31 +314,25 @@ TEST_F(ProfileInfoCacheTest, GAIAName) {
// Sanity check.
EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty());
EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty());
- EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index1));
- EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index2));
- // Set GAIA name.
+ // Set GAIA name. This re-sorts the cache.
base::string16 gaia_name(ASCIIToUTF16("Pat Smith"));
GetCache()->SetGAIANameOfProfileAtIndex(index2, gaia_name);
- EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty());
- EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
- EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(index2));
-
- // Use GAIA name as profile name. This re-sorts the cache.
- GetCache()->SetIsUsingGAIANameOfProfileAtIndex(index2, true);
index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1"));
index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2"));
- EXPECT_EQ(GetCache()->IsUsingGAIANameOfProfileAtIndex(index2), true);
- EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(index2));
+ // Since there is a GAIA name, we use that as a display name.
+ EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty());
EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
+ EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(index2));
// Don't use GAIA name as profile name. This re-sorts the cache.
- GetCache()->SetIsUsingGAIANameOfProfileAtIndex(index2, false);
+ base::string16 custom_name(ASCIIToUTF16("Custom name"));
+ GetCache()->SetNameOfProfileAtIndex(index2, custom_name);
index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1"));
index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2"));
- EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(index2));
+ EXPECT_EQ(custom_name, GetCache()->GetNameOfProfileAtIndex(index2));
EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
}
@@ -474,7 +440,6 @@ TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) {
// Set empty GAIA info.
GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16());
GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL);
- GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true);
GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true);
// Verify that the profile name and picture are not empty.
diff --git a/chrome/browser/profiles/profile_info_interface.h b/chrome/browser/profiles/profile_info_interface.h
index d369f6a..66f6741 100644
--- a/chrome/browser/profiles/profile_info_interface.h
+++ b/chrome/browser/profiles/profile_info_interface.h
@@ -53,9 +53,6 @@ class ProfileInfoInterface {
virtual base::string16 GetGAIAGivenNameOfProfileAtIndex(
size_t index) const = 0;
- // Checks if the GAIA name should be used as the profile's name.
- virtual bool IsUsingGAIANameOfProfileAtIndex(size_t index) const = 0;
-
virtual const gfx::Image* GetGAIAPictureOfProfileAtIndex(
size_t index) const = 0;
diff --git a/chrome/browser/profiles/profiles_state.cc b/chrome/browser/profiles/profiles_state.cc
index a2cc924..282ffd3 100644
--- a/chrome/browser/profiles/profiles_state.cc
+++ b/chrome/browser/profiles/profiles_state.cc
@@ -84,32 +84,11 @@ base::string16 GetAvatarNameForProfile(Profile* profile) {
void UpdateProfileName(Profile* profile,
const base::string16& new_profile_name) {
- ProfileInfoCache& cache =
- g_browser_process->profile_manager()->GetProfileInfoCache();
- base::FilePath profile_file_path = profile->GetPath();
- size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
-
- if ((new_profile_name ==
- cache.GetGAIAGivenNameOfProfileAtIndex(profile_index)) ||
- (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index))) {
- // Set the profile to use the GAIA name as the profile name. Note, this
- // is a little weird if the user typed their GAIA name manually but
- // it's not a big deal.
- cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true);
- } else {
- PrefService* pref_service = profile->GetPrefs();
- // Updating the profile preference will cause the cache to be updated for
- // this preference.
- pref_service->SetString(prefs::kProfileName,
- base::UTF16ToUTF8(new_profile_name));
-
- // Changing the profile name can invalidate the profile index.
- profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
- if (profile_index == std::string::npos)
- return;
-
- cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false);
- }
+ PrefService* pref_service = profile->GetPrefs();
+ // Updating the profile preference will cause the cache to be updated for
+ // this preference.
+ pref_service->SetString(prefs::kProfileName,
+ base::UTF16ToUTF8(new_profile_name));
}
std::vector<std::string> GetSecondaryAccountsForProfile(