| Index: chrome/browser/profiles/profile_info_cache.cc
|
| diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
|
| index 8aaa047c963dfd8f409d9fe59c13bb508ecdfc4b..c5ba808526041b4c849bc0f019910fbe1f3b63e9 100644
|
| --- a/chrome/browser/profiles/profile_info_cache.cc
|
| +++ b/chrome/browser/profiles/profile_info_cache.cc
|
| @@ -169,13 +169,10 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
|
| }
|
| }
|
|
|
| - // If needed, start downloading the high-res avatars.
|
| - if (switches::IsNewAvatarMenu()) {
|
| - for (size_t i = 0; i < GetNumberOfProfiles(); i++) {
|
| - DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i),
|
| - GetPathOfProfileAtIndex(i));
|
| - }
|
| - }
|
| + // If needed, start downloading the high-res avatars and migrate any legacy
|
| + // profile names.
|
| + if (switches::IsNewAvatarMenu())
|
| + MigrateLegacyProfileNamesAndDownloadAvatars();
|
| }
|
|
|
| ProfileInfoCache::~ProfileInfoCache() {
|
| @@ -1067,3 +1064,45 @@ void ProfileInfoCache::OnAvatarPictureSaved(
|
| delete avatar_images_downloads_in_progress_[file_name];
|
| avatar_images_downloads_in_progress_[file_name] = NULL;
|
| }
|
| +
|
| +void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() {
|
| + DCHECK(switches::IsNewAvatarMenu());
|
| +
|
| + // Only do this on desktop platforms.
|
| +#if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
|
| + // Migrate any legacy profile names ("First user", "Default Profile") to
|
| + // new style default names ("Person 1"). The problem here is that every
|
| + // time you rename a profile, the ProfileInfoCache sorts itself, so
|
| + // whatever you were iterating through is no longer valid. We need to
|
| + // save a list of the profile paths (which thankfully do not change) that
|
| + // need to be renamed. We also can't pre-compute the new names, as they
|
| + // depend on the names of all the other profiles in the info cache, so they
|
| + // need to be re-computed after each rename.
|
| + std::vector<base::FilePath> profiles_to_rename;
|
| +
|
| + const base::string16 default_profile_name = base::i18n::ToLower(
|
| + l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME));
|
| + const base::string16 default_legacy_profile_name = base::i18n::ToLower(
|
| + l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME));
|
| +
|
| + for (size_t i = 0; i < GetNumberOfProfiles(); i++) {
|
| + // If needed, start downloading the high-res avatar for this profile.
|
| + DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i),
|
| + GetPathOfProfileAtIndex(i));
|
| +
|
| + base::string16 name = base::i18n::ToLower(GetNameOfProfileAtIndex(i));
|
| + if (name == default_profile_name || name == default_legacy_profile_name)
|
| + profiles_to_rename.push_back(GetPathOfProfileAtIndex(i));
|
| + }
|
| +
|
| + // Rename the necessary profiles.
|
| + std::vector<base::FilePath>::const_iterator it;
|
| + for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) {
|
| + size_t profile_index = GetIndexOfProfileWithPath(*it);
|
| + SetProfileIsUsingDefaultNameAtIndex(profile_index, true);
|
| + // This will assign a new "Person %d" type name and re-sort the cache.
|
| + SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile(
|
| + GetAvatarIconIndexOfProfileAtIndex(profile_index)));
|
| + }
|
| +#endif
|
| +}
|
|
|