| Index: chrome/browser/profiles/profiles_state.cc
|
| diff --git a/chrome/browser/profiles/profiles_state.cc b/chrome/browser/profiles/profiles_state.cc
|
| index 488964e1de16c883d3f3fcaea60e7d42d04768bb..cfbf333812973f3027bb6287ee4f18abc4e435db 100644
|
| --- a/chrome/browser/profiles/profiles_state.cc
|
| +++ b/chrome/browser/profiles/profiles_state.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "chrome/browser/profiles/profiles_state.h"
|
|
|
| +#include <stdio.h>
|
| +
|
| #include "base/files/file_path.h"
|
| #include "base/prefs/pref_registry_simple.h"
|
| #include "base/prefs/pref_service.h"
|
| @@ -50,20 +52,42 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
|
| registry->RegisterListPref(prefs::kProfilesLastActive);
|
| }
|
|
|
| -base::string16 GetActiveProfileDisplayName(Browser* browser) {
|
| - base::string16 profile_name;
|
| - Profile* profile = browser->profile();
|
| +base::string16 GetAvatarNameForProfile(Profile* profile) {
|
| + base::string16 display_name;
|
|
|
| if (profile->IsGuestSession()) {
|
| - profile_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME);
|
| + display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME);
|
| } else {
|
| ProfileInfoCache& cache =
|
| g_browser_process->profile_manager()->GetProfileInfoCache();
|
| size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| - if (index != std::string::npos)
|
| - profile_name = cache.GetNameOfProfileAtIndex(index);
|
| +
|
| + if (index == std::string::npos)
|
| + return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
|
| +
|
| + // Using the --new-profile-management flag, there's a couple of rules
|
| + // about what the avatar button displays. If there's a single, local
|
| + // profile, with a default name (i.e. of the form Person %d), it should
|
| + // display IDS_SINGLE_PROFILE_DISPLAY_NAME. If this is a signed in profile,
|
| + // or the user has edited the profile name, or there are multiple profiles,
|
| + // it will return the actual name of the profile.
|
| + base::string16 profile_name = cache.GetNameOfProfileAtIndex(index);
|
| + 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(profile_name).c_str(),
|
| + default_name_format.c_str(),
|
| + &generic_profile_number);
|
| + bool has_default_name = (assignments == 1);
|
| +
|
| + if (cache.GetNumberOfProfiles() == 1 && has_default_name &&
|
| + cache.GetUserNameOfProfileAtIndex(index).empty()) {
|
| + display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
|
| + } else {
|
| + display_name = profile_name;
|
| + }
|
| }
|
| - return profile_name;
|
| + return display_name;
|
| }
|
|
|
| void UpdateProfileName(Profile* profile,
|
|
|