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 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "chrome/browser/profiles/profile_keyed_service.h" | 10 #include "chrome/browser/profiles/profile_keyed_service.h" |
11 | 11 |
12 class Profile; | 12 class Profile; |
13 | 13 |
14 namespace content { | |
15 class WebUI; | |
16 }; | |
17 | |
18 // The LoginUIService helps track per-profile information for the login UI - | 14 // The LoginUIService helps track per-profile information for the login UI - |
19 // for example, whether there is login UI currently on-screen. | 15 // for example, whether there is login UI currently on-screen. |
20 class LoginUIService : public ProfileKeyedService { | 16 class LoginUIService : public ProfileKeyedService { |
21 public: | 17 public: |
| 18 // Various UI components implement this API to allow LoginUIService to |
| 19 // manipulate their associated login UI. |
| 20 class LoginUI { |
| 21 public: |
| 22 // Invoked when the login UI should be brought to the foreground. |
| 23 virtual void FocusUI() = 0; |
| 24 |
| 25 // Invoked when the login UI should be closed. This can be invoked if the |
| 26 // user takes an action that should display new login UI. |
| 27 virtual void CloseUI() = 0; |
| 28 protected: |
| 29 virtual ~LoginUI() {} |
| 30 }; |
| 31 |
22 // Creates a LoginUIService associated with the passed |profile|. |profile| | 32 // Creates a LoginUIService associated with the passed |profile|. |profile| |
23 // is used to create a new browser in the case that ShowLoginUI() is invoked | 33 // is used to create a new browser in the case that ShowLoginUI() is invoked |
24 // when no browser windows are open (e.g. via the Mac menu bar). | 34 // when no browser windows are open (e.g. via the Mac menu bar). |
25 explicit LoginUIService(Profile* profile); | 35 explicit LoginUIService(Profile* profile); |
26 virtual ~LoginUIService(); | 36 virtual ~LoginUIService(); |
27 | 37 |
28 // Gets the currently active login UI, or null if no login UI is active. | 38 // Gets the currently active login UI, or null if no login UI is active. |
29 content::WebUI* current_login_ui() const { | 39 LoginUI* current_login_ui() const { |
30 return ui_; | 40 return ui_; |
31 } | 41 } |
32 | 42 |
33 // Sets the currently active login UI. It is illegal to call this if there is | 43 // Sets the currently active login UI. It is illegal to call this if there is |
34 // already login UI visible. | 44 // already login UI visible. |
35 void SetLoginUI(content::WebUI* ui); | 45 void SetLoginUI(LoginUI* ui); |
36 | 46 |
37 // Called when login UI is closed. If the passed UI is the current login UI, | 47 // Called when login UI is closed. If the passed UI is the current login UI, |
38 // sets current_login_ui() to null. | 48 // sets current_login_ui() to null. |
39 void LoginUIClosed(content::WebUI* ui); | 49 void LoginUIClosed(LoginUI* ui); |
40 | 50 |
41 // Brings the current login UI for this profile to the foreground (it is an | 51 // Brings the login UI to the foreground, or if there is no login UI, |
42 // error to call this if there is no visible login UI. | 52 // navigates to the login UI page in a new browser tab. |
43 void FocusLoginUI(); | 53 // Virtual for mocking purposes. |
44 | 54 virtual void ShowLoginUI(); |
45 // Displays the login dialog if the user is not yet logged in, otherwise | |
46 // displays the sync setup dialog. If |force_login| is true, then the login | |
47 // UI is displayed even if the user is already logged in (useful if we need | |
48 // to gather GAIA credentials for oauth tokens). Virtual for mocking purposes. | |
49 // TODO(atwilson): Refactor this API to make the behavior more clear and use | |
50 // an enum instead of a boolean (http://crbug.com/118795). | |
51 virtual void ShowLoginUI(bool force_login); | |
52 | 55 |
53 private: | 56 private: |
54 // Weak pointer to the currently active login UI, or null if none. | 57 // Weak pointer to the currently active login UI, or null if none. |
55 content::WebUI* ui_; | 58 LoginUI* ui_; |
56 | 59 |
57 // Weak pointer to the profile this service is associated with. | 60 // Weak pointer to the profile this service is associated with. |
58 Profile* profile_; | 61 Profile* profile_; |
59 | 62 |
60 DISALLOW_COPY_AND_ASSIGN(LoginUIService); | 63 DISALLOW_COPY_AND_ASSIGN(LoginUIService); |
61 }; | 64 }; |
62 | 65 |
63 | 66 |
64 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ | 67 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ |
OLD | NEW |