OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/sync_global_error.h" | 5 #include "chrome/browser/sync/sync_global_error.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/api/sync/profile_sync_service_observer.h" | 8 #include "chrome/browser/api/sync/profile_sync_service_observer.h" |
9 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
10 #include "chrome/browser/sync/sync_ui_util.h" | 10 #include "chrome/browser/sync/sync_ui_util.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/chrome_pages.h" | 13 #include "chrome/browser/ui/chrome_pages.h" |
14 #include "chrome/browser/ui/global_error/global_error_service.h" | 14 #include "chrome/browser/ui/global_error/global_error_service.h" |
15 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 15 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "google_apis/gaia/google_service_auth_error.h" | 19 #include "google_apis/gaia/google_service_auth_error.h" |
20 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 | 23 |
24 typedef GoogleServiceAuthError AuthError; | |
25 | |
26 SyncGlobalError::SyncGlobalError(ProfileSyncService* service, | 24 SyncGlobalError::SyncGlobalError(ProfileSyncService* service, |
27 SigninManager* signin) | 25 SigninManager* signin) |
28 : service_(service), | 26 : service_(service), |
29 signin_(signin) { | 27 signin_(signin) { |
30 DCHECK(service_); | 28 DCHECK(service_); |
31 DCHECK(signin_); | 29 DCHECK(signin_); |
32 OnStateChanged(); | 30 OnStateChanged(); |
33 } | 31 } |
34 | 32 |
35 SyncGlobalError::~SyncGlobalError() { | 33 SyncGlobalError::~SyncGlobalError() { |
36 } | 34 } |
37 | 35 |
38 bool SyncGlobalError::HasBadge() { | 36 bool SyncGlobalError::HasBadge() { |
39 return !menu_label_.empty(); | 37 return !menu_label_.empty(); |
40 } | 38 } |
41 | 39 |
42 bool SyncGlobalError::HasMenuItem() { | 40 bool SyncGlobalError::HasMenuItem() { |
43 // When we're on Chrome OS we need to add a separate menu item to the wrench | 41 // When we're on Chrome OS we need to add a separate menu item to the wrench |
44 // menu to the show the error. On other platforms we can just reuse the | 42 // menu to the show the error. On other platforms we can just reuse the |
45 // "Sign in to Chrome..." menu item to show the error. | 43 // "Sign in to Chrome..." menu item to show the error. |
46 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
47 return !menu_label_.empty(); | 45 return !menu_label_.empty(); |
48 #else | 46 #else |
49 return false; | 47 return false; |
50 #endif | 48 #endif |
51 } | 49 } |
52 | 50 |
53 int SyncGlobalError::MenuItemCommandID() { | 51 int SyncGlobalError::MenuItemCommandID() { |
54 return IDC_SHOW_SYNC_ERROR; | 52 return IDC_SHOW_SIGNIN_ERROR; |
55 } | 53 } |
56 | 54 |
57 string16 SyncGlobalError::MenuItemLabel() { | 55 string16 SyncGlobalError::MenuItemLabel() { |
58 return menu_label_; | 56 return menu_label_; |
59 } | 57 } |
60 | 58 |
61 void SyncGlobalError::ExecuteMenuItem(Browser* browser) { | 59 void SyncGlobalError::ExecuteMenuItem(Browser* browser) { |
62 #if defined(OS_CHROMEOS) | |
63 if (service_->GetAuthError().state() != AuthError::NONE) { | |
64 DLOG(INFO) << "Signing out the user to fix a sync error."; | |
65 // TODO(beng): seems like this could just call browser::AttemptUserExit(). | |
66 chrome::ExecuteCommand(browser, IDC_EXIT); | |
67 return; | |
68 } | |
69 #endif | |
70 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile( | 60 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile( |
71 service_->profile()); | 61 service_->profile()); |
72 if (login_ui->current_login_ui()) { | 62 if (login_ui->current_login_ui()) { |
73 login_ui->current_login_ui()->FocusUI(); | 63 login_ui->current_login_ui()->FocusUI(); |
74 return; | 64 return; |
75 } | 65 } |
76 // Need to navigate to the settings page and display the UI. | 66 // Need to navigate to the settings page and display the UI. |
77 chrome::ShowSettingsSubPage(browser, chrome::kSyncSetupSubPage); | 67 chrome::ShowSettingsSubPage(browser, chrome::kSyncSetupSubPage); |
78 } | 68 } |
79 | 69 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 bubble_accept_label_ = bubble_accept_label; | 118 bubble_accept_label_ = bubble_accept_label; |
129 | 119 |
130 // Profile can be NULL during tests. | 120 // Profile can be NULL during tests. |
131 Profile* profile = service_->profile(); | 121 Profile* profile = service_->profile(); |
132 if (profile) { | 122 if (profile) { |
133 GlobalErrorServiceFactory::GetForProfile( | 123 GlobalErrorServiceFactory::GetForProfile( |
134 profile)->NotifyErrorsChanged(this); | 124 profile)->NotifyErrorsChanged(this); |
135 } | 125 } |
136 } | 126 } |
137 } | 127 } |
138 | |
139 bool SyncGlobalError::HasCustomizedSyncMenuItem() { | |
140 return !menu_label_.empty(); | |
141 } | |
OLD | NEW |