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