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

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

Issue 2911493002: cros: Pull user info from session_controller_client.mojom into separate mojom. (Closed)
Patch Set: Fix ordering in typemaps Created 3 years, 7 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/public/interfaces/user_info_traits.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 #include <utility> 8 #include <utility>
9 9
10 #include "ash/public/interfaces/user_info.mojom.h"
10 #include "ash/session/session_observer.h" 11 #include "ash/session/session_observer.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/system/power/power_event_observer.h" 13 #include "ash/system/power/power_event_observer.h"
13 #include "ash/wm/lock_state_controller.h" 14 #include "ash/wm/lock_state_controller.h"
14 #include "base/bind.h" 15 #include "base/bind.h"
15 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
16 #include "base/command_line.h" 17 #include "base/command_line.h"
17 #include "chromeos/chromeos_switches.h" 18 #include "chromeos/chromeos_switches.h"
18 #include "components/signin/core/account_id/account_id.h" 19 #include "components/signin/core/account_id/account_id.h"
19 #include "components/user_manager/user_type.h" 20 #include "components/user_manager/user_type.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (index < 0 || index >= static_cast<UserIndex>(user_sessions_.size())) 133 if (index < 0 || index >= static_cast<UserIndex>(user_sessions_.size()))
133 return nullptr; 134 return nullptr;
134 135
135 return user_sessions_[index].get(); 136 return user_sessions_[index].get();
136 } 137 }
137 138
138 bool SessionController::IsUserSupervised() const { 139 bool SessionController::IsUserSupervised() const {
139 if (!IsActiveUserSessionStarted()) 140 if (!IsActiveUserSessionStarted())
140 return false; 141 return false;
141 142
142 user_manager::UserType active_user_type = GetUserSession(0)->type; 143 user_manager::UserType active_user_type = GetUserSession(0)->user_info->type;
143 return active_user_type == user_manager::USER_TYPE_SUPERVISED || 144 return active_user_type == user_manager::USER_TYPE_SUPERVISED ||
144 active_user_type == user_manager::USER_TYPE_CHILD; 145 active_user_type == user_manager::USER_TYPE_CHILD;
145 } 146 }
146 147
147 bool SessionController::IsUserChild() const { 148 bool SessionController::IsUserChild() const {
148 if (!IsActiveUserSessionStarted()) 149 if (!IsActiveUserSessionStarted())
149 return false; 150 return false;
150 151
151 user_manager::UserType active_user_type = GetUserSession(0)->type; 152 user_manager::UserType active_user_type = GetUserSession(0)->user_info->type;
152 return active_user_type == user_manager::USER_TYPE_CHILD; 153 return active_user_type == user_manager::USER_TYPE_CHILD;
153 } 154 }
154 155
155 bool SessionController::IsKioskSession() const { 156 bool SessionController::IsKioskSession() const {
156 if (!IsActiveUserSessionStarted()) 157 if (!IsActiveUserSessionStarted())
157 return false; 158 return false;
158 159
159 user_manager::UserType active_user_type = GetUserSession(0)->type; 160 user_manager::UserType active_user_type = GetUserSession(0)->user_info->type;
160 return active_user_type == user_manager::USER_TYPE_KIOSK_APP || 161 return active_user_type == user_manager::USER_TYPE_KIOSK_APP ||
161 active_user_type == user_manager::USER_TYPE_ARC_KIOSK_APP; 162 active_user_type == user_manager::USER_TYPE_ARC_KIOSK_APP;
162 } 163 }
163 164
164 void SessionController::LockScreen() { 165 void SessionController::LockScreen() {
165 if (client_) 166 if (client_)
166 client_->RequestLockScreen(); 167 client_->RequestLockScreen();
167 } 168 }
168 169
169 void SessionController::SwitchActiveUser(const AccountId& account_id) { 170 void SessionController::SwitchActiveUser(const AccountId& account_id) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 [&user_session](const mojom::UserSessionPtr& session) { 202 [&user_session](const mojom::UserSessionPtr& session) {
202 return session->session_id == user_session->session_id; 203 return session->session_id == user_session->session_id;
203 }); 204 });
204 if (it == user_sessions_.end()) { 205 if (it == user_sessions_.end()) {
205 AddUserSession(std::move(user_session)); 206 AddUserSession(std::move(user_session));
206 return; 207 return;
207 } 208 }
208 209
209 *it = std::move(user_session); 210 *it = std::move(user_session);
210 for (auto& observer : observers_) 211 for (auto& observer : observers_)
211 observer.OnUserSessionUpdated((*it)->account_id); 212 observer.OnUserSessionUpdated((*it)->user_info->account_id);
212 213
213 UpdateLoginStatus(); 214 UpdateLoginStatus();
214 } 215 }
215 216
216 void SessionController::SetUserSessionOrder( 217 void SessionController::SetUserSessionOrder(
217 const std::vector<uint32_t>& user_session_order) { 218 const std::vector<uint32_t>& user_session_order) {
218 DCHECK_EQ(user_sessions_.size(), user_session_order.size()); 219 DCHECK_EQ(user_sessions_.size(), user_session_order.size());
219 220
220 // Adjusts |user_sessions_| to match the given order. 221 // Adjusts |user_sessions_| to match the given order.
221 std::vector<mojom::UserSessionPtr> sessions; 222 std::vector<mojom::UserSessionPtr> sessions;
222 for (const auto& session_id : user_session_order) { 223 for (const auto& session_id : user_session_order) {
223 auto it = 224 auto it =
224 std::find_if(user_sessions_.begin(), user_sessions_.end(), 225 std::find_if(user_sessions_.begin(), user_sessions_.end(),
225 [session_id](const mojom::UserSessionPtr& session) { 226 [session_id](const mojom::UserSessionPtr& session) {
226 return session && session->session_id == session_id; 227 return session && session->session_id == session_id;
227 }); 228 });
228 if (it == user_sessions_.end()) { 229 if (it == user_sessions_.end()) {
229 LOG(ERROR) << "Unknown session id =" << session_id; 230 LOG(ERROR) << "Unknown session id =" << session_id;
230 continue; 231 continue;
231 } 232 }
232 233
233 sessions.push_back(std::move(*it)); 234 sessions.push_back(std::move(*it));
234 } 235 }
235 user_sessions_.swap(sessions); 236 user_sessions_.swap(sessions);
236 237
237 // Check active user change and notifies observers. 238 // Check active user change and notifies observers.
238 if (user_sessions_[0]->session_id != active_session_id_) { 239 if (user_sessions_[0]->session_id != active_session_id_) {
239 active_session_id_ = user_sessions_[0]->session_id; 240 active_session_id_ = user_sessions_[0]->session_id;
240 241
241 for (auto& observer : observers_) 242 for (auto& observer : observers_) {
242 observer.OnActiveUserSessionChanged(user_sessions_[0]->account_id); 243 observer.OnActiveUserSessionChanged(
244 user_sessions_[0]->user_info->account_id);
245 }
243 246
244 UpdateLoginStatus(); 247 UpdateLoginStatus();
245 } 248 }
246 } 249 }
247 250
248 void SessionController::StartLock(StartLockCallback callback) { 251 void SessionController::StartLock(StartLockCallback callback) {
249 DCHECK(start_lock_callback_.is_null()); 252 DCHECK(start_lock_callback_.is_null());
250 start_lock_callback_ = std::move(callback); 253 start_lock_callback_ = std::move(callback);
251 254
252 LockStateController* const lock_state_controller = 255 LockStateController* const lock_state_controller =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 if (was_locked != locked) { 308 if (was_locked != locked) {
306 if (!locked) 309 if (!locked)
307 is_unlocking_ = false; 310 is_unlocking_ = false;
308 311
309 for (auto& observer : observers_) 312 for (auto& observer : observers_)
310 observer.OnLockStateChanged(locked); 313 observer.OnLockStateChanged(locked);
311 } 314 }
312 } 315 }
313 316
314 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { 317 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) {
315 const AccountId account_id(user_session->account_id); 318 const AccountId account_id(user_session->user_info->account_id);
316 319
317 user_sessions_.push_back(std::move(user_session)); 320 user_sessions_.push_back(std::move(user_session));
318 321
319 for (auto& observer : observers_) 322 for (auto& observer : observers_)
320 observer.OnUserSessionAdded(account_id); 323 observer.OnUserSessionAdded(account_id);
321 } 324 }
322 325
323 LoginStatus SessionController::CalculateLoginStatus() const { 326 LoginStatus SessionController::CalculateLoginStatus() const {
324 // TODO(jamescook|xiyuan): There is not a 1:1 mapping of SessionState to 327 // TODO(jamescook|xiyuan): There is not a 1:1 mapping of SessionState to
325 // LoginStatus. Fix the cases that don't match. http://crbug.com/701193 328 // LoginStatus. Fix the cases that don't match. http://crbug.com/701193
(...skipping 17 matching lines...) Expand all
343 NOTREACHED(); 346 NOTREACHED();
344 return LoginStatus::NOT_LOGGED_IN; 347 return LoginStatus::NOT_LOGGED_IN;
345 } 348 }
346 349
347 LoginStatus SessionController::CalculateLoginStatusForActiveSession() const { 350 LoginStatus SessionController::CalculateLoginStatusForActiveSession() const {
348 DCHECK(state_ == SessionState::ACTIVE); 351 DCHECK(state_ == SessionState::ACTIVE);
349 352
350 if (user_sessions_.empty()) // Can be empty in tests. 353 if (user_sessions_.empty()) // Can be empty in tests.
351 return LoginStatus::USER; 354 return LoginStatus::USER;
352 355
353 switch (user_sessions_[0]->type) { 356 switch (user_sessions_[0]->user_info->type) {
354 case user_manager::USER_TYPE_REGULAR: 357 case user_manager::USER_TYPE_REGULAR:
355 // TODO: This needs to distinguish between owner and non-owner. 358 // TODO: This needs to distinguish between owner and non-owner.
356 return LoginStatus::USER; 359 return LoginStatus::USER;
357 case user_manager::USER_TYPE_GUEST: 360 case user_manager::USER_TYPE_GUEST:
358 return LoginStatus::GUEST; 361 return LoginStatus::GUEST;
359 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: 362 case user_manager::USER_TYPE_PUBLIC_ACCOUNT:
360 return LoginStatus::PUBLIC; 363 return LoginStatus::PUBLIC;
361 case user_manager::USER_TYPE_SUPERVISED: 364 case user_manager::USER_TYPE_SUPERVISED:
362 return LoginStatus::SUPERVISED; 365 return LoginStatus::SUPERVISED;
363 case user_manager::USER_TYPE_KIOSK_APP: 366 case user_manager::USER_TYPE_KIOSK_APP:
(...skipping 23 matching lines...) Expand all
387 for (auto& observer : observers_) 390 for (auto& observer : observers_)
388 observer.OnLoginStatusChanged(login_status_); 391 observer.OnLoginStatusChanged(login_status_);
389 } 392 }
390 393
391 void SessionController::OnLockAnimationFinished() { 394 void SessionController::OnLockAnimationFinished() {
392 if (!start_lock_callback_.is_null()) 395 if (!start_lock_callback_.is_null())
393 std::move(start_lock_callback_).Run(true /* locked */); 396 std::move(start_lock_callback_).Run(true /* locked */);
394 } 397 }
395 398
396 } // namespace ash 399 } // namespace ash
OLDNEW
« no previous file with comments | « ash/public/interfaces/user_info_traits.h ('k') | ash/session/session_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698