• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/sync/sync_global_error.h"
6 
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"
22 
SyncGlobalError(SyncErrorController * error_controller,ProfileSyncService * profile_sync_service)23 SyncGlobalError::SyncGlobalError(SyncErrorController* error_controller,
24                                  ProfileSyncService* profile_sync_service)
25     : error_controller_(error_controller),
26       service_(profile_sync_service) {
27   DCHECK(service_);
28   error_controller_->AddObserver(this);
29   GlobalErrorServiceFactory::GetForProfile(service_->profile())->
30       AddGlobalError(this);
31 }
32 
~SyncGlobalError()33 SyncGlobalError::~SyncGlobalError() {
34   DCHECK(!error_controller_)
35       << "SigninGlobalError::Shutdown() was not called";
36 }
37 
Shutdown()38 void SyncGlobalError::Shutdown() {
39   GlobalErrorServiceFactory::GetForProfile(service_->profile())->
40       RemoveGlobalError(this);
41   error_controller_->RemoveObserver(this);
42   error_controller_ = NULL;
43 }
44 
HasMenuItem()45 bool SyncGlobalError::HasMenuItem() {
46   return !menu_label_.empty();
47 }
48 
MenuItemCommandID()49 int SyncGlobalError::MenuItemCommandID() {
50   return IDC_SHOW_SYNC_ERROR;
51 }
52 
MenuItemLabel()53 base::string16 SyncGlobalError::MenuItemLabel() {
54   return menu_label_;
55 }
56 
ExecuteMenuItem(Browser * browser)57 void SyncGlobalError::ExecuteMenuItem(Browser* browser) {
58   LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(
59       service_->profile());
60   if (login_ui->current_login_ui()) {
61     login_ui->current_login_ui()->FocusUI();
62     return;
63   }
64   // Need to navigate to the settings page and display the UI.
65   chrome::ShowSettingsSubPage(browser, chrome::kSyncSetupSubPage);
66 }
67 
HasBubbleView()68 bool SyncGlobalError::HasBubbleView() {
69   return !bubble_message_.empty() && !bubble_accept_label_.empty();
70 }
71 
GetBubbleViewTitle()72 base::string16 SyncGlobalError::GetBubbleViewTitle() {
73   return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE);
74 }
75 
GetBubbleViewMessages()76 std::vector<base::string16> SyncGlobalError::GetBubbleViewMessages() {
77   return std::vector<base::string16>(1, bubble_message_);
78 }
79 
GetBubbleViewAcceptButtonLabel()80 base::string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() {
81   return bubble_accept_label_;
82 }
83 
GetBubbleViewCancelButtonLabel()84 base::string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() {
85   return base::string16();
86 }
87 
OnBubbleViewDidClose(Browser * browser)88 void SyncGlobalError::OnBubbleViewDidClose(Browser* browser) {
89 }
90 
BubbleViewAcceptButtonPressed(Browser * browser)91 void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) {
92   ExecuteMenuItem(browser);
93 }
94 
BubbleViewCancelButtonPressed(Browser * browser)95 void SyncGlobalError::BubbleViewCancelButtonPressed(Browser* browser) {
96   NOTREACHED();
97 }
98 
OnErrorChanged()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);
105 
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()));
111 
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;
117 
118     // Profile can be NULL during tests.
119     Profile* profile = service_->profile();
120     if (profile) {
121       GlobalErrorServiceFactory::GetForProfile(
122           profile)->NotifyErrorsChanged(this);
123     }
124   }
125 }
126