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 <stdio.h> |
| 8 |
7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
8 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
(...skipping 26 matching lines...) Expand all Loading... |
43 default_profile_dir.AppendASCII(chrome::kInitialProfile); | 45 default_profile_dir.AppendASCII(chrome::kInitialProfile); |
44 return default_profile_dir; | 46 return default_profile_dir; |
45 } | 47 } |
46 | 48 |
47 void RegisterPrefs(PrefRegistrySimple* registry) { | 49 void RegisterPrefs(PrefRegistrySimple* registry) { |
48 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); | 50 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); |
49 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 51 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
50 registry->RegisterListPref(prefs::kProfilesLastActive); | 52 registry->RegisterListPref(prefs::kProfilesLastActive); |
51 } | 53 } |
52 | 54 |
53 base::string16 GetActiveProfileDisplayName(Browser* browser) { | 55 base::string16 GetAvatarNameForProfile(Profile* profile) { |
54 base::string16 profile_name; | 56 base::string16 display_name; |
55 Profile* profile = browser->profile(); | |
56 | 57 |
57 if (profile->IsGuestSession()) { | 58 if (profile->IsGuestSession()) { |
58 profile_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); | 59 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); |
59 } else { | 60 } else { |
60 ProfileInfoCache& cache = | 61 ProfileInfoCache& cache = |
61 g_browser_process->profile_manager()->GetProfileInfoCache(); | 62 g_browser_process->profile_manager()->GetProfileInfoCache(); |
62 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 63 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
63 if (index != std::string::npos) | 64 |
64 profile_name = cache.GetNameOfProfileAtIndex(index); | 65 if (index == std::string::npos) |
| 66 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 67 |
| 68 // Using the --new-profile-management flag, there's a couple of rules |
| 69 // about what the avatar button displays. If there's a single, local |
| 70 // profile, with a default name (i.e. of the form Person %d), it should |
| 71 // display IDS_SINGLE_PROFILE_DISPLAY_NAME. If this is a signed in profile, |
| 72 // or the user has edited the profile name, or there are multiple profiles, |
| 73 // it will return the actual name of the profile. |
| 74 base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); |
| 75 std::string default_name_format = l10n_util::GetStringFUTF8( |
| 76 IDS_NEW_NUMBERED_PROFILE_NAME, base::string16()) + "%d"; |
| 77 int generic_profile_number; // Unused. Just a placeholder for sscanf. |
| 78 int assignments = sscanf(base::UTF16ToUTF8(profile_name).c_str(), |
| 79 default_name_format.c_str(), |
| 80 &generic_profile_number); |
| 81 bool has_default_name = (assignments == 1); |
| 82 |
| 83 if (cache.GetNumberOfProfiles() == 1 && has_default_name && |
| 84 cache.GetUserNameOfProfileAtIndex(index).empty()) { |
| 85 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 86 } else { |
| 87 display_name = profile_name; |
| 88 } |
65 } | 89 } |
66 return profile_name; | 90 return display_name; |
67 } | 91 } |
68 | 92 |
69 void UpdateProfileName(Profile* profile, | 93 void UpdateProfileName(Profile* profile, |
70 const base::string16& new_profile_name) { | 94 const base::string16& new_profile_name) { |
71 ProfileInfoCache& cache = | 95 ProfileInfoCache& cache = |
72 g_browser_process->profile_manager()->GetProfileInfoCache(); | 96 g_browser_process->profile_manager()->GetProfileInfoCache(); |
73 base::FilePath profile_file_path = profile->GetPath(); | 97 base::FilePath profile_file_path = profile->GetPath(); |
74 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 98 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
75 | 99 |
76 if ((new_profile_name == | 100 if ((new_profile_name == |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 136 |
113 return accounts; | 137 return accounts; |
114 } | 138 } |
115 | 139 |
116 bool IsRegularOrGuestSession(Browser* browser) { | 140 bool IsRegularOrGuestSession(Browser* browser) { |
117 Profile* profile = browser->profile(); | 141 Profile* profile = browser->profile(); |
118 return profile->IsGuestSession() || !profile->IsOffTheRecord(); | 142 return profile->IsGuestSession() || !profile->IsOffTheRecord(); |
119 } | 143 } |
120 | 144 |
121 } // namespace profiles | 145 } // namespace profiles |
OLD | NEW |