| 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 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" | 24 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/grit/theme_resources.h" | 26 #include "chrome/grit/theme_resources.h" |
| 27 #include "chromeos/dbus/dbus_thread_manager.h" | 27 #include "chromeos/dbus/dbus_thread_manager.h" |
| 28 #include "chromeos/dbus/session_manager_client.h" | 28 #include "chromeos/dbus/session_manager_client.h" |
| 29 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
| 30 #include "components/session_manager/core/session_manager.h" | 30 #include "components/session_manager/core/session_manager.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/common/service_manager_connection.h" | 32 #include "content/public/common/service_manager_connection.h" |
| 33 #include "content/public/common/service_names.mojom.h" | 33 #include "content/public/common/service_names.mojom.h" |
| 34 #include "mojo/public/cpp/bindings/equals_traits.h" |
| 34 #include "services/service_manager/public/cpp/connector.h" | 35 #include "services/service_manager/public/cpp/connector.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/gfx/image/image_skia.h" |
| 36 | 38 |
| 37 using session_manager::Session; | 39 using session_manager::Session; |
| 38 using session_manager::SessionManager; | 40 using session_manager::SessionManager; |
| 39 using user_manager::UserManager; | 41 using user_manager::UserManager; |
| 40 using user_manager::User; | 42 using user_manager::User; |
| 41 using user_manager::UserList; | 43 using user_manager::UserList; |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 SessionControllerClient* g_instance = nullptr; | 47 SessionControllerClient* g_instance = nullptr; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 96 |
| 95 return session; | 97 return session; |
| 96 } | 98 } |
| 97 | 99 |
| 98 void DoSwitchUser(const AccountId& account_id) { | 100 void DoSwitchUser(const AccountId& account_id) { |
| 99 UserManager::Get()->SwitchActiveUser(account_id); | 101 UserManager::Get()->SwitchActiveUser(account_id); |
| 100 } | 102 } |
| 101 | 103 |
| 102 } // namespace | 104 } // namespace |
| 103 | 105 |
| 106 namespace mojo { |
| 107 |
| 108 // When comparing two mojom::UserSession objects we need to decide if the avatar |
| 109 // images are changed. Consider them equal if they have the same storage rather |
| 110 // than comparing the backing pixels. |
| 111 template <> |
| 112 struct EqualsTraits<gfx::ImageSkia> { |
| 113 static bool Equals(const gfx::ImageSkia& a, const gfx::ImageSkia& b) { |
| 114 return a.BackedBySameObjectAs(b); |
| 115 } |
| 116 }; |
| 117 |
| 118 } // namespace mojo |
| 119 |
| 104 SessionControllerClient::SessionControllerClient() | 120 SessionControllerClient::SessionControllerClient() |
| 105 : binding_(this), weak_ptr_factory_(this) { | 121 : binding_(this), weak_ptr_factory_(this) { |
| 106 SessionManager::Get()->AddObserver(this); | 122 SessionManager::Get()->AddObserver(this); |
| 107 UserManager::Get()->AddSessionStateObserver(this); | 123 UserManager::Get()->AddSessionStateObserver(this); |
| 108 UserManager::Get()->AddObserver(this); | 124 UserManager::Get()->AddObserver(this); |
| 109 | 125 |
| 110 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 126 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 111 content::NotificationService::AllSources()); | 127 content::NotificationService::AllSources()); |
| 112 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 128 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 113 content::NotificationService::AllSources()); | 129 content::NotificationService::AllSources()); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 void SessionControllerClient::SendUserSession(const User& user) { | 401 void SessionControllerClient::SendUserSession(const User& user) { |
| 386 ash::mojom::UserSessionPtr user_session = UserToUserSession(user); | 402 ash::mojom::UserSessionPtr user_session = UserToUserSession(user); |
| 387 | 403 |
| 388 // Bail if the user has no session. Currently the only code path that hits | 404 // Bail if the user has no session. Currently the only code path that hits |
| 389 // this condition is from OnUserImageChanged when user images are changed | 405 // this condition is from OnUserImageChanged when user images are changed |
| 390 // on the login screen (e.g. policy change that adds a public session user, | 406 // on the login screen (e.g. policy change that adds a public session user, |
| 391 // or tests that create new users on the login screen). | 407 // or tests that create new users on the login screen). |
| 392 if (!user_session) | 408 if (!user_session) |
| 393 return; | 409 return; |
| 394 | 410 |
| 395 // TODO(jamescook): Only send if it changed. This will require an Equals() | 411 if (user_session != last_sent_user_session_) { |
| 396 // method for gfx::ImageSkia to allow mojom::UserSession comparison. | 412 last_sent_user_session_ = user_session->Clone(); |
| 397 // http://crbug.com/714689 | 413 session_controller_->UpdateUserSession(std::move(user_session)); |
| 398 session_controller_->UpdateUserSession(std::move(user_session)); | 414 } |
| 399 } | 415 } |
| 400 | 416 |
| 401 void SessionControllerClient::SendUserSessionOrder() { | 417 void SessionControllerClient::SendUserSessionOrder() { |
| 402 UserManager* const user_manager = UserManager::Get(); | 418 UserManager* const user_manager = UserManager::Get(); |
| 403 | 419 |
| 404 const UserList logged_in_users = user_manager->GetLoggedInUsers(); | 420 const UserList logged_in_users = user_manager->GetLoggedInUsers(); |
| 405 std::vector<uint32_t> user_session_ids; | 421 std::vector<uint32_t> user_session_ids; |
| 406 for (auto* user : user_manager->GetLRULoggedInUsers()) { | 422 for (auto* user : user_manager->GetLRULoggedInUsers()) { |
| 407 const uint32_t user_session_id = GetSessionId(*user); | 423 const uint32_t user_session_id = GetSessionId(*user); |
| 408 DCHECK_NE(0u, user_session_id); | 424 DCHECK_NE(0u, user_session_id); |
| 409 user_session_ids.push_back(user_session_id); | 425 user_session_ids.push_back(user_session_id); |
| 410 } | 426 } |
| 411 | 427 |
| 412 session_controller_->SetUserSessionOrder(user_session_ids); | 428 session_controller_->SetUserSessionOrder(user_session_ids); |
| 413 } | 429 } |
| OLD | NEW |