OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ | 5 #ifndef ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ |
6 #define ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ | 6 #define ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Returns true if the screen can be locked. | 54 // Returns true if the screen can be locked. |
55 bool CanLockScreen() const; | 55 bool CanLockScreen() const; |
56 | 56 |
57 // Returns true if the screen is currently locked. | 57 // Returns true if the screen is currently locked. |
58 bool IsScreenLocked() const; | 58 bool IsScreenLocked() const; |
59 | 59 |
60 // Returns true if the screen should be locked automatically when the screen | 60 // Returns true if the screen should be locked automatically when the screen |
61 // is turned off or the system is suspended. | 61 // is turned off or the system is suspended. |
62 bool ShouldLockScreenAutomatically() const; | 62 bool ShouldLockScreenAutomatically() const; |
63 | 63 |
64 // Returns |true| if user session blocked by some overlying UI. It can be | 64 // Returns true if user session blocked by some overlying UI. It can be |
65 // login screen, lock screen or screen for adding users into multi-profile | 65 // login screen, lock screen or screen for adding users into multi-profile |
66 // session. | 66 // session. |
67 bool IsUserSessionBlocked() const; | 67 bool IsUserSessionBlocked() const; |
68 | 68 |
| 69 // Convenience function that returns true if session state is LOGIN_SECONDARY. |
| 70 bool IsInSecondaryLoginScreen() const; |
| 71 |
69 // Gets the ash session state. | 72 // Gets the ash session state. |
70 session_manager::SessionState GetSessionState() const; | 73 session_manager::SessionState GetSessionState() const; |
71 | 74 |
72 // Gets the user sessions in LRU order with the active session being first. | 75 // Gets the user sessions in LRU order with the active session being first. |
73 const std::vector<mojom::UserSessionPtr>& GetUserSessions() const; | 76 const std::vector<mojom::UserSessionPtr>& GetUserSessions() const; |
74 | 77 |
| 78 // Convenience helper to gets the user session at a given index. Returns |
| 79 // nullptr if no user session is found for the index. |
| 80 const mojom::UserSession* GetUserSession(UserIndex index) const; |
| 81 |
75 // Locks the screen. The locking happens asynchronously. | 82 // Locks the screen. The locking happens asynchronously. |
76 void LockScreen(); | 83 void LockScreen(); |
77 | 84 |
78 // Switches to another active user with |account_id| (if that user has | 85 // Switches to another active user with |account_id| (if that user has |
79 // already signed in). | 86 // already signed in). |
80 void SwitchActiveUser(const AccountId& account_id); | 87 void SwitchActiveUser(const AccountId& account_id); |
81 | 88 |
82 // Switches the active user to the next or previous user, with the same | 89 // Switches the active user to the next or previous user, with the same |
83 // ordering as user sessions are created. | 90 // ordering as user sessions are created. |
84 void CycleActiveUser(CycleUserDirection direction); | 91 void CycleActiveUser(CycleUserDirection direction); |
85 | 92 |
86 void AddSessionStateObserver(SessionStateObserver* observer); | 93 void AddSessionStateObserver(SessionStateObserver* observer); |
87 void RemoveSessionStateObserver(SessionStateObserver* observer); | 94 void RemoveSessionStateObserver(SessionStateObserver* observer); |
88 | 95 |
89 // Returns the ash notion of login status. | 96 // Returns the ash notion of login status. |
90 // NOTE: Prefer GetSessionState() in new code because the concept of | 97 // NOTE: Prefer GetSessionState() in new code because the concept of |
91 // SessionState more closes matches the state in chrome. | 98 // SessionState more closes matches the state in chrome. |
92 LoginStatus GetLoginStatus() const; | 99 LoginStatus GetLoginStatus() const; |
93 | 100 |
94 // mojom::SessionController | 101 // mojom::SessionController |
95 void SetClient(mojom::SessionControllerClientPtr client) override; | 102 void SetClient(mojom::SessionControllerClientPtr client) override; |
96 void SetSessionInfo(mojom::SessionInfoPtr info) override; | 103 void SetSessionInfo(mojom::SessionInfoPtr info) override; |
97 void UpdateUserSession(mojom::UserSessionPtr user_session) override; | 104 void UpdateUserSession(mojom::UserSessionPtr user_session) override; |
98 void SetUserSessionOrder( | 105 void SetUserSessionOrder( |
99 const std::vector<uint32_t>& user_session_order) override; | 106 const std::vector<uint32_t>& user_session_order) override; |
100 | 107 |
| 108 // Test helpers. |
| 109 void ClearUserSessionsForTest(); |
| 110 void FlushMojoForTest(); |
| 111 void LockScreenAndFlushForTest(); |
| 112 |
101 private: | 113 private: |
102 void SetSessionState(session_manager::SessionState state); | 114 void SetSessionState(session_manager::SessionState state); |
103 void AddUserSession(mojom::UserSessionPtr user_session); | 115 void AddUserSession(mojom::UserSessionPtr user_session); |
104 | 116 |
105 // Helper that returns login status when the session state is ACTIVE. | 117 // Helper that returns login status when the session state is ACTIVE. |
106 LoginStatus GetLoginStatusForActiveSession() const; | 118 LoginStatus GetLoginStatusForActiveSession() const; |
107 | 119 |
108 // Bindings for mojom::SessionController interface. | 120 // Bindings for mojom::SessionController interface. |
109 mojo::BindingSet<mojom::SessionController> bindings_; | 121 mojo::BindingSet<mojom::SessionController> bindings_; |
110 | 122 |
111 // Client interface to session manager code (chrome). | 123 // Client interface to session manager code (chrome). |
112 mojom::SessionControllerClientPtr client_; | 124 mojom::SessionControllerClientPtr client_; |
113 | 125 |
114 // Cached session info. | 126 // Cached session info. |
115 bool can_lock_ = false; | 127 bool can_lock_ = false; |
116 bool should_lock_screen_automatically_ = false; | 128 bool should_lock_screen_automatically_ = false; |
117 AddUserSessionPolicy add_user_session_policy_ = AddUserSessionPolicy::ALLOWED; | 129 AddUserSessionPolicy add_user_session_policy_ = AddUserSessionPolicy::ALLOWED; |
118 session_manager::SessionState state_ = session_manager::SessionState::UNKNOWN; | 130 session_manager::SessionState state_; |
119 | 131 |
120 // Cached user session info sorted by the order from SetUserSessionOrder. | 132 // Cached user session info sorted by the order from SetUserSessionOrder. |
121 // Currently the session manager code (chrome) sets a LRU order with the | 133 // Currently the session manager code (chrome) sets a LRU order with the |
122 // active session being the first. | 134 // active session being the first. |
123 std::vector<mojom::UserSessionPtr> user_sessions_; | 135 std::vector<mojom::UserSessionPtr> user_sessions_; |
124 | 136 |
125 // The user session id of the current active user session. User session id | 137 // The user session id of the current active user session. User session id |
126 // is managed by session manager code, starting at 1. 0u is an invalid id | 138 // is managed by session manager code, starting at 1. 0u is an invalid id |
127 // to detect first active user session. | 139 // to detect first active user session. |
128 uint32_t active_session_id_ = 0u; | 140 uint32_t active_session_id_ = 0u; |
129 | 141 |
130 base::ObserverList<ash::SessionStateObserver> observers_; | 142 base::ObserverList<ash::SessionStateObserver> observers_; |
131 | 143 |
132 DISALLOW_COPY_AND_ASSIGN(SessionController); | 144 DISALLOW_COPY_AND_ASSIGN(SessionController); |
133 }; | 145 }; |
134 | 146 |
135 } // namespace ash | 147 } // namespace ash |
136 | 148 |
137 #endif // ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ | 149 #endif // ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ |
OLD | NEW |