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

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

Issue 2098023002: mash: Migrate remaining tray observers and notify functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 6 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/system/user/tray_user.h" 5 #include "ash/system/user/tray_user.h"
6 6
7 #include "ash/common/ash_switches.h" 7 #include "ash/common/ash_switches.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 9 #include "ash/common/shelf/wm_shelf_util.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/tray_constants.h" 12 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_item_view.h" 13 #include "ash/common/system/tray/tray_item_view.h"
13 #include "ash/common/system/tray/tray_utils.h" 14 #include "ash/common/system/tray/tray_utils.h"
14 #include "ash/common/system/user/rounded_image_view.h" 15 #include "ash/common/system/user/rounded_image_view.h"
15 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
16 #include "ash/shelf/shelf_layout_manager.h" 17 #include "ash/shelf/shelf_layout_manager.h"
17 #include "ash/shelf/shelf_util.h" 18 #include "ash/shelf/shelf_util.h"
18 #include "ash/shell.h"
19 #include "ash/system/tray/system_tray.h" 19 #include "ash/system/tray/system_tray.h"
20 #include "ash/system/tray/system_tray_notifier.h"
21 #include "ash/system/user/user_view.h" 20 #include "ash/system/user/user_view.h"
22 #include "base/logging.h" 21 #include "base/logging.h"
23 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
24 #include "components/signin/core/account_id/account_id.h" 23 #include "components/signin/core/account_id/account_id.h"
25 #include "components/user_manager/user_info.h" 24 #include "components/user_manager/user_info.h"
26 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
27 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
29 #include "ui/views/border.h" 28 #include "ui/views/border.h"
30 #include "ui/views/controls/label.h" 29 #include "ui/views/controls/label.h"
31 #include "ui/views/layout/box_layout.h" 30 #include "ui/views/layout/box_layout.h"
32 #include "ui/views/view.h" 31 #include "ui/views/view.h"
33 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
34 33
35 namespace { 34 namespace {
36 35
37 const int kUserLabelToIconPadding = 5; 36 const int kUserLabelToIconPadding = 5;
38 37
39 } // namespace 38 } // namespace
40 39
41 namespace ash { 40 namespace ash {
42 41
43 TrayUser::TrayUser(SystemTray* system_tray, UserIndex index) 42 TrayUser::TrayUser(SystemTray* system_tray, UserIndex index)
44 : SystemTrayItem(system_tray), 43 : SystemTrayItem(system_tray),
45 user_index_(index), 44 user_index_(index),
46 user_(nullptr), 45 user_(nullptr),
47 layout_view_(nullptr), 46 layout_view_(nullptr),
48 avatar_(nullptr), 47 avatar_(nullptr),
49 label_(nullptr) { 48 label_(nullptr) {
50 Shell::GetInstance()->system_tray_notifier()->AddUserObserver(this); 49 WmShell::Get()->system_tray_notifier()->AddUserObserver(this);
51 } 50 }
52 51
53 TrayUser::~TrayUser() { 52 TrayUser::~TrayUser() {
54 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); 53 WmShell::Get()->system_tray_notifier()->RemoveUserObserver(this);
55 } 54 }
56 55
57 TrayUser::TestState TrayUser::GetStateForTest() const { 56 TrayUser::TestState TrayUser::GetStateForTest() const {
58 if (!user_) 57 if (!user_)
59 return HIDDEN; 58 return HIDDEN;
60 return user_->GetStateForTest(); 59 return user_->GetStateForTest();
61 } 60 }
62 61
63 gfx::Size TrayUser::GetLayoutSizeForTest() const { 62 gfx::Size TrayUser::GetLayoutSizeForTest() const {
64 if (!layout_view_) { 63 if (!layout_view_) {
(...skipping 20 matching lines...) Expand all
85 new views::BoxLayout(views::BoxLayout::kHorizontal, 84 new views::BoxLayout(views::BoxLayout::kHorizontal,
86 0, 0, kUserLabelToIconPadding)); 85 0, 0, kUserLabelToIconPadding));
87 UpdateAfterLoginStatusChange(status); 86 UpdateAfterLoginStatusChange(status);
88 return layout_view_; 87 return layout_view_;
89 } 88 }
90 89
91 views::View* TrayUser::CreateDefaultView(LoginStatus status) { 90 views::View* TrayUser::CreateDefaultView(LoginStatus status) {
92 if (status == LoginStatus::NOT_LOGGED_IN) 91 if (status == LoginStatus::NOT_LOGGED_IN)
93 return nullptr; 92 return nullptr;
94 const SessionStateDelegate* session_state_delegate = 93 const SessionStateDelegate* session_state_delegate =
95 Shell::GetInstance()->session_state_delegate(); 94 WmShell::Get()->GetSessionStateDelegate();
96 95
97 // If the screen is locked or a system modal dialog box is shown, show only 96 // If the screen is locked or a system modal dialog box is shown, show only
98 // the currently active user. 97 // the currently active user.
99 if (user_index_ && (session_state_delegate->IsUserSessionBlocked() || 98 if (user_index_ && (session_state_delegate->IsUserSessionBlocked() ||
100 WmShell::Get()->IsSystemModalWindowOpen())) 99 WmShell::Get()->IsSystemModalWindowOpen()))
101 return nullptr; 100 return nullptr;
102 101
103 CHECK(user_ == nullptr); 102 CHECK(user_ == nullptr);
104 103
105 int logged_in_users = session_state_delegate->NumberOfLoggedInUsers(); 104 int logged_in_users = session_state_delegate->NumberOfLoggedInUsers();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 232 }
234 } 233 }
235 234
236 void TrayUser::OnUserUpdate() { 235 void TrayUser::OnUserUpdate() {
237 UpdateAvatarImage( 236 UpdateAvatarImage(
238 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); 237 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus());
239 } 238 }
240 239
241 void TrayUser::OnUserAddedToSession() { 240 void TrayUser::OnUserAddedToSession() {
242 SessionStateDelegate* session_state_delegate = 241 SessionStateDelegate* session_state_delegate =
243 Shell::GetInstance()->session_state_delegate(); 242 WmShell::Get()->GetSessionStateDelegate();
244 // Only create views for user items which are logged in. 243 // Only create views for user items which are logged in.
245 if (user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) 244 if (user_index_ >= session_state_delegate->NumberOfLoggedInUsers())
246 return; 245 return;
247 246
248 // Enforce a layout change that newly added items become visible. 247 // Enforce a layout change that newly added items become visible.
249 UpdateLayoutOfItem(); 248 UpdateLayoutOfItem();
250 249
251 // Update the user item. 250 // Update the user item.
252 UpdateAvatarImage( 251 UpdateAvatarImage(
253 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); 252 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus());
254 } 253 }
255 254
256 void TrayUser::UpdateAvatarImage(LoginStatus status) { 255 void TrayUser::UpdateAvatarImage(LoginStatus status) {
257 SessionStateDelegate* session_state_delegate = 256 SessionStateDelegate* session_state_delegate =
258 Shell::GetInstance()->session_state_delegate(); 257 WmShell::Get()->GetSessionStateDelegate();
259 if (!avatar_ || 258 if (!avatar_ ||
260 user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) 259 user_index_ >= session_state_delegate->NumberOfLoggedInUsers())
261 return; 260 return;
262 261
263 const user_manager::UserInfo* user_info = 262 const user_manager::UserInfo* user_info =
264 session_state_delegate->GetUserInfo(user_index_); 263 session_state_delegate->GetUserInfo(user_index_);
265 CHECK(user_info); 264 CHECK(user_info);
266 avatar_->SetImage(user_info->GetImage(), 265 avatar_->SetImage(user_info->GetImage(),
267 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 266 gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
268 267
269 // Unit tests might come here with no images for some users. 268 // Unit tests might come here with no images for some users.
270 if (avatar_->size().IsEmpty()) 269 if (avatar_->size().IsEmpty())
271 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 270 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
272 } 271 }
273 272
274 void TrayUser::UpdateLayoutOfItem() { 273 void TrayUser::UpdateLayoutOfItem() {
275 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); 274 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment());
276 } 275 }
277 276
278 } // namespace ash 277 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698