Chromium Code Reviews| 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 <string> | |
|
tommycli
2016/10/28 21:21:09
nit: not needed if included in .h file'
Moe
2016/11/01 19:44:01
Done.
| |
| 8 | |
| 7 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/signin/account_tracker_service_factory.h" | 13 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 12 #include "chrome/browser/signin/signin_error_controller_factory.h" | 14 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 13 #include "chrome/browser/signin/signin_global_error.h" | 15 #include "chrome/browser/signin/signin_global_error.h" |
| 14 #include "chrome/browser/signin/signin_global_error_factory.h" | 16 #include "chrome/browser/signin/signin_global_error_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 46 // Original email (containing dots) is stored as "display email". | 48 // Original email (containing dots) is stored as "display email". |
| 47 user_display_name = user_manager::UserManager::Get()->GetUserDisplayEmail( | 49 user_display_name = user_manager::UserManager::Get()->GetUserDisplayEmail( |
| 48 AccountId::FromUserEmail(user_display_name)); | 50 AccountId::FromUserEmail(user_display_name)); |
| 49 } | 51 } |
| 50 #endif // defined(OS_CHROMEOS) | 52 #endif // defined(OS_CHROMEOS) |
| 51 } | 53 } |
| 52 | 54 |
| 53 return base::UTF8ToUTF16(user_display_name); | 55 return base::UTF8ToUTF16(user_display_name); |
| 54 } | 56 } |
| 55 | 57 |
| 56 // Given an authentication state this helper function returns various labels | |
| 57 // that can be used to display information about the state. | |
| 58 void GetStatusLabelsForAuthError(Profile* profile, | |
| 59 const SigninManagerBase& signin_manager, | |
| 60 base::string16* status_label, | |
| 61 base::string16* link_label) { | |
| 62 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | |
| 63 if (link_label) | |
| 64 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); | |
| 65 | |
| 66 const GoogleServiceAuthError::State state = | |
| 67 SigninErrorControllerFactory::GetForProfile(profile)-> | |
| 68 auth_error().state(); | |
| 69 switch (state) { | |
| 70 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: | |
| 71 case GoogleServiceAuthError::SERVICE_ERROR: | |
| 72 case GoogleServiceAuthError::ACCOUNT_DELETED: | |
| 73 case GoogleServiceAuthError::ACCOUNT_DISABLED: | |
| 74 // If the user name is empty then the first login failed, otherwise the | |
| 75 // credentials are out-of-date. | |
| 76 if (!signin_manager.IsAuthenticated()) { | |
| 77 if (status_label) { | |
| 78 status_label->assign( | |
| 79 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); | |
| 80 } | |
| 81 } else { | |
| 82 if (status_label) { | |
| 83 status_label->assign( | |
| 84 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); | |
| 85 } | |
| 86 } | |
| 87 break; | |
| 88 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: | |
| 89 if (status_label) { | |
| 90 status_label->assign( | |
| 91 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); | |
| 92 } | |
| 93 if (link_label) | |
| 94 link_label->clear(); | |
| 95 break; | |
| 96 case GoogleServiceAuthError::CONNECTION_FAILED: | |
| 97 if (status_label) { | |
| 98 status_label->assign( | |
| 99 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE, | |
| 100 product_name)); | |
| 101 } | |
| 102 // Note that there is little the user can do if the server is not | |
| 103 // reachable. Since attempting to re-connect is done automatically by | |
| 104 // the Syncer, we do not show the (re)login link. | |
| 105 if (link_label) | |
| 106 link_label->clear(); | |
| 107 break; | |
| 108 default: | |
| 109 if (status_label) { | |
| 110 status_label->assign(l10n_util::GetStringUTF16( | |
| 111 IDS_SYNC_ERROR_SIGNING_IN)); | |
| 112 } | |
| 113 break; | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 void InitializePrefsForProfile(Profile* profile) { | 58 void InitializePrefsForProfile(Profile* profile) { |
| 118 if (profile->IsNewProfile()) { | 59 if (profile->IsNewProfile()) { |
| 119 // Suppresses the upgrade tutorial for a new profile. | 60 // Suppresses the upgrade tutorial for a new profile. |
| 120 profile->GetPrefs()->SetInteger( | 61 profile->GetPrefs()->SetInteger( |
| 121 prefs::kProfileAvatarTutorialShown, kUpgradeWelcomeTutorialShowMax + 1); | 62 prefs::kProfileAvatarTutorialShown, kUpgradeWelcomeTutorialShowMax + 1); |
| 122 } | 63 } |
| 123 } | 64 } |
| 124 | 65 |
| 125 void ShowSigninErrorLearnMorePage(Profile* profile) { | 66 void ShowSigninErrorLearnMorePage(Profile* profile) { |
| 126 static const char kSigninErrorLearnMoreUrl[] = | 67 static const char kSigninErrorLearnMoreUrl[] = |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 137 std::string email = account_tracker->GetAccountInfo(account_id).email; | 78 std::string email = account_tracker->GetAccountInfo(account_id).email; |
| 138 if (email.empty()) { | 79 if (email.empty()) { |
| 139 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, | 80 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
| 140 account_tracker->GetMigrationState()); | 81 account_tracker->GetMigrationState()); |
| 141 return account_id; | 82 return account_id; |
| 142 } | 83 } |
| 143 return email; | 84 return email; |
| 144 } | 85 } |
| 145 | 86 |
| 146 } // namespace signin_ui_util | 87 } // namespace signin_ui_util |
| OLD | NEW |