OLD | NEW |
---|---|
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 Loading... | |
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 GetAvatarButtonDisplayNameForProfile(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) |
rpetterson
2014/02/20 21:41:32
shouldn't this be at least 0?
noms (inactive)
2014/02/24 22:35:06
Not always. GetIndexOfProfile returns std::string:
| |
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, it should display | |
69 // IDS_SINGLE_PROFILE_DISPLAY_NAME. If this is a signed in profile, or | |
70 // the user has edited the profile name, it should display the actual | |
71 // name of the profile. In all other cases, it should also display the | |
72 // actual name of the profile. | |
73 base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); | |
74 bool has_default_name = profile_name.find(l10n_util::GetStringFUTF16( | |
75 IDS_NEW_NUMBERED_PROFILE_NAME, base::string16())) != std::string::npos; | |
76 | |
77 if (cache.GetNumberOfProfiles() == 1 && has_default_name && | |
78 cache.GetUserNameOfProfileAtIndex(index).empty()) { | |
79 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | |
80 } else { | |
81 display_name = profile_name; | |
82 } | |
65 } | 83 } |
66 return profile_name; | 84 return display_name; |
67 } | 85 } |
68 | 86 |
69 void UpdateProfileName(Profile* profile, | 87 void UpdateProfileName(Profile* profile, |
70 const base::string16& new_profile_name) { | 88 const base::string16& new_profile_name) { |
71 ProfileInfoCache& cache = | 89 ProfileInfoCache& cache = |
72 g_browser_process->profile_manager()->GetProfileInfoCache(); | 90 g_browser_process->profile_manager()->GetProfileInfoCache(); |
73 base::FilePath profile_file_path = profile->GetPath(); | 91 base::FilePath profile_file_path = profile->GetPath(); |
74 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 92 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
75 | 93 |
76 if ((new_profile_name == | 94 if ((new_profile_name == |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 | 130 |
113 return accounts; | 131 return accounts; |
114 } | 132 } |
115 | 133 |
116 bool IsRegularOrGuestSession(Browser* browser) { | 134 bool IsRegularOrGuestSession(Browser* browser) { |
117 Profile* profile = browser->profile(); | 135 Profile* profile = browser->profile(); |
118 return profile->IsGuestSession() || !profile->IsOffTheRecord(); | 136 return profile->IsGuestSession() || !profile->IsOffTheRecord(); |
119 } | 137 } |
120 | 138 |
121 } // namespace profiles | 139 } // namespace profiles |
OLD | NEW |