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

Side by Side Diff: chrome/browser/profiles/profiles_state.cc

Issue 171523004: Stop using the old-style profile names when using --new-profile-management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profiles_state.h" 5 #include "chrome/browser/profiles/profiles_state.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 default_profile_dir.AppendASCII(chrome::kInitialProfile); 43 default_profile_dir.AppendASCII(chrome::kInitialProfile);
44 return default_profile_dir; 44 return default_profile_dir;
45 } 45 }
46 46
47 void RegisterPrefs(PrefRegistrySimple* registry) { 47 void RegisterPrefs(PrefRegistrySimple* registry) {
48 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); 48 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string());
49 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); 49 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
50 registry->RegisterListPref(prefs::kProfilesLastActive); 50 registry->RegisterListPref(prefs::kProfilesLastActive);
51 } 51 }
52 52
53 base::string16 GetActiveProfileDisplayName(Browser* browser) { 53 base::string16 GetAvatarNameForProfile(Profile* profile) {
54 base::string16 profile_name; 54 base::string16 display_name;
55 Profile* profile = browser->profile();
56 55
57 if (profile->IsGuestSession()) { 56 if (profile->IsGuestSession()) {
58 profile_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); 57 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME);
59 } else { 58 } else {
60 ProfileInfoCache& cache = 59 ProfileInfoCache& cache =
61 g_browser_process->profile_manager()->GetProfileInfoCache(); 60 g_browser_process->profile_manager()->GetProfileInfoCache();
62 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 61 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
63 if (index != std::string::npos) 62
64 profile_name = cache.GetNameOfProfileAtIndex(index); 63 if (index == std::string::npos)
64 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
65
66 // Using the --new-profile-management flag, there's a couple of rules
67 // about what the avatar button displays. If there's a single, local
68 // profile, with a default name (i.e. of the form Person %d), it should
69 // display IDS_SINGLE_PROFILE_DISPLAY_NAME. If this is a signed in profile,
70 // or the user has edited the profile name, or there are multiple profiles,
71 // it will return the actual name of the profile.
72 base::string16 profile_name = cache.GetNameOfProfileAtIndex(index);
73 std::string default_name_format = l10n_util::GetStringFUTF8(
74 IDS_NEW_NUMBERED_PROFILE_NAME, base::string16()) + "%d";
75 int generic_profile_number; // Unused. Just a placeholder for sscanf.
76 int assignments = std::sscanf(UTF16ToUTF8(profile_name).c_str(),
77 default_name_format.c_str(),
78 &generic_profile_number);
79 bool has_default_name = (assignments == 1);
80
81 if (cache.GetNumberOfProfiles() == 1 && has_default_name &&
82 cache.GetUserNameOfProfileAtIndex(index).empty()) {
83 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
84 } else {
85 display_name = profile_name;
86 }
65 } 87 }
66 return profile_name; 88 return display_name;
67 } 89 }
68 90
69 void UpdateProfileName(Profile* profile, 91 void UpdateProfileName(Profile* profile,
70 const base::string16& new_profile_name) { 92 const base::string16& new_profile_name) {
71 ProfileInfoCache& cache = 93 ProfileInfoCache& cache =
72 g_browser_process->profile_manager()->GetProfileInfoCache(); 94 g_browser_process->profile_manager()->GetProfileInfoCache();
73 base::FilePath profile_file_path = profile->GetPath(); 95 base::FilePath profile_file_path = profile->GetPath();
74 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 96 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
75 97
76 if ((new_profile_name == 98 if ((new_profile_name ==
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 134
113 return accounts; 135 return accounts;
114 } 136 }
115 137
116 bool IsRegularOrGuestSession(Browser* browser) { 138 bool IsRegularOrGuestSession(Browser* browser) {
117 Profile* profile = browser->profile(); 139 Profile* profile = browser->profile();
118 return profile->IsGuestSession() || !profile->IsOffTheRecord(); 140 return profile->IsGuestSession() || !profile->IsOffTheRecord();
119 } 141 }
120 142
121 } // namespace profiles 143 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698