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 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ 7 8 #include "base/basictypes.h" 9 #include "base/observer_list.h" 10 #include "components/browser_context_keyed_service/browser_context_keyed_service.h" 11 12 class Browser; 13 class Profile; 14 15 // The LoginUIService helps track per-profile information for the login UI - 16 // for example, whether there is login UI currently on-screen. 17 class LoginUIService : public BrowserContextKeyedService { 18 public: 19 // Various UI components implement this API to allow LoginUIService to 20 // manipulate their associated login UI. 21 class LoginUI { 22 public: 23 // Invoked when the login UI should be brought to the foreground. 24 virtual void FocusUI() = 0; 25 26 // Invoked when the login UI should be closed. This can be invoked if the 27 // user takes an action that should display new login UI. 28 virtual void CloseUI() = 0; 29 protected: 30 virtual ~LoginUI() {} 31 }; 32 33 // Interface for obervers of LoginUIService. 34 class Observer { 35 public: 36 // Called when a new login UI is shown. 37 // |ui| The login UI that was just shown. Will never be null. 38 virtual void OnLoginUIShown(LoginUI* ui) = 0; 39 40 // Called when a login UI is closed. 41 // |ui| The login UI that was just closed; will never be null. 42 virtual void OnLoginUIClosed(LoginUI* ui) = 0; 43 44 protected: 45 virtual ~Observer() {} 46 }; 47 48 explicit LoginUIService(Profile* profile); 49 virtual ~LoginUIService(); 50 51 // Gets the currently active login UI, or null if no login UI is active. 52 LoginUI* current_login_ui() const { 53 return ui_; 54 } 55 56 // |observer| The observer to add or remove; cannot be NULL. 57 void AddObserver(Observer* observer); 58 void RemoveObserver(Observer* observer); 59 60 // Sets the currently active login UI. It is illegal to call this if there is 61 // already login UI visible. 62 void SetLoginUI(LoginUI* ui); 63 64 // Called when login UI is closed. If the passed UI is the current login UI, 65 // sets current_login_ui() to null. 66 void LoginUIClosed(LoginUI* ui); 67 68 // Delegate to an existing login dialog if one exists. 69 // If not, we make a new popup dialog window, and set it to 70 // chrome://signin to ask the user to sign in to chrome. 71 void ShowLoginPopup(); 72 73 private: 74 // Weak pointer to the currently active login UI, or null if none. 75 LoginUI* ui_; 76 Profile* profile_; 77 78 // List of observers. 79 ObserverList<Observer> observer_list_; 80 81 DISALLOW_COPY_AND_ASSIGN(LoginUIService); 82 }; 83 84 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ 85