| 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 16 matching lines...) Expand all Loading... |
| 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 session_manager::SessionManager; | 30 using session_manager::SessionManager; |
| 31 using user_manager::UserManager; | 31 using user_manager::UserManager; |
| 32 using user_manager::User; | 32 using user_manager::User; |
| 33 using user_manager::UserList; | 33 using user_manager::UserList; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 SessionControllerClient* g_instance = nullptr; |
| 38 |
| 37 uint32_t GetSessionId(const User* user) { | 39 uint32_t GetSessionId(const User* user) { |
| 38 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers(); | 40 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers(); |
| 39 // TODO(xiyuan): Update with real session id when user session tracking | 41 // TODO(xiyuan): Update with real session id when user session tracking |
| 40 // code is moved from UserManager to SessionManager. | 42 // code is moved from UserManager to SessionManager. |
| 41 for (size_t i = 0; i < logged_in_users.size(); ++i) { | 43 for (size_t i = 0; i < logged_in_users.size(); ++i) { |
| 42 if (logged_in_users[i] == user) | 44 if (logged_in_users[i] == user) |
| 43 return i + 1; | 45 return i + 1; |
| 44 } | 46 } |
| 45 | 47 |
| 46 NOTREACHED(); | 48 NOTREACHED(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 76 } // namespace | 78 } // namespace |
| 77 | 79 |
| 78 SessionControllerClient::SessionControllerClient() : binding_(this) { | 80 SessionControllerClient::SessionControllerClient() : binding_(this) { |
| 79 SessionManager::Get()->AddObserver(this); | 81 SessionManager::Get()->AddObserver(this); |
| 80 UserManager::Get()->AddSessionStateObserver(this); | 82 UserManager::Get()->AddSessionStateObserver(this); |
| 81 | 83 |
| 82 ConnectToSessionControllerAndSetClient(); | 84 ConnectToSessionControllerAndSetClient(); |
| 83 SendSessionInfoIfChanged(); | 85 SendSessionInfoIfChanged(); |
| 84 // User sessions and their order will be sent via UserSessionStateObserver | 86 // User sessions and their order will be sent via UserSessionStateObserver |
| 85 // even for crash-n-restart. | 87 // even for crash-n-restart. |
| 88 |
| 89 DCHECK(!g_instance); |
| 90 g_instance = this; |
| 86 } | 91 } |
| 87 | 92 |
| 88 SessionControllerClient::~SessionControllerClient() { | 93 SessionControllerClient::~SessionControllerClient() { |
| 94 DCHECK_EQ(this, g_instance); |
| 95 g_instance = nullptr; |
| 96 |
| 89 SessionManager::Get()->RemoveObserver(this); | 97 SessionManager::Get()->RemoveObserver(this); |
| 90 UserManager::Get()->RemoveSessionStateObserver(this); | 98 UserManager::Get()->RemoveSessionStateObserver(this); |
| 91 } | 99 } |
| 92 | 100 |
| 93 void SessionControllerClient::RequestLockScreen() { | 101 void SessionControllerClient::RequestLockScreen() { |
| 94 DoLockScreen(); | 102 DoLockScreen(); |
| 95 } | 103 } |
| 96 | 104 |
| 97 void SessionControllerClient::SwitchActiveUser( | 105 void SessionControllerClient::SwitchActiveUser( |
| 98 const std::string& serialized_account_id) { | 106 const std::string& serialized_account_id) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 account_id = (*it)->GetAccountId(); | 226 account_id = (*it)->GetAccountId(); |
| 219 } else { | 227 } else { |
| 220 if (it == logged_in_users.begin()) | 228 if (it == logged_in_users.begin()) |
| 221 it = logged_in_users.end(); | 229 it = logged_in_users.end(); |
| 222 account_id = (*(--it))->GetAccountId(); | 230 account_id = (*(--it))->GetAccountId(); |
| 223 } | 231 } |
| 224 | 232 |
| 225 DoSwitchActiveUser(account_id); | 233 DoSwitchActiveUser(account_id); |
| 226 } | 234 } |
| 227 | 235 |
| 236 // static |
| 237 void SessionControllerClient::FlushForTesting() { |
| 238 g_instance->session_controller_.FlushForTesting(); |
| 239 } |
| 240 |
| 228 void SessionControllerClient::OnSessionStateChanged() { | 241 void SessionControllerClient::OnSessionStateChanged() { |
| 229 SendSessionInfoIfChanged(); | 242 SendSessionInfoIfChanged(); |
| 230 } | 243 } |
| 231 | 244 |
| 232 void SessionControllerClient::ConnectToSessionControllerAndSetClient() { | 245 void SessionControllerClient::ConnectToSessionControllerAndSetClient() { |
| 233 content::ServiceManagerConnection::GetForProcess() | 246 content::ServiceManagerConnection::GetForProcess() |
| 234 ->GetConnector() | 247 ->GetConnector() |
| 235 ->BindInterface(ash_util::GetAshServiceName(), &session_controller_); | 248 ->BindInterface(ash_util::GetAshServiceName(), &session_controller_); |
| 236 | 249 |
| 237 // Set as |session_controller_|'s client. | 250 // Set as |session_controller_|'s client. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 261 void SessionControllerClient::SendUserSessionOrder() { | 274 void SessionControllerClient::SendUserSessionOrder() { |
| 262 UserManager* const user_manager = UserManager::Get(); | 275 UserManager* const user_manager = UserManager::Get(); |
| 263 | 276 |
| 264 const UserList logged_in_users = user_manager->GetLoggedInUsers(); | 277 const UserList logged_in_users = user_manager->GetLoggedInUsers(); |
| 265 std::vector<uint32_t> user_session_ids; | 278 std::vector<uint32_t> user_session_ids; |
| 266 for (auto* user : user_manager->GetLRULoggedInUsers()) | 279 for (auto* user : user_manager->GetLRULoggedInUsers()) |
| 267 user_session_ids.push_back(GetSessionId(user)); | 280 user_session_ids.push_back(GetSessionId(user)); |
| 268 | 281 |
| 269 session_controller_->SetUserSessionOrder(user_session_ids); | 282 session_controller_->SetUserSessionOrder(user_session_ids); |
| 270 } | 283 } |
| OLD | NEW |