Chromium Code Reviews| 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 cfaba750321956e90de9f87d83f70f26007be741..8c3c306a5d5a4c8d7e2016e54c98f1303ed8bace 100644 |
| --- a/chrome/browser/profiles/profile_info_cache.cc |
| +++ b/chrome/browser/profiles/profile_info_cache.cc |
| @@ -137,29 +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)) |
| - 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, |
| @@ -176,8 +153,17 @@ 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->HasKey(kIsUsingDefaultNameKey)) { |
| + info->GetBoolean(kIsUsingDefaultNameKey, &using_default_name); |
|
Bernhard Bauer
2014/08/15 14:39:22
GetBoolean() returns a bool that says whether the
noms (inactive)
2014/08/15 16:22:47
Done.
|
| + } else { |
| + // 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)) { |
| @@ -222,7 +208,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()); |
| @@ -488,7 +474,6 @@ 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()); |
| @@ -537,8 +522,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. |
| @@ -757,6 +740,29 @@ 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)) |
| + 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"; |
|
Bernhard Bauer
2014/08/15 14:39:22
Use ASCIIToUTF16('%d') instead of base::string16()
Roger Tawa OOO till Jul 10th
2014/08/15 14:46:40
Why not:
std::string default_name_format =
noms (inactive)
2014/08/15 16:22:47
Acknowledged.
noms (inactive)
2014/08/15 16:22:47
I'll take Bernhard's version, since his compiles :
|
| + |
| + 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; |