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

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

Issue 476993002: [Profiles] Fix the usage of custom/default names and avatars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: all rebase all the time 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 10a3259d968b8d45a1fe6408c1477fd84c449400..8aaa047c963dfd8f409d9fe59c13bb508ecdfc4b 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -137,30 +137,6 @@ void DeleteBitmap(const base::FilePath& image_path) {
base::DeleteFile(image_path, false);
}
-bool IsDefaultName(const base::string16& name) {
- // Check if it's a "First user" old-style name.
- if (name == l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME) ||
- name == l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME))
- return true;
-
- // Check if it's one of the old-style profile names.
- for (size_t i = 0; i < arraysize(kDefaultNames); ++i) {
- if (name == l10n_util::GetStringUTF16(kDefaultNames[i]))
- return true;
- }
-
- // Check whether it's one of the "Person %d" style names.
- std::string default_name_format = l10n_util::GetStringFUTF8(
- IDS_NEW_NUMBERED_PROFILE_NAME, base::string16()) + "%d";
-
- int generic_profile_number; // Unused. Just a placeholder for sscanf.
- int assignments = sscanf(base::UTF16ToUTF8(name).c_str(),
- default_name_format.c_str(),
- &generic_profile_number);
- // Unless it matched the format, this is a custom name.
- return assignments == 1;
-}
-
} // namespace
ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
@@ -177,8 +153,15 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
base::string16 name;
info->GetString(kNameKey, &name);
sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key());
- bool using_default_name = IsDefaultName(name);
- info->SetBoolean(kIsUsingDefaultNameKey, using_default_name);
+
+ bool using_default_name;
+ if (!info->GetBoolean(kIsUsingDefaultNameKey, &using_default_name)) {
+ // If the preference hasn't been set, and the name is default, assume
+ // that the user hasn't done this on purpose.
+ using_default_name = IsDefaultProfileName(name);
+ info->SetBoolean(kIsUsingDefaultNameKey, using_default_name);
+ }
+
// For profiles that don't have the "using default avatar" state set yet,
// assume it's the same as the "using default name" state.
if (!info->HasKey(kIsUsingDefaultAvatarKey)) {
@@ -223,7 +206,7 @@ void ProfileInfoCache::AddProfileToCache(
info->SetString(kSupervisedUserId, supervised_user_id);
info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty());
info->SetBoolean(kProfileIsEphemeral, false);
- info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultName(name));
+ info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name));
// Assume newly created profiles use a default avatar.
info->SetBoolean(kIsUsingDefaultAvatarKey, true);
cache->SetWithoutPathExpansion(key, info.release());
@@ -489,10 +472,10 @@ void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
base::string16 old_display_name = GetNameOfProfileAtIndex(index);
info->SetString(kNameKey, name);
- info->SetBoolean(kIsUsingDefaultNameKey, false);
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
+
base::string16 new_display_name = GetNameOfProfileAtIndex(index);
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
@@ -538,8 +521,6 @@ void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
- SetProfileIsUsingDefaultAvatarAtIndex(index, false);
-
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
// If needed, start downloading the high-res avatar.
@@ -758,6 +739,30 @@ void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex(
SetInfoForProfileAtIndex(index, info.release());
}
+bool ProfileInfoCache::IsDefaultProfileName(const base::string16& name) {
+ // Check if it's a "First user" old-style name.
+ if (name == l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME) ||
+ name == l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME))
+ return true;
+
+ // Check if it's one of the old-style profile names.
+ for (size_t i = 0; i < arraysize(kDefaultNames); ++i) {
+ if (name == l10n_util::GetStringUTF16(kDefaultNames[i]))
+ return true;
+ }
+
+ // Check whether it's one of the "Person %d" style names.
+ std::string default_name_format = l10n_util::GetStringFUTF8(
+ IDS_NEW_NUMBERED_PROFILE_NAME, base::ASCIIToUTF16("%d"));
+
+ int generic_profile_number; // Unused. Just a placeholder for sscanf.
+ int assignments = sscanf(base::UTF16ToUTF8(name).c_str(),
+ default_name_format.c_str(),
+ &generic_profile_number);
+ // Unless it matched the format, this is a custom name.
+ return assignments == 1;
+}
+
base::string16 ProfileInfoCache::ChooseNameForNewProfile(
size_t icon_index) const {
base::string16 name;
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698