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

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

Issue 2780963002: ash: Fix system tray avatar not updated regression (Closed)
Patch Set: resized_ -> resized_image_ 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
« no previous file with comments | « ash/common/system/user/tray_user.h ('k') | ash/common/system/user/tray_user_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
12 #include "ash/common/system/tray/tray_constants.h" 11 #include "ash/common/system/tray/tray_constants.h"
13 #include "ash/common/system/tray/tray_item_view.h" 12 #include "ash/common/system/tray/tray_item_view.h"
14 #include "ash/common/system/tray/tray_utils.h" 13 #include "ash/common/system/tray/tray_utils.h"
15 #include "ash/common/system/user/rounded_image_view.h" 14 #include "ash/common/system/user/rounded_image_view.h"
16 #include "ash/common/system/user/user_view.h" 15 #include "ash/common/system/user/user_view.h"
17 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
18 #include "ash/shell.h" 17 #include "ash/shell.h"
19 #include "ash/strings/grit/ash_strings.h" 18 #include "ash/strings/grit/ash_strings.h"
20 #include "base/logging.h" 19 #include "base/logging.h"
21 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
(...skipping 10 matching lines...) Expand all
32 namespace { 31 namespace {
33 32
34 const int kUserLabelToIconPadding = 5; 33 const int kUserLabelToIconPadding = 5;
35 34
36 } // namespace 35 } // namespace
37 36
38 namespace ash { 37 namespace ash {
39 38
40 TrayUser::TrayUser(SystemTray* system_tray, UserIndex index) 39 TrayUser::TrayUser(SystemTray* system_tray, UserIndex index)
41 : SystemTrayItem(system_tray, UMA_USER), 40 : SystemTrayItem(system_tray, UMA_USER),
42 user_index_(index), 41 scoped_session_observer_(this),
43 user_(nullptr), 42 user_index_(index) {}
44 layout_view_(nullptr),
45 avatar_(nullptr),
46 label_(nullptr) {
47 Shell::Get()->system_tray_notifier()->AddUserObserver(this);
48 }
49 43
50 TrayUser::~TrayUser() { 44 TrayUser::~TrayUser() {}
51 Shell::Get()->system_tray_notifier()->RemoveUserObserver(this);
52 }
53 45
54 TrayUser::TestState TrayUser::GetStateForTest() const { 46 TrayUser::TestState TrayUser::GetStateForTest() const {
55 if (!user_) 47 if (!user_)
56 return HIDDEN; 48 return HIDDEN;
57 return user_->GetStateForTest(); 49 return user_->GetStateForTest();
58 } 50 }
59 51
60 gfx::Size TrayUser::GetLayoutSizeForTest() const { 52 gfx::Size TrayUser::GetLayoutSizeForTest() const {
61 return layout_view_ ? layout_view_->size() : gfx::Size(); 53 return layout_view_ ? layout_view_->size() : gfx::Size();
62 } 54 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 kTrayLabelItemVerticalPaddingVerticalAlignment, 203 kTrayLabelItemVerticalPaddingVerticalAlignment,
212 kTrayLabelItemHorizontalPaddingBottomAlignment, 204 kTrayLabelItemHorizontalPaddingBottomAlignment,
213 kTrayLabelItemVerticalPaddingVerticalAlignment, 205 kTrayLabelItemVerticalPaddingVerticalAlignment,
214 kTrayLabelItemHorizontalPaddingBottomAlignment)); 206 kTrayLabelItemHorizontalPaddingBottomAlignment));
215 } 207 }
216 layout_view_->SetLayoutManager(new views::BoxLayout( 208 layout_view_->SetLayoutManager(new views::BoxLayout(
217 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); 209 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding));
218 } 210 }
219 } 211 }
220 212
221 void TrayUser::OnUserUpdate() { 213 void TrayUser::ActiveUserChanged(const AccountId& account_id) {
222 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); 214 UserSessionUpdated(account_id);
223 } 215 }
224 216
225 void TrayUser::OnUserAddedToSession() { 217 void TrayUser::UserAddedToSession(const AccountId& account_id) {
226 const SessionController* const session_controller = 218 const SessionController* const session_controller =
227 Shell::Get()->session_controller(); 219 Shell::Get()->session_controller();
228 // Only create views for user items which are logged in. 220 // Only create views for user items which are logged in.
229 if (user_index_ >= session_controller->NumberOfLoggedInUsers()) 221 if (user_index_ >= session_controller->NumberOfLoggedInUsers())
230 return; 222 return;
231 223
232 // Enforce a layout change that newly added items become visible. 224 // Enforce a layout change that newly added items become visible.
233 UpdateLayoutOfItem(); 225 UpdateLayoutOfItem();
234 226
235 // Update the user item. 227 // Update the user item.
236 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); 228 UpdateAvatarImage(Shell::Get()->session_controller()->GetLoginStatus());
229 }
230
231 void TrayUser::UserSessionUpdated(const AccountId& account_id) {
232 UpdateAvatarImage(Shell::Get()->session_controller()->GetLoginStatus());
237 } 233 }
238 234
239 void TrayUser::UpdateAvatarImage(LoginStatus status) { 235 void TrayUser::UpdateAvatarImage(LoginStatus status) {
240 const SessionController* const session_controller = 236 const SessionController* const session_controller =
241 Shell::Get()->session_controller(); 237 Shell::Get()->session_controller();
242 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers()) 238 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers())
243 return; 239 return;
244 240
245 const mojom::UserSession* const user_session = 241 const mojom::UserSession* const user_session =
246 session_controller->GetUserSession(user_index_); 242 session_controller->GetUserSession(user_index_);
247 CHECK(user_session); 243 CHECK(user_session);
248 avatar_->SetImage(user_session->avatar, 244 avatar_->SetImage(user_session->avatar,
249 gfx::Size(kTrayItemSize, kTrayItemSize)); 245 gfx::Size(kTrayItemSize, kTrayItemSize));
250 246
251 // Unit tests might come here with no images for some users. 247 // Unit tests might come here with no images for some users.
252 if (avatar_->size().IsEmpty()) 248 if (avatar_->size().IsEmpty())
253 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); 249 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize));
254 } 250 }
255 251
256 void TrayUser::UpdateLayoutOfItem() { 252 void TrayUser::UpdateLayoutOfItem() {
257 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); 253 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment());
258 } 254 }
259 255
260 } // namespace ash 256 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/user/tray_user.h ('k') | ash/common/system/user/tray_user_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698