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 "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 Loading... |
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(ash::CycleUser cycle_user) { |
114 DoCycleActiveUser(next_user); | 114 DoCycleActiveUser(cycle_user); |
115 } | 115 } |
116 | 116 |
117 void SessionControllerClient::ActiveUserChanged(const User* active_user) { | 117 void SessionControllerClient::ActiveUserChanged(const User* active_user) { |
118 SendSessionInfoIfChanged(); | 118 SendSessionInfoIfChanged(); |
119 | 119 |
120 // UserAddedToSession is not called for the primary user session so send its | 120 // UserAddedToSession is not called for the primary user session so send its |
121 // meta data here once. | 121 // meta data here once. |
122 if (!primary_user_session_sent_ && | 122 if (!primary_user_session_sent_ && |
123 UserManager::Get()->GetPrimaryUser() == active_user) { | 123 UserManager::Get()->GetPrimaryUser() == active_user) { |
124 primary_user_session_sent_ = true; | 124 primary_user_session_sent_ = true; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // static | 190 // static |
191 void SessionControllerClient::DoSwitchActiveUser(const AccountId& account_id) { | 191 void SessionControllerClient::DoSwitchActiveUser(const AccountId& account_id) { |
192 // Disallow switching to an already active user since that might crash. | 192 // Disallow switching to an already active user since that might crash. |
193 if (account_id == UserManager::Get()->GetActiveUser()->GetAccountId()) | 193 if (account_id == UserManager::Get()->GetActiveUser()->GetAccountId()) |
194 return; | 194 return; |
195 | 195 |
196 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id)); | 196 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id)); |
197 } | 197 } |
198 | 198 |
199 // static | 199 // static |
200 void SessionControllerClient::DoCycleActiveUser(bool next_user) { | 200 void SessionControllerClient::DoCycleActiveUser(ash::CycleUser cycle_user) { |
201 const UserList& logged_in_users = UserManager::Get()->GetLoggedInUsers(); | 201 const UserList& logged_in_users = UserManager::Get()->GetLoggedInUsers(); |
202 if (logged_in_users.size() <= 1) | 202 if (logged_in_users.size() <= 1) |
203 return; | 203 return; |
204 | 204 |
205 AccountId account_id = UserManager::Get()->GetActiveUser()->GetAccountId(); | 205 AccountId account_id = UserManager::Get()->GetActiveUser()->GetAccountId(); |
206 | 206 |
207 // Get an iterator positioned at the active user. | 207 // Get an iterator positioned at the active user. |
208 auto it = std::find_if(logged_in_users.begin(), logged_in_users.end(), | 208 auto it = std::find_if(logged_in_users.begin(), logged_in_users.end(), |
209 [account_id](const User* user) { | 209 [account_id](const User* user) { |
210 return user->GetAccountId() == account_id; | 210 return user->GetAccountId() == account_id; |
211 }); | 211 }); |
212 | 212 |
213 // Active user not found. | 213 // Active user not found. |
214 if (it == logged_in_users.end()) | 214 if (it == logged_in_users.end()) |
215 return; | 215 return; |
216 | 216 |
217 // Get the user's email to select, wrapping to the start/end of the list if | 217 // Get the user's email to select, wrapping to the start/end of the list if |
218 // necessary. | 218 // necessary. |
219 if (next_user) { | 219 if (cycle_user == ash::CycleUser::CYCLE_TO_NEXT_USER) { |
220 if (++it == logged_in_users.end()) | 220 if (++it == logged_in_users.end()) |
221 account_id = (*logged_in_users.begin())->GetAccountId(); | 221 account_id = (*logged_in_users.begin())->GetAccountId(); |
222 else | 222 else |
223 account_id = (*it)->GetAccountId(); | 223 account_id = (*it)->GetAccountId(); |
224 } else { | 224 } else if (cycle_user == ash::CycleUser::CYCLE_TO_NEXT_USER) { |
225 if (it == logged_in_users.begin()) | 225 if (it == logged_in_users.begin()) |
226 it = logged_in_users.end(); | 226 it = logged_in_users.end(); |
227 account_id = (*(--it))->GetAccountId(); | 227 account_id = (*(--it))->GetAccountId(); |
| 228 } else { |
| 229 NOTREACHED() << "Invalid cycle_user=" << static_cast<int>(cycle_user); |
| 230 return; |
228 } | 231 } |
229 | 232 |
230 DoSwitchActiveUser(account_id); | 233 DoSwitchActiveUser(account_id); |
231 } | 234 } |
232 | 235 |
233 // static | 236 // static |
234 void SessionControllerClient::FlushForTesting() { | 237 void SessionControllerClient::FlushForTesting() { |
235 g_instance->session_controller_.FlushForTesting(); | 238 g_instance->session_controller_.FlushForTesting(); |
236 } | 239 } |
237 | 240 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 const UserList logged_in_users = user_manager->GetLoggedInUsers(); | 285 const UserList logged_in_users = user_manager->GetLoggedInUsers(); |
283 std::vector<uint32_t> user_session_ids; | 286 std::vector<uint32_t> user_session_ids; |
284 for (auto* user : user_manager->GetLRULoggedInUsers()) { | 287 for (auto* user : user_manager->GetLRULoggedInUsers()) { |
285 const uint32_t user_session_id = GetSessionId(*user); | 288 const uint32_t user_session_id = GetSessionId(*user); |
286 DCHECK_NE(0u, user_session_id); | 289 DCHECK_NE(0u, user_session_id); |
287 user_session_ids.push_back(user_session_id); | 290 user_session_ids.push_back(user_session_id); |
288 } | 291 } |
289 | 292 |
290 session_controller_->SetUserSessionOrder(user_session_ids); | 293 session_controller_->SetUserSessionOrder(user_session_ids); |
291 } | 294 } |
OLD | NEW |