Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/browser/ui/webui/signin/login_ui_service.h

Issue 1984863002: Clean up LoginUIService. Remove Singleton behavior from PeopleHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix merge issue Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 7
8 #include <list>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/observer_list.h" 11 #include "base/observer_list.h"
10 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
11 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
12 14
13 class Browser; 15 class Browser;
14 class Profile; 16 class Profile;
15 17
16 // The LoginUIService helps track per-profile information for the login related 18 // The LoginUIService helps track per-profile information for the login related
17 // UIs - for example, whether there is login UI currently on-screen. 19 // UIs - for example, whether there is login UI currently on-screen.
18 class LoginUIService : public KeyedService { 20 class LoginUIService : public KeyedService {
19 public: 21 public:
20 // Various UI components implement this API to allow LoginUIService to 22 // Various UI components implement this API to allow LoginUIService to
21 // manipulate their associated login UI. 23 // manipulate their associated login UI.
22 class LoginUI { 24 class LoginUI {
23 public: 25 public:
24 // Invoked when the login UI should be brought to the foreground. 26 // Invoked when the login UI should be brought to the foreground.
25 virtual void FocusUI() = 0; 27 virtual void FocusUI() = 0;
26 28
27 // Invoked when the login UI should be closed. This can be invoked if the
28 // user takes an action that should display new login UI.
29 virtual void CloseUI() = 0;
30 protected: 29 protected:
31 virtual ~LoginUI() {} 30 virtual ~LoginUI() {}
32 }; 31 };
33 32
34 // Used when the sync confirmation UI is closed to signify which option was 33 // Used when the sync confirmation UI is closed to signify which option was
35 // selected by the user. 34 // selected by the user.
36 enum SyncConfirmationUIClosedResult { 35 enum SyncConfirmationUIClosedResult {
37 // Start sync immediately. 36 // Start sync immediately.
38 SYNC_WITH_DEFAULT_SETTINGS, 37 SYNC_WITH_DEFAULT_SETTINGS,
39 // Show the user the sync settings before starting sync. 38 // Show the user the sync settings before starting sync.
40 CONFIGURE_SYNC_FIRST, 39 CONFIGURE_SYNC_FIRST,
41 // The signing process was aborted, don't start sync or show settings. 40 // The signing process was aborted, don't start sync or show settings.
42 ABORT_SIGNIN, 41 ABORT_SIGNIN,
43 }; 42 };
44 43
45 // Interface for obervers of LoginUIService. 44 // Interface for obervers of LoginUIService.
46 class Observer { 45 class Observer {
47 public: 46 public:
48 // Called when a new login UI is shown.
49 // |ui| The login UI that was just shown. Will never be null.
50 virtual void OnLoginUIShown(LoginUI* ui) {}
51
52 // Called when a login UI is closed.
53 // |ui| The login UI that was just closed; will never be null.
54 virtual void OnLoginUIClosed(LoginUI* ui) {}
55
56 // Called when the sync confirmation UI is closed. |result| indicates the 47 // Called when the sync confirmation UI is closed. |result| indicates the
57 // option chosen by the user in the confirmation UI. 48 // option chosen by the user in the confirmation UI.
58 virtual void OnSyncConfirmationUIClosed( 49 virtual void OnSyncConfirmationUIClosed(
59 SyncConfirmationUIClosedResult result) {} 50 SyncConfirmationUIClosedResult result) {}
60 51
61 // Called when a confirmation UI for untrusted signin is shown.
62 virtual void OnUntrustedLoginUIShown() {}
63
64 protected: 52 protected:
65 virtual ~Observer() {} 53 virtual ~Observer() {}
66 }; 54 };
67 55
68 explicit LoginUIService(Profile* profile); 56 explicit LoginUIService(Profile* profile);
69 ~LoginUIService() override; 57 ~LoginUIService() override;
70 58
71 // Gets the currently active login UI, or null if no login UI is active.
72 LoginUI* current_login_ui() const {
73 return ui_;
74 }
75
76 // |observer| The observer to add or remove; cannot be NULL. 59 // |observer| The observer to add or remove; cannot be NULL.
77 void AddObserver(Observer* observer); 60 void AddObserver(Observer* observer);
78 void RemoveObserver(Observer* observer); 61 void RemoveObserver(Observer* observer);
79 62
80 // Sets the currently active login UI. It is illegal to call this if there is 63 // Gets the currently active login UI, or null if no login UI is active.
81 // already login UI visible. 64 LoginUI* current_login_ui() const;
65
66 // Sets the currently active login UI. Callers must call LoginUIClosed when
67 // |ui| is no longer valid.
82 void SetLoginUI(LoginUI* ui); 68 void SetLoginUI(LoginUI* ui);
83 69
84 // Called when login UI is closed. If the passed UI is the current login UI, 70 // Called when login UI is closed.
85 // sets current_login_ui() to null.
86 void LoginUIClosed(LoginUI* ui); 71 void LoginUIClosed(LoginUI* ui);
87 72
88 // Called when the sync confirmation UI is closed. |result| indicates the 73 // Called when the sync confirmation UI is closed. |result| indicates the
89 // option chosen by the user in the confirmation UI. 74 // option chosen by the user in the confirmation UI.
90 void SyncConfirmationUIClosed(SyncConfirmationUIClosedResult result); 75 void SyncConfirmationUIClosed(SyncConfirmationUIClosedResult result);
91 76
92 // Called when a confirmation UI for untrusted signin is shown.
93 void UntrustedLoginUIShown();
94
95 // Delegate to an existing login dialog if one exists. 77 // Delegate to an existing login dialog if one exists.
96 // If not, we make a new popup dialog window, and set it to 78 // If not, we make a new popup dialog window, and set it to
97 // chrome://signin to ask the user to sign in to chrome. 79 // chrome://signin to ask the user to sign in to chrome.
98 void ShowLoginPopup(); 80 void ShowLoginPopup();
99 81
100 // Displays login results. 82 // Displays login results.
101 void DisplayLoginResult(Browser* browser, const base::string16& message); 83 void DisplayLoginResult(Browser* browser, const base::string16& message);
102 84
103 // Gets the last login result set through |DisplayLoginResult|. 85 // Gets the last login result set through |DisplayLoginResult|.
104 const base::string16& GetLastLoginResult(); 86 const base::string16& GetLastLoginResult();
105 87
106 private: 88 private:
107 // Weak pointer to the currently active login UI, or null if none. 89 // Weak pointers to the recently opened UIs, with the most recent in front.
108 LoginUI* ui_ = nullptr; 90 std::list<LoginUI*> ui_list_;
109 #if !defined(OS_CHROMEOS) 91 #if !defined(OS_CHROMEOS)
110 Profile* profile_; 92 Profile* profile_;
111 #endif 93 #endif
112 94
113 // List of observers. 95 // List of observers.
114 base::ObserverList<Observer> observer_list_; 96 base::ObserverList<Observer> observer_list_;
115 97
116 base::string16 last_login_result_; 98 base::string16 last_login_result_;
117 99
118 DISALLOW_COPY_AND_ASSIGN(LoginUIService); 100 DISALLOW_COPY_AND_ASSIGN(LoginUIService);
119 }; 101 };
120 102
121 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_ 103 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc ('k') | chrome/browser/ui/webui/signin/login_ui_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698