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

Side by Side Diff: chrome/browser/ui/ash/session_controller_client.cc

Issue 2619083002: Clean up SessionStateDelegate in chrome (Closed)
Patch Set: fix LauncherContextMenuTest Created 3 years, 11 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 "chrome/browser/ui/ash/session_controller_client.h" 5 #include "chrome/browser/ui/ash/session_controller_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/public/cpp/session_types.h" 10 #include "ash/public/cpp/session_types.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/common/service_names.mojom.h" 26 #include "content/public/common/service_names.mojom.h"
27 #include "services/service_manager/public/cpp/connector.h" 27 #include "services/service_manager/public/cpp/connector.h"
28 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
29 29
30 using user_manager::UserManager; 30 using user_manager::UserManager;
31 using user_manager::User; 31 using user_manager::User;
32 using user_manager::UserList; 32 using user_manager::UserList;
33 33
34 namespace { 34 namespace {
35 35
36 // Limits the number of logged in users to 10 due to memory constraints.
37 constexpr uint32_t kMaxUsers = 10;
38
39 SessionControllerClient* g_instance = nullptr; 36 SessionControllerClient* g_instance = nullptr;
40 37
41 uint32_t GetSessionId(const User* user) { 38 uint32_t GetSessionId(const User* user) {
42 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers(); 39 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers();
43 // TODO(xiyuan): Update with real session id when user session tracking 40 // TODO(xiyuan): Update with real session id when user session tracking
44 // code is moved from UserManager to SessionManager. 41 // code is moved from UserManager to SessionManager.
45 for (size_t i = 0; i < logged_in_users.size(); ++i) { 42 for (size_t i = 0; i < logged_in_users.size(); ++i) {
46 if (logged_in_users[i] == user) 43 if (logged_in_users[i] == user)
47 return i + 1; 44 return i + 1;
48 } 45 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ash::AddUserSessionPolicy SessionControllerClient::GetAddUserSessionPolicy() { 160 ash::AddUserSessionPolicy SessionControllerClient::GetAddUserSessionPolicy() {
164 UserManager* const user_manager = UserManager::Get(); 161 UserManager* const user_manager = UserManager::Get();
165 if (user_manager->GetUsersAllowedForMultiProfile().empty()) 162 if (user_manager->GetUsersAllowedForMultiProfile().empty())
166 return ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS; 163 return ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS;
167 164
168 if (chromeos::MultiProfileUserController::GetPrimaryUserPolicy() != 165 if (chromeos::MultiProfileUserController::GetPrimaryUserPolicy() !=
169 chromeos::MultiProfileUserController::ALLOWED) { 166 chromeos::MultiProfileUserController::ALLOWED) {
170 return ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER; 167 return ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER;
171 } 168 }
172 169
173 if (UserManager::Get()->GetLoggedInUsers().size() >= kMaxUsers) 170 if (UserManager::Get()->GetLoggedInUsers().size() >=
171 session_manager::SessionManager::Get()->GetMaximumNumberOfUserSessions())
174 return ash::AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED; 172 return ash::AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED;
175 173
176 return ash::AddUserSessionPolicy::ALLOWED; 174 return ash::AddUserSessionPolicy::ALLOWED;
177 } 175 }
178 176
179 // static 177 // static
180 void SessionControllerClient::DoLockScreen() { 178 void SessionControllerClient::DoLockScreen() {
181 if (!CanLockScreen()) 179 if (!CanLockScreen())
182 return; 180 return;
183 181
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void SessionControllerClient::ConnectToSessionControllerAndSetClient() { 244 void SessionControllerClient::ConnectToSessionControllerAndSetClient() {
247 content::ServiceManagerConnection::GetForProcess() 245 content::ServiceManagerConnection::GetForProcess()
248 ->GetConnector() 246 ->GetConnector()
249 ->ConnectToInterface(ash_util::GetAshServiceName(), &session_controller_); 247 ->ConnectToInterface(ash_util::GetAshServiceName(), &session_controller_);
250 248
251 // Set as |session_controller_|'s client. 249 // Set as |session_controller_|'s client.
252 session_controller_->SetClient(binding_.CreateInterfacePtrAndBind()); 250 session_controller_->SetClient(binding_.CreateInterfacePtrAndBind());
253 } 251 }
254 252
255 void SessionControllerClient::SendSessionInfoIfChanged() { 253 void SessionControllerClient::SendSessionInfoIfChanged() {
254 session_manager::SessionManager* const session_manager =
James Cook 2017/01/06 23:52:43 optional: I'm OK with "using session_manager::Sess
xiyuan 2017/01/07 00:07:32 Done.
255 session_manager::SessionManager::Get();
256
256 ash::mojom::SessionInfoPtr info = ash::mojom::SessionInfo::New(); 257 ash::mojom::SessionInfoPtr info = ash::mojom::SessionInfo::New();
257 info->max_users = kMaxUsers; 258 info->max_users = session_manager->GetMaximumNumberOfUserSessions();
258 info->can_lock_screen = CanLockScreen(); 259 info->can_lock_screen = CanLockScreen();
259 info->should_lock_screen_automatically = ShouldLockScreenAutomatically(); 260 info->should_lock_screen_automatically = ShouldLockScreenAutomatically();
260 info->add_user_session_policy = GetAddUserSessionPolicy(); 261 info->add_user_session_policy = GetAddUserSessionPolicy();
261 info->state = session_manager::SessionManager::Get()->session_state(); 262 info->state = session_manager->session_state();
262 263
263 if (info != last_sent_session_info_) { 264 if (info != last_sent_session_info_) {
264 last_sent_session_info_ = info->Clone(); 265 last_sent_session_info_ = info->Clone();
265 session_controller_->SetSessionInfo(std::move(info)); 266 session_controller_->SetSessionInfo(std::move(info));
266 } 267 }
267 } 268 }
268 269
269 void SessionControllerClient::SendUserSession(const User& user) { 270 void SessionControllerClient::SendUserSession(const User& user) {
270 session_controller_->UpdateUserSession(UserToUserSession(user)); 271 session_controller_->UpdateUserSession(UserToUserSession(user));
271 } 272 }
272 273
273 void SessionControllerClient::SendUserSessionOrder() { 274 void SessionControllerClient::SendUserSessionOrder() {
274 UserManager* const user_manager = UserManager::Get(); 275 UserManager* const user_manager = UserManager::Get();
275 276
276 const UserList logged_in_users = user_manager->GetLoggedInUsers(); 277 const UserList logged_in_users = user_manager->GetLoggedInUsers();
277 std::vector<uint32_t> user_session_ids; 278 std::vector<uint32_t> user_session_ids;
278 for (auto* user : user_manager->GetLRULoggedInUsers()) 279 for (auto* user : user_manager->GetLRULoggedInUsers())
279 user_session_ids.push_back(GetSessionId(user)); 280 user_session_ids.push_back(GetSessionId(user));
280 281
281 session_controller_->SetUserSessionOrder(user_session_ids); 282 session_controller_->SetUserSessionOrder(user_session_ids);
282 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698