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

Side by Side Diff: chrome/browser/signin/signin_ui_util.cc

Issue 2393643004: [MD Settings][People] Updates positions of username and sync status message (Closed)
Patch Set: rebase Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/signin/signin_ui_util.h" 5 #include "chrome/browser/signin/signin_ui_util.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/signin/account_tracker_service_factory.h" 11 #include "chrome/browser/signin/account_tracker_service_factory.h"
12 #include "chrome/browser/signin/signin_error_controller_factory.h" 12 #include "chrome/browser/signin/signin_error_controller_factory.h"
13 #include "chrome/browser/signin/signin_global_error.h" 13 #include "chrome/browser/signin/signin_global_error.h"
14 #include "chrome/browser/signin/signin_global_error_factory.h" 14 #include "chrome/browser/signin/signin_global_error_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/sync/profile_sync_service_factory.h" 16 #include "chrome/browser/sync/profile_sync_service_factory.h"
17 #include "chrome/browser/sync/sync_global_error.h" 17 #include "chrome/browser/sync/sync_global_error.h"
18 #include "chrome/browser/sync/sync_global_error_factory.h" 18 #include "chrome/browser/sync/sync_global_error_factory.h"
19 #include "chrome/browser/ui/browser_navigator.h" 19 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_navigator_params.h" 20 #include "chrome/browser/ui/browser_navigator_params.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/grit/chromium_strings.h" 22 #include "chrome/grit/chromium_strings.h"
23 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "components/browser_sync/profile_sync_service.h" 24 #include "components/browser_sync/profile_sync_service.h"
25 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
26 #include "components/signin/core/browser/account_tracker_service.h" 26 #include "components/signin/core/browser/account_tracker_service.h"
27 #include "components/signin/core/browser/signin_manager.h" 27 #include "components/signin/core/browser/signin_manager.h"
28 #include "components/signin/core/common/profile_management_switches.h" 28 #include "components/signin/core/common/profile_management_switches.h"
29 #include "components/strings/grit/components_strings.h" 29 #include "components/strings/grit/components_strings.h"
30 #include "components/user_manager/user_manager.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/gfx/font_list.h" 32 #include "ui/gfx/font_list.h"
32 #include "ui/gfx/text_elider.h" 33 #include "ui/gfx/text_elider.h"
33 34
34 namespace signin_ui_util { 35 namespace signin_ui_util {
35 36
36 namespace { 37 namespace {
37 38
38 // Maximum width of a username - we trim emails that are wider than this so 39 // Maximum width of a username - we trim emails that are wider than this so
39 // the wrench menu doesn't get ridiculously wide. 40 // the wrench menu doesn't get ridiculously wide.
(...skipping 29 matching lines...) Expand all
69 // object associated with that service, or null if no errors are reported. 70 // object associated with that service, or null if no errors are reported.
70 GlobalError* GetSignedInServiceError(Profile* profile) { 71 GlobalError* GetSignedInServiceError(Profile* profile) {
71 std::vector<GlobalError*> errors = GetSignedInServiceErrors(profile); 72 std::vector<GlobalError*> errors = GetSignedInServiceErrors(profile);
72 if (errors.empty()) 73 if (errors.empty())
73 return nullptr; 74 return nullptr;
74 return errors[0]; 75 return errors[0];
75 } 76 }
76 77
77 } // namespace 78 } // namespace
78 79
80 base::string16 GetAuthenticatedUsername(const SigninManagerBase* signin) {
81 std::string user_display_name;
82
83 if (signin->IsAuthenticated()) {
84 user_display_name = signin->GetAuthenticatedAccountInfo().email;
85
86 #if defined(OS_CHROMEOS)
87 if (user_manager::UserManager::IsInitialized()) {
88 // On CrOS user email is sanitized and then passed to the signin manager.
89 // Original email (containing dots) is stored as "display email".
90 user_display_name = user_manager::UserManager::Get()->GetUserDisplayEmail(
91 AccountId::FromUserEmail(user_display_name));
92 }
93 #endif // defined(OS_CHROMEOS)
94 }
95
96 return base::UTF8ToUTF16(user_display_name);
97 }
98
79 base::string16 GetSigninMenuLabel(Profile* profile) { 99 base::string16 GetSigninMenuLabel(Profile* profile) {
80 GlobalError* error = signin_ui_util::GetSignedInServiceError(profile); 100 GlobalError* error = signin_ui_util::GetSignedInServiceError(profile);
81 if (error) 101 if (error)
82 return error->MenuItemLabel(); 102 return error->MenuItemLabel();
83 103
84 // No errors, so just display the signed in user, if any. 104 // No errors, so just display the signed in user, if any.
85 browser_sync::ProfileSyncService* service = 105 browser_sync::ProfileSyncService* service =
86 profile->IsSyncAllowed() 106 profile->IsSyncAllowed()
87 ? ProfileSyncServiceFactory::GetForProfile(profile) 107 ? ProfileSyncServiceFactory::GetForProfile(profile)
88 : nullptr; 108 : nullptr;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 std::string email = account_tracker->GetAccountInfo(account_id).email; 209 std::string email = account_tracker->GetAccountInfo(account_id).email;
190 if (email.empty()) { 210 if (email.empty()) {
191 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, 211 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED,
192 account_tracker->GetMigrationState()); 212 account_tracker->GetMigrationState());
193 return account_id; 213 return account_id;
194 } 214 }
195 return email; 215 return email;
196 } 216 }
197 217
198 } // namespace signin_ui_util 218 } // namespace signin_ui_util
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_ui_util.h ('k') | chrome/browser/sync/profile_sync_service_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698