| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/sync_ui_util.h" | 5 #include "chrome/browser/sync/sync_ui_util.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 return l10n_util::GetStringFUTF16( | 91 return l10n_util::GetStringFUTF16( |
| 92 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK, | 92 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK, |
| 93 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 93 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); |
| 94 default: | 94 default: |
| 95 NOTREACHED(); | 95 NOTREACHED(); |
| 96 return nullptr; | 96 return nullptr; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void GetStatusForActionableError( | 100 void GetStatusForActionableError(const syncer::SyncProtocolError& error, |
| 101 const syncer::SyncProtocolError& error, | 101 base::string16* status_label, |
| 102 base::string16* status_label) { | 102 ActionType* action_type) { |
| 103 DCHECK(status_label); | 103 DCHECK(status_label); |
| 104 switch (error.action) { | 104 switch (error.action) { |
| 105 case syncer::STOP_AND_RESTART_SYNC: | |
| 106 status_label->assign( | |
| 107 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); | |
| 108 break; | |
| 109 case syncer::UPGRADE_CLIENT: | 105 case syncer::UPGRADE_CLIENT: |
| 110 status_label->assign( | 106 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_UPGRADE_CLIENT)); |
| 111 l10n_util::GetStringFUTF16(IDS_SYNC_UPGRADE_CLIENT, | 107 *action_type = UPGRADE_CLIENT; |
| 112 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
| 113 break; | 108 break; |
| 114 case syncer::ENABLE_SYNC_ON_ACCOUNT: | 109 case syncer::ENABLE_SYNC_ON_ACCOUNT: |
| 115 status_label->assign( | 110 status_label->assign( |
| 116 l10n_util::GetStringUTF16(IDS_SYNC_ENABLE_SYNC_ON_ACCOUNT)); | 111 l10n_util::GetStringUTF16(IDS_SYNC_STATUS_ENABLE_SYNC_ON_ACCOUNT)); |
| 117 break; | |
| 118 case syncer::CLEAR_USER_DATA_AND_RESYNC: | |
| 119 status_label->assign( | |
| 120 l10n_util::GetStringUTF16(IDS_SYNC_CLEAR_USER_DATA)); | |
| 121 break; | 112 break; |
| 122 default: | 113 default: |
| 123 NOTREACHED(); | 114 status_label->clear(); |
| 115 break; |
| 124 } | 116 } |
| 125 } | 117 } |
| 126 | 118 |
| 119 void GetStatusForUnrecoverableError(Profile* profile, |
| 120 ProfileSyncService* service, |
| 121 base::string16* status_label, |
| 122 ActionType* action_type) { |
| 123 // Unrecoverable error is sometimes accompanied by actionable error. |
| 124 // If status message is set display that message, otherwise show generic |
| 125 // unrecoverable error message. |
| 126 ProfileSyncService::Status status; |
| 127 service->QueryDetailedSyncStatus(&status); |
| 128 GetStatusForActionableError(status.sync_protocol_error, status_label, |
| 129 action_type); |
| 130 if (status_label->empty()) { |
| 131 *action_type = REAUTHENTICATE; |
| 132 |
| 133 #if !defined(OS_CHROMEOS) |
| 134 status_label->assign(l10n_util::GetStringUTF16( |
| 135 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR)); |
| 136 // The message for managed accounts is the same as that of the cros. |
| 137 if (SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited()) { |
| 138 status_label->assign(l10n_util::GetStringUTF16( |
| 139 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR_NEEDS_SIGNOUT)); |
| 140 } |
| 141 #else |
| 142 status_label->assign(l10n_util::GetStringUTF16( |
| 143 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR_NEEDS_SIGNOUT)); |
| 144 #endif |
| 145 } |
| 146 } |
| 147 |
| 148 // Depending on the authentication state, returns labels to be used to display |
| 149 // information about the sync status. |
| 150 void GetStatusForAuthError(Profile* profile, |
| 151 const SigninManagerBase& signin_manager, |
| 152 base::string16* status_label, |
| 153 base::string16* link_label, |
| 154 ActionType* action_type) { |
| 155 DCHECK(status_label); |
| 156 DCHECK(link_label); |
| 157 const GoogleServiceAuthError::State state = |
| 158 SigninErrorControllerFactory::GetForProfile(profile)-> |
| 159 auth_error().state(); |
| 160 switch (state) { |
| 161 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: |
| 162 status_label->assign( |
| 163 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); |
| 164 break; |
| 165 case GoogleServiceAuthError::CONNECTION_FAILED: |
| 166 status_label->assign( |
| 167 l10n_util::GetStringUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE)); |
| 168 // Note that there is little the user can do if the server is not |
| 169 // reachable. Since attempting to re-connect is done automatically by |
| 170 // the Syncer, we do not show the (re)login link. |
| 171 break; |
| 172 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
| 173 case GoogleServiceAuthError::SERVICE_ERROR: |
| 174 case GoogleServiceAuthError::ACCOUNT_DELETED: |
| 175 case GoogleServiceAuthError::ACCOUNT_DISABLED: |
| 176 default: |
| 177 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_ERROR)); |
| 178 link_label->assign( |
| 179 l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); |
| 180 *action_type = REAUTHENTICATE; |
| 181 break; |
| 182 } |
| 183 } |
| 184 |
| 127 // TODO(akalin): Write unit tests for these three functions below. | 185 // TODO(akalin): Write unit tests for these three functions below. |
| 128 | 186 |
| 129 // status_label and link_label must either be both null or both non-null. | 187 // status_label and link_label must either be both null or both non-null. |
| 130 MessageType GetStatusInfo(Profile* profile, | 188 MessageType GetStatusInfo(Profile* profile, |
| 131 ProfileSyncService* service, | 189 ProfileSyncService* service, |
| 132 const SigninManagerBase& signin, | 190 const SigninManagerBase& signin, |
| 133 StatusLabelStyle style, | 191 StatusLabelStyle style, |
| 134 base::string16* status_label, | 192 base::string16* status_label, |
| 135 base::string16* link_label) { | 193 base::string16* link_label, |
| 194 ActionType* action_type) { |
| 136 DCHECK_EQ(status_label == nullptr, link_label == nullptr); | 195 DCHECK_EQ(status_label == nullptr, link_label == nullptr); |
| 137 | 196 |
| 138 MessageType result_type(SYNCED); | 197 MessageType result_type(SYNCED); |
| 139 | 198 |
| 140 if (!signin.IsAuthenticated()) | 199 if (!signin.IsAuthenticated()) |
| 141 return PRE_SYNCED; | 200 return PRE_SYNCED; |
| 142 | 201 |
| 143 if (!service || service->IsManaged() || service->IsFirstSetupComplete() || | 202 if (!service || service->IsManaged() || service->IsFirstSetupComplete() || |
| 144 !service->IsSyncRequested()) { | 203 !service->IsSyncRequested()) { |
| 145 // The order or priority is going to be: 1. Unrecoverable errors. | 204 // The order or priority is going to be: 1. Unrecoverable errors. |
| 146 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. | 205 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. |
| 147 | 206 |
| 148 if (service && service->HasUnrecoverableError()) { | 207 if (service && service->HasUnrecoverableError()) { |
| 149 if (status_label) { | 208 if (status_label) { |
| 150 // Unrecoverable error is sometimes accompanied by actionable error. | 209 GetStatusForUnrecoverableError(profile, service, status_label, |
| 151 // If actionable error is set then display corresponding message, | 210 action_type); |
| 152 // otherwise show generic unrecoverable error message. | |
| 153 ProfileSyncService::Status status; | |
| 154 service->QueryDetailedSyncStatus(&status); | |
| 155 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { | |
| 156 GetStatusForActionableError(status.sync_protocol_error, status_label); | |
| 157 } else { | |
| 158 status_label->assign(l10n_util::GetStringFUTF16( | |
| 159 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR, | |
| 160 l10n_util::GetStringUTF16( | |
| 161 IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL))); | |
| 162 } | |
| 163 } | 211 } |
| 164 return SYNC_ERROR; | 212 return SYNC_ERROR; |
| 165 } | 213 } |
| 166 | 214 |
| 167 // For auth errors first check if an auth is in progress. | 215 // For auth errors first check if an auth is in progress. |
| 168 if (signin.AuthInProgress()) { | 216 if (signin.AuthInProgress()) { |
| 169 if (status_label) { | 217 if (status_label) { |
| 170 status_label->assign( | 218 status_label->assign( |
| 171 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 219 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
| 172 } | 220 } |
| 173 return PRE_SYNCED; | 221 return PRE_SYNCED; |
| 174 } | 222 } |
| 175 | 223 |
| 176 // Check for sync errors if the sync service is enabled. | 224 // Check for sync errors if the sync service is enabled. |
| 177 if (service) { | 225 if (service) { |
| 178 // Since there is no auth in progress, check for an auth error first. | 226 // Since there is no auth in progress, check for an auth error first. |
| 179 AuthError auth_error = | 227 AuthError auth_error = |
| 180 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); | 228 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); |
| 181 if (auth_error.state() != AuthError::NONE) { | 229 if (auth_error.state() != AuthError::NONE) { |
| 182 if (status_label && link_label) | 230 if (status_label && link_label) { |
| 183 signin_ui_util::GetStatusLabelsForAuthError(profile, signin, | 231 GetStatusForAuthError(profile, signin, status_label, link_label, |
| 184 status_label, link_label); | 232 action_type); |
| 233 } |
| 185 return SYNC_ERROR; | 234 return SYNC_ERROR; |
| 186 } | 235 } |
| 187 | 236 |
| 188 // We don't have an auth error. Check for an actionable error. | 237 // We don't have an auth error. Check for an actionable error. |
| 189 ProfileSyncService::Status status; | 238 ProfileSyncService::Status status; |
| 190 service->QueryDetailedSyncStatus(&status); | 239 service->QueryDetailedSyncStatus(&status); |
| 191 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { | 240 if (status_label) { |
| 192 if (status_label) { | 241 GetStatusForActionableError(status.sync_protocol_error, status_label, |
| 193 GetStatusForActionableError(status.sync_protocol_error, | 242 action_type); |
| 194 status_label); | 243 if (!status_label->empty()) |
| 244 return SYNC_ERROR; |
| 245 } |
| 246 |
| 247 // Check for a passphrase error. |
| 248 if (service->IsPassphraseRequired() && |
| 249 service->IsPassphraseRequiredForDecryption()) { |
| 250 if (status_label && link_label) { |
| 251 status_label->assign( |
| 252 l10n_util::GetStringUTF16(IDS_SYNC_STATUS_NEEDS_PASSWORD)); |
| 253 link_label->assign( |
| 254 l10n_util::GetStringUTF16( |
| 255 IDS_SYNC_STATUS_NEEDS_PASSWORD_LINK_LABEL)); |
| 256 *action_type = ENTER_PASSPHRASE; |
| 195 } | 257 } |
| 196 return SYNC_ERROR; | 258 return SYNC_ERROR; |
| 197 } | 259 } |
| 198 | 260 |
| 199 // Check for a passphrase error. | |
| 200 if (service->IsPassphraseRequired()) { | |
| 201 if (service->IsPassphraseRequiredForDecryption()) { | |
| 202 // TODO(lipalani) : Ask tim if this is still needed. | |
| 203 // NOT first machine. | |
| 204 // Show a link ("needs attention"), but still indicate the | |
| 205 // current synced status. Return SYNC_PROMO so that | |
| 206 // the configure link will still be shown. | |
| 207 if (status_label && link_label) { | |
| 208 status_label->assign(GetSyncedStateStatusLabel( | |
| 209 service, signin, style)); | |
| 210 link_label->assign( | |
| 211 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); | |
| 212 } | |
| 213 return SYNC_PROMO; | |
| 214 } | |
| 215 } | |
| 216 | |
| 217 // Check to see if sync has been disabled via the dasboard and needs to be | 261 // Check to see if sync has been disabled via the dasboard and needs to be |
| 218 // set up once again. | 262 // set up once again. |
| 219 if (!service->IsSyncRequested() && | 263 if (!service->IsSyncRequested() && |
| 220 status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) { | 264 status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) { |
| 221 if (status_label) { | 265 if (status_label) { |
| 222 status_label->assign(GetSyncedStateStatusLabel(service, | 266 status_label->assign(GetSyncedStateStatusLabel(service, |
| 223 signin, | 267 signin, |
| 224 style)); | 268 style)); |
| 225 } | 269 } |
| 226 return PRE_SYNCED; | 270 return PRE_SYNCED; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 245 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); | 289 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); |
| 246 } | 290 } |
| 247 if (signin.AuthInProgress()) { | 291 if (signin.AuthInProgress()) { |
| 248 if (status_label) { | 292 if (status_label) { |
| 249 status_label->assign( | 293 status_label->assign( |
| 250 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 294 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
| 251 } | 295 } |
| 252 } else if (auth_error.state() != AuthError::NONE && | 296 } else if (auth_error.state() != AuthError::NONE && |
| 253 auth_error.state() != AuthError::TWO_FACTOR) { | 297 auth_error.state() != AuthError::TWO_FACTOR) { |
| 254 if (status_label && link_label) { | 298 if (status_label && link_label) { |
| 255 status_label->clear(); | 299 GetStatusForAuthError(profile, signin, status_label, link_label, |
| 256 signin_ui_util::GetStatusLabelsForAuthError(profile, signin, | 300 action_type); |
| 257 status_label, link_label); | |
| 258 } | 301 } |
| 259 result_type = SYNC_ERROR; | 302 result_type = SYNC_ERROR; |
| 260 } | 303 } |
| 261 } else if (service->HasUnrecoverableError()) { | 304 } else if (service->HasUnrecoverableError()) { |
| 262 result_type = SYNC_ERROR; | 305 result_type = SYNC_ERROR; |
| 263 ProfileSyncService::Status status; | 306 if (status_label) { |
| 264 service->QueryDetailedSyncStatus(&status); | 307 GetStatusForUnrecoverableError(profile, service, status_label, |
| 265 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { | 308 action_type); |
| 266 if (status_label) { | |
| 267 GetStatusForActionableError(status.sync_protocol_error, | |
| 268 status_label); | |
| 269 } | |
| 270 } else if (status_label) { | |
| 271 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); | |
| 272 } | 309 } |
| 273 } else if (signin.IsAuthenticated()) { | 310 } else if (signin.IsAuthenticated()) { |
| 274 // The user is signed in, but sync has been stopped. | 311 // The user is signed in, but sync has been stopped. |
| 312 result_type = PRE_SYNCED; |
| 275 if (status_label) { | 313 if (status_label) { |
| 276 base::string16 label = l10n_util::GetStringUTF16( | 314 status_label->assign( |
| 277 IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED); | 315 l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED)); |
| 278 status_label->assign(label); | |
| 279 result_type = PRE_SYNCED; | |
| 280 } | 316 } |
| 281 } | 317 } |
| 282 } | 318 } |
| 283 return result_type; | 319 return result_type; |
| 284 } | 320 } |
| 285 | 321 |
| 286 // Returns the status info for use on the new tab page, where we want slightly | 322 // Returns the status info for use on the new tab page, where we want slightly |
| 287 // different information than in the settings panel. | 323 // different information than in the settings panel. |
| 288 MessageType GetStatusInfoForNewTabPage(Profile* profile, | 324 MessageType GetStatusInfoForNewTabPage(Profile* profile, |
| 289 ProfileSyncService* service, | 325 ProfileSyncService* service, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 311 if (status_label && link_label) { | 347 if (status_label && link_label) { |
| 312 status_label->assign(base::string16()); | 348 status_label->assign(base::string16()); |
| 313 link_label->assign( | 349 link_label->assign( |
| 314 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); | 350 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); |
| 315 } | 351 } |
| 316 return SYNC_ERROR; | 352 return SYNC_ERROR; |
| 317 } | 353 } |
| 318 } | 354 } |
| 319 | 355 |
| 320 // Fallback to default. | 356 // Fallback to default. |
| 357 ActionType action_type = NO_ACTION; |
| 321 return GetStatusInfo(profile, service, signin, WITH_HTML, status_label, | 358 return GetStatusInfo(profile, service, signin, WITH_HTML, status_label, |
| 322 link_label); | 359 link_label, &action_type); |
| 323 } | 360 } |
| 324 | 361 |
| 325 } // namespace | 362 } // namespace |
| 326 | 363 |
| 327 MessageType GetStatusLabels(Profile* profile, | 364 MessageType GetStatusLabels(Profile* profile, |
| 328 ProfileSyncService* service, | 365 ProfileSyncService* service, |
| 329 const SigninManagerBase& signin, | 366 const SigninManagerBase& signin, |
| 330 StatusLabelStyle style, | 367 StatusLabelStyle style, |
| 331 base::string16* status_label, | 368 base::string16* status_label, |
| 332 base::string16* link_label) { | 369 base::string16* link_label, |
| 370 ActionType* action_type) { |
| 333 DCHECK(status_label); | 371 DCHECK(status_label); |
| 334 DCHECK(link_label); | 372 DCHECK(link_label); |
| 335 return sync_ui_util::GetStatusInfo(profile, service, signin, style, | 373 return sync_ui_util::GetStatusInfo(profile, service, signin, style, |
| 336 status_label, link_label); | 374 status_label, link_label, action_type); |
| 337 } | 375 } |
| 338 | 376 |
| 339 MessageType GetStatusLabelsForNewTabPage(Profile* profile, | 377 MessageType GetStatusLabelsForNewTabPage(Profile* profile, |
| 340 ProfileSyncService* service, | 378 ProfileSyncService* service, |
| 341 const SigninManagerBase& signin, | 379 const SigninManagerBase& signin, |
| 342 base::string16* status_label, | 380 base::string16* status_label, |
| 343 base::string16* link_label) { | 381 base::string16* link_label) { |
| 344 DCHECK(status_label); | 382 DCHECK(status_label); |
| 345 DCHECK(link_label); | 383 DCHECK(link_label); |
| 346 return sync_ui_util::GetStatusInfoForNewTabPage(profile, service, signin, | 384 return sync_ui_util::GetStatusInfoForNewTabPage(profile, service, signin, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 486 } |
| 449 | 487 |
| 450 // There is no error. | 488 // There is no error. |
| 451 return NO_SYNC_ERROR; | 489 return NO_SYNC_ERROR; |
| 452 } | 490 } |
| 453 #endif | 491 #endif |
| 454 | 492 |
| 455 MessageType GetStatus(Profile* profile, | 493 MessageType GetStatus(Profile* profile, |
| 456 ProfileSyncService* service, | 494 ProfileSyncService* service, |
| 457 const SigninManagerBase& signin) { | 495 const SigninManagerBase& signin) { |
| 496 ActionType action_type = NO_ACTION; |
| 458 return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML, | 497 return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML, |
| 459 nullptr, nullptr); | 498 nullptr, nullptr, &action_type); |
| 460 } | 499 } |
| 461 | 500 |
| 462 base::string16 ConstructTime(int64_t time_in_int) { | 501 base::string16 ConstructTime(int64_t time_in_int) { |
| 463 base::Time time = base::Time::FromInternalValue(time_in_int); | 502 base::Time time = base::Time::FromInternalValue(time_in_int); |
| 464 | 503 |
| 465 // If time is null the format function returns a time in 1969. | 504 // If time is null the format function returns a time in 1969. |
| 466 if (time.is_null()) | 505 if (time.is_null()) |
| 467 return base::string16(); | 506 return base::string16(); |
| 468 return base::TimeFormatFriendlyDateAndTime(time); | 507 return base::TimeFormatFriendlyDateAndTime(time); |
| 469 } | 508 } |
| 470 | 509 |
| 471 } // namespace sync_ui_util | 510 } // namespace sync_ui_util |
| OLD | NEW |