| 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_SESSION_SESSION_CONTROLLER_H_ | 5 #ifndef ASH_SESSION_SESSION_CONTROLLER_H_ |
| 6 #define ASH_SESSION_SESSION_CONTROLLER_H_ | 6 #define ASH_SESSION_SESSION_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/ash_export.h" | 12 #include "ash/ash_export.h" |
| 13 #include "ash/login_status.h" | 13 #include "ash/login_status.h" |
| 14 #include "ash/public/cpp/session_types.h" | 14 #include "ash/public/cpp/session_types.h" |
| 15 #include "ash/public/interfaces/session_controller.mojom.h" | 15 #include "ash/public/interfaces/session_controller.mojom.h" |
| 16 #include "base/callback.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 18 #include "mojo/public/cpp/bindings/binding_set.h" | 20 #include "mojo/public/cpp/bindings/binding_set.h" |
| 19 | 21 |
| 20 class AccountId; | 22 class AccountId; |
| 21 | 23 |
| 22 namespace ash { | 24 namespace ash { |
| 23 | 25 |
| 24 class SessionObserver; | 26 class SessionObserver; |
| 25 | 27 |
| 26 // Implements mojom::SessionController to cache session related info such as | 28 // Implements mojom::SessionController to cache session related info such as |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // NOTE: Prefer GetSessionState() in new code because the concept of | 105 // NOTE: Prefer GetSessionState() in new code because the concept of |
| 104 // SessionState more closes matches the state in chrome. | 106 // SessionState more closes matches the state in chrome. |
| 105 LoginStatus login_status() const { return login_status_; } | 107 LoginStatus login_status() const { return login_status_; } |
| 106 | 108 |
| 107 // mojom::SessionController | 109 // mojom::SessionController |
| 108 void SetClient(mojom::SessionControllerClientPtr client) override; | 110 void SetClient(mojom::SessionControllerClientPtr client) override; |
| 109 void SetSessionInfo(mojom::SessionInfoPtr info) override; | 111 void SetSessionInfo(mojom::SessionInfoPtr info) override; |
| 110 void UpdateUserSession(mojom::UserSessionPtr user_session) override; | 112 void UpdateUserSession(mojom::UserSessionPtr user_session) override; |
| 111 void SetUserSessionOrder( | 113 void SetUserSessionOrder( |
| 112 const std::vector<uint32_t>& user_session_order) override; | 114 const std::vector<uint32_t>& user_session_order) override; |
| 115 void StartLock(const StartLockCallback& callback) override; |
| 113 void RunUnlockAnimation(const RunUnlockAnimationCallback& callback) override; | 116 void RunUnlockAnimation(const RunUnlockAnimationCallback& callback) override; |
| 114 void NotifyChromeTerminating() override; | 117 void NotifyChromeTerminating() override; |
| 115 | 118 |
| 116 // Test helpers. | 119 // Test helpers. |
| 117 void ClearUserSessionsForTest(); | 120 void ClearUserSessionsForTest(); |
| 118 void FlushMojoForTest(); | 121 void FlushMojoForTest(); |
| 119 void LockScreenAndFlushForTest(); | 122 void LockScreenAndFlushForTest(); |
| 120 | 123 |
| 121 private: | 124 private: |
| 122 void SetSessionState(session_manager::SessionState state); | 125 void SetSessionState(session_manager::SessionState state); |
| 123 void AddUserSession(mojom::UserSessionPtr user_session); | 126 void AddUserSession(mojom::UserSessionPtr user_session); |
| 124 | 127 |
| 125 // Calculate login status based on session state and active user session. | 128 // Calculate login status based on session state and active user session. |
| 126 LoginStatus CalculateLoginStatus() const; | 129 LoginStatus CalculateLoginStatus() const; |
| 127 | 130 |
| 128 // Helper that returns login status when the session state is ACTIVE. | 131 // Helper that returns login status when the session state is ACTIVE. |
| 129 LoginStatus CalculateLoginStatusForActiveSession() const; | 132 LoginStatus CalculateLoginStatusForActiveSession() const; |
| 130 | 133 |
| 131 // Update the |login_status_| and notify observers. | 134 // Update the |login_status_| and notify observers. |
| 132 void UpdateLoginStatus(); | 135 void UpdateLoginStatus(); |
| 133 | 136 |
| 137 // Used as lock screen displayed callback of LockStateController and invoked |
| 138 // when post lock animation finishes and ash is fully locked. It would then |
| 139 // run |start_lock_callback_| to indicate ash is locked successfully. |
| 140 void OnLockAnimationFinished(); |
| 141 |
| 134 // Bindings for mojom::SessionController interface. | 142 // Bindings for mojom::SessionController interface. |
| 135 mojo::BindingSet<mojom::SessionController> bindings_; | 143 mojo::BindingSet<mojom::SessionController> bindings_; |
| 136 | 144 |
| 137 // Client interface to session manager code (chrome). | 145 // Client interface to session manager code (chrome). |
| 138 mojom::SessionControllerClientPtr client_; | 146 mojom::SessionControllerClientPtr client_; |
| 139 | 147 |
| 140 // Cached session info. | 148 // Cached session info. |
| 141 bool can_lock_ = false; | 149 bool can_lock_ = false; |
| 142 bool should_lock_screen_automatically_ = false; | 150 bool should_lock_screen_automatically_ = false; |
| 143 AddUserSessionPolicy add_user_session_policy_ = AddUserSessionPolicy::ALLOWED; | 151 AddUserSessionPolicy add_user_session_policy_ = AddUserSessionPolicy::ALLOWED; |
| 144 session_manager::SessionState state_; | 152 session_manager::SessionState state_; |
| 145 | 153 |
| 146 // Cached user session info sorted by the order from SetUserSessionOrder. | 154 // Cached user session info sorted by the order from SetUserSessionOrder. |
| 147 // Currently the session manager code (chrome) sets a LRU order with the | 155 // Currently the session manager code (chrome) sets a LRU order with the |
| 148 // active session being the first. | 156 // active session being the first. |
| 149 std::vector<mojom::UserSessionPtr> user_sessions_; | 157 std::vector<mojom::UserSessionPtr> user_sessions_; |
| 150 | 158 |
| 151 // The user session id of the current active user session. User session id | 159 // The user session id of the current active user session. User session id |
| 152 // is managed by session manager code, starting at 1. 0u is an invalid id | 160 // is managed by session manager code, starting at 1. 0u is an invalid id |
| 153 // to detect first active user session. | 161 // to detect first active user session. |
| 154 uint32_t active_session_id_ = 0u; | 162 uint32_t active_session_id_ = 0u; |
| 155 | 163 |
| 156 // Last known login status. Used to track login status changes. | 164 // Last known login status. Used to track login status changes. |
| 157 LoginStatus login_status_ = LoginStatus::NOT_LOGGED_IN; | 165 LoginStatus login_status_ = LoginStatus::NOT_LOGGED_IN; |
| 158 | 166 |
| 159 // Whether unlocking is in progress. The flag is set when the pre-unlock | 167 // Whether unlocking is in progress. The flag is set when the pre-unlock |
| 160 // animation starts and reset when session state is no longer LOCKED. | 168 // animation starts and reset when session state is no longer LOCKED. |
| 161 bool is_unlocking_ = false; | 169 bool is_unlocking_ = false; |
| 162 | 170 |
| 171 // Pending callback for the StartLock request. |
| 172 base::OnceCallback<void(bool)> start_lock_callback_; |
| 173 |
| 163 base::ObserverList<ash::SessionObserver> observers_; | 174 base::ObserverList<ash::SessionObserver> observers_; |
| 164 | 175 |
| 176 base::WeakPtrFactory<SessionController> weak_ptr_factory_; |
| 177 |
| 165 DISALLOW_COPY_AND_ASSIGN(SessionController); | 178 DISALLOW_COPY_AND_ASSIGN(SessionController); |
| 166 }; | 179 }; |
| 167 | 180 |
| 168 } // namespace ash | 181 } // namespace ash |
| 169 | 182 |
| 170 #endif // ASH_SESSION_SESSION_CONTROLLER_H_ | 183 #endif // ASH_SESSION_SESSION_CONTROLLER_H_ |
| OLD | NEW |