blob: e3297190b6c51b2d7bf030eca569c7f2adebf6e7 [file] [log] [blame]
[email protected]c6b207c2012-01-25 04:25:451// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2710ca62011-09-21 00:52:522// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/sync/sync_global_error.h"
6
[email protected]fbf356892011-10-13 00:45:107#include "chrome/app/chrome_command_ids.h"
[email protected]2710ca62011-09-21 00:52:528#include "chrome/browser/sync/profile_sync_service.h"
[email protected]07cd37382013-03-20 14:52:479#include "chrome/browser/sync/profile_sync_service_observer.h"
[email protected]2710ca62011-09-21 00:52:5210#include "chrome/browser/sync/sync_ui_util.h"
[email protected]e09155d2012-02-17 23:57:3111#include "chrome/browser/ui/browser.h"
[email protected]5d98294912012-06-27 22:57:4012#include "chrome/browser/ui/browser_commands.h"
[email protected]91305c8c2012-12-18 00:52:2113#include "chrome/browser/ui/chrome_pages.h"
[email protected]1ba55cf2012-06-29 19:11:3914#include "chrome/browser/ui/global_error/global_error_service.h"
15#include "chrome/browser/ui/global_error/global_error_service_factory.h"
[email protected]abb842a2012-04-26 00:46:1716#include "chrome/browser/ui/webui/signin/login_ui_service.h"
17#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
[email protected]91305c8c2012-12-18 00:52:2118#include "chrome/common/url_constants.h"
[email protected]6386cf52012-09-07 04:26:3719#include "google_apis/gaia/google_service_auth_error.h"
[email protected]2710ca62011-09-21 00:52:5220#include "grit/chromium_strings.h"
21#include "grit/generated_resources.h"
22#include "ui/base/l10n/l10n_util.h"
23
[email protected]bd985a22012-04-11 03:58:3824SyncGlobalError::SyncGlobalError(ProfileSyncService* service,
[email protected]d5bcd06f2013-04-21 08:07:2425 SigninManagerBase* signin)
[email protected]bd985a22012-04-11 03:58:3826 : service_(service),
27 signin_(signin) {
28 DCHECK(service_);
29 DCHECK(signin_);
[email protected]2710ca62011-09-21 00:52:5230 OnStateChanged();
31}
32
33SyncGlobalError::~SyncGlobalError() {
34}
35
[email protected]2710ca62011-09-21 00:52:5236bool SyncGlobalError::HasMenuItem() {
[email protected]9c60fa402011-10-17 22:38:5037 return !menu_label_.empty();
[email protected]2710ca62011-09-21 00:52:5238}
39
40int SyncGlobalError::MenuItemCommandID() {
[email protected]d28c6b2c2013-01-17 16:05:1941 return IDC_SHOW_SIGNIN_ERROR;
[email protected]2710ca62011-09-21 00:52:5242}
43
44string16 SyncGlobalError::MenuItemLabel() {
[email protected]9c60fa402011-10-17 22:38:5045 return menu_label_;
[email protected]2710ca62011-09-21 00:52:5246}
47
48void SyncGlobalError::ExecuteMenuItem(Browser* browser) {
[email protected]91305c8c2012-12-18 00:52:2149 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(
50 service_->profile());
51 if (login_ui->current_login_ui()) {
52 login_ui->current_login_ui()->FocusUI();
53 return;
54 }
55 // Need to navigate to the settings page and display the UI.
56 chrome::ShowSettingsSubPage(browser, chrome::kSyncSetupSubPage);
[email protected]2710ca62011-09-21 00:52:5257}
58
59bool SyncGlobalError::HasBubbleView() {
[email protected]9c60fa402011-10-17 22:38:5060 return !bubble_message_.empty() && !bubble_accept_label_.empty();
[email protected]2710ca62011-09-21 00:52:5261}
62
63string16 SyncGlobalError::GetBubbleViewTitle() {
64 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE);
65}
66
[email protected]44d628f2013-04-16 19:13:0167std::vector<string16> SyncGlobalError::GetBubbleViewMessages() {
68 return std::vector<string16>(1, bubble_message_);
[email protected]2710ca62011-09-21 00:52:5269}
70
71string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() {
[email protected]9c60fa402011-10-17 22:38:5072 return bubble_accept_label_;
[email protected]2710ca62011-09-21 00:52:5273}
74
75string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() {
76 return string16();
77}
78
[email protected]c6b207c2012-01-25 04:25:4579void SyncGlobalError::OnBubbleViewDidClose(Browser* browser) {
[email protected]2710ca62011-09-21 00:52:5280}
81
[email protected]c6b207c2012-01-25 04:25:4582void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) {
[email protected]e09155d2012-02-17 23:57:3183 ExecuteMenuItem(browser);
[email protected]2710ca62011-09-21 00:52:5284}
85
[email protected]c6b207c2012-01-25 04:25:4586void SyncGlobalError::BubbleViewCancelButtonPressed(Browser* browser) {
[email protected]2710ca62011-09-21 00:52:5287 NOTREACHED();
88}
89
90void SyncGlobalError::OnStateChanged() {
[email protected]9c60fa402011-10-17 22:38:5091 string16 menu_label;
92 string16 bubble_message;
93 string16 bubble_accept_label;
94 sync_ui_util::GetStatusLabelsForSyncGlobalError(
[email protected]bd985a22012-04-11 03:58:3895 service_, *signin_, &menu_label, &bubble_message, &bubble_accept_label);
[email protected]9c60fa402011-10-17 22:38:5096
97 // All the labels should be empty or all of them non-empty.
98 DCHECK((menu_label.empty() && bubble_message.empty() &&
99 bubble_accept_label.empty()) ||
100 (!menu_label.empty() && !bubble_message.empty() &&
101 !bubble_accept_label.empty()));
102
103 if (menu_label != menu_label_ || bubble_message != bubble_message_ ||
104 bubble_accept_label != bubble_accept_label_) {
105 menu_label_ = menu_label;
106 bubble_message_ = bubble_message;
107 bubble_accept_label_ = bubble_accept_label;
108
109 // Profile can be NULL during tests.
110 Profile* profile = service_->profile();
111 if (profile) {
112 GlobalErrorServiceFactory::GetForProfile(
113 profile)->NotifyErrorsChanged(this);
114 }
[email protected]5afcbf42011-09-22 01:58:02115 }
[email protected]2710ca62011-09-21 00:52:52116}