[email protected] | c6b207c | 2012-01-25 04:25:45 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 2 | // 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] | fbf35689 | 2011-10-13 00:45:10 | [diff] [blame] | 7 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 8 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 07cd3738 | 2013-03-20 14:52:47 | [diff] [blame] | 9 | #include "chrome/browser/sync/profile_sync_service_observer.h" |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 10 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | e09155d | 2012-02-17 23:57:31 | [diff] [blame] | 11 | #include "chrome/browser/ui/browser.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 91305c8c | 2012-12-18 00:52:21 | [diff] [blame] | 13 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 1ba55cf | 2012-06-29 19:11:39 | [diff] [blame] | 14 | #include "chrome/browser/ui/global_error/global_error_service.h" |
15 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" | ||||
[email protected] | abb842a | 2012-04-26 00:46:17 | [diff] [blame] | 16 | #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
17 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | ||||
[email protected] | 91305c8c | 2012-12-18 00:52:21 | [diff] [blame] | 18 | #include "chrome/common/url_constants.h" |
[email protected] | 6386cf5 | 2012-09-07 04:26:37 | [diff] [blame] | 19 | #include "google_apis/gaia/google_service_auth_error.h" |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 20 | #include "grit/chromium_strings.h" |
21 | #include "grit/generated_resources.h" | ||||
22 | #include "ui/base/l10n/l10n_util.h" | ||||
23 | |||||
[email protected] | bd985a2 | 2012-04-11 03:58:38 | [diff] [blame] | 24 | SyncGlobalError::SyncGlobalError(ProfileSyncService* service, |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 25 | SigninManagerBase* signin) |
[email protected] | bd985a2 | 2012-04-11 03:58:38 | [diff] [blame] | 26 | : service_(service), |
27 | signin_(signin) { | ||||
28 | DCHECK(service_); | ||||
29 | DCHECK(signin_); | ||||
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 30 | OnStateChanged(); |
31 | } | ||||
32 | |||||
33 | SyncGlobalError::~SyncGlobalError() { | ||||
34 | } | ||||
35 | |||||
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 36 | bool SyncGlobalError::HasMenuItem() { |
[email protected] | 9c60fa40 | 2011-10-17 22:38:50 | [diff] [blame] | 37 | return !menu_label_.empty(); |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 38 | } |
39 | |||||
40 | int SyncGlobalError::MenuItemCommandID() { | ||||
[email protected] | d28c6b2c | 2013-01-17 16:05:19 | [diff] [blame] | 41 | return IDC_SHOW_SIGNIN_ERROR; |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 42 | } |
43 | |||||
44 | string16 SyncGlobalError::MenuItemLabel() { | ||||
[email protected] | 9c60fa40 | 2011-10-17 22:38:50 | [diff] [blame] | 45 | return menu_label_; |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 46 | } |
47 | |||||
48 | void SyncGlobalError::ExecuteMenuItem(Browser* browser) { | ||||
[email protected] | 91305c8c | 2012-12-18 00:52:21 | [diff] [blame] | 49 | 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] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 57 | } |
58 | |||||
59 | bool SyncGlobalError::HasBubbleView() { | ||||
[email protected] | 9c60fa40 | 2011-10-17 22:38:50 | [diff] [blame] | 60 | return !bubble_message_.empty() && !bubble_accept_label_.empty(); |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 61 | } |
62 | |||||
63 | string16 SyncGlobalError::GetBubbleViewTitle() { | ||||
64 | return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE); | ||||
65 | } | ||||
66 | |||||
[email protected] | 44d628f | 2013-04-16 19:13:01 | [diff] [blame] | 67 | std::vector<string16> SyncGlobalError::GetBubbleViewMessages() { |
68 | return std::vector<string16>(1, bubble_message_); | ||||
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 69 | } |
70 | |||||
71 | string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() { | ||||
[email protected] | 9c60fa40 | 2011-10-17 22:38:50 | [diff] [blame] | 72 | return bubble_accept_label_; |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 73 | } |
74 | |||||
75 | string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() { | ||||
76 | return string16(); | ||||
77 | } | ||||
78 | |||||
[email protected] | c6b207c | 2012-01-25 04:25:45 | [diff] [blame] | 79 | void SyncGlobalError::OnBubbleViewDidClose(Browser* browser) { |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 80 | } |
81 | |||||
[email protected] | c6b207c | 2012-01-25 04:25:45 | [diff] [blame] | 82 | void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { |
[email protected] | e09155d | 2012-02-17 23:57:31 | [diff] [blame] | 83 | ExecuteMenuItem(browser); |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 84 | } |
85 | |||||
[email protected] | c6b207c | 2012-01-25 04:25:45 | [diff] [blame] | 86 | void SyncGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 87 | NOTREACHED(); |
88 | } | ||||
89 | |||||
90 | void SyncGlobalError::OnStateChanged() { | ||||
[email protected] | 9c60fa40 | 2011-10-17 22:38:50 | [diff] [blame] | 91 | string16 menu_label; |
92 | string16 bubble_message; | ||||
93 | string16 bubble_accept_label; | ||||
94 | sync_ui_util::GetStatusLabelsForSyncGlobalError( | ||||
[email protected] | bd985a2 | 2012-04-11 03:58:38 | [diff] [blame] | 95 | service_, *signin_, &menu_label, &bubble_message, &bubble_accept_label); |
[email protected] | 9c60fa40 | 2011-10-17 22:38:50 | [diff] [blame] | 96 | |
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] | 5afcbf4 | 2011-09-22 01:58:02 | [diff] [blame] | 115 | } |
[email protected] | 2710ca6 | 2011-09-21 00:52:52 | [diff] [blame] | 116 | } |