Skip to content

Commit

Permalink
[Profile names]: Never show the profile name if it's equal to GAIA name.
Browse files Browse the repository at this point in the history
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/+/1904189
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Monica Basta <msalama@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713500}
  • Loading branch information
Monica Basta authored and Commit Bot committed Nov 7, 2019
1 parent 2f25614 commit beb4a57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 43 deletions.
50 changes: 21 additions & 29 deletions chrome/browser/profiles/profile_attributes_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,51 +131,43 @@ base::string16 ProfileAttributesEntry::GetGAIANameToDisplay() const {

bool ProfileAttributesEntry::ShouldShowProfileLocalName(
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.
if (!is_using_default_name &&
!base::EqualsCaseInsensitiveASCII(gaia_name_to_display,
GetLocalProfileName())) {
// Customized profile name that is not equal to Gaia name, e.g. Matt (Work).
if (!IsUsingDefaultName())
return true;
}

// The profile local name is a default profile name : Person n.
std::vector<ProfileAttributesEntry*> entries =
profile_info_cache_->GetAllProfilesAttributes();

for (ProfileAttributesEntry* entry : entries) {
if (entry == this) {
if (entry == this)
continue;
}

base::string16 other_gaia_name_to_display = entry->GetGAIANameToDisplay();
if (other_gaia_name_to_display.empty() ||
other_gaia_name_to_display != gaia_name_to_display)
continue;

bool other_is_using_default_name = entry->IsUsingDefaultName();
if (is_using_default_name) {
// Both profiles have a default profile name.
if (other_is_using_default_name) {
return true;
}
// The other profile name will be shown, no need to show |Person %n|.
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.
// Another profile with the same GAIA name.
bool other_profile_name_equal_GAIA_name = base::EqualsCaseInsensitiveASCII(
other_gaia_name_to_display, entry->GetLocalProfileName());
// If for the other profile, the profile name is equal to GAIA name then it
// will not be shown. For disambiguation, show for the current profile the
// profile name even if it is Person n.
if (other_profile_name_equal_GAIA_name)
return true;
}

// The other profile has a custom name. If for both profiles, the profile
// name is equal to Gaia name, then the profile name must be shown for both
// of them.
base::string16 other_local_profile_name = entry->GetLocalProfileName();
if (base::EqualsCaseInsensitiveASCII(other_gaia_name_to_display,
other_local_profile_name)) {
bool other_is_using_default_name = entry->IsUsingDefaultName();
// Both profiles have a default profile name,
// e.g. Matt (Person 1), Matt (Person 2).
if (other_is_using_default_name) {
return true;
}
}
Expand Down
21 changes: 7 additions & 14 deletions chrome/browser/profiles/profile_info_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ TEST_F(ProfileInfoCacheTest, ConcatenateGaiaNameAndProfileName) {
GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("patt"));
EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1));

// Multiple profiles.
// Add another profile with the same GAIA name and a default profile name.
GetCache()->AddProfileToCache(
Expand Down Expand Up @@ -383,27 +384,19 @@ TEST_F(ProfileInfoCacheTest, ConcatenateGaiaNameAndProfileName) {
EXPECT_EQ(ASCIIToUTF16("Patt (Personal)"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3));

// Set one of the profile names to be equal to GAIA name, we should still show
// the profile name to clear ambiguity.
// Set one of the profile names to be equal to GAIA name, we should show
// the profile name even if it is Person n to clear ambiguity.
GetCache()->SetLocalProfileNameOfProfileAtIndex(index3, ASCIIToUTF16("patt"));
EXPECT_EQ(ASCIIToUTF16("Patt"),
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)"),
EXPECT_EQ(ASCIIToUTF16("Patt (Person 1)"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1));
EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3));

// Never show the profile name if it is equal GAIA name.
GetCache()->SetLocalProfileNameOfProfileAtIndex(index1, ASCIIToUTF16("Patt"));
EXPECT_EQ(ASCIIToUTF16("Patt (Patt)"),
EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index1));
EXPECT_EQ(ASCIIToUTF16("Patt (patt)"),
EXPECT_EQ(ASCIIToUTF16("Patt"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index3));
EXPECT_EQ(ASCIIToUTF16("Olly"),
GetCache()->GetNameToDisplayOfProfileAtIndex(index2));
Expand Down

0 comments on commit beb4a57

Please sign in to comment.