From 5c086d79fabc962ec30ed6755e4a379a65681092 Mon Sep 17 00:00:00 2001 From: "akalin@chromium.org" Date: Mon, 14 Dec 2009 20:49:04 +0000 Subject: Add a UI helper method to just get the sync status without needing labels. Patch by thiago.farina@gmail.com ( original code review: http://codereview.chromium.org/469017 ). BUG=none TEST=trybots Review URL: http://codereview.chromium.org/486044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34487 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/sync/sync_ui_util.cc | 70 ++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 17 deletions(-) (limited to '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 b973362..56f6915 100644 --- a/chrome/browser/sync/sync_ui_util.cc +++ b/chrome/browser/sync/sync_ui_util.cc @@ -64,11 +64,14 @@ string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { WideToUTF16(service->GetLastSyncedTimeString())); } -} // namespace +// TODO(akalin): Write unit tests for these three functions below. + +// status_label and link_label must either be both NULL or both non-NULL. +MessageType GetStatusInfo(ProfileSyncService* service, + string16* status_label, + string16* link_label) { + DCHECK_EQ(status_label == NULL, link_label == NULL); -MessageType GetStatusLabels(ProfileSyncService* service, - string16* status_label, - string16* link_label) { MessageType result_type(SYNCED); if (!service) { @@ -83,15 +86,21 @@ MessageType GetStatusLabels(ProfileSyncService* service, // or note that everything is OK with the last synced time. if (status.authenticated) { // Everything is peachy. - status_label->assign(GetSyncedStateStatusLabel(service)); + if (status_label) { + status_label->assign(GetSyncedStateStatusLabel(service)); + } DCHECK_EQ(auth_error.state(), AuthError::NONE); } else if (service->UIShouldDepictAuthInProgress()) { - status_label->assign( + if (status_label) { + status_label->assign( l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); + } result_type = PRE_SYNCED; } else if (auth_error.state() != AuthError::NONE) { - GetStatusLabelsForAuthError(auth_error, service, - status_label, link_label); + if (status_label && link_label) { + GetStatusLabelsForAuthError(auth_error, service, + status_label, link_label); + } result_type = SYNC_ERROR; } } else { @@ -101,29 +110,56 @@ MessageType GetStatusLabels(ProfileSyncService* service, if (service->SetupInProgress()) { ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); const AuthError& auth_error = service->GetAuthError(); - status_label->assign( - l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); - if (service->UIShouldDepictAuthInProgress()) { + if (status_label) { status_label->assign( - l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); + l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); + } + if (service->UIShouldDepictAuthInProgress()) { + if (status_label) { + status_label->assign( + l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); + } } else if (auth_error.state() != AuthError::NONE) { - status_label->clear(); + if (status_label) { + status_label->clear(); + } GetStatusLabelsForAuthError(auth_error, service, status_label, NULL); result_type = SYNC_ERROR; } else if (!status.authenticated) { - status_label->assign( - l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED)); + if (status_label) { + status_label->assign( + l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED)); + } } } else if (service->unrecoverable_error_detected()) { result_type = SYNC_ERROR; - status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); + if (status_label) { + status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); + } } else { - status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_NOT_SET_UP_INFO)); + if (status_label) { + status_label->assign( + l10n_util::GetStringUTF16(IDS_SYNC_NOT_SET_UP_INFO)); + } } } return result_type; } +} // namespace + +MessageType GetStatusLabels(ProfileSyncService* service, + string16* status_label, + string16* link_label) { + DCHECK(status_label); + DCHECK(link_label); + return sync_ui_util::GetStatusInfo(service, status_label, link_label); +} + +MessageType GetStatus(ProfileSyncService* service) { + return sync_ui_util::GetStatusInfo(service, NULL, NULL); +} + void OpenSyncMyBookmarksDialog( Profile* profile, ProfileSyncService::SyncEventCodes code) { ProfileSyncService* service = -- cgit v1.1