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/ui/webui/signin/login_ui_service.h" 6 7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/signin/signin_promo.h" 9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_navigator.h" 12 #include "chrome/browser/ui/chrome_pages.h" 13 #include "chrome/browser/ui/host_desktop.h" 14 #include "chrome/browser/ui/sync/inline_login_dialog.h" 15 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 16 #include "chrome/common/url_constants.h" 17 18 #if defined(OS_CHROMEOS) 19 #include "chrome/browser/app_mode/app_mode_utils.h" 20 #endif 21 22 LoginUIService::LoginUIService(Profile* profile) 23 : ui_(NULL), profile_(profile) { 24 } 25 26 LoginUIService::~LoginUIService() {} 27 28 void LoginUIService::AddObserver(LoginUIService::Observer* observer) { 29 observer_list_.AddObserver(observer); 30 } 31 32 void LoginUIService::RemoveObserver(LoginUIService::Observer* observer) { 33 observer_list_.RemoveObserver(observer); 34 } 35 36 void LoginUIService::SetLoginUI(LoginUI* ui) { 37 DCHECK(!current_login_ui() || current_login_ui() == ui); 38 ui_ = ui; 39 FOR_EACH_OBSERVER(Observer, observer_list_, OnLoginUIShown(ui_)); 40 } 41 42 void LoginUIService::LoginUIClosed(LoginUI* ui) { 43 if (current_login_ui() != ui) 44 return; 45 46 ui_ = NULL; 47 FOR_EACH_OBSERVER(Observer, observer_list_, OnLoginUIClosed(ui)); 48 } 49 50 void LoginUIService::ShowLoginPopup() { 51 #if defined(OS_CHROMEOS) 52 if (chrome::IsRunningInForcedAppMode()) 53 InlineLoginDialog::Show(profile_); 54 #else 55 Browser* browser = FindOrCreateTabbedBrowser(profile_, 56 chrome::GetActiveDesktop()); 57 chrome::ShowBrowserSignin(browser, signin::SOURCE_APP_LAUNCHER); 58 #endif 59 } 60