blob: 1e539c8bc674b676d9197b938cbc81bf1b3c274b [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]e6cb45bd2012-09-19 17:46:108#include "chrome/browser/api/sync/profile_sync_service_observer.h"
[email protected]2710ca62011-09-21 00:52:529#include "chrome/browser/sync/profile_sync_service.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,
25 SigninManager* signin)
26 : 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
36bool SyncGlobalError::HasBadge() {
[email protected]9c60fa402011-10-17 22:38:5037 return !menu_label_.empty();
[email protected]2710ca62011-09-21 00:52:5238}
39
40bool SyncGlobalError::HasMenuItem() {
[email protected]fbf356892011-10-13 00:45:1041 // When we're on Chrome OS we need to add a separate menu item to the wrench
42 // menu to the show the error. On other platforms we can just reuse the
43 // "Sign in to Chrome..." menu item to show the error.
44#if defined(OS_CHROMEOS)
[email protected]9c60fa402011-10-17 22:38:5045 return !menu_label_.empty();
[email protected]fbf356892011-10-13 00:45:1046#else
[email protected]2710ca62011-09-21 00:52:5247 return false;
[email protected]fbf356892011-10-13 00:45:1048#endif
[email protected]2710ca62011-09-21 00:52:5249}
50
51int SyncGlobalError::MenuItemCommandID() {
[email protected]d28c6b2c2013-01-17 16:05:1952 return IDC_SHOW_SIGNIN_ERROR;
[email protected]2710ca62011-09-21 00:52:5253}
54
55string16 SyncGlobalError::MenuItemLabel() {
[email protected]9c60fa402011-10-17 22:38:5056 return menu_label_;
[email protected]2710ca62011-09-21 00:52:5257}
58
59void SyncGlobalError::ExecuteMenuItem(Browser* browser) {
[email protected]91305c8c2012-12-18 00:52:2160 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(
61 service_->profile());
62 if (login_ui->current_login_ui()) {
63 login_ui->current_login_ui()->FocusUI();
64 return;
65 }
66 // Need to navigate to the settings page and display the UI.
67 chrome::ShowSettingsSubPage(browser, chrome::kSyncSetupSubPage);
[email protected]2710ca62011-09-21 00:52:5268}
69
70bool SyncGlobalError::HasBubbleView() {
[email protected]9c60fa402011-10-17 22:38:5071 return !bubble_message_.empty() && !bubble_accept_label_.empty();
[email protected]2710ca62011-09-21 00:52:5272}
73
74string16 SyncGlobalError::GetBubbleViewTitle() {
75 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE);
76}
77
78string16 SyncGlobalError::GetBubbleViewMessage() {
[email protected]9c60fa402011-10-17 22:38:5079 return bubble_message_;
[email protected]2710ca62011-09-21 00:52:5280}
81
82string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() {
[email protected]9c60fa402011-10-17 22:38:5083 return bubble_accept_label_;
[email protected]2710ca62011-09-21 00:52:5284}
85
86string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() {
87 return string16();
88}
89
[email protected]c6b207c2012-01-25 04:25:4590void SyncGlobalError::OnBubbleViewDidClose(Browser* browser) {
[email protected]2710ca62011-09-21 00:52:5291}
92
[email protected]c6b207c2012-01-25 04:25:4593void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) {
[email protected]e09155d2012-02-17 23:57:3194 ExecuteMenuItem(browser);
[email protected]2710ca62011-09-21 00:52:5295}
96
[email protected]c6b207c2012-01-25 04:25:4597void SyncGlobalError::BubbleViewCancelButtonPressed(Browser* browser) {
[email protected]2710ca62011-09-21 00:52:5298 NOTREACHED();
99}
100
101void SyncGlobalError::OnStateChanged() {
[email protected]9c60fa402011-10-17 22:38:50102 string16 menu_label;
103 string16 bubble_message;
104 string16 bubble_accept_label;
105 sync_ui_util::GetStatusLabelsForSyncGlobalError(
[email protected]bd985a22012-04-11 03:58:38106 service_, *signin_, &menu_label, &bubble_message, &bubble_accept_label);
[email protected]9c60fa402011-10-17 22:38:50107
108 // All the labels should be empty or all of them non-empty.
109 DCHECK((menu_label.empty() && bubble_message.empty() &&
110 bubble_accept_label.empty()) ||
111 (!menu_label.empty() && !bubble_message.empty() &&
112 !bubble_accept_label.empty()));
113
114 if (menu_label != menu_label_ || bubble_message != bubble_message_ ||
115 bubble_accept_label != bubble_accept_label_) {
116 menu_label_ = menu_label;
117 bubble_message_ = bubble_message;
118 bubble_accept_label_ = bubble_accept_label;
119
120 // Profile can be NULL during tests.
121 Profile* profile = service_->profile();
122 if (profile) {
123 GlobalErrorServiceFactory::GetForProfile(
124 profile)->NotifyErrorsChanged(this);
125 }
[email protected]5afcbf42011-09-22 01:58:02126 }
[email protected]2710ca62011-09-21 00:52:52127}