| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 if (profile_path == ProfileManager::GetGuestProfilePath()) { | 52 if (profile_path == ProfileManager::GetGuestProfilePath()) { |
| 53 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); | 53 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); |
| 54 } else { | 54 } else { |
| 55 ProfileInfoCache& cache = | 55 ProfileInfoCache& cache = |
| 56 g_browser_process->profile_manager()->GetProfileInfoCache(); | 56 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 57 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 57 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
| 58 | 58 |
| 59 if (index == std::string::npos) | 59 if (index == std::string::npos) |
| 60 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 60 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 61 | 61 |
| 62 // Using the --new-profile-management flag, there's a couple of rules | 62 // Using the --new-avatar-menu flag, there's a couple of rules about what |
| 63 // about what the avatar button displays. If there's a single, local | 63 // the avatar button displays. If there's a single profile, with a default |
| 64 // profile, with a default name (i.e. of the form Person %d), it should | 64 // name (i.e. of the form Person %d) not manually set, it should display |
| 65 // display IDS_SINGLE_PROFILE_DISPLAY_NAME. If this is a signed in profile, | 65 // IDS_SINGLE_PROFILE_DISPLAY_NAME. Otherwise, it will return the actual |
| 66 // or the user has edited the profile name, or there are multiple profiles, | 66 // name of the profile. |
| 67 // it will return the actual name of the profile. | |
| 68 base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); | 67 base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); |
| 69 bool has_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index); | 68 bool has_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index) && |
| 69 cache.IsDefaultProfileName(profile_name); |
| 70 | 70 |
| 71 if (cache.GetNumberOfProfiles() == 1 && has_default_name && | 71 if (cache.GetNumberOfProfiles() == 1 && has_default_name) |
| 72 cache.GetUserNameOfProfileAtIndex(index).empty()) { | |
| 73 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 72 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 74 } else { | 73 else |
| 75 display_name = profile_name; | 74 display_name = profile_name; |
| 76 } | |
| 77 } | 75 } |
| 78 return display_name; | 76 return display_name; |
| 79 } | 77 } |
| 80 | 78 |
| 81 base::string16 GetAvatarButtonTextForProfile(Profile* profile) { | 79 base::string16 GetAvatarButtonTextForProfile(Profile* profile) { |
| 82 const int kMaxCharactersToDisplay = 15; | 80 const int kMaxCharactersToDisplay = 15; |
| 83 base::string16 name = GetAvatarNameForProfile(profile->GetPath()); | 81 base::string16 name = GetAvatarNameForProfile(profile->GetPath()); |
| 84 name = gfx::TruncateString(name, | 82 name = gfx::TruncateString(name, |
| 85 kMaxCharactersToDisplay, | 83 kMaxCharactersToDisplay, |
| 86 gfx::CHARACTER_BREAK); | 84 gfx::CHARACTER_BREAK); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); | 143 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); |
| 146 } | 144 } |
| 147 | 145 |
| 148 SigninErrorController* GetSigninErrorController(Profile* profile) { | 146 SigninErrorController* GetSigninErrorController(Profile* profile) { |
| 149 ProfileOAuth2TokenService* token_service = | 147 ProfileOAuth2TokenService* token_service = |
| 150 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 148 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 151 return token_service ? token_service->signin_error_controller() : NULL; | 149 return token_service ? token_service->signin_error_controller() : NULL; |
| 152 } | 150 } |
| 153 | 151 |
| 154 } // namespace profiles | 152 } // namespace profiles |
| OLD | NEW |