| 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/ui/webui/signin/login_ui_service.h" | 5 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/signin_promo.h" | 9 #include "chrome/browser/signin/signin_promo.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/chrome_pages.h" | 12 #include "chrome/browser/ui/chrome_pages.h" |
| 13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "components/signin/core/browser/signin_header_helper.h" | 16 #include "components/signin/core/browser/signin_header_helper.h" |
| 17 #include "components/signin/core/common/profile_management_switches.h" | 17 #include "components/signin/core/common/profile_management_switches.h" |
| 18 | 18 |
| 19 LoginUIService::LoginUIService(Profile* profile) | 19 LoginUIService::LoginUIService(Profile* profile) |
| 20 : ui_(NULL), profile_(profile) { | 20 : profile_(profile) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 LoginUIService::~LoginUIService() {} | 23 LoginUIService::~LoginUIService() {} |
| 24 | 24 |
| 25 void LoginUIService::AddObserver(LoginUIService::Observer* observer) { | 25 void LoginUIService::AddObserver(LoginUIService::Observer* observer) { |
| 26 observer_list_.AddObserver(observer); | 26 observer_list_.AddObserver(observer); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void LoginUIService::RemoveObserver(LoginUIService::Observer* observer) { | 29 void LoginUIService::RemoveObserver(LoginUIService::Observer* observer) { |
| 30 observer_list_.RemoveObserver(observer); | 30 observer_list_.RemoveObserver(observer); |
| 31 } | 31 } |
| 32 | 32 |
| 33 LoginUIService::LoginUI* LoginUIService::current_login_ui() const { |
| 34 return ui_list_.empty() ? nullptr : ui_list_.front(); |
| 35 } |
| 36 |
| 33 void LoginUIService::SetLoginUI(LoginUI* ui) { | 37 void LoginUIService::SetLoginUI(LoginUI* ui) { |
| 34 DCHECK(!current_login_ui() || current_login_ui() == ui); | 38 ui_list_.remove(ui); |
| 35 ui_ = ui; | 39 ui_list_.push_front(ui); |
| 36 FOR_EACH_OBSERVER(Observer, observer_list_, OnLoginUIShown(ui_)); | |
| 37 } | 40 } |
| 38 | 41 |
| 39 void LoginUIService::LoginUIClosed(LoginUI* ui) { | 42 void LoginUIService::LoginUIClosed(LoginUI* ui) { |
| 40 if (current_login_ui() != ui) | 43 ui_list_.remove(ui); |
| 41 return; | |
| 42 | |
| 43 ui_ = NULL; | |
| 44 FOR_EACH_OBSERVER(Observer, observer_list_, OnLoginUIClosed(ui)); | |
| 45 } | 44 } |
| 46 | 45 |
| 47 void LoginUIService::SyncConfirmationUIClosed( | 46 void LoginUIService::SyncConfirmationUIClosed( |
| 48 SyncConfirmationUIClosedResult result) { | 47 SyncConfirmationUIClosedResult result) { |
| 49 FOR_EACH_OBSERVER( | 48 FOR_EACH_OBSERVER( |
| 50 Observer, | 49 Observer, |
| 51 observer_list_, | 50 observer_list_, |
| 52 OnSyncConfirmationUIClosed(result)); | 51 OnSyncConfirmationUIClosed(result)); |
| 53 } | 52 } |
| 54 | 53 |
| 55 void LoginUIService::UntrustedLoginUIShown() { | |
| 56 FOR_EACH_OBSERVER(Observer, observer_list_, OnUntrustedLoginUIShown()); | |
| 57 } | |
| 58 | |
| 59 void LoginUIService::ShowLoginPopup() { | 54 void LoginUIService::ShowLoginPopup() { |
| 60 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 61 NOTREACHED(); | 56 NOTREACHED(); |
| 62 #else | 57 #else |
| 63 chrome::ScopedTabbedBrowserDisplayer displayer(profile_); | 58 chrome::ScopedTabbedBrowserDisplayer displayer(profile_); |
| 64 chrome::ShowBrowserSignin( | 59 chrome::ShowBrowserSignin( |
| 65 displayer.browser(), | 60 displayer.browser(), |
| 66 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSIONS); | 61 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSIONS); |
| 67 #endif | 62 #endif |
| 68 } | 63 } |
| 69 | 64 |
| 70 void LoginUIService::DisplayLoginResult(Browser* browser, | 65 void LoginUIService::DisplayLoginResult(Browser* browser, |
| 71 const base::string16& message) { | 66 const base::string16& message) { |
| 72 #if defined(OS_CHROMEOS) | 67 #if defined(OS_CHROMEOS) |
| 73 // ChromeOS doesn't have the avatar bubble so it never calls this function. | 68 // ChromeOS doesn't have the avatar bubble so it never calls this function. |
| 74 NOTREACHED(); | 69 NOTREACHED(); |
| 75 #endif | 70 #endif |
| 76 last_login_result_ = message; | 71 last_login_result_ = message; |
| 77 browser->window()->ShowAvatarBubbleFromAvatarButton( | 72 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 78 message.empty() ? BrowserWindow::AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN | 73 message.empty() ? BrowserWindow::AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN |
| 79 : BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR, | 74 : BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR, |
| 80 signin::ManageAccountsParams(), | 75 signin::ManageAccountsParams(), |
| 81 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSIONS); | 76 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSIONS); |
| 82 } | 77 } |
| 83 | 78 |
| 84 const base::string16& LoginUIService::GetLastLoginResult() { | 79 const base::string16& LoginUIService::GetLastLoginResult() { |
| 85 return last_login_result_; | 80 return last_login_result_; |
| 86 } | 81 } |
| OLD | NEW |