Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: chrome/browser/ui/ash/session_controller_client.cc

Issue 2619653002: ash: SessionControllerClient observes user image change (Closed)
Patch Set: more test failures Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" 14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" 15 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/ash/ash_util.h" 17 #include "chrome/browser/ui/ash/ash_util.h"
18 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" 18 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/grit/theme_resources.h" 20 #include "chrome/grit/theme_resources.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/session_manager_client.h" 22 #include "chromeos/dbus/session_manager_client.h"
23 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "components/session_manager/core/session_manager.h" 24 #include "components/session_manager/core/session_manager.h"
25 #include "content/public/common/service_manager_connection.h" 25 #include "content/public/common/service_manager_connection.h"
26 #include "content/public/common/service_names.mojom.h" 26 #include "content/public/common/service_names.mojom.h"
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::Session;
30 using session_manager::SessionManager; 31 using session_manager::SessionManager;
31 using user_manager::UserManager; 32 using user_manager::UserManager;
32 using user_manager::User; 33 using user_manager::User;
33 using user_manager::UserList; 34 using user_manager::UserList;
34 35
35 namespace { 36 namespace {
36 37
37 SessionControllerClient* g_instance = nullptr; 38 SessionControllerClient* g_instance = nullptr;
38 39
39 uint32_t GetSessionId(const User* user) { 40 // Returns the session id of a given user or 0 if user has no session.
40 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers(); 41 uint32_t GetSessionId(const User& user) {
41 // TODO(xiyuan): Update with real session id when user session tracking 42 const AccountId& account_id = user.GetAccountId();
42 // code is moved from UserManager to SessionManager. 43 for (auto& session : SessionManager::Get()->sessions()) {
43 for (size_t i = 0; i < logged_in_users.size(); ++i) { 44 if (session.user_account_id == account_id)
44 if (logged_in_users[i] == user) 45 return session.id;
45 return i + 1;
46 } 46 }
47 47
48 NOTREACHED();
49 return 0u; 48 return 0u;
50 } 49 }
51 50
52 ash::mojom::UserSessionPtr UserToUserSession(const User& user) { 51 ash::mojom::UserSessionPtr UserToUserSession(const User& user) {
James Cook 2017/01/11 19:27:20 nit: Document this function (especially why/what i
xiyuan 2017/01/11 20:48:38 Done.
52 const uint32_t user_session_id = GetSessionId(user);
53 if (user_session_id == 0u)
54 return nullptr;
55
53 ash::mojom::UserSessionPtr session = ash::mojom::UserSession::New(); 56 ash::mojom::UserSessionPtr session = ash::mojom::UserSession::New();
54 session->session_id = GetSessionId(&user); 57 session->session_id = user_session_id;
55 session->type = user.GetType(); 58 session->type = user.GetType();
56 // TODO(xiyuan): Add type map for AccountId. 59 // TODO(xiyuan): Add type map for AccountId.
57 session->serialized_account_id = user.GetAccountId().Serialize(); 60 session->serialized_account_id = user.GetAccountId().Serialize();
58 session->display_name = base::UTF16ToUTF8(user.display_name()); 61 session->display_name = base::UTF16ToUTF8(user.display_name());
59 session->display_email = user.display_email(); 62 session->display_email = user.display_email();
60 63
61 // TODO(xiyuan): Observe user image change and update.
62 // Tracked in http://crbug.com/670422
63 // TODO(xiyuan): Support multiple scale factor. 64 // TODO(xiyuan): Support multiple scale factor.
64 session->avatar = *user.GetImage().bitmap(); 65 session->avatar = *user.GetImage().bitmap();
65 if (session->avatar.isNull()) { 66 if (session->avatar.isNull()) {
66 session->avatar = *ResourceBundle::GetSharedInstance() 67 session->avatar = *ResourceBundle::GetSharedInstance()
67 .GetImageSkiaNamed(IDR_PROFILE_PICTURE_LOADING) 68 .GetImageSkiaNamed(IDR_PROFILE_PICTURE_LOADING)
68 ->bitmap(); 69 ->bitmap();
69 } 70 }
70 71
71 return session; 72 return session;
72 } 73 }
73 74
74 void DoSwitchUser(const AccountId& account_id) { 75 void DoSwitchUser(const AccountId& account_id) {
75 UserManager::Get()->SwitchActiveUser(account_id); 76 UserManager::Get()->SwitchActiveUser(account_id);
76 } 77 }
77 78
78 } // namespace 79 } // namespace
79 80
80 SessionControllerClient::SessionControllerClient() : binding_(this) { 81 SessionControllerClient::SessionControllerClient() : binding_(this) {
81 SessionManager::Get()->AddObserver(this); 82 SessionManager::Get()->AddObserver(this);
82 UserManager::Get()->AddSessionStateObserver(this); 83 UserManager::Get()->AddSessionStateObserver(this);
84 UserManager::Get()->AddObserver(this);
83 85
84 ConnectToSessionControllerAndSetClient(); 86 ConnectToSessionControllerAndSetClient();
85 SendSessionInfoIfChanged(); 87 SendSessionInfoIfChanged();
86 // User sessions and their order will be sent via UserSessionStateObserver 88 // User sessions and their order will be sent via UserSessionStateObserver
87 // even for crash-n-restart. 89 // even for crash-n-restart.
88 90
89 DCHECK(!g_instance); 91 DCHECK(!g_instance);
90 g_instance = this; 92 g_instance = this;
91 } 93 }
92 94
93 SessionControllerClient::~SessionControllerClient() { 95 SessionControllerClient::~SessionControllerClient() {
94 DCHECK_EQ(this, g_instance); 96 DCHECK_EQ(this, g_instance);
95 g_instance = nullptr; 97 g_instance = nullptr;
96 98
97 SessionManager::Get()->RemoveObserver(this); 99 SessionManager::Get()->RemoveObserver(this);
100 UserManager::Get()->RemoveObserver(this);
98 UserManager::Get()->RemoveSessionStateObserver(this); 101 UserManager::Get()->RemoveSessionStateObserver(this);
99 } 102 }
100 103
101 void SessionControllerClient::RequestLockScreen() { 104 void SessionControllerClient::RequestLockScreen() {
102 DoLockScreen(); 105 DoLockScreen();
103 } 106 }
104 107
105 void SessionControllerClient::SwitchActiveUser( 108 void SessionControllerClient::SwitchActiveUser(
106 const std::string& serialized_account_id) { 109 const std::string& serialized_account_id) {
107 // TODO(xiyuan): Add type map for AccountId. 110 // TODO(xiyuan): Add type map for AccountId.
(...skipping 22 matching lines...) Expand all
130 } 133 }
131 134
132 SendUserSessionOrder(); 135 SendUserSessionOrder();
133 } 136 }
134 137
135 void SessionControllerClient::UserAddedToSession(const User* added_user) { 138 void SessionControllerClient::UserAddedToSession(const User* added_user) {
136 SendSessionInfoIfChanged(); 139 SendSessionInfoIfChanged();
137 SendUserSession(*added_user); 140 SendUserSession(*added_user);
138 } 141 }
139 142
143 void SessionControllerClient::OnUserImageChanged(
144 const user_manager::User& user) {
145 SendUserSession(user);
146 }
147
140 // static 148 // static
141 bool SessionControllerClient::CanLockScreen() { 149 bool SessionControllerClient::CanLockScreen() {
142 return !UserManager::Get()->GetUnlockUsers().empty(); 150 return !UserManager::Get()->GetUnlockUsers().empty();
143 } 151 }
144 152
145 // static 153 // static
146 bool SessionControllerClient::ShouldLockScreenAutomatically() { 154 bool SessionControllerClient::ShouldLockScreenAutomatically() {
147 // TODO(xiyuan): Observe prefs::kEnableAutoScreenLock and update ash. 155 // TODO(xiyuan): Observe prefs::kEnableAutoScreenLock and update ash.
148 // Tracked in http://crbug.com/670423 156 // Tracked in http://crbug.com/670423
149 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers(); 157 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 info->add_user_session_policy = GetAddUserSessionPolicy(); 269 info->add_user_session_policy = GetAddUserSessionPolicy();
262 info->state = session_manager->session_state(); 270 info->state = session_manager->session_state();
263 271
264 if (info != last_sent_session_info_) { 272 if (info != last_sent_session_info_) {
265 last_sent_session_info_ = info->Clone(); 273 last_sent_session_info_ = info->Clone();
266 session_controller_->SetSessionInfo(std::move(info)); 274 session_controller_->SetSessionInfo(std::move(info));
267 } 275 }
268 } 276 }
269 277
270 void SessionControllerClient::SendUserSession(const User& user) { 278 void SessionControllerClient::SendUserSession(const User& user) {
271 session_controller_->UpdateUserSession(UserToUserSession(user)); 279 ash::mojom::UserSessionPtr user_session = UserToUserSession(user);
280
281 // Bail if user has no session.
James Cook 2017/01/11 19:27:20 Is this for tests or does it happen in production?
xiyuan 2017/01/11 20:48:38 OnUserImageChanged can be called on the login scre
282 if (!user_session)
283 return;
284
285 session_controller_->UpdateUserSession(std::move(user_session));
272 } 286 }
273 287
274 void SessionControllerClient::SendUserSessionOrder() { 288 void SessionControllerClient::SendUserSessionOrder() {
275 UserManager* const user_manager = UserManager::Get(); 289 UserManager* const user_manager = UserManager::Get();
276 290
277 const UserList logged_in_users = user_manager->GetLoggedInUsers(); 291 const UserList logged_in_users = user_manager->GetLoggedInUsers();
278 std::vector<uint32_t> user_session_ids; 292 std::vector<uint32_t> user_session_ids;
279 for (auto* user : user_manager->GetLRULoggedInUsers()) 293 for (auto* user : user_manager->GetLRULoggedInUsers()) {
280 user_session_ids.push_back(GetSessionId(user)); 294 const uint32_t user_session_id = GetSessionId(*user);
295 DCHECK_NE(0u, user_session_id);
296 user_session_ids.push_back(user_session_id);
297 }
281 298
282 session_controller_->SetUserSessionOrder(user_session_ids); 299 session_controller_->SetUserSessionOrder(user_session_ids);
283 } 300 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698