| OLD | NEW |
| 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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.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" | |
| 14 #include "chrome/browser/signin/signin_global_error_factory.h" | |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
| 17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 15 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 18 #include "chrome/browser/sync/sync_global_error.h" | 16 #include "chrome/browser/sync/sync_global_error.h" |
| 19 #include "chrome/browser/sync/sync_global_error_factory.h" | 17 #include "chrome/browser/sync/sync_global_error_factory.h" |
| 20 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 21 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/grit/chromium_strings.h" | 20 #include "chrome/grit/chromium_strings.h" |
| 23 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 24 #include "components/signin/core/browser/account_tracker_service.h" | 22 #include "components/signin/core/browser/account_tracker_service.h" |
| 25 #include "components/signin/core/browser/signin_manager.h" | 23 #include "components/signin/core/browser/signin_manager.h" |
| 26 #include "components/signin/core/common/profile_management_switches.h" | 24 #include "components/signin/core/common/profile_management_switches.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/gfx/font_list.h" | 26 #include "ui/gfx/font_list.h" |
| 29 #include "ui/gfx/text_elider.h" | 27 #include "ui/gfx/text_elider.h" |
| 30 | 28 |
| 31 namespace { | |
| 32 // Maximum width of a username - we trim emails that are wider than this so | |
| 33 // the wrench menu doesn't get ridiculously wide. | |
| 34 const int kUsernameMaxWidth = 200; | |
| 35 } // namespace | |
| 36 | |
| 37 namespace signin_ui_util { | 29 namespace signin_ui_util { |
| 38 | 30 |
| 39 GlobalError* GetSignedInServiceError(Profile* profile) { | |
| 40 std::vector<GlobalError*> errors = GetSignedInServiceErrors(profile); | |
| 41 if (errors.empty()) | |
| 42 return NULL; | |
| 43 return errors[0]; | |
| 44 } | |
| 45 | |
| 46 std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile) { | |
| 47 std::vector<GlobalError*> errors; | |
| 48 // Chrome OS doesn't use SigninGlobalError or SyncGlobalError. Other platforms | |
| 49 // may use these services to show auth and sync errors in the toolbar menu. | |
| 50 #if !defined(OS_CHROMEOS) | |
| 51 // Auth errors have the highest priority - after that, individual service | |
| 52 // errors. | |
| 53 SigninGlobalError* signin_error = | |
| 54 SigninGlobalErrorFactory::GetForProfile(profile); | |
| 55 if (signin_error && signin_error->HasError()) | |
| 56 errors.push_back(signin_error); | |
| 57 | |
| 58 // No auth error - now try other services. Currently the list is just hard- | |
| 59 // coded but in the future if we add more we can create some kind of | |
| 60 // registration framework. | |
| 61 if (profile->IsSyncAllowed()) { | |
| 62 SyncGlobalError* error = SyncGlobalErrorFactory::GetForProfile(profile); | |
| 63 if (error && error->HasMenuItem()) | |
| 64 errors.push_back(error); | |
| 65 } | |
| 66 #endif | |
| 67 | |
| 68 return errors; | |
| 69 } | |
| 70 | |
| 71 base::string16 GetSigninMenuLabel(Profile* profile) { | |
| 72 GlobalError* error = signin_ui_util::GetSignedInServiceError(profile); | |
| 73 if (error) | |
| 74 return error->MenuItemLabel(); | |
| 75 | |
| 76 // No errors, so just display the signed in user, if any. | |
| 77 ProfileSyncService* service = profile->IsSyncAllowed() ? | |
| 78 ProfileSyncServiceFactory::GetForProfile(profile) : NULL; | |
| 79 | |
| 80 // Even if the user is signed in, don't display the "signed in as..." | |
| 81 // label if we're still setting up sync. | |
| 82 if (!service || !service->FirstSetupInProgress()) { | |
| 83 std::string username; | |
| 84 SigninManagerBase* signin_manager = | |
| 85 SigninManagerFactory::GetForProfileIfExists(profile); | |
| 86 if (signin_manager) | |
| 87 username = signin_manager->GetAuthenticatedUsername(); | |
| 88 if (!username.empty() && !signin_manager->AuthInProgress()) { | |
| 89 const base::string16 elided = gfx::ElideText(base::UTF8ToUTF16(username), | |
| 90 gfx::FontList(), kUsernameMaxWidth, gfx::ELIDE_EMAIL); | |
| 91 return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL, elided); | |
| 92 } | |
| 93 } | |
| 94 return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_PRE_SYNCED_LABEL, | |
| 95 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | |
| 96 } | |
| 97 | |
| 98 // Given an authentication state this helper function returns various labels | 31 // Given an authentication state this helper function returns various labels |
| 99 // that can be used to display information about the state. | 32 // that can be used to display information about the state. |
| 100 void GetStatusLabelsForAuthError(Profile* profile, | 33 void GetStatusLabelsForAuthError(Profile* profile, |
| 101 const SigninManagerBase& signin_manager, | 34 const SigninManagerBase& signin_manager, |
| 102 base::string16* status_label, | 35 base::string16* status_label, |
| 103 base::string16* link_label) { | 36 base::string16* link_label) { |
| 104 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 37 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| 105 if (link_label) | 38 if (link_label) |
| 106 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); | 39 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); |
| 107 | 40 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 std::string email = account_tracker->GetAccountInfo(account_id).email; | 112 std::string email = account_tracker->GetAccountInfo(account_id).email; |
| 180 if (email.empty()) { | 113 if (email.empty()) { |
| 181 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, | 114 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
| 182 account_tracker->GetMigrationState()); | 115 account_tracker->GetMigrationState()); |
| 183 return account_id; | 116 return account_id; |
| 184 } | 117 } |
| 185 return email; | 118 return email; |
| 186 } | 119 } |
| 187 | 120 |
| 188 } // namespace signin_ui_util | 121 } // namespace signin_ui_util |
| OLD | NEW |