Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 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 "mojo/public/cpp/bindings/equals_traits.h" |
| 35 #include "services/service_manager/public/cpp/connector.h" | 35 #include "services/service_manager/public/cpp/connector.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/gfx/image/image_skia.h" | 37 #include "ui/gfx/image/image_skia.h" |
| 38 | 38 |
| 39 using session_manager::Session; | 39 using session_manager::Session; |
| 40 using session_manager::SessionManager; | 40 using session_manager::SessionManager; |
| 41 using session_manager::SessionState; | |
| 41 using user_manager::UserManager; | 42 using user_manager::UserManager; |
| 42 using user_manager::User; | 43 using user_manager::User; |
| 43 using user_manager::UserList; | 44 using user_manager::UserList; |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 SessionControllerClient* g_instance = nullptr; | 48 SessionControllerClient* g_instance = nullptr; |
| 48 | 49 |
| 49 // Returns the session id of a given user or 0 if user has no session. | 50 // Returns the session id of a given user or 0 if user has no session. |
| 50 uint32_t GetSessionId(const User& user) { | 51 uint32_t GetSessionId(const User& user) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 182 } |
| 182 | 183 |
| 183 void SessionControllerClient::CycleActiveUser( | 184 void SessionControllerClient::CycleActiveUser( |
| 184 ash::CycleUserDirection direction) { | 185 ash::CycleUserDirection direction) { |
| 185 DoCycleActiveUser(direction); | 186 DoCycleActiveUser(direction); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void SessionControllerClient::ActiveUserChanged(const User* active_user) { | 189 void SessionControllerClient::ActiveUserChanged(const User* active_user) { |
| 189 SendSessionInfoIfChanged(); | 190 SendSessionInfoIfChanged(); |
| 190 | 191 |
| 191 // UserAddedToSession is not called for the primary user session so send its | 192 // UserAddedToSession is not called for the primary user session so its meta |
|
James Cook
2017/05/08 16:23:02
It would be very nice if it was called. Hopefully
xiyuan
2017/05/08 16:46:19
Agree. I don't know why we send out ActiveUserChan
| |
| 192 // meta data here once. | 193 // data here needs to be sent to ash before setting user session order. |
| 194 // However, ActiveUserChanged happens at different timing for primary user | |
| 195 // and secondary users. For primary user, it happens before user profile load. | |
| 196 // For secondary users, it happens after user profile load. This caused | |
| 197 // confusing down the path. Bail out here to defer the primary user session | |
| 198 // meta sent until it becomes active so that ash side could expect a | |
|
James Cook
2017/05/08 16:23:02
super nit: "meta" -> "metadata"?
xiyuan
2017/05/08 16:46:20
Done.
| |
| 199 // consistent state. | |
| 200 // TODO(xiyuan): Get rid of this after http://crbug.com/657149 refactoring. | |
| 193 if (!primary_user_session_sent_ && | 201 if (!primary_user_session_sent_ && |
| 194 UserManager::Get()->GetPrimaryUser() == active_user) { | 202 UserManager::Get()->GetPrimaryUser() == active_user) { |
| 195 primary_user_session_sent_ = true; | 203 return; |
| 196 SendUserSession(*active_user); | |
| 197 } | 204 } |
| 198 | 205 |
| 199 SendUserSessionOrder(); | 206 SendUserSessionOrder(); |
| 200 } | 207 } |
| 201 | 208 |
| 202 void SessionControllerClient::UserAddedToSession(const User* added_user) { | 209 void SessionControllerClient::UserAddedToSession(const User* added_user) { |
| 203 SendSessionInfoIfChanged(); | 210 SendSessionInfoIfChanged(); |
| 204 SendUserSession(*added_user); | 211 SendUserSession(*added_user); |
| 205 } | 212 } |
| 206 | 213 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 | 315 |
| 309 DoSwitchActiveUser(account_id); | 316 DoSwitchActiveUser(account_id); |
| 310 } | 317 } |
| 311 | 318 |
| 312 // static | 319 // static |
| 313 void SessionControllerClient::FlushForTesting() { | 320 void SessionControllerClient::FlushForTesting() { |
| 314 g_instance->session_controller_.FlushForTesting(); | 321 g_instance->session_controller_.FlushForTesting(); |
| 315 } | 322 } |
| 316 | 323 |
| 317 void SessionControllerClient::OnSessionStateChanged() { | 324 void SessionControllerClient::OnSessionStateChanged() { |
| 325 // Sent the primary user meta and order that are deferred from | |
|
James Cook
2017/05/08 16:23:02
super nit: "meta" -> "metadata"?
xiyuan
2017/05/08 16:46:19
Done.
| |
| 326 // ActiveUserChanged before update session state. | |
| 327 if (!primary_user_session_sent_ && | |
| 328 SessionManager::Get()->session_state() == SessionState::ACTIVE) { | |
| 329 DCHECK_EQ(UserManager::Get()->GetPrimaryUser(), | |
| 330 UserManager::Get()->GetActiveUser()); | |
| 331 primary_user_session_sent_ = true; | |
| 332 SendUserSession(*UserManager::Get()->GetPrimaryUser()); | |
| 333 SendUserSessionOrder(); | |
| 334 } | |
| 335 | |
| 318 SendSessionInfoIfChanged(); | 336 SendSessionInfoIfChanged(); |
| 319 } | 337 } |
| 320 | 338 |
| 321 void SessionControllerClient::OnCustodianInfoChanged() { | 339 void SessionControllerClient::OnCustodianInfoChanged() { |
| 322 DCHECK(supervised_user_profile_); | 340 DCHECK(supervised_user_profile_); |
| 323 User* user = chromeos::ProfileHelper::Get()->GetUserByProfile( | 341 User* user = chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 324 supervised_user_profile_); | 342 supervised_user_profile_); |
| 325 if (user) | 343 if (user) |
| 326 SendUserSession(*user); | 344 SendUserSession(*user); |
| 327 } | 345 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 const UserList logged_in_users = user_manager->GetLoggedInUsers(); | 438 const UserList logged_in_users = user_manager->GetLoggedInUsers(); |
| 421 std::vector<uint32_t> user_session_ids; | 439 std::vector<uint32_t> user_session_ids; |
| 422 for (auto* user : user_manager->GetLRULoggedInUsers()) { | 440 for (auto* user : user_manager->GetLRULoggedInUsers()) { |
| 423 const uint32_t user_session_id = GetSessionId(*user); | 441 const uint32_t user_session_id = GetSessionId(*user); |
| 424 DCHECK_NE(0u, user_session_id); | 442 DCHECK_NE(0u, user_session_id); |
| 425 user_session_ids.push_back(user_session_id); | 443 user_session_ids.push_back(user_session_id); |
| 426 } | 444 } |
| 427 | 445 |
| 428 session_controller_->SetUserSessionOrder(user_session_ids); | 446 session_controller_->SetUserSessionOrder(user_session_ids); |
| 429 } | 447 } |
| OLD | NEW |