| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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/signin/core/browser/account_tracker_service.h" | 24 #include "components/signin/core/browser/account_tracker_service.h" |
| 25 #include "components/signin/core/browser/signin_manager.h" | 25 #include "components/signin/core/browser/signin_manager.h" |
| 26 #include "components/signin/core/common/profile_management_switches.h" | 26 #include "components/signin/core/common/profile_management_switches.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/gfx/font_list.h" | 28 #include "ui/gfx/font_list.h" |
| 29 #include "ui/gfx/text_elider.h" | 29 #include "ui/gfx/text_elider.h" |
| 30 | 30 |
| 31 namespace signin_ui_util { |
| 32 |
| 31 namespace { | 33 namespace { |
| 34 |
| 32 // Maximum width of a username - we trim emails that are wider than this so | 35 // Maximum width of a username - we trim emails that are wider than this so |
| 33 // the wrench menu doesn't get ridiculously wide. | 36 // the wrench menu doesn't get ridiculously wide. |
| 34 const int kUsernameMaxWidth = 200; | 37 const int kUsernameMaxWidth = 200; |
| 35 } // namespace | |
| 36 | 38 |
| 37 namespace signin_ui_util { | 39 // Returns all errors reported by signed in services. |
| 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) { | 40 std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile) { |
| 47 std::vector<GlobalError*> errors; | 41 std::vector<GlobalError*> errors; |
| 48 // Chrome OS doesn't use SigninGlobalError or SyncGlobalError. Other platforms | 42 // 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. | 43 // may use these services to show auth and sync errors in the toolbar menu. |
| 50 #if !defined(OS_CHROMEOS) | 44 #if !defined(OS_CHROMEOS) |
| 51 // Auth errors have the highest priority - after that, individual service | 45 // Auth errors have the highest priority - after that, individual service |
| 52 // errors. | 46 // errors. |
| 53 SigninGlobalError* signin_error = | 47 SigninGlobalError* signin_error = |
| 54 SigninGlobalErrorFactory::GetForProfile(profile); | 48 SigninGlobalErrorFactory::GetForProfile(profile); |
| 55 if (signin_error && signin_error->HasError()) | 49 if (signin_error && signin_error->HasError()) |
| 56 errors.push_back(signin_error); | 50 errors.push_back(signin_error); |
| 57 | 51 |
| 58 // No auth error - now try other services. Currently the list is just hard- | 52 // 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 | 53 // coded but in the future if we add more we can create some kind of |
| 60 // registration framework. | 54 // registration framework. |
| 61 if (profile->IsSyncAllowed()) { | 55 if (profile->IsSyncAllowed()) { |
| 62 SyncGlobalError* error = SyncGlobalErrorFactory::GetForProfile(profile); | 56 SyncGlobalError* error = SyncGlobalErrorFactory::GetForProfile(profile); |
| 63 if (error && error->HasMenuItem()) | 57 if (error && error->HasMenuItem()) |
| 64 errors.push_back(error); | 58 errors.push_back(error); |
| 65 } | 59 } |
| 66 #endif | 60 #endif |
| 67 | 61 |
| 68 return errors; | 62 return errors; |
| 69 } | 63 } |
| 70 | 64 |
| 65 // If a signed in service is reporting an error, returns the GlobalError |
| 66 // object associated with that service, or NULL if no errors are reported. |
| 67 GlobalError* GetSignedInServiceError(Profile* profile) { |
| 68 std::vector<GlobalError*> errors = GetSignedInServiceErrors(profile); |
| 69 if (errors.empty()) |
| 70 return NULL; |
| 71 return errors[0]; |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 |
| 71 base::string16 GetSigninMenuLabel(Profile* profile) { | 76 base::string16 GetSigninMenuLabel(Profile* profile) { |
| 72 GlobalError* error = signin_ui_util::GetSignedInServiceError(profile); | 77 GlobalError* error = signin_ui_util::GetSignedInServiceError(profile); |
| 73 if (error) | 78 if (error) |
| 74 return error->MenuItemLabel(); | 79 return error->MenuItemLabel(); |
| 75 | 80 |
| 76 // No errors, so just display the signed in user, if any. | 81 // No errors, so just display the signed in user, if any. |
| 77 ProfileSyncService* service = profile->IsSyncAllowed() ? | 82 ProfileSyncService* service = profile->IsSyncAllowed() ? |
| 78 ProfileSyncServiceFactory::GetForProfile(profile) : NULL; | 83 ProfileSyncServiceFactory::GetForProfile(profile) : NULL; |
| 79 | 84 |
| 80 // Even if the user is signed in, don't display the "signed in as..." | 85 // Even if the user is signed in, don't display the "signed in as..." |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 std::string email = account_tracker->GetAccountInfo(account_id).email; | 184 std::string email = account_tracker->GetAccountInfo(account_id).email; |
| 180 if (email.empty()) { | 185 if (email.empty()) { |
| 181 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, | 186 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
| 182 account_tracker->GetMigrationState()); | 187 account_tracker->GetMigrationState()); |
| 183 return account_id; | 188 return account_id; |
| 184 } | 189 } |
| 185 return email; | 190 return email; |
| 186 } | 191 } |
| 187 | 192 |
| 188 } // namespace signin_ui_util | 193 } // namespace signin_ui_util |
| OLD | NEW |