Chromium Code Reviews| Index: chrome/browser/sync/sync_ui_util.cc |
| diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc |
| index 8259e6e5ad46c6528fb5ec4b6b258c3f1bced3c3..2af6b269758e6b0639a3ec140faada6756ee7edf 100644 |
| --- a/chrome/browser/sync/sync_ui_util.cc |
| +++ b/chrome/browser/sync/sync_ui_util.cc |
| @@ -97,33 +97,92 @@ base::string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
| } |
| } |
| -void GetStatusForActionableError( |
| - const syncer::SyncProtocolError& error, |
| - base::string16* status_label) { |
| +void GetStatusForActionableError(const syncer::SyncProtocolError& error, |
| + base::string16* status_label, |
| + ActionType* action_type) { |
| DCHECK(status_label); |
| switch (error.action) { |
| - case syncer::STOP_AND_RESTART_SYNC: |
| - status_label->assign( |
| - l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); |
| - break; |
| case syncer::UPGRADE_CLIENT: |
| - status_label->assign( |
| - l10n_util::GetStringFUTF16(IDS_SYNC_UPGRADE_CLIENT, |
| - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| + status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_UPGRADE_CLIENT)); |
| + *action_type = UPGRADE_CLIENT; |
| break; |
| case syncer::ENABLE_SYNC_ON_ACCOUNT: |
| - status_label->assign( |
| - l10n_util::GetStringUTF16(IDS_SYNC_ENABLE_SYNC_ON_ACCOUNT)); |
| - break; |
| - case syncer::CLEAR_USER_DATA_AND_RESYNC: |
| - status_label->assign( |
| - l10n_util::GetStringUTF16(IDS_SYNC_CLEAR_USER_DATA)); |
| + status_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SYNC_ENABLE_SYNC_ON_ACCOUNT)); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| } |
| +void GetStatusForUnrecoverableError(Profile* profile, |
| + ProfileSyncService* service, |
| + base::string16* status_label, |
| + ActionType* action_type) { |
| + // Unrecoverable error is sometimes accompanied by actionable error. |
| + // If actionable error is set then display corresponding message, |
| + // otherwise show generic unrecoverable error message. |
| + ProfileSyncService::Status status; |
| + service->QueryDetailedSyncStatus(&status); |
| + if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { |
|
tommycli
2016/10/28 21:21:09
Hmm this looks odd to read, since ShouldShowAction
Moe
2016/11/01 19:44:01
Here's my interpretation:
in the new design, the R
|
| + GetStatusForActionableError(status.sync_protocol_error, status_label, |
| + action_type); |
| + } else { |
| + *action_type = REAUTHENTICATE; |
| + |
| +#if !defined(OS_CHROMEOS) |
|
tommycli
2016/10/28 21:21:09
this can be an #if, #else, #endif
Moe
2016/11/01 19:44:01
Done.
|
| + status_label->assign(l10n_util::GetStringUTF16( |
| + IDS_SYNC_STATUS_UNRECOVERABLE_ERROR)); |
| + // The message for managed accounts is the same as that of the cros. |
| + if (SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited()) { |
| + status_label->assign(l10n_util::GetStringUTF16( |
| + IDS_SYNC_STATUS_UNRECOVERABLE_ERROR_CROS)); |
| + } |
| +#endif |
| +#if defined(OS_CHROMEOS) |
| + status_label->assign(l10n_util::GetStringUTF16( |
| + IDS_SYNC_STATUS_UNRECOVERABLE_ERROR_CROS)); |
| +#endif |
| + } |
| +} |
| + |
| +// Depending on the authentication state, returns labels to be used to display |
| +// information about the sync status. |
| +void GetStatusForAuthError(Profile* profile, |
| + const SigninManagerBase& signin_manager, |
| + base::string16* status_label, |
| + base::string16* link_label, |
| + ActionType* action_type) { |
| + DCHECK(status_label); |
| + DCHECK(link_label); |
| + const GoogleServiceAuthError::State state = |
| + SigninErrorControllerFactory::GetForProfile(profile)-> |
| + auth_error().state(); |
| + switch (state) { |
| + case GoogleServiceAuthError::SERVICE_UNAVAILABLE: |
| + status_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); |
| + break; |
| + case GoogleServiceAuthError::CONNECTION_FAILED: |
| + status_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE)); |
| + // Note that there is little the user can do if the server is not |
| + // reachable. Since attempting to re-connect is done automatically by |
| + // the Syncer, we do not show the (re)login link. |
| + break; |
| + case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
| + case GoogleServiceAuthError::SERVICE_ERROR: |
| + case GoogleServiceAuthError::ACCOUNT_DELETED: |
| + case GoogleServiceAuthError::ACCOUNT_DISABLED: |
| + default: |
| + status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_ERROR)); |
| + link_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); |
| + *action_type = REAUTHENTICATE; |
| + break; |
| + } |
| +} |
| + |
| // TODO(akalin): Write unit tests for these three functions below. |
| // status_label and link_label must either be both NULL or both non-NULL. |
| @@ -132,7 +191,8 @@ MessageType GetStatusInfo(Profile* profile, |
| const SigninManagerBase& signin, |
| StatusLabelStyle style, |
| base::string16* status_label, |
| - base::string16* link_label) { |
| + base::string16* link_label, |
| + ActionType* action_type) { |
| DCHECK_EQ(status_label == NULL, link_label == NULL); |
| MessageType result_type(SYNCED); |
| @@ -146,21 +206,8 @@ MessageType GetStatusInfo(Profile* profile, |
| // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. |
| if (service && service->HasUnrecoverableError()) { |
| - if (status_label) { |
| - // Unrecoverable error is sometimes accompanied by actionable error. |
| - // If actionable error is set then display corresponding message, |
| - // otherwise show generic unrecoverable error message. |
| - ProfileSyncService::Status status; |
| - service->QueryDetailedSyncStatus(&status); |
| - if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { |
| - GetStatusForActionableError(status.sync_protocol_error, status_label); |
| - } else { |
| - status_label->assign(l10n_util::GetStringFUTF16( |
| - IDS_SYNC_STATUS_UNRECOVERABLE_ERROR, |
| - l10n_util::GetStringUTF16( |
| - IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL))); |
| - } |
| - } |
| + GetStatusForUnrecoverableError(profile, service, status_label, |
| + action_type); |
| return SYNC_ERROR; |
| } |
| @@ -180,8 +227,8 @@ MessageType GetStatusInfo(Profile* profile, |
| SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); |
| if (auth_error.state() != AuthError::NONE) { |
| if (status_label && link_label) |
| - signin_ui_util::GetStatusLabelsForAuthError(profile, signin, |
| - status_label, link_label); |
| + GetStatusForAuthError(profile, signin, status_label, link_label, |
| + action_type); |
| return SYNC_ERROR; |
| } |
| @@ -190,28 +237,23 @@ MessageType GetStatusInfo(Profile* profile, |
| service->QueryDetailedSyncStatus(&status); |
| if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { |
| if (status_label) { |
| - GetStatusForActionableError(status.sync_protocol_error, |
| - status_label); |
| + GetStatusForActionableError(status.sync_protocol_error, status_label, |
| + action_type); |
| } |
| return SYNC_ERROR; |
| } |
| // Check for a passphrase error. |
| - if (service->IsPassphraseRequired()) { |
| - if (service->IsPassphraseRequiredForDecryption()) { |
| - // TODO(lipalani) : Ask tim if this is still needed. |
| - // NOT first machine. |
| - // Show a link ("needs attention"), but still indicate the |
| - // current synced status. Return SYNC_PROMO so that |
| - // the configure link will still be shown. |
| - if (status_label && link_label) { |
| - status_label->assign(GetSyncedStateStatusLabel( |
| - service, signin, style)); |
| - link_label->assign( |
| - l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); |
| - } |
| - return SYNC_PROMO; |
| + if (service->IsPassphraseRequired() && |
| + service->IsPassphraseRequiredForDecryption()) { |
| + if (status_label && link_label) { |
| + status_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); |
| + link_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_LINK_LABEL)); |
| + *action_type = ENTER_PASSPHRASE; |
| } |
| + return SYNC_ERROR; |
| } |
| // Check to see if sync has been disabled via the dasboard and needs to be |
| @@ -253,30 +295,23 @@ MessageType GetStatusInfo(Profile* profile, |
| auth_error.state() != AuthError::TWO_FACTOR) { |
| if (status_label && link_label) { |
| status_label->clear(); |
| - signin_ui_util::GetStatusLabelsForAuthError(profile, signin, |
| - status_label, link_label); |
| + GetStatusForAuthError(profile, signin, status_label, link_label, |
| + action_type); |
| } |
| result_type = SYNC_ERROR; |
| } |
| } else if (service->HasUnrecoverableError()) { |
| result_type = SYNC_ERROR; |
| - ProfileSyncService::Status status; |
| - service->QueryDetailedSyncStatus(&status); |
| - if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { |
| - if (status_label) { |
| - GetStatusForActionableError(status.sync_protocol_error, |
| - status_label); |
| - } |
| - } else if (status_label) { |
| - status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); |
| + if (status_label) { |
| + GetStatusForUnrecoverableError(profile, service, status_label, |
| + action_type); |
| } |
| } else if (signin.IsAuthenticated()) { |
| // The user is signed in, but sync has been stopped. |
| + result_type = PRE_SYNCED; |
| if (status_label) { |
| - base::string16 label = l10n_util::GetStringUTF16( |
| - IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED); |
| - status_label->assign(label); |
| - result_type = PRE_SYNCED; |
| + status_label->assign( |
| + l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED)); |
| } |
| } |
| } |
| @@ -318,8 +353,9 @@ MessageType GetStatusInfoForNewTabPage(Profile* profile, |
| } |
| // Fallback to default. |
| + ActionType actionType(sync_ui_util::NO_ACTION); |
| return GetStatusInfo(profile, service, signin, WITH_HTML, status_label, |
| - link_label); |
| + link_label, &actionType); |
| } |
| } // namespace |
| @@ -329,11 +365,12 @@ MessageType GetStatusLabels(Profile* profile, |
| const SigninManagerBase& signin, |
| StatusLabelStyle style, |
| base::string16* status_label, |
| - base::string16* link_label) { |
| + base::string16* link_label, |
| + ActionType* action_type) { |
| DCHECK(status_label); |
| DCHECK(link_label); |
| return sync_ui_util::GetStatusInfo(profile, service, signin, style, |
| - status_label, link_label); |
| + status_label, link_label, action_type); |
| } |
| MessageType GetStatusLabelsForNewTabPage(Profile* profile, |
| @@ -455,8 +492,9 @@ AvatarSyncErrorType GetMessagesForAvatarSyncError(Profile* profile, |
| MessageType GetStatus(Profile* profile, |
| ProfileSyncService* service, |
| const SigninManagerBase& signin) { |
| + ActionType actionType(sync_ui_util::NO_ACTION); |
| return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML, |
| - nullptr, nullptr); |
| + nullptr, nullptr, &actionType); |
| } |
| base::string16 ConstructTime(int64_t time_in_int) { |