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

Side by Side Diff: ash/session/session_controller.cc

Issue 2801333002: mash: Run pre-unlock animation via SessionController (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « ash/session/session_controller.h ('k') | ash/session/session_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/session/session_controller.h" 5 #include "ash/session/session_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/session/session_state_observer.h" 9 #include "ash/session/session_state_observer.h"
10 #include "ash/shell.h"
11 #include "ash/wm/lock_state_controller.h"
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 14 #include "base/command_line.h"
13 #include "chromeos/chromeos_switches.h" 15 #include "chromeos/chromeos_switches.h"
14 #include "components/signin/core/account_id/account_id.h" 16 #include "components/signin/core/account_id/account_id.h"
15 #include "services/service_manager/public/cpp/connector.h" 17 #include "services/service_manager/public/cpp/connector.h"
16 18
19 using session_manager::SessionState;
20
17 namespace ash { 21 namespace ash {
18 22
19 namespace { 23 namespace {
20 24
21 // Get the default session state. Default session state is ACTIVE when the 25 // Get the default session state. Default session state is ACTIVE when the
22 // process starts with a user session, i.e. the process has kLoginUser command 26 // process starts with a user session, i.e. the process has kLoginUser command
23 // line switch. This is needed because ash focus rules depends on whether 27 // line switch. This is needed because ash focus rules depends on whether
24 // session is blocked to pick an activatable window and chrome needs to create a 28 // session is blocked to pick an activatable window and chrome needs to create a
25 // focused browser window when starting with a user session (both in production 29 // focused browser window when starting with a user session (both in production
26 // and in tests). Using ACTIVE as default in this situation allows chrome to run 30 // and in tests). Using ACTIVE as default in this situation allows chrome to run
27 // without having to wait for session state to reach to ash. For other cases 31 // without having to wait for session state to reach to ash. For other cases
28 // (oobe/login), there is only one login window. The login window always gets 32 // (oobe/login), there is only one login window. The login window always gets
29 // focus so default session state does not matter. Use UNKNOWN and wait for 33 // focus so default session state does not matter. Use UNKNOWN and wait for
30 // chrome to update ash for such cases. 34 // chrome to update ash for such cases.
31 session_manager::SessionState GetDefaultSessionState() { 35 SessionState GetDefaultSessionState() {
32 const bool start_with_user = 36 const bool start_with_user =
33 base::CommandLine::ForCurrentProcess()->HasSwitch( 37 base::CommandLine::ForCurrentProcess()->HasSwitch(
34 chromeos::switches::kLoginUser); 38 chromeos::switches::kLoginUser);
35 return start_with_user ? session_manager::SessionState::ACTIVE 39 return start_with_user ? SessionState::ACTIVE : SessionState::UNKNOWN;
36 : session_manager::SessionState::UNKNOWN;
37 } 40 }
38 41
39 } // namespace 42 } // namespace
40 43
41 SessionController::SessionController() : state_(GetDefaultSessionState()) {} 44 SessionController::SessionController() : state_(GetDefaultSessionState()) {}
42 45
43 SessionController::~SessionController() {} 46 SessionController::~SessionController() {}
44 47
45 void SessionController::BindRequest(mojom::SessionControllerRequest request) { 48 void SessionController::BindRequest(mojom::SessionControllerRequest request) {
46 bindings_.AddBinding(this, std::move(request)); 49 bindings_.AddBinding(this, std::move(request));
(...skipping 13 matching lines...) Expand all
60 63
61 bool SessionController::IsActiveUserSessionStarted() const { 64 bool SessionController::IsActiveUserSessionStarted() const {
62 return !user_sessions_.empty(); 65 return !user_sessions_.empty();
63 } 66 }
64 67
65 bool SessionController::CanLockScreen() const { 68 bool SessionController::CanLockScreen() const {
66 return IsActiveUserSessionStarted() && can_lock_; 69 return IsActiveUserSessionStarted() && can_lock_;
67 } 70 }
68 71
69 bool SessionController::IsScreenLocked() const { 72 bool SessionController::IsScreenLocked() const {
70 return state_ == session_manager::SessionState::LOCKED; 73 return state_ == SessionState::LOCKED;
71 } 74 }
72 75
73 bool SessionController::ShouldLockScreenAutomatically() const { 76 bool SessionController::ShouldLockScreenAutomatically() const {
74 return should_lock_screen_automatically_; 77 return should_lock_screen_automatically_;
75 } 78 }
76 79
77 bool SessionController::IsUserSessionBlocked() const { 80 bool SessionController::IsUserSessionBlocked() const {
78 return state_ != session_manager::SessionState::ACTIVE; 81 // User sessions are blocked when session state is not ACTIVE, except that
82 // LOCKED state with a running unlocking animation. This is made an exception
83 // because the unlocking animation hides lock container at the end. During the
84 // unlock animation, IsUserSessionBlocked needs to return unblocked so that
85 // user windows are deemed activatable and ash correctly restore the active
86 // window before locking.
87 return state_ != SessionState::ACTIVE &&
88 !(state_ == SessionState::LOCKED && is_unlocking_);
79 } 89 }
80 90
81 bool SessionController::IsInSecondaryLoginScreen() const { 91 bool SessionController::IsInSecondaryLoginScreen() const {
82 return state_ == session_manager::SessionState::LOGIN_SECONDARY; 92 return state_ == SessionState::LOGIN_SECONDARY;
83 } 93 }
84 94
85 session_manager::SessionState SessionController::GetSessionState() const { 95 SessionState SessionController::GetSessionState() const {
86 return state_; 96 return state_;
87 } 97 }
88 98
89 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() 99 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions()
90 const { 100 const {
91 return user_sessions_; 101 return user_sessions_;
92 } 102 }
93 103
94 const mojom::UserSession* SessionController::GetUserSession( 104 const mojom::UserSession* SessionController::GetUserSession(
95 UserIndex index) const { 105 UserIndex index) const {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (user_sessions_[0]->session_id != active_session_id_) { 188 if (user_sessions_[0]->session_id != active_session_id_) {
179 active_session_id_ = user_sessions_[0]->session_id; 189 active_session_id_ = user_sessions_[0]->session_id;
180 190
181 for (auto& observer : observers_) 191 for (auto& observer : observers_)
182 observer.ActiveUserChanged(user_sessions_[0]->account_id); 192 observer.ActiveUserChanged(user_sessions_[0]->account_id);
183 193
184 UpdateLoginStatus(); 194 UpdateLoginStatus();
185 } 195 }
186 } 196 }
187 197
198 void SessionController::RunUnlockAnimation(
199 const RunUnlockAnimationCallback& callback) {
200 is_unlocking_ = true;
201
202 // Shell could have no instance in tests.
203 if (Shell::HasInstance())
204 Shell::Get()->lock_state_controller()->OnLockScreenHide(callback);
205 }
206
188 void SessionController::ClearUserSessionsForTest() { 207 void SessionController::ClearUserSessionsForTest() {
189 user_sessions_.clear(); 208 user_sessions_.clear();
190 } 209 }
191 210
192 void SessionController::FlushMojoForTest() { 211 void SessionController::FlushMojoForTest() {
193 client_.FlushForTesting(); 212 client_.FlushForTesting();
194 } 213 }
195 214
196 void SessionController::LockScreenAndFlushForTest() { 215 void SessionController::LockScreenAndFlushForTest() {
197 LockScreen(); 216 LockScreen();
198 FlushMojoForTest(); 217 FlushMojoForTest();
199 } 218 }
200 219
201 void SessionController::SetSessionState(session_manager::SessionState state) { 220 void SessionController::SetSessionState(SessionState state) {
202 if (state_ == state) 221 if (state_ == state)
203 return; 222 return;
204 223
224 const bool was_locked = state_ == SessionState::LOCKED;
205 state_ = state; 225 state_ = state;
206 for (auto& observer : observers_) 226 for (auto& observer : observers_)
207 observer.SessionStateChanged(state_); 227 observer.SessionStateChanged(state_);
208 228
209 UpdateLoginStatus(); 229 UpdateLoginStatus();
230
231 const bool locked = state_ == SessionState::LOCKED;
232 if (was_locked != locked) {
233 if (!locked)
234 is_unlocking_ = false;
235
236 for (auto& observer : observers_)
237 observer.LockStateChanged(locked);
238 }
210 } 239 }
211 240
212 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { 241 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) {
213 const AccountId account_id(user_session->account_id); 242 const AccountId account_id(user_session->account_id);
214 243
215 user_sessions_.push_back(std::move(user_session)); 244 user_sessions_.push_back(std::move(user_session));
216 245
217 for (auto& observer : observers_) 246 for (auto& observer : observers_)
218 observer.UserAddedToSession(account_id); 247 observer.UserAddedToSession(account_id);
219 } 248 }
220 249
221 LoginStatus SessionController::CalculateLoginStatus() const { 250 LoginStatus SessionController::CalculateLoginStatus() const {
222 using session_manager::SessionState;
223
224 // TODO(jamescook|xiyuan): There is not a 1:1 mapping of SessionState to 251 // TODO(jamescook|xiyuan): There is not a 1:1 mapping of SessionState to
225 // LoginStatus. Fix the cases that don't match. http://crbug.com/701193 252 // LoginStatus. Fix the cases that don't match. http://crbug.com/701193
226 switch (state_) { 253 switch (state_) {
227 case SessionState::UNKNOWN: 254 case SessionState::UNKNOWN:
228 case SessionState::OOBE: 255 case SessionState::OOBE:
229 case SessionState::LOGIN_PRIMARY: 256 case SessionState::LOGIN_PRIMARY:
230 case SessionState::LOGGED_IN_NOT_ACTIVE: 257 case SessionState::LOGGED_IN_NOT_ACTIVE:
231 return LoginStatus::NOT_LOGGED_IN; 258 return LoginStatus::NOT_LOGGED_IN;
232 259
233 case SessionState::ACTIVE: 260 case SessionState::ACTIVE:
234 return CalculateLoginStatusForActiveSession(); 261 return CalculateLoginStatusForActiveSession();
235 262
236 case SessionState::LOCKED: 263 case SessionState::LOCKED:
237 return LoginStatus::LOCKED; 264 return LoginStatus::LOCKED;
238 265
239 case SessionState::LOGIN_SECONDARY: 266 case SessionState::LOGIN_SECONDARY:
240 // TODO: There is no LoginStatus for this. 267 // TODO: There is no LoginStatus for this.
241 return LoginStatus::USER; 268 return LoginStatus::USER;
242 } 269 }
243 NOTREACHED(); 270 NOTREACHED();
244 return LoginStatus::NOT_LOGGED_IN; 271 return LoginStatus::NOT_LOGGED_IN;
245 } 272 }
246 273
247 LoginStatus SessionController::CalculateLoginStatusForActiveSession() const { 274 LoginStatus SessionController::CalculateLoginStatusForActiveSession() const {
248 DCHECK(state_ == session_manager::SessionState::ACTIVE); 275 DCHECK(state_ == SessionState::ACTIVE);
249 276
250 if (user_sessions_.empty()) // Can be empty in tests. 277 if (user_sessions_.empty()) // Can be empty in tests.
251 return LoginStatus::USER; 278 return LoginStatus::USER;
252 279
253 switch (user_sessions_[0]->type) { 280 switch (user_sessions_[0]->type) {
254 case user_manager::USER_TYPE_REGULAR: 281 case user_manager::USER_TYPE_REGULAR:
255 // TODO: This needs to distinguish between owner and non-owner. 282 // TODO: This needs to distinguish between owner and non-owner.
256 return LoginStatus::USER; 283 return LoginStatus::USER;
257 case user_manager::USER_TYPE_GUEST: 284 case user_manager::USER_TYPE_GUEST:
258 return LoginStatus::GUEST; 285 return LoginStatus::GUEST;
(...skipping 23 matching lines...) Expand all
282 const LoginStatus new_login_status = CalculateLoginStatus(); 309 const LoginStatus new_login_status = CalculateLoginStatus();
283 if (new_login_status == login_status_) 310 if (new_login_status == login_status_)
284 return; 311 return;
285 312
286 login_status_ = new_login_status; 313 login_status_ = new_login_status;
287 for (auto& observer : observers_) 314 for (auto& observer : observers_)
288 observer.LoginStatusChanged(login_status_); 315 observer.LoginStatusChanged(login_status_);
289 } 316 }
290 317
291 } // namespace ash 318 } // namespace ash
OLDNEW
« no previous file with comments | « ash/session/session_controller.h ('k') | ash/session/session_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698