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

[Profile names]: Never show the profile name if it's equal to GAIA name.

We never show the profile name if it is equal to GAIA name, e.g. Matt
(Matt), in that case the profile name will be the GAIA name: Matt. In
case of ambiguity, we prefer showing 'Person n' over showing redundancy.

Bug: 1022438
Change-Id: I8f5e6a959a70ded588b435000a69e59bf7e2a762
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904189Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Monica Basta <msalama@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713500}
parent 2f256141
...@@ -131,51 +131,43 @@ base::string16 ProfileAttributesEntry::GetGAIANameToDisplay() const { ...@@ -131,51 +131,43 @@ base::string16 ProfileAttributesEntry::GetGAIANameToDisplay() const {
bool ProfileAttributesEntry::ShouldShowProfileLocalName( bool ProfileAttributesEntry::ShouldShowProfileLocalName(
const base::string16& gaia_name_to_display) const { const base::string16& gaia_name_to_display) const {
bool is_using_default_name = IsUsingDefaultName(); // Never show the profile name if it is equal to GAIA given name,
// e.g. Matt (Matt), in that case we should only show the GAIA name.
if (base::EqualsCaseInsensitiveASCII(gaia_name_to_display,
GetLocalProfileName())) {
return false;
}
// Customized profile name that is not equal to Gaia name. // Customized profile name that is not equal to Gaia name, e.g. Matt (Work).
if (!is_using_default_name && if (!IsUsingDefaultName())
!base::EqualsCaseInsensitiveASCII(gaia_name_to_display,
GetLocalProfileName())) {
return true; return true;
}
// The profile local name is a default profile name : Person n.
std::vector<ProfileAttributesEntry*> entries = std::vector<ProfileAttributesEntry*> entries =
profile_info_cache_->GetAllProfilesAttributes(); profile_info_cache_->GetAllProfilesAttributes();
for (ProfileAttributesEntry* entry : entries) { for (ProfileAttributesEntry* entry : entries) {
if (entry == this) { if (entry == this)
continue; continue;
}
base::string16 other_gaia_name_to_display = entry->GetGAIANameToDisplay(); base::string16 other_gaia_name_to_display = entry->GetGAIANameToDisplay();
if (other_gaia_name_to_display.empty() || if (other_gaia_name_to_display.empty() ||
other_gaia_name_to_display != gaia_name_to_display) other_gaia_name_to_display != gaia_name_to_display)
continue; continue;
bool other_is_using_default_name = entry->IsUsingDefaultName(); // Another profile with the same GAIA name.
if (is_using_default_name) { bool other_profile_name_equal_GAIA_name = base::EqualsCaseInsensitiveASCII(
// Both profiles have a default profile name. other_gaia_name_to_display, entry->GetLocalProfileName());
if (other_is_using_default_name) { // If for the other profile, the profile name is equal to GAIA name then it
return true; // will not be shown. For disambiguation, show for the current profile the
} // profile name even if it is Person n.
// The other profile name will be shown, no need to show |Person %n|. if (other_profile_name_equal_GAIA_name)
continue;
}
// Current profile has a custom profile name that is equal to GAIA name.
if (other_is_using_default_name) {
// The other profile has a default profile name (Person %n) that will not
// be shown. Show the profile name for this profile to clear ambiguity.
return true; return true;
}
// The other profile has a custom name. If for both profiles, the profile bool other_is_using_default_name = entry->IsUsingDefaultName();
// name is equal to Gaia name, then the profile name must be shown for both // Both profiles have a default profile name,
// of them. // e.g. Matt (Person 1), Matt (Person 2).
base::string16 other_local_profile_name = entry->GetLocalProfileName(); if (other_is_using_default_name) {
if (base::EqualsCaseInsensitiveASCII(other_gaia_name_to_display,
other_local_profile_name)) {
return true; return true;
} }
} }
......
...@@ -314,6 +314,7 @@ TEST_F(ProfileInfoCacheTest, ConcatenateGaiaNameAndProfileName) { ...@@ -314,6 +314,7 @@ TEST_F(ProfileInfoCacheTest, ConcatenateGaiaNameAndProfileName) {
GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("patt")); GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("patt"));
EXPECT_EQ(ASCIIToUTF16("Patt"), EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1)); GetCache()->GetNameToDisplayOfProfileAtIndex(index1));
// Multiple profiles. // Multiple profiles.
// Add another profile with the same GAIA name and a default profile name. // Add another profile with the same GAIA name and a default profile name.
GetCache()->AddProfileToCache( GetCache()->AddProfileToCache(
...@@ -383,27 +384,19 @@ TEST_F(ProfileInfoCacheTest, ConcatenateGaiaNameAndProfileName) { ...@@ -383,27 +384,19 @@ TEST_F(ProfileInfoCacheTest, ConcatenateGaiaNameAndProfileName) {
EXPECT_EQ(ASCIIToUTF16("Patt (Personal)"), EXPECT_EQ(ASCIIToUTF16("Patt (Personal)"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3)); GetCache()->GetNameToDisplayOfProfileAtIndex(index3));
// Set one of the profile names to be equal to GAIA name, we should still show // Set one of the profile names to be equal to GAIA name, we should show
// the profile name to clear ambiguity. // the profile name even if it is Person n to clear ambiguity.
GetCache()->SetLocalProfileNameOfProfileAtIndex(index3, ASCIIToUTF16("patt")); GetCache()->SetLocalProfileNameOfProfileAtIndex(index3, ASCIIToUTF16("patt"));
EXPECT_EQ(ASCIIToUTF16("Patt"), EXPECT_EQ(ASCIIToUTF16("Patt (Person 1)"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1));
EXPECT_EQ(ASCIIToUTF16("Patt (patt)"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3));
// One profile with a custom name and another profile with a custom name equal
// to GAIA name.
GetCache()->SetProfileIsUsingDefaultNameAtIndex(index1, false);
GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("Work"));
EXPECT_EQ(ASCIIToUTF16("Patt (Work)"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1)); GetCache()->GetNameToDisplayOfProfileAtIndex(index1));
EXPECT_EQ(ASCIIToUTF16("Patt"), EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3)); GetCache()->GetNameToDisplayOfProfileAtIndex(index3));
// Never show the profile name if it is equal GAIA name.
GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("Patt")); GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("Patt"));
EXPECT_EQ(ASCIIToUTF16("Patt (Patt)"), EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1)); GetCache()->GetNameToDisplayOfProfileAtIndex(index1));
EXPECT_EQ(ASCIIToUTF16("Patt (patt)"), EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3)); GetCache()->GetNameToDisplayOfProfileAtIndex(index3));
EXPECT_EQ(ASCIIToUTF16("Olly"), EXPECT_EQ(ASCIIToUTF16("Olly"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index2)); GetCache()->GetNameToDisplayOfProfileAtIndex(index2));
......
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