Chromium Code Reviews| Index: chrome/browser/sync/sync_global_error.cc |
| diff --git a/chrome/browser/sync/sync_global_error.cc b/chrome/browser/sync/sync_global_error.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bfe81da582d0fcb6a506f94db5192ddeb2a426c4 |
| --- /dev/null |
| +++ b/chrome/browser/sync/sync_global_error.cc |
| @@ -0,0 +1,164 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/sync/sync_global_error.h" |
| + |
| +#include "chrome/browser/sync/profile_sync_service.h" |
| +#include "chrome/browser/sync/profile_sync_service_observer.h" |
| +#include "chrome/common/net/gaia/google_service_auth_error.h" |
| +#include "grit/chromium_strings.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +typedef GoogleServiceAuthError AuthError; |
| + |
| +SyncGlobalError::SyncGlobalError(ProfileSyncService* service) |
| + : error_type_(ERROR_TYPE_NONE), |
| + service_(service) { |
| + OnStateChanged(); |
| +} |
| + |
| +SyncGlobalError::~SyncGlobalError() { |
| +} |
| + |
| +bool SyncGlobalError::HasBadge() { |
| +#if defined(OS_CHROMEOS) |
| + // TODO(sail): Due to http://crbug.com/96608 we don't have a wrench menu |
| + // item on ChromeOS thus we don't badge the wrench menu either. |
| + return false; |
| +#else |
| + return error_type_ != ERROR_TYPE_NONE; |
| +#endif |
| +} |
| + |
| +bool SyncGlobalError::HasMenuItem() { |
| + // TODO(sail): Once http://crbug.com/96608 is fixed this should return |
| + // true for ChromeOS. |
| + return false; |
| +} |
| + |
| +int SyncGlobalError::MenuItemCommandID() { |
| + NOTREACHED(); |
| + return 0; |
| +} |
| + |
| +string16 SyncGlobalError::MenuItemLabel() { |
| + switch (error_type_) { |
| + case ERROR_TYPE_PASSPHRASE: |
| + return l10n_util::GetStringUTF16( |
| + IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); |
| + default: |
| + return l10n_util::GetStringUTF16( |
| + IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); |
| + } |
| +} |
| + |
| +void SyncGlobalError::ExecuteMenuItem(Browser* browser) { |
| + service_->ShowErrorUI(); |
| +} |
| + |
| +bool SyncGlobalError::HasBubbleView() { |
| + return error_type_ != ERROR_TYPE_NONE; |
| +} |
| + |
| +string16 SyncGlobalError::GetBubbleViewTitle() { |
| + return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE); |
| +} |
| + |
| +string16 SyncGlobalError::GetBubbleViewMessage() { |
| + string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| + switch (error_type_) { |
| + case ERROR_TYPE_PASSPHRASE: |
| + return l10n_util::GetStringFUTF16( |
| + IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
| + case ERROR_TYPE_SIGN_IN: |
| + return l10n_util::GetStringFUTF16( |
| + IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
| + case ERROR_TYPE_UNAVAILABLE: |
| + return l10n_util::GetStringFUTF16( |
| + IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
| + case ERROR_TYPE_OTHER: |
| + return l10n_util::GetStringFUTF16( |
| + IDS_SYNC_OTHER_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
| + default: |
| + NOTREACHED(); |
| + return string16(); |
| + } |
| +} |
| + |
| +string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() { |
| + switch (error_type_) { |
| + case ERROR_TYPE_PASSPHRASE: |
| + return l10n_util::GetStringUTF16( |
| + IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); |
| + case ERROR_TYPE_SIGN_IN: |
| + case ERROR_TYPE_OTHER: |
| + return l10n_util::GetStringUTF16( |
| + IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT); |
| + case ERROR_TYPE_UNAVAILABLE: |
| + return l10n_util::GetStringUTF16( |
| + IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_ACCEPT); |
| + default: |
| + NOTREACHED(); |
| + return string16(); |
| + } |
| +} |
| + |
| +string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() { |
| + return string16(); |
| +} |
| + |
| +void SyncGlobalError::BubbleViewDidClose() { |
| +} |
| + |
| +void SyncGlobalError::BubbleViewAcceptButtonPressed() { |
| + service_->ShowErrorUI(); |
| +} |
| + |
| +void SyncGlobalError::BubbleViewCancelButtonPressed() { |
| + NOTREACHED(); |
| +} |
| + |
| +void SyncGlobalError::OnStateChanged() { |
| + error_type_ = GetUpdatedErrorType(); |
| +} |
| + |
| +bool SyncGlobalError::HasCustomizedSyncMenuItem() { |
| + return error_type_ != ERROR_TYPE_NONE; |
| +} |
| + |
| + |
|
sky
2011/09/15 19:52:07
nit: remove this line.
sail
2011/09/15 20:22:52
Done.
|
| +SyncGlobalError::ErrorType SyncGlobalError::GetUpdatedErrorType() { |
| + return ERROR_TYPE_PASSPHRASE; |
| + |
| + // If the user hasn't completed sync setup then we don't worry about errors. |
| + if (!service_->HasSyncSetupCompleted()) |
| + return ERROR_TYPE_NONE; |
| + |
| + const AuthError& auth_error = service_->GetAuthError(); |
| + switch (auth_error.state()) { |
| + case AuthError::NONE: |
| + case AuthError::CONNECTION_FAILED: |
| + break; |
| + case AuthError::INVALID_GAIA_CREDENTIALS: |
| + case AuthError::ACCOUNT_DELETED: |
| + case AuthError::ACCOUNT_DISABLED: |
| + // If no user name is entered then the error should be handled in the |
| + // setup UI. |
| + if (service_->GetAuthenticatedUsername().empty()) |
| + break; |
| + else |
| + return ERROR_TYPE_SIGN_IN; |
| + case AuthError::SERVICE_UNAVAILABLE: |
| + return ERROR_TYPE_UNAVAILABLE; |
| + default: |
| + return ERROR_TYPE_OTHER; |
| + } |
| + |
| + if (service_->IsPassphraseRequired() && |
| + service_->IsPassphraseRequiredForDecryption()) |
| + return ERROR_TYPE_PASSPHRASE; |
| + |
| + return ERROR_TYPE_NONE; |
| +} |