OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ |
| 6 #define ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "ash/ash_export.h" |
| 13 #include "ash/public/cpp/session_types.h" |
| 14 #include "ash/public/interfaces/session_controller.mojom.h" |
| 15 #include "base/macros.h" |
| 16 #include "base/observer_list.h" |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" |
| 18 |
| 19 class AccountId; |
| 20 |
| 21 namespace ash { |
| 22 |
| 23 class SessionStateObserver; |
| 24 |
| 25 // Implements mojom::SessionController to cache session related info such as |
| 26 // session state, meta data about user sessions to support synchronous |
| 27 // queries for ash. It is targeted as a replacement for SessionStateDelegate. |
| 28 class ASH_EXPORT SessionController |
| 29 : NON_EXPORTED_BASE(public mojom::SessionController) { |
| 30 public: |
| 31 SessionController(); |
| 32 ~SessionController() override; |
| 33 |
| 34 // Binds the mojom::SessionControllerRequest to this object. |
| 35 void BindRequest(mojom::SessionControllerRequest request); |
| 36 |
| 37 // Returns the maximum possible number of logged in users. |
| 38 int GetMaximumNumberOfLoggedInUsers() const; |
| 39 |
| 40 // Returns the number of signed in users. If 0 is returned, there is either |
| 41 // no session in progress or no active user. |
| 42 int NumberOfLoggedInUsers() const; |
| 43 |
| 44 // Gets the policy of adding a user session to ash. |
| 45 AddUserSessionPolicy GetAddUserPolicy() const; |
| 46 |
| 47 // Returns |true| if the session has been fully started for the active user. |
| 48 // When a user becomes active, the profile and browser UI are not immediately |
| 49 // available. Only once this method starts returning |true| is the browser |
| 50 // startup complete and both profile and UI are fully available. |
| 51 bool IsActiveUserSessionStarted() const; |
| 52 |
| 53 // Returns true if the screen can be locked. |
| 54 bool CanLockScreen() const; |
| 55 |
| 56 // Returns true if the screen is currently locked. |
| 57 bool IsScreenLocked() const; |
| 58 |
| 59 // Returns true if the screen should be locked automatically when the screen |
| 60 // is turned off or the system is suspended. |
| 61 bool ShouldLockScreenAutomatically() const; |
| 62 |
| 63 // Returns |true| if user session blocked by some overlying UI. It can be |
| 64 // login screen, lock screen or screen for adding users into multi-profile |
| 65 // session. |
| 66 bool IsUserSessionBlocked() const; |
| 67 |
| 68 // Gets the ash session state. |
| 69 session_manager::SessionState GetSessionState() const; |
| 70 |
| 71 // Gets the user sessions in LRU order with the active session being first. |
| 72 const std::vector<mojom::UserSessionPtr>& GetUserSessions() const; |
| 73 |
| 74 // Locks the screen. The locking happens asynchronously. |
| 75 void LockScreen(); |
| 76 |
| 77 // Switches to another active user with |account_id| (if that user has |
| 78 // already signed in). |
| 79 void SwitchActiveUser(const AccountId& account_id); |
| 80 |
| 81 // Switches the active user to the next or previous user, with the same |
| 82 // ordering as user sessions are created. |
| 83 void CycleActiveUser(bool next_user); |
| 84 |
| 85 void AddSessionStateObserver(SessionStateObserver* observer); |
| 86 void RemoveSessionStateObserver(SessionStateObserver* observer); |
| 87 |
| 88 // mojom::SessionController |
| 89 void SetClient(mojom::SessionControllerClientPtr client) override; |
| 90 void SetSessionInfo(mojom::SessionInfoPtr info) override; |
| 91 void UpdateUserSession(mojom::UserSessionPtr user_session) override; |
| 92 void SetUserSessionOrder( |
| 93 const std::vector<uint32_t>& user_session_order) override; |
| 94 |
| 95 private: |
| 96 void SetSessionState(session_manager::SessionState state); |
| 97 void AddUserSession(mojom::UserSessionPtr user_session); |
| 98 |
| 99 // Bindings for mojom::SessionController interface. |
| 100 mojo::BindingSet<mojom::SessionController> bindings_; |
| 101 |
| 102 // Client interface to session manager code (chrome). |
| 103 mojom::SessionControllerClientPtr client_; |
| 104 |
| 105 // Cached session info. |
| 106 uint32_t max_users_ = 0u; |
| 107 bool can_lock_ = false; |
| 108 bool should_lock_screen_automatically_ = false; |
| 109 AddUserSessionPolicy add_user_session_policy_ = AddUserSessionPolicy::ALLOWED; |
| 110 session_manager::SessionState state_ = session_manager::SessionState::UNKNOWN; |
| 111 |
| 112 // Cached user session info sorted by the order from SetUserSessionOrder. |
| 113 // Currently the session manager code (chrome) sets a LRU order with the |
| 114 // active session being the first. |
| 115 std::vector<mojom::UserSessionPtr> user_sessions_; |
| 116 |
| 117 // The user session id of the current active user session. User session id |
| 118 // is managed by session manager code, starting at 1. 0u is an invalid id |
| 119 // to detect first active user session. |
| 120 uint32_t active_session_id_ = 0u; |
| 121 |
| 122 base::ObserverList<ash::SessionStateObserver> observers_; |
| 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(SessionController); |
| 125 }; |
| 126 |
| 127 } // namespace ash |
| 128 |
| 129 #endif // ASH_COMMON_SESSION_SESSION_CONTROLLER_H_ |
OLD | NEW |