Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1422)

Unified Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 186803003: Use custom profile names (if available) for signed in profiles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0ae399f5310c4395719e44bcea6adb0de3df6d3d..b06aaaf79163211884753dd2dfe1f3d431b45122 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -44,6 +44,7 @@ const char kGAIANameKey[] = "gaia_name";
const char kGAIAGivenNameKey[] = "gaia_given_name";
const char kUseGAIANameKey[] = "use_gaia_name";
const char kUserNameKey[] = "user_name";
+const char kIsUsingDefaultName[] = "is_using_default_name";
const char kAvatarIconKey[] = "avatar_icon";
const char kAuthCredentialsKey[] = "local_auth_credentials";
const char kUseGAIAPictureKey[] = "use_gaia_picture";
@@ -173,6 +174,29 @@ 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,
@@ -196,6 +220,7 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
info->Remove(kIsManagedKey, NULL);
info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string());
}
+ info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name));
}
}
@@ -222,6 +247,7 @@ void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
info->SetString(kManagedUserId, managed_user_id);
info->SetBoolean(kIsOmittedFromProfileListKey, !managed_user_id.empty());
info->SetBoolean(kProfileIsEphemeral, false);
+ info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name));
cache->SetWithoutPathExpansion(key, info.release());
sorted_keys_.insert(FindPositionForProfile(key, name), key);
@@ -291,11 +317,13 @@ size_t ProfileInfoCache::GetIndexOfProfileWithPath(
base::string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const {
base::string16 name;
- if (IsUsingGAIANameOfProfileAtIndex(index)) {
+ // Unless the user has customized the profile name, we should use the
+ // profile's Gaia given name, if it's available.
+ if (IsUsingGAIANameOfProfileAtIndex(index) &&
+ ProfileIsUsingDefaultNameAtIndex(index)) {
base::string16 given_name = GetGAIAGivenNameOfProfileAtIndex(index);
name = given_name.empty() ? GetGAIANameOfProfileAtIndex(index) : given_name;
}
-
if (name.empty())
GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name);
return name;
@@ -441,6 +469,12 @@ bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const {
return value;
}
+bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const {
+ bool value = false;
+ GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultName, &value);
+ return value;
+}
+
void ProfileInfoCache::OnGAIAPictureLoaded(const base::FilePath& path,
gfx::Image** image) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -513,6 +547,8 @@ void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
base::string16 old_display_name = GetNameOfProfileAtIndex(index);
info->SetString(kNameKey, name);
+ info->SetBoolean(kIsUsingDefaultName, false);
+
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
base::string16 new_display_name = GetNameOfProfileAtIndex(index);
@@ -762,6 +798,18 @@ void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) {
SetInfoForProfileAtIndex(index, info.release());
}
+void ProfileInfoCache::SetProfileIsUsingDefaultNameAtIndex(
+ size_t index, bool value) {
+ if (value == ProfileIsUsingDefaultNameAtIndex(index))
+ return;
+
+ scoped_ptr<base::DictionaryValue> info(
+ GetInfoForProfileAtIndex(index)->DeepCopy());
+ info->SetBoolean(kIsUsingDefaultName, value);
+ // This takes ownership of |info|.
+ SetInfoForProfileAtIndex(index, info.release());
+}
+
base::string16 ProfileInfoCache::ChooseNameForNewProfile(
size_t icon_index) const {
base::string16 name;
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698