This source file includes following definitions.
- error_controller_
- Shutdown
- HasMenuItem
- MenuItemCommandID
- MenuItemLabel
- ExecuteMenuItem
- HasBubbleView
- GetBubbleViewTitle
- GetBubbleViewMessages
- GetBubbleViewAcceptButtonLabel
- GetBubbleViewCancelButtonLabel
- OnBubbleViewDidClose
- BubbleViewAcceptButtonPressed
- BubbleViewCancelButtonPressed
- OnErrorChanged
#include "chrome/browser/signin/signin_global_error.h"
#include "base/logging.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/url_constants.h"
#include "components/signin/core/browser/signin_manager.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h"
SigninGlobalError::SigninGlobalError(
SigninErrorController* error_controller,
Profile* profile)
: profile_(profile),
error_controller_(error_controller) {
error_controller_->AddObserver(this);
GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this);
}
SigninGlobalError::~SigninGlobalError() {
DCHECK(!error_controller_)
<< "SigninGlobalError::Shutdown() was not called";
}
void SigninGlobalError::Shutdown() {
GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this);
error_controller_->RemoveObserver(this);
error_controller_ = NULL;
}
bool SigninGlobalError::HasMenuItem() {
return error_controller_->HasError();
}
int SigninGlobalError::MenuItemCommandID() {
return IDC_SHOW_SIGNIN_ERROR;
}
base::string16 SigninGlobalError::MenuItemLabel() {
if (error_controller_->HasError())
return l10n_util::GetStringUTF16(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM);
return base::string16();
}
void SigninGlobalError::ExecuteMenuItem(Browser* browser) {
#if defined(OS_CHROMEOS)
if (error_controller_->auth_error().state() !=
GoogleServiceAuthError::NONE) {
DVLOG(1) << "Signing out the user to fix a sync error.";
chrome::ExecuteCommand(browser, IDC_EXIT);
return;
}
#endif
#if !defined(OS_ANDROID)
LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_);
if (login_ui->current_login_ui()) {
login_ui->current_login_ui()->FocusUI();
return;
}
chrome::ShowSingletonTab(
browser,
signin::GetReauthURL(profile_, error_controller_->error_account_id()));
#endif
}
bool SigninGlobalError::HasBubbleView() {
return !GetBubbleViewMessages().empty();
}
base::string16 SigninGlobalError::GetBubbleViewTitle() {
return l10n_util::GetStringUTF16(IDS_SIGNIN_ERROR_BUBBLE_VIEW_TITLE);
}
std::vector<base::string16> SigninGlobalError::GetBubbleViewMessages() {
std::vector<base::string16> messages;
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfileIfExists(profile_);
if (signin_manager) {
std::string username = signin_manager->GetAuthenticatedUsername();
if (username.empty())
return messages;
}
if (!error_controller_->HasError())
return messages;
switch (error_controller_->auth_error().state()) {
case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
case GoogleServiceAuthError::SERVICE_ERROR:
case GoogleServiceAuthError::ACCOUNT_DELETED:
case GoogleServiceAuthError::ACCOUNT_DISABLED:
messages.push_back(l10n_util::GetStringUTF16(
IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE));
break;
case GoogleServiceAuthError::SERVICE_UNAVAILABLE:
messages.push_back(l10n_util::GetStringUTF16(
IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_MESSAGE));
break;
default:
messages.push_back(l10n_util::GetStringUTF16(
IDS_SYNC_OTHER_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE));
}
return messages;
}
base::string16 SigninGlobalError::GetBubbleViewAcceptButtonLabel() {
if (error_controller_->auth_error().state() ==
GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
return l10n_util::GetStringUTF16(
IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_ACCEPT);
} else {
return l10n_util::GetStringUTF16(IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT);
}
}
base::string16 SigninGlobalError::GetBubbleViewCancelButtonLabel() {
return base::string16();
}
void SigninGlobalError::OnBubbleViewDidClose(Browser* browser) {
}
void SigninGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) {
ExecuteMenuItem(browser);
}
void SigninGlobalError::BubbleViewCancelButtonPressed(Browser* browser) {
NOTREACHED();
}
void SigninGlobalError::OnErrorChanged() {
GlobalErrorServiceFactory::GetForProfile(profile_)->NotifyErrorsChanged(this);
}