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" |
| 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 session_manager::SessionState GetDefaultSessionState() { | |
|
James Cook
2017/03/19 19:02:51
This function needs comments explaining why the de
xiyuan
2017/03/20 17:12:56
Done.
| |
| 23 const bool start_with_user = | |
| 24 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 25 chromeos::switches::kLoginUser); | |
| 26 return start_with_user ? session_manager::SessionState::ACTIVE | |
| 27 : session_manager::SessionState::UNKNOWN; | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 SessionController::SessionController() : state_(GetDefaultSessionState()) {} | |
| 19 | 33 |
| 20 SessionController::~SessionController() {} | 34 SessionController::~SessionController() {} |
| 21 | 35 |
| 22 void SessionController::BindRequest(mojom::SessionControllerRequest request) { | 36 void SessionController::BindRequest(mojom::SessionControllerRequest request) { |
| 23 bindings_.AddBinding(this, std::move(request)); | 37 bindings_.AddBinding(this, std::move(request)); |
| 24 } | 38 } |
| 25 | 39 |
| 26 int SessionController::GetMaximumNumberOfLoggedInUsers() const { | 40 int SessionController::GetMaximumNumberOfLoggedInUsers() const { |
| 27 return session_manager::kMaxmiumNumberOfUserSessions; | 41 return session_manager::kMaxmiumNumberOfUserSessions; |
| 28 } | 42 } |
| 29 | 43 |
| 30 int SessionController::NumberOfLoggedInUsers() const { | 44 int SessionController::NumberOfLoggedInUsers() const { |
| 31 return static_cast<int>(user_sessions_.size()); | 45 return static_cast<int>(user_sessions_.size()); |
| 32 } | 46 } |
| 33 | 47 |
| 34 AddUserSessionPolicy SessionController::GetAddUserPolicy() const { | 48 AddUserSessionPolicy SessionController::GetAddUserPolicy() const { |
| 35 return add_user_session_policy_; | 49 return add_user_session_policy_; |
| 36 } | 50 } |
| 37 | 51 |
| 38 bool SessionController::IsActiveUserSessionStarted() const { | 52 bool SessionController::IsActiveUserSessionStarted() const { |
| 39 return !user_sessions_.empty(); | 53 return !user_sessions_.empty(); |
| 40 } | 54 } |
| 41 | 55 |
| 42 bool SessionController::CanLockScreen() const { | 56 bool SessionController::CanLockScreen() const { |
| 43 return can_lock_; | 57 return IsActiveUserSessionStarted() && can_lock_; |
| 44 } | 58 } |
| 45 | 59 |
| 46 bool SessionController::IsScreenLocked() const { | 60 bool SessionController::IsScreenLocked() const { |
| 47 return state_ == session_manager::SessionState::LOCKED; | 61 return state_ == session_manager::SessionState::LOCKED; |
| 48 } | 62 } |
| 49 | 63 |
| 50 bool SessionController::ShouldLockScreenAutomatically() const { | 64 bool SessionController::ShouldLockScreenAutomatically() const { |
| 51 return should_lock_screen_automatically_; | 65 return should_lock_screen_automatically_; |
| 52 } | 66 } |
| 53 | 67 |
| 54 bool SessionController::IsUserSessionBlocked() const { | 68 bool SessionController::IsUserSessionBlocked() const { |
| 55 return state_ != session_manager::SessionState::ACTIVE; | 69 return state_ != session_manager::SessionState::ACTIVE; |
| 56 } | 70 } |
| 57 | 71 |
| 72 bool SessionController::IsInSecondaryLoginScreen() const { | |
| 73 return state_ == session_manager::SessionState::LOGIN_SECONDARY; | |
| 74 } | |
| 75 | |
| 58 session_manager::SessionState SessionController::GetSessionState() const { | 76 session_manager::SessionState SessionController::GetSessionState() const { |
| 59 return state_; | 77 return state_; |
| 60 } | 78 } |
| 61 | 79 |
| 62 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() | 80 const std::vector<mojom::UserSessionPtr>& SessionController::GetUserSessions() |
| 63 const { | 81 const { |
| 64 return user_sessions_; | 82 return user_sessions_; |
| 65 } | 83 } |
| 66 | 84 |
| 85 const mojom::UserSession* SessionController::GetUserSession( | |
| 86 UserIndex index) const { | |
| 87 if (index < 0 || index >= static_cast<UserIndex>(user_sessions_.size())) | |
| 88 return nullptr; | |
| 89 | |
| 90 return user_sessions_[index].get(); | |
| 91 } | |
| 92 | |
| 67 void SessionController::LockScreen() { | 93 void SessionController::LockScreen() { |
| 68 if (client_) | 94 if (client_) |
| 69 client_->RequestLockScreen(); | 95 client_->RequestLockScreen(); |
| 70 } | 96 } |
| 71 | 97 |
| 72 void SessionController::SwitchActiveUser(const AccountId& account_id) { | 98 void SessionController::SwitchActiveUser(const AccountId& account_id) { |
| 73 if (client_) | 99 if (client_) |
| 74 client_->SwitchActiveUser(account_id); | 100 client_->SwitchActiveUser(account_id); |
| 75 } | 101 } |
| 76 | 102 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 191 |
| 166 // Check active user change and notifies observers. | 192 // Check active user change and notifies observers. |
| 167 if (user_sessions_[0]->session_id != active_session_id_) { | 193 if (user_sessions_[0]->session_id != active_session_id_) { |
| 168 active_session_id_ = user_sessions_[0]->session_id; | 194 active_session_id_ = user_sessions_[0]->session_id; |
| 169 | 195 |
| 170 for (auto& observer : observers_) | 196 for (auto& observer : observers_) |
| 171 observer.ActiveUserChanged(user_sessions_[0]->account_id); | 197 observer.ActiveUserChanged(user_sessions_[0]->account_id); |
| 172 } | 198 } |
| 173 } | 199 } |
| 174 | 200 |
| 201 void SessionController::ClearUserSessionsForTest() { | |
| 202 user_sessions_.clear(); | |
| 203 } | |
| 204 | |
| 205 void SessionController::FlushMojoForTest() { | |
| 206 client_.FlushForTesting(); | |
| 207 } | |
| 208 | |
| 209 void SessionController::LockScreenAndFlushForTest() { | |
| 210 LockScreen(); | |
| 211 FlushMojoForTest(); | |
| 212 } | |
| 213 | |
| 175 void SessionController::SetSessionState(session_manager::SessionState state) { | 214 void SessionController::SetSessionState(session_manager::SessionState state) { |
| 176 if (state_ == state) | 215 if (state_ == state) |
| 177 return; | 216 return; |
| 178 | 217 |
| 179 state_ = state; | 218 state_ = state; |
| 180 for (auto& observer : observers_) | 219 for (auto& observer : observers_) |
| 181 observer.SessionStateChanged(state_); | 220 observer.SessionStateChanged(state_); |
| 182 } | 221 } |
| 183 | 222 |
| 184 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { | 223 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: | 257 case user_manager::NUM_USER_TYPES: |
| 219 // Avoid having a "default" case so the compiler catches new enum values. | 258 // Avoid having a "default" case so the compiler catches new enum values. |
| 220 NOTREACHED(); | 259 NOTREACHED(); |
| 221 return LoginStatus::USER; | 260 return LoginStatus::USER; |
| 222 } | 261 } |
| 223 NOTREACHED(); | 262 NOTREACHED(); |
| 224 return LoginStatus::USER; | 263 return LoginStatus::USER; |
| 225 } | 264 } |
| 226 | 265 |
| 227 } // namespace ash | 266 } // namespace ash |
| OLD | NEW |