| 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 25 matching lines...) Expand all Loading... |
| 36 #include "grit/components_strings.h" | 36 #include "grit/components_strings.h" |
| 37 #include "sync/internal_api/public/base/model_type.h" | 37 #include "sync/internal_api/public/base/model_type.h" |
| 38 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 38 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
| 39 #include "sync/protocol/proto_enum_conversions.h" | 39 #include "sync/protocol/proto_enum_conversions.h" |
| 40 #include "sync/protocol/sync_protocol_error.h" | 40 #include "sync/protocol/sync_protocol_error.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 42 | 42 |
| 43 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 44 #include "components/signin/core/account_id/account_id.h" | 44 #include "components/signin/core/account_id/account_id.h" |
| 45 #include "components/user_manager/user_manager.h" | 45 #include "components/user_manager/user_manager.h" |
| 46 #else |
| 47 #include "chrome/browser/signin/signin_manager_factory.h" |
| 48 #include "components/sync_driver/sync_error_controller.h" |
| 46 #endif // defined(OS_CHROMEOS) | 49 #endif // defined(OS_CHROMEOS) |
| 47 | 50 |
| 48 typedef GoogleServiceAuthError AuthError; | 51 typedef GoogleServiceAuthError AuthError; |
| 49 | 52 |
| 50 namespace sync_ui_util { | 53 namespace sync_ui_util { |
| 51 | 54 |
| 52 namespace { | 55 namespace { |
| 53 | 56 |
| 54 bool IsChromeDashboardEnabled() { | 57 bool IsChromeDashboardEnabled() { |
| 55 const std::string group_name = | 58 const std::string group_name = |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // This is not the first machine so ask user to enter passphrase. | 394 // This is not the first machine so ask user to enter passphrase. |
| 392 *menu_label = l10n_util::GetStringUTF16( | 395 *menu_label = l10n_util::GetStringUTF16( |
| 393 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); | 396 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); |
| 394 *bubble_message = l10n_util::GetStringUTF16( | 397 *bubble_message = l10n_util::GetStringUTF16( |
| 395 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE); | 398 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE); |
| 396 *bubble_accept_label = l10n_util::GetStringUTF16( | 399 *bubble_accept_label = l10n_util::GetStringUTF16( |
| 397 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); | 400 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); |
| 398 return; | 401 return; |
| 399 } | 402 } |
| 400 } | 403 } |
| 404 |
| 405 AvatarSyncErrorType GetMessagesForAvatarSyncError(Profile* profile, |
| 406 int* content_string_id, |
| 407 int* button_string_id) { |
| 408 ProfileSyncService* service = |
| 409 ProfileSyncServiceFactory::GetForProfile(profile); |
| 410 |
| 411 // The order or priority is going to be: 1. Unrecoverable errors. |
| 412 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. |
| 413 if (service && service->HasUnrecoverableError()) { |
| 414 // An unrecoverable error is sometimes accompanied by an actionable error. |
| 415 // If an actionable error is not set to be UPGRADE_CLIENT, then show a |
| 416 // generic unrecoverable error message. |
| 417 ProfileSyncService::Status status; |
| 418 service->QueryDetailedSyncStatus(&status); |
| 419 if (status.sync_protocol_error.action != syncer::UPGRADE_CLIENT) { |
| 420 // Display different messages and buttons for managed accounts. |
| 421 if (SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited()) { |
| 422 // For a managed user, the user is directed to the signout |
| 423 // confirmation dialogue in the settings page. |
| 424 *content_string_id = IDS_SYNC_ERROR_USER_MENU_SIGNOUT_MESSAGE; |
| 425 *button_string_id = IDS_SYNC_ERROR_USER_MENU_SIGNOUT_BUTTON; |
| 426 return MANAGED_USER_UNRECOVERABLE_ERROR; |
| 427 } |
| 428 // For a non-managed user, we sign out on the user's behalf and prompt |
| 429 // the user to sign in again. |
| 430 *content_string_id = IDS_SYNC_ERROR_USER_MENU_SIGNIN_AGAIN_MESSAGE; |
| 431 *button_string_id = IDS_SYNC_ERROR_USER_MENU_SIGNIN_AGAIN_BUTTON; |
| 432 return UNRECOVERABLE_ERROR; |
| 433 } |
| 434 } |
| 435 |
| 436 // Check for an auth error. |
| 437 SigninErrorController* signin_error_controller = |
| 438 SigninErrorControllerFactory::GetForProfile(profile); |
| 439 if (signin_error_controller && signin_error_controller->HasError()) { |
| 440 *content_string_id = IDS_SYNC_ERROR_USER_MENU_SIGNIN_MESSAGE; |
| 441 *button_string_id = IDS_SYNC_ERROR_USER_MENU_SIGNIN_BUTTON; |
| 442 return AUTH_ERROR; |
| 443 } |
| 444 |
| 445 // Check for sync errors if the sync service is enabled. |
| 446 if (service) { |
| 447 // Check for an actionable UPGRADE_CLIENT error. |
| 448 ProfileSyncService::Status status; |
| 449 service->QueryDetailedSyncStatus(&status); |
| 450 if (status.sync_protocol_error.action == syncer::UPGRADE_CLIENT) { |
| 451 *content_string_id = IDS_SYNC_ERROR_USER_MENU_UPGRADE_MESSAGE; |
| 452 *button_string_id = IDS_SYNC_ERROR_USER_MENU_UPGRADE_BUTTON; |
| 453 return UPGRADE_CLIENT_ERROR; |
| 454 } |
| 455 |
| 456 // Check for a sync passphrase error. |
| 457 SyncErrorController* sync_error_controller = |
| 458 service->sync_error_controller(); |
| 459 if (sync_error_controller && sync_error_controller->HasError()) { |
| 460 *content_string_id = IDS_SYNC_ERROR_USER_MENU_PASSPHRASE_MESSAGE; |
| 461 *button_string_id = IDS_SYNC_ERROR_USER_MENU_PASSPHRASE_BUTTON; |
| 462 return PASSPHRASE_ERROR; |
| 463 } |
| 464 } |
| 465 |
| 466 // There is no error. |
| 467 return NO_SYNC_ERROR; |
| 468 } |
| 401 #endif | 469 #endif |
| 402 | 470 |
| 403 MessageType GetStatus(Profile* profile, | 471 MessageType GetStatus(Profile* profile, |
| 404 ProfileSyncService* service, | 472 ProfileSyncService* service, |
| 405 const SigninManagerBase& signin) { | 473 const SigninManagerBase& signin) { |
| 406 return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML, | 474 return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML, |
| 407 nullptr, nullptr); | 475 nullptr, nullptr); |
| 408 } | 476 } |
| 409 | 477 |
| 410 base::string16 ConstructTime(int64_t time_in_int) { | 478 base::string16 ConstructTime(int64_t time_in_int) { |
| 411 base::Time time = base::Time::FromInternalValue(time_in_int); | 479 base::Time time = base::Time::FromInternalValue(time_in_int); |
| 412 | 480 |
| 413 // If time is null the format function returns a time in 1969. | 481 // If time is null the format function returns a time in 1969. |
| 414 if (time.is_null()) | 482 if (time.is_null()) |
| 415 return base::string16(); | 483 return base::string16(); |
| 416 return base::TimeFormatFriendlyDateAndTime(time); | 484 return base::TimeFormatFriendlyDateAndTime(time); |
| 417 } | 485 } |
| 418 | 486 |
| 419 } // namespace sync_ui_util | 487 } // namespace sync_ui_util |
| OLD | NEW |