Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 490363002: [Profiles] Update legacy default profile names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..464f994ba19dd387961c0dccb15a6f24a9797a8a 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,47 @@ 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)
+ return;
+#endif
Roger Tawa OOO till Jul 10th 2014/08/22 15:28:04 reverse condition and put #ifdef around all the co
noms (inactive) 2014/08/22 20:44:35 Done.
+
+ // 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)));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698