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

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

Issue 381953002: New avatar button: Consolidate text elision between Mac and Win/Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/gaia_info_update_service.h" 12 #include "chrome/browser/profiles/gaia_info_update_service.h"
13 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" 13 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
16 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "components/signin/core/browser/profile_oauth2_token_service.h" 21 #include "components/signin/core/browser/profile_oauth2_token_service.h"
22 #include "components/signin/core/common/profile_management_switches.h" 22 #include "components/signin/core/common/profile_management_switches.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/font_list.h"
26 #include "ui/gfx/text_elider.h"
25 27
26 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
27 #include "chrome/browser/chromeos/login/users/user_manager.h" 29 #include "chrome/browser/chromeos/login/users/user_manager.h"
28 #endif 30 #endif
29 31
30 namespace profiles { 32 namespace profiles {
31 33
32 bool IsMultipleProfilesEnabled() { 34 bool IsMultipleProfilesEnabled() {
33 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
34 return false; 36 return false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (cache.GetNumberOfProfiles() == 1 && has_default_name && 76 if (cache.GetNumberOfProfiles() == 1 && has_default_name &&
75 cache.GetUserNameOfProfileAtIndex(index).empty()) { 77 cache.GetUserNameOfProfileAtIndex(index).empty()) {
76 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); 78 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
77 } else { 79 } else {
78 display_name = profile_name; 80 display_name = profile_name;
79 } 81 }
80 } 82 }
81 return display_name; 83 return display_name;
82 } 84 }
83 85
86 base::string16 GetAvatarButtonTextForProfile(Profile* profile,
87 const gfx::FontList& font_list) {
88 const int kMaxCharactersToDisplay = 15;
noms (inactive) 2014/07/11 13:21:57 I think msw had suggested we use a max size, and n
msw 2014/07/11 22:17:06 My goal is to remove the explicit call to ElideTex
89 base::string16 name = GetAvatarNameForProfile(profile->GetPath());
90 name = gfx::ElideText(name,
91 font_list,
92 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay),
msw 2014/07/16 16:58:28 Could you use gfx::TruncateString instead, since y
Marc Treib 2014/07/17 08:43:00 Well, that depends on what exactly the intended be
93 gfx::ELIDE_TAIL);
94 if (profile->IsSupervised())
95 name = l10n_util::GetStringFUTF16(IDS_SUPERVISED_USER_NEW_AVATAR_LABEL,
96 name);
97 return name;
98 }
99
84 void UpdateProfileName(Profile* profile, 100 void UpdateProfileName(Profile* profile,
85 const base::string16& new_profile_name) { 101 const base::string16& new_profile_name) {
86 PrefService* pref_service = profile->GetPrefs(); 102 PrefService* pref_service = profile->GetPrefs();
87 // Updating the profile preference will cause the cache to be updated for 103 // Updating the profile preference will cause the cache to be updated for
88 // this preference. 104 // this preference.
89 pref_service->SetString(prefs::kProfileName, 105 pref_service->SetString(prefs::kProfileName,
90 base::UTF16ToUTF8(new_profile_name)); 106 base::UTF16ToUTF8(new_profile_name));
91 } 107 }
92 108
93 std::vector<std::string> GetSecondaryAccountsForProfile( 109 std::vector<std::string> GetSecondaryAccountsForProfile(
(...skipping 28 matching lines...) Expand all
122 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); 138 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update();
123 } 139 }
124 140
125 SigninErrorController* GetSigninErrorController(Profile* profile) { 141 SigninErrorController* GetSigninErrorController(Profile* profile) {
126 ProfileOAuth2TokenService* token_service = 142 ProfileOAuth2TokenService* token_service =
127 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 143 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
128 return token_service ? token_service->signin_error_controller() : NULL; 144 return token_service ? token_service->signin_error_controller() : NULL;
129 } 145 }
130 146
131 } // namespace profiles 147 } // namespace profiles
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profiles_state.h ('k') | chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698