| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/signin/signin_global_error.h" | 5 #include "chrome/browser/signin/signin_global_error.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/signin/signin_promo.h" | 11 #include "chrome/browser/signin/signin_promo.h" |
| 12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
| 13 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/chrome_pages.h" | 14 #include "chrome/browser/ui/chrome_pages.h" |
| 14 #include "chrome/browser/ui/global_error/global_error_service.h" | 15 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 15 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 16 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 16 #include "chrome/browser/ui/singleton_tabs.h" | 17 #include "chrome/browser/ui/singleton_tabs.h" |
| 17 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 18 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 19 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "components/signin/core/browser/signin_manager.h" | 21 #include "components/signin/core/browser/signin_manager.h" |
| 22 #include "components/signin/core/common/profile_management_switches.h" |
| 21 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 23 #include "net/base/url_util.h" | 25 #include "net/base/url_util.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 25 | 27 |
| 26 SigninGlobalError::SigninGlobalError( | 28 SigninGlobalError::SigninGlobalError( |
| 27 SigninErrorController* error_controller, | 29 SigninErrorController* error_controller, |
| 28 Profile* profile) | 30 Profile* profile) |
| 29 : profile_(profile), | 31 : profile_(profile), |
| 30 error_controller_(error_controller) { | 32 error_controller_(error_controller), |
| 33 is_added_to_global_error_service_(false) { |
| 31 error_controller_->AddObserver(this); | 34 error_controller_->AddObserver(this); |
| 32 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this); | 35 is_added_to_global_error_service_ = !switches::IsNewProfileManagement(); |
| 36 if (is_added_to_global_error_service_) |
| 37 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this); |
| 33 } | 38 } |
| 34 | 39 |
| 35 SigninGlobalError::~SigninGlobalError() { | 40 SigninGlobalError::~SigninGlobalError() { |
| 36 DCHECK(!error_controller_) | 41 DCHECK(!error_controller_) |
| 37 << "SigninGlobalError::Shutdown() was not called"; | 42 << "SigninGlobalError::Shutdown() was not called"; |
| 38 } | 43 } |
| 39 | 44 |
| 40 bool SigninGlobalError::HasError() { | 45 bool SigninGlobalError::HasError() { |
| 41 return HasMenuItem(); | 46 return HasMenuItem(); |
| 42 } | 47 } |
| 43 | 48 |
| 44 void SigninGlobalError::AttemptToFixError(Browser* browser) { | 49 void SigninGlobalError::AttemptToFixError(Browser* browser) { |
| 45 if (!HasError()) | 50 if (!HasError()) |
| 46 return; | 51 return; |
| 47 | 52 |
| 48 ExecuteMenuItem(browser); | 53 ExecuteMenuItem(browser); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void SigninGlobalError::Shutdown() { | 56 void SigninGlobalError::Shutdown() { |
| 52 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); | 57 if (is_added_to_global_error_service_) { |
| 58 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); |
| 59 is_added_to_global_error_service_ = false; |
| 60 } |
| 61 |
| 53 error_controller_->RemoveObserver(this); | 62 error_controller_->RemoveObserver(this); |
| 54 error_controller_ = NULL; | 63 error_controller_ = NULL; |
| 55 } | 64 } |
| 56 | 65 |
| 57 bool SigninGlobalError::HasMenuItem() { | 66 bool SigninGlobalError::HasMenuItem() { |
| 58 return error_controller_->HasError(); | 67 return error_controller_->HasError(); |
| 59 } | 68 } |
| 60 | 69 |
| 61 int SigninGlobalError::MenuItemCommandID() { | 70 int SigninGlobalError::MenuItemCommandID() { |
| 62 return IDC_SHOW_SIGNIN_ERROR; | 71 return IDC_SHOW_SIGNIN_ERROR; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 81 #endif | 90 #endif |
| 82 | 91 |
| 83 // Global errors don't show up in the wrench menu on android. | 92 // Global errors don't show up in the wrench menu on android. |
| 84 #if !defined(OS_ANDROID) | 93 #if !defined(OS_ANDROID) |
| 85 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); | 94 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); |
| 86 if (login_ui->current_login_ui()) { | 95 if (login_ui->current_login_ui()) { |
| 87 login_ui->current_login_ui()->FocusUI(); | 96 login_ui->current_login_ui()->FocusUI(); |
| 88 return; | 97 return; |
| 89 } | 98 } |
| 90 | 99 |
| 91 chrome::ShowSingletonTab( | 100 if (switches::IsNewProfileManagement()) { |
| 92 browser, | 101 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 93 signin::GetReauthURL(profile_, error_controller_->error_account_id())); | 102 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH); |
| 103 } else { |
| 104 chrome::ShowSingletonTab( |
| 105 browser, |
| 106 signin::GetReauthURL(profile_, error_controller_->error_account_id())); |
| 107 } |
| 94 #endif | 108 #endif |
| 95 } | 109 } |
| 96 | 110 |
| 97 bool SigninGlobalError::HasBubbleView() { | 111 bool SigninGlobalError::HasBubbleView() { |
| 98 return !GetBubbleViewMessages().empty(); | 112 return !GetBubbleViewMessages().empty(); |
| 99 } | 113 } |
| 100 | 114 |
| 101 base::string16 SigninGlobalError::GetBubbleViewTitle() { | 115 base::string16 SigninGlobalError::GetBubbleViewTitle() { |
| 102 return l10n_util::GetStringUTF16(IDS_SIGNIN_ERROR_BUBBLE_VIEW_TITLE); | 116 return l10n_util::GetStringUTF16(IDS_SIGNIN_ERROR_BUBBLE_VIEW_TITLE); |
| 103 } | 117 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 ExecuteMenuItem(browser); | 180 ExecuteMenuItem(browser); |
| 167 } | 181 } |
| 168 | 182 |
| 169 void SigninGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | 183 void SigninGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
| 170 NOTREACHED(); | 184 NOTREACHED(); |
| 171 } | 185 } |
| 172 | 186 |
| 173 void SigninGlobalError::OnErrorChanged() { | 187 void SigninGlobalError::OnErrorChanged() { |
| 174 GlobalErrorServiceFactory::GetForProfile(profile_)->NotifyErrorsChanged(this); | 188 GlobalErrorServiceFactory::GetForProfile(profile_)->NotifyErrorsChanged(this); |
| 175 } | 189 } |
| OLD | NEW |