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

Side by Side Diff: ash/common/system/user/tray_user.cc

Issue 2780963002: ash: Fix system tray avatar not updated regression (Closed)
Patch Set: Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/system/user/tray_user.h" 5 #include "ash/common/system/user/tray_user.h"
6 6
7 #include "ash/common/session/session_controller.h" 7 #include "ash/common/session/session_controller.h"
8 #include "ash/common/shelf/wm_shelf_util.h" 8 #include "ash/common/shelf/wm_shelf_util.h"
9 #include "ash/common/system/tray/system_tray.h" 9 #include "ash/common/system/tray/system_tray.h"
10 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
11 #include "ash/common/system/tray/system_tray_notifier.h" 11 #include "ash/common/system/tray/system_tray_notifier.h"
James Cook 2017/03/29 00:51:23 nit: is this still needed?
xiyuan 2017/03/29 20:45:30 Nope. Removed.
12 #include "ash/common/system/tray/tray_constants.h" 12 #include "ash/common/system/tray/tray_constants.h"
13 #include "ash/common/system/tray/tray_item_view.h" 13 #include "ash/common/system/tray/tray_item_view.h"
14 #include "ash/common/system/tray/tray_utils.h" 14 #include "ash/common/system/tray/tray_utils.h"
15 #include "ash/common/system/user/rounded_image_view.h" 15 #include "ash/common/system/user/rounded_image_view.h"
16 #include "ash/common/system/user/user_view.h" 16 #include "ash/common/system/user/user_view.h"
17 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
18 #include "ash/shell.h" 18 #include "ash/shell.h"
19 #include "ash/strings/grit/ash_strings.h" 19 #include "ash/strings/grit/ash_strings.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
(...skipping 10 matching lines...) Expand all
32 namespace { 32 namespace {
33 33
34 const int kUserLabelToIconPadding = 5; 34 const int kUserLabelToIconPadding = 5;
35 35
36 } // namespace 36 } // namespace
37 37
38 namespace ash { 38 namespace ash {
39 39
40 TrayUser::TrayUser(SystemTray* system_tray, UserIndex index) 40 TrayUser::TrayUser(SystemTray* system_tray, UserIndex index)
41 : SystemTrayItem(system_tray, UMA_USER), 41 : SystemTrayItem(system_tray, UMA_USER),
42 user_index_(index), 42 scoped_session_observer_(this),
43 user_(nullptr), 43 user_index_(index) {}
44 layout_view_(nullptr),
45 avatar_(nullptr),
46 label_(nullptr) {
47 Shell::Get()->system_tray_notifier()->AddUserObserver(this);
48 }
49 44
50 TrayUser::~TrayUser() { 45 TrayUser::~TrayUser() {}
51 Shell::Get()->system_tray_notifier()->RemoveUserObserver(this);
52 }
53 46
54 TrayUser::TestState TrayUser::GetStateForTest() const { 47 TrayUser::TestState TrayUser::GetStateForTest() const {
55 if (!user_) 48 if (!user_)
56 return HIDDEN; 49 return HIDDEN;
57 return user_->GetStateForTest(); 50 return user_->GetStateForTest();
58 } 51 }
59 52
60 gfx::Size TrayUser::GetLayoutSizeForTest() const { 53 gfx::Size TrayUser::GetLayoutSizeForTest() const {
61 return layout_view_ ? layout_view_->size() : gfx::Size(); 54 return layout_view_ ? layout_view_->size() : gfx::Size();
62 } 55 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 kTrayLabelItemVerticalPaddingVerticalAlignment, 204 kTrayLabelItemVerticalPaddingVerticalAlignment,
212 kTrayLabelItemHorizontalPaddingBottomAlignment, 205 kTrayLabelItemHorizontalPaddingBottomAlignment,
213 kTrayLabelItemVerticalPaddingVerticalAlignment, 206 kTrayLabelItemVerticalPaddingVerticalAlignment,
214 kTrayLabelItemHorizontalPaddingBottomAlignment)); 207 kTrayLabelItemHorizontalPaddingBottomAlignment));
215 } 208 }
216 layout_view_->SetLayoutManager(new views::BoxLayout( 209 layout_view_->SetLayoutManager(new views::BoxLayout(
217 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); 210 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding));
218 } 211 }
219 } 212 }
220 213
221 void TrayUser::OnUserUpdate() { 214 void TrayUser::ActiveUserChanged(const AccountId& account_id) {
222 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); 215 UserSessionUpdated(account_id);
223 } 216 }
224 217
225 void TrayUser::OnUserAddedToSession() { 218 void TrayUser::UserAddedToSession(const AccountId& account_id) {
226 const SessionController* const session_controller = 219 const SessionController* const session_controller =
227 Shell::Get()->session_controller(); 220 Shell::Get()->session_controller();
228 // Only create views for user items which are logged in. 221 // Only create views for user items which are logged in.
229 if (user_index_ >= session_controller->NumberOfLoggedInUsers()) 222 if (user_index_ >= session_controller->NumberOfLoggedInUsers())
230 return; 223 return;
231 224
232 // Enforce a layout change that newly added items become visible. 225 // Enforce a layout change that newly added items become visible.
233 UpdateLayoutOfItem(); 226 UpdateLayoutOfItem();
234 227
235 // Update the user item. 228 // Update the user item.
236 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); 229 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus());
237 } 230 }
238 231
232 void TrayUser::UserSessionUpdated(const AccountId& account_id) {
233 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus());
James Cook 2017/03/29 00:51:23 You have to use SystemTrayDelegate because Session
xiyuan 2017/03/29 20:45:30 Nope. Brain-dead copy. Changed to use SystemContro
234 }
235
239 void TrayUser::UpdateAvatarImage(LoginStatus status) { 236 void TrayUser::UpdateAvatarImage(LoginStatus status) {
240 const SessionController* const session_controller = 237 const SessionController* const session_controller =
241 Shell::Get()->session_controller(); 238 Shell::Get()->session_controller();
242 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers()) 239 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers())
243 return; 240 return;
244 241
245 const mojom::UserSession* const user_session = 242 const mojom::UserSession* const user_session =
246 session_controller->GetUserSession(user_index_); 243 session_controller->GetUserSession(user_index_);
247 CHECK(user_session); 244 CHECK(user_session);
248 avatar_->SetImage(user_session->avatar, 245 avatar_->SetImage(user_session->avatar,
249 gfx::Size(kTrayItemSize, kTrayItemSize)); 246 gfx::Size(kTrayItemSize, kTrayItemSize));
250 247
251 // Unit tests might come here with no images for some users. 248 // Unit tests might come here with no images for some users.
252 if (avatar_->size().IsEmpty()) 249 if (avatar_->size().IsEmpty())
253 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); 250 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize));
254 } 251 }
255 252
256 void TrayUser::UpdateLayoutOfItem() { 253 void TrayUser::UpdateLayoutOfItem() {
257 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); 254 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment());
258 } 255 }
259 256
260 } // namespace ash 257 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698