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 #include "ash/common/session/session_controller.h" | 5 #include "ash/common/session/session_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/login_status.h" | 9 #include "ash/common/login_status.h" |
10 #include "ash/common/session/session_state_observer.h" | 10 #include "ash/common/session/session_state_observer.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" |
| 14 #include "chromeos/chromeos_switches.h" |
13 #include "components/signin/core/account_id/account_id.h" | 15 #include "components/signin/core/account_id/account_id.h" |
14 #include "services/service_manager/public/cpp/connector.h" | 16 #include "services/service_manager/public/cpp/connector.h" |
15 | 17 |
16 namespace ash { | 18 namespace ash { |
17 | 19 |
18 SessionController::SessionController() {} | 20 namespace { |
| 21 |
| 22 // Get the default session state. Default session state is ACTIVE when the |
| 23 // process starts with a user session, i.e. the process has kLoginUser command |
| 24 // line switch. This is needed because ash focus rules depends on whether |
| 25 // session is blocked to pick an activatable window and chrome needs to create a |
| 26 // focused browser window when starting with a user session (both in production |
| 27 // and in tests). Using ACTIVE as default in this situation allows chrome to run |
| 28 // without having to wait for session state to reach to ash. For other cases |
| 29 // (oobe/login), there is only one login window. The login window always gets |
| 30 // focus so default session state does not matter. Use UNKNOWN and wait for |
| 31 // chrome to update ash for such cases. |
| 32 session_manager::SessionState GetDefaultSessionState() { |
| 33 const bool start_with_user = |
| 34 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 35 chromeos::switches::kLoginUser); |
| 36 return start_with_user ? session_manager::SessionState::ACTIVE |
| 37 : session_manager::SessionState::UNKNOWN; |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
| 42 SessionController::SessionController() : state_(GetDefaultSessionState()) {} |
19 | 43 |
20 SessionController::~SessionController() {} | 44 SessionController::~SessionController() {} |
21 | 45 |
22 void SessionController::BindRequest(mojom::SessionControllerRequest request) { | 46 void SessionController::BindRequest(mojom::SessionControllerRequest request) { |
23 bindings_.AddBinding(this, std::move(request)); | 47 bindings_.AddBinding(this, std::move(request)); |
24 } | 48 } |
25 | 49 |
26 int SessionController::GetMaximumNumberOfLoggedInUsers() const { | 50 int SessionController::GetMaximumNumberOfLoggedInUsers() const { |
27 return session_manager::kMaxmiumNumberOfUserSessions; | 51 return session_manager::kMaxmiumNumberOfUserSessions; |
28 } | 52 } |
29 | 53 |
30 int SessionController::NumberOfLoggedInUsers() const { | 54 int SessionController::NumberOfLoggedInUsers() const { |
31 return static_cast<int>(user_sessions_.size()); | 55 return static_cast<int>(user_sessions_.size()); |
32 } | 56 } |
33 | 57 |
34 AddUserSessionPolicy SessionController::GetAddUserPolicy() const { | 58 AddUserSessionPolicy SessionController::GetAddUserPolicy() const { |
35 return add_user_session_policy_; | 59 return add_user_session_policy_; |
36 } | 60 } |
37 | 61 |
38 bool SessionController::IsActiveUserSessionStarted() const { | 62 bool SessionController::IsActiveUserSessionStarted() const { |
39 return !user_sessions_.empty(); | 63 return !user_sessions_.empty(); |
40 } | 64 } |
41 | 65 |
42 bool SessionController::CanLockScreen() const { | 66 bool SessionController::CanLockScreen() const { |
43 return can_lock_; | 67 return IsActiveUserSessionStarted() && can_lock_; |
44 } | 68 } |
45 | 69 |
46 bool SessionController::IsScreenLocked() const { | 70 bool SessionController::IsScreenLocked() const { |
47 return state_ == session_manager::SessionState::LOCKED; | 71 return state_ == session_manager::SessionState::LOCKED; |
48 } | 72 } |
49 | 73 |
50 bool SessionController::ShouldLockScreenAutomatically() const { | 74 bool SessionController::ShouldLockScreenAutomatically() const { |
51 return should_lock_screen_automatically_; | 75 return should_lock_screen_automatically_; |
52 } | 76 } |
53 | 77 |
54 bool SessionController::IsUserSessionBlocked() const { | 78 bool SessionController::IsUserSessionBlocked() const { |
55 return state_ != session_manager::SessionState::ACTIVE; | 79 return state_ != session_manager::SessionState::ACTIVE; |
56 } | 80 } |
57 | 81 |
| 82 bool SessionController::IsInSecondaryLoginScreen() const { |
| 83 return state_ == session_manager::SessionState::LOGIN_SECONDARY; |
| 84 } |
| 85 |
58 session_manager::SessionState SessionController::GetSessionState() const { | 86 session_manager::SessionState SessionController::GetSessionState() const { |
59 return state_; | 87 return state_; |
60 } | 88 } |
61 | 89 |
62 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() | 90 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() |
63 const { | 91 const { |
64 return user_sessions_; | 92 return user_sessions_; |
65 } | 93 } |
66 | 94 |
| 95 const mojom::UserSession* SessionController::GetUserSession( |
| 96 UserIndex index) const { |
| 97 if (index < 0 || index >= static_cast<UserIndex>(user_sessions_.size())) |
| 98 return nullptr; |
| 99 |
| 100 return user_sessions_[index].get(); |
| 101 } |
| 102 |
67 void SessionController::LockScreen() { | 103 void SessionController::LockScreen() { |
68 if (client_) | 104 if (client_) |
69 client_->RequestLockScreen(); | 105 client_->RequestLockScreen(); |
70 } | 106 } |
71 | 107 |
72 void SessionController::SwitchActiveUser(const AccountId& account_id) { | 108 void SessionController::SwitchActiveUser(const AccountId& account_id) { |
73 if (client_) | 109 if (client_) |
74 client_->SwitchActiveUser(account_id); | 110 client_->SwitchActiveUser(account_id); |
75 } | 111 } |
76 | 112 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 201 |
166 // Check active user change and notifies observers. | 202 // Check active user change and notifies observers. |
167 if (user_sessions_[0]->session_id != active_session_id_) { | 203 if (user_sessions_[0]->session_id != active_session_id_) { |
168 active_session_id_ = user_sessions_[0]->session_id; | 204 active_session_id_ = user_sessions_[0]->session_id; |
169 | 205 |
170 for (auto& observer : observers_) | 206 for (auto& observer : observers_) |
171 observer.ActiveUserChanged(user_sessions_[0]->account_id); | 207 observer.ActiveUserChanged(user_sessions_[0]->account_id); |
172 } | 208 } |
173 } | 209 } |
174 | 210 |
| 211 void SessionController::ClearUserSessionsForTest() { |
| 212 user_sessions_.clear(); |
| 213 } |
| 214 |
| 215 void SessionController::FlushMojoForTest() { |
| 216 client_.FlushForTesting(); |
| 217 } |
| 218 |
| 219 void SessionController::LockScreenAndFlushForTest() { |
| 220 LockScreen(); |
| 221 FlushMojoForTest(); |
| 222 } |
| 223 |
175 void SessionController::SetSessionState(session_manager::SessionState state) { | 224 void SessionController::SetSessionState(session_manager::SessionState state) { |
176 if (state_ == state) | 225 if (state_ == state) |
177 return; | 226 return; |
178 | 227 |
179 state_ = state; | 228 state_ = state; |
180 for (auto& observer : observers_) | 229 for (auto& observer : observers_) |
181 observer.SessionStateChanged(state_); | 230 observer.SessionStateChanged(state_); |
182 } | 231 } |
183 | 232 |
184 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { | 233 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 case user_manager::NUM_USER_TYPES: | 267 case user_manager::NUM_USER_TYPES: |
219 // Avoid having a "default" case so the compiler catches new enum values. | 268 // Avoid having a "default" case so the compiler catches new enum values. |
220 NOTREACHED(); | 269 NOTREACHED(); |
221 return LoginStatus::USER; | 270 return LoginStatus::USER; |
222 } | 271 } |
223 NOTREACHED(); | 272 NOTREACHED(); |
224 return LoginStatus::USER; | 273 return LoginStatus::USER; |
225 } | 274 } |
226 | 275 |
227 } // namespace ash | 276 } // namespace ash |
OLD | NEW |