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

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

Issue 2435053002: Remove the sign-in menu item on macOS. (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"
(...skipping 16 matching lines...) Expand all
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 "components/user_manager/user_manager.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/gfx/font_list.h" 32 #include "ui/gfx/font_list.h"
33 #include "ui/gfx/text_elider.h" 33 #include "ui/gfx/text_elider.h"
34 34
35 namespace signin_ui_util { 35 namespace signin_ui_util {
36 36
37 namespace {
38
39 // Maximum width of a username - we trim emails that are wider than this so
40 // the wrench menu doesn't get ridiculously wide.
41 const int kUsernameMaxWidth = 200;
42
43 // Returns all errors reported by signed in services.
44 std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile) {
45 std::vector<GlobalError*> errors;
46 // Chrome OS doesn't use SigninGlobalError or SyncGlobalError. Other platforms
47 // may use these services to show auth and sync errors in the toolbar menu.
48 #if !defined(OS_CHROMEOS)
49 // Auth errors have the highest priority - after that, individual service
50 // errors.
51 SigninGlobalError* signin_error =
52 SigninGlobalErrorFactory::GetForProfile(profile);
53 if (signin_error && signin_error->HasError())
54 errors.push_back(signin_error);
55
56 // No auth error - now try other services. Currently the list is just hard-
57 // coded but in the future if we add more we can create some kind of
58 // registration framework.
59 if (profile->IsSyncAllowed()) {
60 SyncGlobalError* error = SyncGlobalErrorFactory::GetForProfile(profile);
61 if (error && error->HasMenuItem())
62 errors.push_back(error);
63 }
64 #endif
65
66 return errors;
67 }
68
69 // If a signed in service is reporting an error, returns the GlobalError
70 // object associated with that service, or null if no errors are reported.
71 GlobalError* GetSignedInServiceError(Profile* profile) {
72 std::vector<GlobalError*> errors = GetSignedInServiceErrors(profile);
73 if (errors.empty())
74 return nullptr;
75 return errors[0];
76 }
77
78 } // namespace
79
80 base::string16 GetAuthenticatedUsername(const SigninManagerBase* signin) { 37 base::string16 GetAuthenticatedUsername(const SigninManagerBase* signin) {
81 std::string user_display_name; 38 std::string user_display_name;
82 39
83 if (signin->IsAuthenticated()) { 40 if (signin->IsAuthenticated()) {
84 user_display_name = signin->GetAuthenticatedAccountInfo().email; 41 user_display_name = signin->GetAuthenticatedAccountInfo().email;
85 42
86 #if defined(OS_CHROMEOS) 43 #if defined(OS_CHROMEOS)
87 if (user_manager::UserManager::IsInitialized()) { 44 if (user_manager::UserManager::IsInitialized()) {
88 // On CrOS user email is sanitized and then passed to the signin manager. 45 // On CrOS user email is sanitized and then passed to the signin manager.
89 // Original email (containing dots) is stored as "display email". 46 // Original email (containing dots) is stored as "display email".
90 user_display_name = user_manager::UserManager::Get()->GetUserDisplayEmail( 47 user_display_name = user_manager::UserManager::Get()->GetUserDisplayEmail(
91 AccountId::FromUserEmail(user_display_name)); 48 AccountId::FromUserEmail(user_display_name));
92 } 49 }
93 #endif // defined(OS_CHROMEOS) 50 #endif // defined(OS_CHROMEOS)
94 } 51 }
95 52
96 return base::UTF8ToUTF16(user_display_name); 53 return base::UTF8ToUTF16(user_display_name);
97 } 54 }
98 55
99 base::string16 GetSigninMenuLabel(Profile* profile) {
100 GlobalError* error = signin_ui_util::GetSignedInServiceError(profile);
101 if (error)
102 return error->MenuItemLabel();
103
104 // No errors, so just display the signed in user, if any.
105 browser_sync::ProfileSyncService* service =
106 profile->IsSyncAllowed()
107 ? ProfileSyncServiceFactory::GetForProfile(profile)
108 : nullptr;
109
110 // Even if the user is signed in, don't display the "signed in as..."
111 // label if we're still setting up sync.
112 if (!service || !service->IsFirstSetupInProgress()) {
113 std::string username;
114 SigninManagerBase* signin_manager =
115 SigninManagerFactory::GetForProfileIfExists(profile);
116 if (signin_manager)
117 username = signin_manager->GetAuthenticatedAccountInfo().email;
118 if (!username.empty() && !signin_manager->AuthInProgress()) {
119 const base::string16 elided = gfx::ElideText(base::UTF8ToUTF16(username),
120 gfx::FontList(), kUsernameMaxWidth, gfx::ELIDE_EMAIL);
121 return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL, elided);
122 }
123 }
124 return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_PRE_SYNCED_LABEL,
125 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
126 }
127
128 // Given an authentication state this helper function returns various labels 56 // Given an authentication state this helper function returns various labels
129 // that can be used to display information about the state. 57 // that can be used to display information about the state.
130 void GetStatusLabelsForAuthError(Profile* profile, 58 void GetStatusLabelsForAuthError(Profile* profile,
131 const SigninManagerBase& signin_manager, 59 const SigninManagerBase& signin_manager,
132 base::string16* status_label, 60 base::string16* status_label,
133 base::string16* link_label) { 61 base::string16* link_label) {
134 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 62 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
135 if (link_label) 63 if (link_label)
136 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); 64 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL));
137 65
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 std::string email = account_tracker->GetAccountInfo(account_id).email; 137 std::string email = account_tracker->GetAccountInfo(account_id).email;
210 if (email.empty()) { 138 if (email.empty()) {
211 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, 139 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED,
212 account_tracker->GetMigrationState()); 140 account_tracker->GetMigrationState());
213 return account_id; 141 return account_id;
214 } 142 }
215 return email; 143 return email;
216 } 144 }
217 145
218 } // namespace signin_ui_util 146 } // namespace signin_ui_util
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_ui_util.h ('k') | chrome/browser/ui/cocoa/browser_window_command_handler.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698