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

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

Issue 2724163002: ash: Use enum for SessionController::CycleActiveUser (Closed)
Patch Set: fix ash_shell_with_content compile 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 "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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 void SessionControllerClient::RequestLockScreen() { 105 void SessionControllerClient::RequestLockScreen() {
106 DoLockScreen(); 106 DoLockScreen();
107 } 107 }
108 108
109 void SessionControllerClient::SwitchActiveUser(const AccountId& account_id) { 109 void SessionControllerClient::SwitchActiveUser(const AccountId& account_id) {
110 DoSwitchActiveUser(account_id); 110 DoSwitchActiveUser(account_id);
111 } 111 }
112 112
113 void SessionControllerClient::CycleActiveUser(bool next_user) { 113 void SessionControllerClient::CycleActiveUser(
114 DoCycleActiveUser(next_user); 114 ash::CycleUserDirection direction) {
115 DoCycleActiveUser(direction);
115 } 116 }
116 117
117 void SessionControllerClient::ActiveUserChanged(const User* active_user) { 118 void SessionControllerClient::ActiveUserChanged(const User* active_user) {
118 SendSessionInfoIfChanged(); 119 SendSessionInfoIfChanged();
119 120
120 // UserAddedToSession is not called for the primary user session so send its 121 // UserAddedToSession is not called for the primary user session so send its
121 // meta data here once. 122 // meta data here once.
122 if (!primary_user_session_sent_ && 123 if (!primary_user_session_sent_ &&
123 UserManager::Get()->GetPrimaryUser() == active_user) { 124 UserManager::Get()->GetPrimaryUser() == active_user) {
124 primary_user_session_sent_ = true; 125 primary_user_session_sent_ = true;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // static 191 // static
191 void SessionControllerClient::DoSwitchActiveUser(const AccountId& account_id) { 192 void SessionControllerClient::DoSwitchActiveUser(const AccountId& account_id) {
192 // Disallow switching to an already active user since that might crash. 193 // Disallow switching to an already active user since that might crash.
193 if (account_id == UserManager::Get()->GetActiveUser()->GetAccountId()) 194 if (account_id == UserManager::Get()->GetActiveUser()->GetAccountId())
194 return; 195 return;
195 196
196 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id)); 197 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id));
197 } 198 }
198 199
199 // static 200 // static
200 void SessionControllerClient::DoCycleActiveUser(bool next_user) { 201 void SessionControllerClient::DoCycleActiveUser(
202 ash::CycleUserDirection direction) {
201 const UserList& logged_in_users = UserManager::Get()->GetLoggedInUsers(); 203 const UserList& logged_in_users = UserManager::Get()->GetLoggedInUsers();
202 if (logged_in_users.size() <= 1) 204 if (logged_in_users.size() <= 1)
203 return; 205 return;
204 206
205 AccountId account_id = UserManager::Get()->GetActiveUser()->GetAccountId(); 207 AccountId account_id = UserManager::Get()->GetActiveUser()->GetAccountId();
206 208
207 // Get an iterator positioned at the active user. 209 // Get an iterator positioned at the active user.
208 auto it = std::find_if(logged_in_users.begin(), logged_in_users.end(), 210 auto it = std::find_if(logged_in_users.begin(), logged_in_users.end(),
209 [account_id](const User* user) { 211 [account_id](const User* user) {
210 return user->GetAccountId() == account_id; 212 return user->GetAccountId() == account_id;
211 }); 213 });
212 214
213 // Active user not found. 215 // Active user not found.
214 if (it == logged_in_users.end()) 216 if (it == logged_in_users.end())
215 return; 217 return;
216 218
217 // Get the user's email to select, wrapping to the start/end of the list if 219 // Get the user's email to select, wrapping to the start/end of the list if
218 // necessary. 220 // necessary.
219 if (next_user) { 221 if (direction == ash::CycleUserDirection::NEXT) {
220 if (++it == logged_in_users.end()) 222 if (++it == logged_in_users.end())
221 account_id = (*logged_in_users.begin())->GetAccountId(); 223 account_id = (*logged_in_users.begin())->GetAccountId();
222 else 224 else
223 account_id = (*it)->GetAccountId(); 225 account_id = (*it)->GetAccountId();
224 } else { 226 } else if (direction == ash::CycleUserDirection::PREVIOUS) {
225 if (it == logged_in_users.begin()) 227 if (it == logged_in_users.begin())
226 it = logged_in_users.end(); 228 it = logged_in_users.end();
227 account_id = (*(--it))->GetAccountId(); 229 account_id = (*(--it))->GetAccountId();
230 } else {
231 NOTREACHED() << "Invalid direction=" << static_cast<int>(direction);
232 return;
228 } 233 }
229 234
230 DoSwitchActiveUser(account_id); 235 DoSwitchActiveUser(account_id);
231 } 236 }
232 237
233 // static 238 // static
234 void SessionControllerClient::FlushForTesting() { 239 void SessionControllerClient::FlushForTesting() {
235 g_instance->session_controller_.FlushForTesting(); 240 g_instance->session_controller_.FlushForTesting();
236 } 241 }
237 242
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 const UserList logged_in_users = user_manager->GetLoggedInUsers(); 287 const UserList logged_in_users = user_manager->GetLoggedInUsers();
283 std::vector<uint32_t> user_session_ids; 288 std::vector<uint32_t> user_session_ids;
284 for (auto* user : user_manager->GetLRULoggedInUsers()) { 289 for (auto* user : user_manager->GetLRULoggedInUsers()) {
285 const uint32_t user_session_id = GetSessionId(*user); 290 const uint32_t user_session_id = GetSessionId(*user);
286 DCHECK_NE(0u, user_session_id); 291 DCHECK_NE(0u, user_session_id);
287 user_session_ids.push_back(user_session_id); 292 user_session_ids.push_back(user_session_id);
288 } 293 }
289 294
290 session_controller_->SetUserSessionOrder(user_session_ids); 295 session_controller_->SetUserSessionOrder(user_session_ids);
291 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/session_controller_client.h ('k') | chrome/browser/ui/ash/session_state_delegate_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698