Chromium Code Reviews| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 AddUserSessionPolicy SessionController::GetAddUserPolicy() const { | 34 AddUserSessionPolicy SessionController::GetAddUserPolicy() const { |
| 35 return add_user_session_policy_; | 35 return add_user_session_policy_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool SessionController::IsActiveUserSessionStarted() const { | 38 bool SessionController::IsActiveUserSessionStarted() const { |
| 39 return !user_sessions_.empty(); | 39 return !user_sessions_.empty(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool SessionController::CanLockScreen() const { | 42 bool SessionController::CanLockScreen() const { |
| 43 return can_lock_; | 43 return IsActiveUserSessionStarted() && can_lock_; |
|
xiyuan
2017/03/17 07:08:15
Behavior change, caught by LockStateControllerTest
| |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool SessionController::IsScreenLocked() const { | 46 bool SessionController::IsScreenLocked() const { |
| 47 return state_ == session_manager::SessionState::LOCKED; | 47 return state_ == session_manager::SessionState::LOCKED; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SessionController::ShouldLockScreenAutomatically() const { | 50 bool SessionController::ShouldLockScreenAutomatically() const { |
| 51 return should_lock_screen_automatically_; | 51 return should_lock_screen_automatically_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool SessionController::IsUserSessionBlocked() const { | 54 bool SessionController::IsUserSessionBlocked() const { |
| 55 return state_ != session_manager::SessionState::ACTIVE; | 55 return state_ != session_manager::SessionState::ACTIVE; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool SessionController::IsInSecondaryLoginScreen() const { | |
| 59 return state_ == session_manager::SessionState::LOGIN_SECONDARY; | |
| 60 } | |
| 61 | |
| 58 session_manager::SessionState SessionController::GetSessionState() const { | 62 session_manager::SessionState SessionController::GetSessionState() const { |
| 59 return state_; | 63 return state_; |
| 60 } | 64 } |
| 61 | 65 |
| 62 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() | 66 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() |
| 63 const { | 67 const { |
| 64 return user_sessions_; | 68 return user_sessions_; |
| 65 } | 69 } |
| 66 | 70 |
| 71 const mojom::UserSession* SessionController::GetUserSession( | |
| 72 UserIndex index) const { | |
| 73 if (index < 0 || index >= static_cast<UserIndex>(user_sessions_.size())) | |
| 74 return nullptr; | |
| 75 | |
| 76 return user_sessions_[index].get(); | |
| 77 } | |
| 78 | |
| 67 void SessionController::LockScreen() { | 79 void SessionController::LockScreen() { |
| 68 if (client_) | 80 if (client_) |
| 69 client_->RequestLockScreen(); | 81 client_->RequestLockScreen(); |
| 70 } | 82 } |
| 71 | 83 |
| 72 void SessionController::SwitchActiveUser(const AccountId& account_id) { | 84 void SessionController::SwitchActiveUser(const AccountId& account_id) { |
| 73 if (client_) | 85 if (client_) |
| 74 client_->SwitchActiveUser(account_id); | 86 client_->SwitchActiveUser(account_id); |
| 75 } | 87 } |
| 76 | 88 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 177 |
| 166 // Check active user change and notifies observers. | 178 // Check active user change and notifies observers. |
| 167 if (user_sessions_[0]->session_id != active_session_id_) { | 179 if (user_sessions_[0]->session_id != active_session_id_) { |
| 168 active_session_id_ = user_sessions_[0]->session_id; | 180 active_session_id_ = user_sessions_[0]->session_id; |
| 169 | 181 |
| 170 for (auto& observer : observers_) | 182 for (auto& observer : observers_) |
| 171 observer.ActiveUserChanged(user_sessions_[0]->account_id); | 183 observer.ActiveUserChanged(user_sessions_[0]->account_id); |
| 172 } | 184 } |
| 173 } | 185 } |
| 174 | 186 |
| 187 void SessionController::ClearUserSessionsForTest() { | |
| 188 user_sessions_.clear(); | |
| 189 } | |
| 190 | |
| 191 void SessionController::LockScreenAndFlushForTest() { | |
| 192 LockScreen(); | |
| 193 client_.FlushForTesting(); | |
| 194 } | |
| 195 | |
| 175 void SessionController::SetSessionState(session_manager::SessionState state) { | 196 void SessionController::SetSessionState(session_manager::SessionState state) { |
| 176 if (state_ == state) | 197 if (state_ == state) |
| 177 return; | 198 return; |
| 178 | 199 |
| 179 state_ = state; | 200 state_ = state; |
| 180 for (auto& observer : observers_) | 201 for (auto& observer : observers_) |
| 181 observer.SessionStateChanged(state_); | 202 observer.SessionStateChanged(state_); |
| 182 } | 203 } |
| 183 | 204 |
| 184 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { | 205 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: | 239 case user_manager::NUM_USER_TYPES: |
| 219 // Avoid having a "default" case so the compiler catches new enum values. | 240 // Avoid having a "default" case so the compiler catches new enum values. |
| 220 NOTREACHED(); | 241 NOTREACHED(); |
| 221 return LoginStatus::USER; | 242 return LoginStatus::USER; |
| 222 } | 243 } |
| 223 NOTREACHED(); | 244 NOTREACHED(); |
| 224 return LoginStatus::USER; | 245 return LoginStatus::USER; |
| 225 } | 246 } |
| 226 | 247 |
| 227 } // namespace ash | 248 } // namespace ash |
| OLD | NEW |