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" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 16 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 17 #include "chrome/browser/sync/profile_sync_service_factory.h" |
16 #include "chrome/browser/sync/sync_global_error.h" | 18 #include "chrome/browser/sync/sync_global_error.h" |
17 #include "chrome/browser/sync/sync_global_error_factory.h" | 19 #include "chrome/browser/sync/sync_global_error_factory.h" |
18 #include "chrome/browser/ui/browser_navigator.h" | 20 #include "chrome/browser/ui/browser_navigator.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "chrome/grit/chromium_strings.h" | 22 #include "chrome/grit/chromium_strings.h" |
21 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
22 #include "components/signin/core/browser/account_tracker_service.h" | 24 #include "components/signin/core/browser/account_tracker_service.h" |
23 #include "components/signin/core/browser/signin_manager.h" | 25 #include "components/signin/core/browser/signin_manager.h" |
24 #include "components/signin/core/common/profile_management_switches.h" | 26 #include "components/signin/core/common/profile_management_switches.h" |
25 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/gfx/font_list.h" | 28 #include "ui/gfx/font_list.h" |
27 #include "ui/gfx/text_elider.h" | 29 #include "ui/gfx/text_elider.h" |
28 | 30 |
| 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 |
29 namespace signin_ui_util { | 37 namespace signin_ui_util { |
30 | 38 |
| 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 |
31 // Given an authentication state this helper function returns various labels | 98 // Given an authentication state this helper function returns various labels |
32 // that can be used to display information about the state. | 99 // that can be used to display information about the state. |
33 void GetStatusLabelsForAuthError(Profile* profile, | 100 void GetStatusLabelsForAuthError(Profile* profile, |
34 const SigninManagerBase& signin_manager, | 101 const SigninManagerBase& signin_manager, |
35 base::string16* status_label, | 102 base::string16* status_label, |
36 base::string16* link_label) { | 103 base::string16* link_label) { |
37 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 104 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
38 if (link_label) | 105 if (link_label) |
39 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); | 106 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); |
40 | 107 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 std::string email = account_tracker->GetAccountInfo(account_id).email; | 179 std::string email = account_tracker->GetAccountInfo(account_id).email; |
113 if (email.empty()) { | 180 if (email.empty()) { |
114 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, | 181 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
115 account_tracker->GetMigrationState()); | 182 account_tracker->GetMigrationState()); |
116 return account_id; | 183 return account_id; |
117 } | 184 } |
118 return email; | 185 return email; |
119 } | 186 } |
120 | 187 |
121 } // namespace signin_ui_util | 188 } // namespace signin_ui_util |
OLD | NEW |