| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ProfileInfoCache& cache = | 60 ProfileInfoCache& cache = |
| 61 g_browser_process->profile_manager()->GetProfileInfoCache(); | 61 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 62 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 62 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
| 63 | 63 |
| 64 if (index == std::string::npos) | 64 if (index == std::string::npos) |
| 65 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 65 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 66 | 66 |
| 67 // Using the --new-avatar-menu flag, there's a couple of rules about what | 67 // Using the --new-avatar-menu flag, there's a couple of rules about what |
| 68 // the avatar button displays. If there's a single profile, with a default | 68 // the avatar button displays. If there's a single profile, with a default |
| 69 // name (i.e. of the form Person %d) not manually set, it should display | 69 // name (i.e. of the form Person %d) not manually set, it should display |
| 70 // IDS_SINGLE_PROFILE_DISPLAY_NAME. Otherwise, it will return the actual | 70 // IDS_SINGLE_PROFILE_DISPLAY_NAME. If the profile is signed in but is using |
| 71 // name of the profile. | 71 // a default name, use the profiles's email address. Otherwise, it |
| 72 base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); | 72 // will return the actual name of the profile. |
| 73 bool has_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index) && | 73 const base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); |
| 74 const base::string16 email = cache.GetUserNameOfProfileAtIndex(index); |
| 75 bool is_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index) && |
| 74 cache.IsDefaultProfileName(profile_name); | 76 cache.IsDefaultProfileName(profile_name); |
| 75 | 77 |
| 76 if (cache.GetNumberOfProfiles() == 1 && has_default_name) | 78 if (cache.GetNumberOfProfiles() == 1 && is_default_name) |
| 77 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 79 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 78 else | 80 else |
| 79 display_name = profile_name; | 81 display_name = (is_default_name && !email.empty()) ? email : profile_name; |
| 80 } | 82 } |
| 81 return display_name; | 83 return display_name; |
| 82 } | 84 } |
| 83 | 85 |
| 84 base::string16 GetAvatarButtonTextForProfile(Profile* profile) { | 86 base::string16 GetAvatarButtonTextForProfile(Profile* profile) { |
| 85 const int kMaxCharactersToDisplay = 15; | 87 const int kMaxCharactersToDisplay = 15; |
| 86 base::string16 name = GetAvatarNameForProfile(profile->GetPath()); | 88 base::string16 name = GetAvatarNameForProfile(profile->GetPath()); |
| 87 name = gfx::TruncateString(name, | 89 name = gfx::TruncateString(name, |
| 88 kMaxCharactersToDisplay, | 90 kMaxCharactersToDisplay, |
| 89 gfx::CHARACTER_BREAK); | 91 gfx::CHARACTER_BREAK); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); | 150 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 SigninErrorController* GetSigninErrorController(Profile* profile) { | 153 SigninErrorController* GetSigninErrorController(Profile* profile) { |
| 152 ProfileOAuth2TokenService* token_service = | 154 ProfileOAuth2TokenService* token_service = |
| 153 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 155 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 154 return token_service ? token_service->signin_error_controller() : NULL; | 156 return token_service ? token_service->signin_error_controller() : NULL; |
| 155 } | 157 } |
| 156 | 158 |
| 157 } // namespace profiles | 159 } // namespace profiles |
| OLD | NEW |