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

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

Issue 2741403004: mash: Update LoginStatus with session state updates (Closed)
Patch Set: Created 3 years, 9 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
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/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/session/session_state_observer.h" 10 #include "ash/common/session/session_state_observer.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "components/signin/core/account_id/account_id.h" 13 #include "components/signin/core/account_id/account_id.h"
13 #include "services/service_manager/public/cpp/connector.h" 14 #include "services/service_manager/public/cpp/connector.h"
14 15
15 namespace ash { 16 namespace ash {
16 17
17 SessionController::SessionController() {} 18 SessionController::SessionController() {}
18 19
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void SessionController::AddSessionStateObserver( 82 void SessionController::AddSessionStateObserver(
82 SessionStateObserver* observer) { 83 SessionStateObserver* observer) {
83 observers_.AddObserver(observer); 84 observers_.AddObserver(observer);
84 } 85 }
85 86
86 void SessionController::RemoveSessionStateObserver( 87 void SessionController::RemoveSessionStateObserver(
87 SessionStateObserver* observer) { 88 SessionStateObserver* observer) {
88 observers_.RemoveObserver(observer); 89 observers_.RemoveObserver(observer);
89 } 90 }
90 91
92 LoginStatus SessionController::GetLoginStatus() const {
93 using session_manager::SessionState;
94
95 // TODO(jamescook|xiyuan): This is a temporary hack until we decide if we want
96 // to convert code using LoginStatus to use SessionState instead. There isn't
97 // a 1:1 mapping of SessionState to LoginStatus. See also
98 // WmShell::SessionStateChanged().
99 switch (state_) {
100 case SessionState::UNKNOWN:
101 case SessionState::OOBE:
102 case SessionState::LOGIN_PRIMARY:
103 case SessionState::LOGGED_IN_NOT_ACTIVE:
104 return LoginStatus::NOT_LOGGED_IN;
105
106 case SessionState::ACTIVE:
107 return GetLoginStatusForActiveSession();
108
109 case SessionState::LOCKED:
110 return LoginStatus::LOCKED;
111
112 case SessionState::LOGIN_SECONDARY:
113 // TODO: There is no LoginStatus for this.
114 return LoginStatus::USER;
115 }
116 NOTREACHED();
117 return LoginStatus::NOT_LOGGED_IN;
118 }
119
91 void SessionController::SetClient(mojom::SessionControllerClientPtr client) { 120 void SessionController::SetClient(mojom::SessionControllerClientPtr client) {
92 client_ = std::move(client); 121 client_ = std::move(client);
93 } 122 }
94 123
95 void SessionController::SetSessionInfo(mojom::SessionInfoPtr info) { 124 void SessionController::SetSessionInfo(mojom::SessionInfoPtr info) {
96 can_lock_ = info->can_lock_screen; 125 can_lock_ = info->can_lock_screen;
97 should_lock_screen_automatically_ = info->should_lock_screen_automatically; 126 should_lock_screen_automatically_ = info->should_lock_screen_automatically;
98 add_user_session_policy_ = info->add_user_session_policy; 127 add_user_session_policy_ = info->add_user_session_policy;
99 SetSessionState(info->state); 128 SetSessionState(info->state);
100 } 129 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 185
157 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { 186 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) {
158 const AccountId account_id(user_session->account_id); 187 const AccountId account_id(user_session->account_id);
159 188
160 user_sessions_.push_back(std::move(user_session)); 189 user_sessions_.push_back(std::move(user_session));
161 190
162 for (auto& observer : observers_) 191 for (auto& observer : observers_)
163 observer.UserAddedToSession(account_id); 192 observer.UserAddedToSession(account_id);
164 } 193 }
165 194
195 LoginStatus SessionController::GetLoginStatusForActiveSession() const {
196 DCHECK(state_ == session_manager::SessionState::ACTIVE);
197
198 if (user_sessions_.empty()) // Can be empty in tests.
199 return LoginStatus::USER;
200
201 switch (user_sessions_[0]->type) {
202 case user_manager::USER_TYPE_REGULAR:
203 // TODO: This needs to distinguish between owner and non-owner.
204 return LoginStatus::USER;
205 case user_manager::USER_TYPE_GUEST:
206 return LoginStatus::GUEST;
207 case user_manager::USER_TYPE_PUBLIC_ACCOUNT:
208 return LoginStatus::PUBLIC;
209 case user_manager::USER_TYPE_SUPERVISED:
210 return LoginStatus::SUPERVISED;
211 case user_manager::USER_TYPE_KIOSK_APP:
212 return LoginStatus::KIOSK_APP;
213 case user_manager::USER_TYPE_CHILD:
214 return LoginStatus::SUPERVISED;
215 case user_manager::USER_TYPE_ARC_KIOSK_APP:
216 return LoginStatus::ARC_KIOSK_APP;
217 case user_manager::USER_TYPE_ACTIVE_DIRECTORY:
218 // TODO: There is no LoginStatus for this.
219 return LoginStatus::USER;
220 case user_manager::NUM_USER_TYPES:
221 // Avoid having a "default" case so the compiler catches new enum values.
222 NOTREACHED();
223 return LoginStatus::USER;
224 }
225 NOTREACHED();
226 return LoginStatus::USER;
227 }
228
166 } // namespace ash 229 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/session/session_controller.h ('k') | ash/common/session/session_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698