1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/sync_global_error.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/sync/profile_sync_service.h"
9 #include "chrome/browser/sync/sync_ui_util.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/chrome_pages.h"
13 #include "chrome/browser/ui/global_error/global_error_service.h"
14 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
15 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
17 #include "chrome/common/url_constants.h"
18 #include "google_apis/gaia/google_service_auth_error.h"
19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h"
23 SyncGlobalError::SyncGlobalError(SyncErrorController
* error_controller
,
24 ProfileSyncService
* profile_sync_service
)
25 : error_controller_(error_controller
),
26 service_(profile_sync_service
) {
28 error_controller_
->AddObserver(this);
29 GlobalErrorServiceFactory::GetForProfile(service_
->profile())->
33 SyncGlobalError::~SyncGlobalError() {
34 DCHECK(!error_controller_
)
35 << "SigninGlobalError::Shutdown() was not called";
38 void SyncGlobalError::Shutdown() {
39 GlobalErrorServiceFactory::GetForProfile(service_
->profile())->
40 RemoveGlobalError(this);
41 error_controller_
->RemoveObserver(this);
42 error_controller_
= NULL
;
45 bool SyncGlobalError::HasMenuItem() {
46 return !menu_label_
.empty();
49 int SyncGlobalError::MenuItemCommandID() {
50 return IDC_SHOW_SYNC_ERROR
;
53 base::string16
SyncGlobalError::MenuItemLabel() {
57 void SyncGlobalError::ExecuteMenuItem(Browser
* browser
) {
58 LoginUIService
* login_ui
= LoginUIServiceFactory::GetForProfile(
60 if (login_ui
->current_login_ui()) {
61 login_ui
->current_login_ui()->FocusUI();
64 // Need to navigate to the settings page and display the UI.
65 chrome::ShowSettingsSubPage(browser
, chrome::kSyncSetupSubPage
);
68 bool SyncGlobalError::HasBubbleView() {
69 return !bubble_message_
.empty() && !bubble_accept_label_
.empty();
72 base::string16
SyncGlobalError::GetBubbleViewTitle() {
73 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE
);
76 std::vector
<base::string16
> SyncGlobalError::GetBubbleViewMessages() {
77 return std::vector
<base::string16
>(1, bubble_message_
);
80 base::string16
SyncGlobalError::GetBubbleViewAcceptButtonLabel() {
81 return bubble_accept_label_
;
84 base::string16
SyncGlobalError::GetBubbleViewCancelButtonLabel() {
85 return base::string16();
88 void SyncGlobalError::OnBubbleViewDidClose(Browser
* browser
) {
91 void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser
* browser
) {
92 ExecuteMenuItem(browser
);
95 void SyncGlobalError::BubbleViewCancelButtonPressed(Browser
* browser
) {
99 void SyncGlobalError::OnErrorChanged() {
100 base::string16 menu_label
;
101 base::string16 bubble_message
;
102 base::string16 bubble_accept_label
;
103 sync_ui_util::GetStatusLabelsForSyncGlobalError(
104 service_
, &menu_label
, &bubble_message
, &bubble_accept_label
);
106 // All the labels should be empty or all of them non-empty.
107 DCHECK((menu_label
.empty() && bubble_message
.empty() &&
108 bubble_accept_label
.empty()) ||
109 (!menu_label
.empty() && !bubble_message
.empty() &&
110 !bubble_accept_label
.empty()));
112 if (menu_label
!= menu_label_
|| bubble_message
!= bubble_message_
||
113 bubble_accept_label
!= bubble_accept_label_
) {
114 menu_label_
= menu_label
;
115 bubble_message_
= bubble_message
;
116 bubble_accept_label_
= bubble_accept_label
;
118 // Profile can be NULL during tests.
119 Profile
* profile
= service_
->profile();
121 GlobalErrorServiceFactory::GetForProfile(
122 profile
)->NotifyErrorsChanged(this);