OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifdef CHROME_PERSONALIZATION |
| 6 |
| 7 #include "chrome/browser/sync/sync_status_ui_helper.h" |
| 8 |
| 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/sync/auth_error_state.h" |
| 11 #include "chrome/browser/sync/personalization_strings.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 |
| 14 static void GetLabelsForAuthError(AuthErrorState auth_error, |
| 15 ProfileSyncService* service, std::wstring* status_label, |
| 16 std::wstring* link_label) { |
| 17 if (link_label) |
| 18 link_label->assign(kSyncReLoginLinkLabel); |
| 19 if (auth_error == AUTH_ERROR_INVALID_GAIA_CREDENTIALS) { |
| 20 // If the user name is empty then the first login failed, otherwise the |
| 21 // credentials are out-of-date. |
| 22 if (service->GetAuthenticatedUsername().empty()) |
| 23 status_label->append(kSyncInvalidCredentialsError); |
| 24 else |
| 25 status_label->append(kSyncExpiredCredentialsError); |
| 26 } else if (auth_error == AUTH_ERROR_CONNECTION_FAILED) { |
| 27 // Note that there is little the user can do if the server is not |
| 28 // reachable. Since attempting to re-connect is done automatically by |
| 29 // the Syncer, we do not show the (re)login link. |
| 30 status_label->append(kSyncServerUnavailableMsg); |
| 31 if (link_label) |
| 32 link_label->clear(); |
| 33 } else { |
| 34 status_label->append(kSyncOtherLoginErrorLabel); |
| 35 } |
| 36 } |
| 37 |
| 38 static std::wstring GetSyncedStateStatusLabel(ProfileSyncService* service) { |
| 39 std::wstring label; |
| 40 std::wstring user_name(UTF16ToWide(service->GetAuthenticatedUsername())); |
| 41 if (user_name.empty()) |
| 42 return label; |
| 43 |
| 44 label += kSyncAccountLabel; |
| 45 label += user_name; |
| 46 label += L"\n"; |
| 47 label += kLastSyncedLabel; |
| 48 label += service->GetLastSyncedTimeString(); |
| 49 return label; |
| 50 } |
| 51 |
| 52 // static |
| 53 SyncStatusUIHelper::MessageType SyncStatusUIHelper::GetLabels( |
| 54 ProfileSyncService* service, std::wstring* status_label, |
| 55 std::wstring* link_label) { |
| 56 MessageType result_type(SYNCED); |
| 57 bool sync_enabled = service->IsSyncEnabledByUser(); |
| 58 |
| 59 if (sync_enabled) { |
| 60 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
| 61 AuthErrorState auth_error(service->GetAuthErrorState()); |
| 62 // Either show auth error information with a link to re-login, auth in prog, |
| 63 // or note that everything is OK with the last synced time. |
| 64 status_label->assign(GetSyncedStateStatusLabel(service)); |
| 65 if (status.authenticated) { |
| 66 // Everything is peachy. |
| 67 DCHECK_EQ(auth_error, AUTH_ERROR_NONE); |
| 68 } else if (service->UIShouldDepictAuthInProgress()) { |
| 69 status_label->append(kSyncAuthenticatingLabel); |
| 70 result_type = PRE_SYNCED; |
| 71 } else if (auth_error != AUTH_ERROR_NONE) { |
| 72 GetLabelsForAuthError(auth_error, service, status_label, link_label); |
| 73 result_type = SYNC_ERROR; |
| 74 } else { |
| 75 NOTREACHED() << "Setup complete, backend !authenticated, AUTH_ERROR_NONE"; |
| 76 } |
| 77 } else { |
| 78 // Either show auth error information with a link to re-login, auth in prog, |
| 79 // or provide a link to continue with setup. |
| 80 result_type = PRE_SYNCED; |
| 81 if (service->SetupInProgress()) { |
| 82 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
| 83 AuthErrorState auth_error(service->GetAuthErrorState()); |
| 84 status_label->assign(UTF8ToWide(kSettingUpText)); |
| 85 if (service->UIShouldDepictAuthInProgress()) { |
| 86 status_label->assign(kSyncAuthenticatingLabel); |
| 87 } else if (auth_error != AUTH_ERROR_NONE) { |
| 88 status_label->clear(); |
| 89 GetLabelsForAuthError(auth_error, service, status_label, NULL); |
| 90 result_type = SYNC_ERROR; |
| 91 } else if (!status.authenticated) { |
| 92 status_label->assign(kSyncCredentialsNeededLabel); |
| 93 } |
| 94 } else { |
| 95 status_label->assign(kSyncNotSetupInfo); |
| 96 } |
| 97 } |
| 98 return result_type; |
| 99 } |
| 100 |
| 101 #endif // CHROME_PERSONALIZATION |
OLD | NEW |