Commit bafd44c2 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[Signin]: Show the concatenation of the GAIA name and profile name.

Use the concatenation of GAIA name and profile name as the identity of
the profile to be shown in the User Menu and the profile switcher. With
the efforts towards encouraging the use of multiple profiles, it becomes
more important to show a clear identity for the profile and clear
transitions on events like sign in, enable sync, sign out. If no primary
account or unconsented primary account exists for the profile, the local
profile name is used. Otherwise, we show the concatenation of GAIA name
and profile name in this format: |GAIA name (profile name)|. The only
exception where we only show the GAIA name is if the profile name is a
substring of the GAIA name. The implementation is behind a kill switch
|kConcatenateGaiaAndProfileName| enabled by default.

Bug: 1012182
Change-Id: I27626d9e9c77f38698db1012abf5e3fceccc266d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845766Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Monica Basta <msalama@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704541}
parent 736c9b51
......@@ -298,7 +298,7 @@ TEST_F(GAIAInfoUpdateServiceTest, ProfileLockEnabledForWhitelist) {
// of ProfileInfoCache is complete.
TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) {
size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
GetCache()->SetNameOfProfileAtIndex(index, FullName16("B"));
GetCache()->SetLocalProfileNameOfProfileAtIndex(index, FullName16("B"));
GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
CreateProfile(FullName("A"));
......
......@@ -45,6 +45,8 @@ int NextAvailableMetricsBucketIndex() {
const base::Feature kPersistUPAInProfileInfoCache{
"PersistUPAInProfileInfoCache", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kConcatenateGaiaAndProfileName{
"ConcatenateGaiaAndProfileName", base::FEATURE_ENABLED_BY_DEFAULT};
const char ProfileAttributesEntry::kAvatarIconKey[] = "avatar_icon";
const char ProfileAttributesEntry::kBackgroundAppsKey[] = "background_apps";
......@@ -108,7 +110,42 @@ void ProfileAttributesEntry::Initialize(ProfileInfoCache* cache,
}
}
base::string16 ProfileAttributesEntry::GetLocalProfileName() const {
return GetString16(ProfileInfoCache::kNameKey);
}
base::string16 ProfileAttributesEntry::GetNameToDisplay() const {
DCHECK(base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName));
base::string16 name_to_display =
GetString16(ProfileInfoCache::kGAIAGivenNameKey);
if (name_to_display.empty())
name_to_display = GetString16(ProfileInfoCache::kGAIANameKey);
base::string16 local_profile_name = GetLocalProfileName();
if (name_to_display.empty())
return local_profile_name;
size_t number_of_profiles = profile_info_cache_->GetNumberOfProfiles();
if (number_of_profiles == 1)
return name_to_display;
auto it = std::search(name_to_display.begin(), name_to_display.end(),
local_profile_name.begin(), local_profile_name.end(),
base::CaseInsensitiveCompareASCII<char>());
if (it != name_to_display.end())
return name_to_display;
name_to_display.append(base::UTF8ToUTF16(" ("));
name_to_display.append(local_profile_name);
name_to_display.append(base::UTF8ToUTF16(")"));
return name_to_display;
}
base::string16 ProfileAttributesEntry::GetName() const {
if (base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName))
return GetNameToDisplay();
return profile_info_cache_->GetNameOfProfileAtIndex(profile_index());
}
......@@ -267,8 +304,9 @@ size_t ProfileAttributesEntry::GetMetricsBucketIndex() {
return bucket_index;
}
void ProfileAttributesEntry::SetName(const base::string16& name) {
profile_info_cache_->SetNameOfProfileAtIndex(profile_index(), name);
void ProfileAttributesEntry::SetLocalProfileName(const base::string16& name) {
profile_info_cache_->SetLocalProfileNameOfProfileAtIndex(profile_index(),
name);
}
void ProfileAttributesEntry::SetShortcutName(const base::string16& name) {
......
......@@ -33,6 +33,7 @@ enum class SigninState {
};
extern const base::Feature kPersistUPAInProfileInfoCache;
extern const base::Feature kConcatenateGaiaAndProfileName;
class ProfileAttributesEntry {
public:
......@@ -41,8 +42,11 @@ class ProfileAttributesEntry {
ProfileAttributesEntry();
virtual ~ProfileAttributesEntry() {}
// Gets the name of the profile, which is the one displayed in the User Menu.
// Gets the name of the profile to be displayed in the User Menu. The name can
// be the GAIA name, local profile name or a combination of them.
base::string16 GetName() const;
// Gets the local profile name.
base::string16 GetLocalProfileName() const;
base::string16 GetShortcutName() const;
// Gets the path to the profile. Should correspond to the path passed to
......@@ -112,7 +116,7 @@ class ProfileAttributesEntry {
// reserved for the guest profile.
size_t GetMetricsBucketIndex();
void SetName(const base::string16& name);
void SetLocalProfileName(const base::string16& name);
void SetShortcutName(const base::string16& name);
void SetActiveTimeToNow();
void SetIsOmitted(bool is_omitted);
......@@ -156,6 +160,10 @@ class ProfileAttributesEntry {
const base::FilePath& path,
PrefService* prefs);
// Gets the name of the profile as the concatenation of the Gaia name and the
// profile name, which is the one displayed in the User Menu.
base::string16 GetNameToDisplay() const;
// Loads or uses an already loaded high resolution image of the generic
// profile avatar.
const gfx::Image* GetHighResAvatar() const;
......
......@@ -215,7 +215,8 @@ base::string16 ProfileAttributesStorage::ChooseNameForNewProfile(
if (std::none_of(entries.begin(), entries.end(),
[name](ProfileAttributesEntry* entry) {
return entry->GetName() == name;
return entry->GetLocalProfileName() == name ||
entry->GetName() == name;
})) {
return name;
}
......
......@@ -298,7 +298,7 @@ TEST_F(ProfileAttributesStorageTest, EntryAccessors) {
EXPECT_EQ(path, entry->GetPath());
EXPECT_CALL(observer(), OnProfileNameChanged(path, _)).Times(2);
TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, Name);
TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, LocalProfileName);
VerifyAndResetCallExpectations();
TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, ShortcutName);
......@@ -307,8 +307,10 @@ TEST_F(ProfileAttributesStorageTest, EntryAccessors) {
ProfileAttributesEntry, entry, PasswordChangeDetectionToken);
TEST_ACCESSORS(ProfileAttributesEntry, entry, BackgroundStatus, true, false);
EXPECT_CALL(observer(), OnProfileNameChanged(path, _)).Times(4);
TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, GAIAName);
TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, GAIAGivenName);
VerifyAndResetCallExpectations();
EXPECT_CALL(observer(), OnProfileAvatarChanged(path)).Times(2);
TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingGAIAPicture);
......@@ -320,7 +322,6 @@ TEST_F(ProfileAttributesStorageTest, EntryAccessors) {
TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsEphemeral);
EXPECT_CALL(observer(), OnProfileNameChanged(path, _)).Times(2);
TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingDefaultName);
VerifyAndResetCallExpectations();
......@@ -521,7 +522,7 @@ TEST_F(ProfileAttributesStorageTest, ReSortTriggered) {
GetProfilePath("alpha_path"), &entry));
// Trigger a ProfileInfoCache re-sort.
entry->SetName(base::ASCIIToUTF16("zulu_name"));
entry->SetLocalProfileName(base::ASCIIToUTF16("zulu_name"));
EXPECT_EQ(GetProfilePath("alpha_path"), entry->GetPath());
}
......@@ -576,7 +577,7 @@ TEST_F(ProfileAttributesStorageTest, AccessFromElsewhere) {
ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
GetProfilePath("testing_profile_path0"), &second_entry));
first_entry->SetName(base::ASCIIToUTF16("NewName"));
first_entry->SetLocalProfileName(base::ASCIIToUTF16("NewName"));
EXPECT_EQ(base::ASCIIToUTF16("NewName"), second_entry->GetName());
EXPECT_EQ(first_entry, second_entry);
......@@ -585,9 +586,9 @@ TEST_F(ProfileAttributesStorageTest, AccessFromElsewhere) {
size_t index = profile_info_cache()->GetIndexOfProfileWithPath(
GetProfilePath("testing_profile_path0"));
EXPECT_EQ(base::ASCIIToUTF16("NewName"),
profile_info_cache()->GetNameOfProfileAtIndex(index));
profile_info_cache()->GetNameToDisplayOfProfileAtIndex(index));
profile_info_cache()->SetNameOfProfileAtIndex(
profile_info_cache()->SetLocalProfileNameOfProfileAtIndex(
index, base::ASCIIToUTF16("OtherNewName"));
EXPECT_EQ(base::ASCIIToUTF16("OtherNewName"), first_entry->GetName());
}
......
......@@ -1526,7 +1526,7 @@ void ProfileImpl::UpdateNameInStorage() {
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(GetPath(), &entry);
if (has_entry) {
entry->SetName(
entry->SetLocalProfileName(
base::UTF8ToUTF16(GetPrefs()->GetString(prefs::kProfileName)));
entry->SetIsUsingDefaultName(
GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName));
......
......@@ -40,9 +40,6 @@
namespace {
const char kNameKey[] = "name";
const char kGAIANameKey[] = "gaia_name";
const char kGAIAGivenNameKey[] = "gaia_given_name";
const char kGAIAIdKey[] = "gaia_id";
const char kIsUsingDefaultNameKey[] = "is_using_default_name";
const char kIsUsingDefaultAvatarKey[] = "is_using_default_avatar";
......@@ -60,6 +57,9 @@ void DeleteBitmap(const base::FilePath& image_path) {
}
} // namespace
const char ProfileInfoCache::kNameKey[] = "name";
const char ProfileInfoCache::kGAIANameKey[] = "gaia_name";
const char ProfileInfoCache::kGAIAGivenNameKey[] = "gaia_given_name";
ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
const base::FilePath& user_data_dir)
......@@ -153,15 +153,34 @@ void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
info->SetString(kAccountIdKey, account_id.GetAccountIdKey());
cache->SetWithoutPathExpansion(key, std::move(info));
// Switching from single profile to multi-profile might change the existing
// profile display name. We append the profile name to GAIA name only in case
// of multi-profile.
ProfileAttributesEntry* entry = nullptr;
base::string16 old_single_profile_name;
if (GetNumberOfProfiles() == 1 &&
base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName)) {
std::vector<ProfileAttributesEntry*> entries = GetAllProfilesAttributes();
entry = entries[0];
old_single_profile_name = entry->GetName();
}
sorted_keys_.insert(FindPositionForProfile(key, name), key);
profile_attributes_entries_[user_data_dir_.AppendASCII(key).value()] =
std::unique_ptr<ProfileAttributesEntry>();
bool single_profile_name_changed =
entry && (entry->GetName() != old_single_profile_name);
if (!disable_avatar_download_for_testing_)
DownloadHighResAvatarIfNeeded(icon_index, profile_path);
for (auto& observer : observer_list_)
for (auto& observer : observer_list_) {
observer.OnProfileAdded(profile_path);
if (single_profile_name_changed) {
observer.OnProfileNameChanged(entry->GetPath(), old_single_profile_name);
}
}
}
void ProfileInfoCache::DeleteProfileFromCache(
......@@ -171,6 +190,24 @@ void ProfileInfoCache::DeleteProfileFromCache(
NOTREACHED();
return;
}
// Switching from multi-profile to single profile might change the profile
// display name for the single profile left after deletion of the profile with
// |profile_path|. We append the profile name to GAIA name only in case of
// multi-profile.
size_t number_of_profiles = GetNumberOfProfiles();
ProfileAttributesEntry* single_profile_entry = nullptr;
base::string16 old_single_profile_name;
if (number_of_profiles == 2 &&
base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName)) {
for (auto& it : profile_attributes_entries_) {
base::FilePath path(it.first);
if (it.first != profile_path.value()) {
GetProfileAttributesWithPath(path, &single_profile_entry);
old_single_profile_name = single_profile_entry->GetName();
}
}
}
base::string16 name = entry->GetName();
for (auto& observer : observer_list_)
......@@ -183,8 +220,17 @@ void ProfileInfoCache::DeleteProfileFromCache(
sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
profile_attributes_entries_.erase(profile_path.value());
for (auto& observer : observer_list_)
bool single_profile_name_changed =
single_profile_entry &&
single_profile_entry->GetName() != old_single_profile_name;
for (auto& observer : observer_list_) {
observer.OnProfileWasRemoved(profile_path, name);
if (single_profile_name_changed) {
observer.OnProfileNameChanged(single_profile_entry->GetPath(),
old_single_profile_name);
}
}
}
size_t ProfileInfoCache::GetNumberOfProfiles() const {
......@@ -203,7 +249,21 @@ size_t ProfileInfoCache::GetIndexOfProfileWithPath(
return std::string::npos;
}
base::string16 ProfileInfoCache::GetNameToDisplayOfProfileAtIndex(
size_t index) {
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
ProfileAttributesEntry* entry;
GetProfileAttributesWithPath(profile_path, &entry);
if (!entry) {
DLOG(ERROR) << "No entry found for this profile!";
return base::string16();
}
return entry->GetName();
}
base::string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const {
DCHECK(!base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName));
base::string16 name;
// Unless the user has customized the profile name, we should use the
// profile's Gaia given name, if it's available.
......@@ -376,8 +436,9 @@ size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index)
return icon_index;
}
void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
const base::string16& name) {
void ProfileInfoCache::SetLocalProfileNameOfProfileAtIndex(
size_t index,
const base::string16& name) {
std::unique_ptr<base::DictionaryValue> info(
GetInfoForProfileAtIndex(index)->DeepCopy());
base::string16 current_name;
......@@ -385,12 +446,12 @@ void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
if (name == current_name)
return;
base::string16 old_display_name = GetNameOfProfileAtIndex(index);
base::string16 old_display_name = GetNameToDisplayOfProfileAtIndex(index);
info->SetString(kNameKey, name);
SetInfoForProfileAtIndex(index, std::move(info));
base::string16 new_display_name = GetNameOfProfileAtIndex(index);
base::string16 new_display_name = GetNameToDisplayOfProfileAtIndex(index);
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
......@@ -502,12 +563,12 @@ void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index,
if (name == GetGAIANameOfProfileAtIndex(index))
return;
base::string16 old_display_name = GetNameOfProfileAtIndex(index);
base::string16 old_display_name = GetNameToDisplayOfProfileAtIndex(index);
std::unique_ptr<base::DictionaryValue> info(
GetInfoForProfileAtIndex(index)->DeepCopy());
info->SetString(kGAIANameKey, name);
SetInfoForProfileAtIndex(index, std::move(info));
base::string16 new_display_name = GetNameOfProfileAtIndex(index);
base::string16 new_display_name = GetNameToDisplayOfProfileAtIndex(index);
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
......@@ -523,12 +584,12 @@ void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex(
if (name == GetGAIAGivenNameOfProfileAtIndex(index))
return;
base::string16 old_display_name = GetNameOfProfileAtIndex(index);
base::string16 old_display_name = GetNameToDisplayOfProfileAtIndex(index);
std::unique_ptr<base::DictionaryValue> info(
GetInfoForProfileAtIndex(index)->DeepCopy());
info->SetString(kGAIAGivenNameKey, name);
SetInfoForProfileAtIndex(index, std::move(info));
base::string16 new_display_name = GetNameOfProfileAtIndex(index);
base::string16 new_display_name = GetNameToDisplayOfProfileAtIndex(index);
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
......@@ -612,14 +673,14 @@ void ProfileInfoCache::SetProfileIsUsingDefaultNameAtIndex(
if (value == ProfileIsUsingDefaultNameAtIndex(index))
return;
base::string16 old_display_name = GetNameOfProfileAtIndex(index);
base::string16 old_display_name = GetNameToDisplayOfProfileAtIndex(index);
std::unique_ptr<base::DictionaryValue> info(
GetInfoForProfileAtIndex(index)->DeepCopy());
info->SetBoolean(kIsUsingDefaultNameKey, value);
SetInfoForProfileAtIndex(index, std::move(info));
base::string16 new_display_name = GetNameOfProfileAtIndex(index);
base::string16 new_display_name = GetNameToDisplayOfProfileAtIndex(index);
const base::FilePath profile_path = GetPathOfProfileAtIndex(index);
if (old_display_name != new_display_name) {
......@@ -684,7 +745,8 @@ std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile(
const base::string16& search_name) {
base::string16 search_name_l = base::i18n::ToLower(search_name);
for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
base::string16 name_l = base::i18n::ToLower(GetNameOfProfileAtIndex(i));
base::string16 name_l =
base::i18n::ToLower(GetNameToDisplayOfProfileAtIndex(i));
int name_compare = search_name_l.compare(name_l);
if (name_compare < 0)
return sorted_keys_.begin() + i;
......@@ -698,7 +760,7 @@ std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile(
}
void ProfileInfoCache::UpdateSortForProfileIndex(size_t index) {
base::string16 name = GetNameOfProfileAtIndex(index);
base::string16 name = GetNameToDisplayOfProfileAtIndex(index);
// Remove and reinsert key in |sorted_keys_| to alphasort.
std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index));
......@@ -743,10 +805,11 @@ void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() {
entry->GetPath());
// Rename the necessary profiles.
base::string16 name = base::i18n::ToLower(entry->GetName());
base::string16 name = base::i18n::ToLower(entry->GetLocalProfileName());
if (name == default_profile_name || name == default_legacy_profile_name) {
entry->SetIsUsingDefaultName(true);
entry->SetName(ChooseNameForNewProfile(entry->GetAvatarIconIndex()));
entry->SetLocalProfileName(
ChooseNameForNewProfile(entry->GetAvatarIconIndex()));
}
}
#endif
......
......@@ -73,6 +73,8 @@ class ProfileInfoCache : public ProfileInfoInterface,
// directly referring to this implementation.
size_t GetIndexOfProfileWithPath(
const base::FilePath& profile_path) const override;
// Deprecated 10/2019, Do not use!
// Use GetNameToDisplayOfProfileAtIndex instead.
base::string16 GetNameOfProfileAtIndex(size_t index) const override;
// Will be removed SOON with ProfileInfoCache tests. Do not use!
base::FilePath GetPathOfProfileAtIndex(size_t index) const override;
......@@ -109,7 +111,8 @@ class ProfileInfoCache : public ProfileInfoInterface,
size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
// Warning: This will re-sort profiles and thus may change indices!
void SetNameOfProfileAtIndex(size_t index, const base::string16& name);
void SetLocalProfileNameOfProfileAtIndex(size_t index,
const base::string16& name);
void SetAuthInfoOfProfileAtIndex(size_t index,
const std::string& gaia_id,
const base::string16& user_name,
......@@ -137,6 +140,9 @@ class ProfileInfoCache : public ProfileInfoInterface,
const base::FilePath& GetUserDataDir() const;
// Gets the name of the profile, which is the one displayed in the User Menu.
base::string16 GetNameToDisplayOfProfileAtIndex(size_t index);
// Register cache related preferences in Local State.
static void RegisterPrefs(PrefRegistrySimple* registry);
......@@ -155,6 +161,10 @@ class ProfileInfoCache : public ProfileInfoInterface,
bool GetProfileAttributesWithPath(const base::FilePath& path,
ProfileAttributesEntry** entry) override;
static const char kNameKey[];
static const char kGAIANameKey[];
static const char kGAIAGivenNameKey[];
private:
FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
DownloadHighResAvatarTest);
......
......@@ -217,7 +217,7 @@ TEST_F(ProfileListDesktopTest, ModifyingNameResortsCorrectly) {
ProfileAttributesEntry* entry;
ASSERT_TRUE(manager()->profile_attributes_storage()->
GetProfileAttributesWithPath(profile1->GetPath(), &entry));
entry->SetName(ASCIIToUTF16(newname1));
entry->SetLocalProfileName(ASCIIToUTF16(newname1));
EXPECT_EQ(1, change_count());
// Now the first menu item should be named "beta", and the second be "gamma".
......
......@@ -1009,7 +1009,7 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
// data in the profile attributes storage.
if (has_entry) {
avatar_index = entry->GetAvatarIconIndex();
profile_name = base::UTF16ToUTF8(entry->GetName());
profile_name = base::UTF16ToUTF8(entry->GetLocalProfileName());
supervised_user_id = entry->GetSupervisedUserId();
} else if (profile->GetPath() ==
profiles::GetDefaultProfileDir(user_data_dir())) {
......@@ -1030,8 +1030,9 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex))
profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index);
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName))
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) {
profile->GetPrefs()->SetString(prefs::kProfileName, profile_name);
}
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool force_supervised_user_id =
......
......@@ -1444,7 +1444,7 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) {
// We should display custom names for local profiles.
const base::string16 custom_profile_name = ASCIIToUTF16("Batman");
ProfileAttributesEntry* entry = storage.GetAllProfilesAttributes()[0];
entry->SetName(custom_profile_name);
entry->SetLocalProfileName(custom_profile_name);
entry->SetIsUsingDefaultName(false);
EXPECT_EQ(custom_profile_name, entry->GetName());
EXPECT_EQ(custom_profile_name,
......@@ -1501,13 +1501,17 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) {
entry->SetGAIAGivenName(gaia_given_name);
EXPECT_EQ(gaia_given_name, entry->GetName());
EXPECT_EQ(gaia_given_name,
profiles::GetAvatarNameForProfile(profile1->GetPath()));
profiles::GetAvatarNameForProfile(profile1->GetPath()));
// Multiple profiles means displaying the actual profile names.
const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u);
Profile* profile2 = AddProfileToStorage(profile_manager,
"path_2", profile_name2);
EXPECT_EQ(gaia_given_name,
base::string16 expected_profile_name(gaia_given_name);
expected_profile_name.append(ASCIIToUTF16(" ("));
expected_profile_name.append(profile_name1);
expected_profile_name.append(ASCIIToUTF16(")"));
EXPECT_EQ(expected_profile_name,
profiles::GetAvatarNameForProfile(profile1->GetPath()));
EXPECT_EQ(profile_name2,
profiles::GetAvatarNameForProfile(profile2->GetPath()));
......@@ -1576,7 +1580,7 @@ TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) {
// Adding a Gaia name to a profile that previously had a default name should
// start displaying it.
const base::string16 gaia_given_name(ASCIIToUTF16("Robin"));
const base::string16 gaia_given_name(ASCIIToUTF16("Robin (Person 1)"));
ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile1->GetPath(),
&entry));
entry->SetGAIAGivenName(gaia_given_name);
......
......@@ -199,7 +199,7 @@ bool ProfileMetrics::CountProfileInformation(ProfileManager* manager,
counts->unused++;
} else {
counts->active++;
if (!storage.IsDefaultProfileName(entry->GetName()))
if (!storage.IsDefaultProfileName(entry->GetLocalProfileName()))
counts->named++;
if (entry->IsSupervised())
counts->supervised++;
......
......@@ -314,8 +314,8 @@ class ProfileShortcutManagerTest : public testing::Test {
ProfileAttributesEntry* entry;
ASSERT_TRUE(profile_attributes_storage_->
GetProfileAttributesWithPath(profile_path, &entry));
ASSERT_NE(entry->GetName(), new_profile_name);
entry->SetName(new_profile_name);
ASSERT_NE(entry->GetLocalProfileName(), new_profile_name);
entry->SetLocalProfileName(new_profile_name);
task_environment_.RunUntilIdle();
}
......@@ -783,7 +783,7 @@ TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) {
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
const base::string16 new_profile_3_name = L"New Name 3";
entry_3->SetName(new_profile_3_name);
entry_3->SetLocalProfileName(new_profile_3_name);
task_environment_.RunUntilIdle();
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_3_name));
......@@ -793,7 +793,7 @@ TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) {
ProfileAttributesEntry* entry_2;
ASSERT_TRUE(profile_attributes_storage_->
GetProfileAttributesWithPath(profile_2_path_, &entry_2));
entry_2->SetName(new_profile_2_name);
entry_2->SetLocalProfileName(new_profile_2_name);
task_environment_.RunUntilIdle();
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
......
......@@ -133,7 +133,12 @@ void UpdateProfileName(Profile* profile,
return;
}
if (new_profile_name == entry->GetName())
base::string16 current_profile_name =
base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName)
? entry->GetLocalProfileName()
: entry->GetName();
if (new_profile_name == current_profile_name)
return;
// This is only called when updating the profile name through the UI,
......
......@@ -152,7 +152,10 @@ ProfileInfoHandler::GetAccountNameAndIcon() const {
if (g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
name = base::UTF16ToUTF8(entry->GetName());
name = base::UTF16ToUTF8(
base::FeatureList::IsEnabled(kConcatenateGaiaAndProfileName)
? entry->GetLocalProfileName()
: entry->GetName());
// TODO(crbug.com/710660): return chrome://theme/IDR_PROFILE_AVATAR_*
// and update theme_source.cc to get high res avatar icons. This does less
// work here, sends less over IPC, and is more stable with returned results.
......
......@@ -121,7 +121,7 @@ TestingProfile* TestingProfileManager::CreateTestingProfile(
DCHECK(success);
entry->SetAvatarIconIndex(avatar_id);
entry->SetSupervisedUserId(supervised_user_id);
entry->SetName(user_name);
entry->SetLocalProfileName(user_name);
testing_profiles_.insert(std::make_pair(profile_name, profile_ptr));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment