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

Side by Side Diff: ash/common/system/chromeos/supervised/tray_supervised_user.cc

Issue 2715463004: Remove non-MD code from LabelTrayView (Closed)
Patch Set: estade comments 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/supervised/tray_supervised_user.h" 5 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/login_status.h" 9 #include "ash/common/login_status.h"
10 #include "ash/common/system/system_notifier.h" 10 #include "ash/common/system/system_notifier.h"
11 #include "ash/common/system/tray/label_tray_view.h" 11 #include "ash/common/system/tray/label_tray_view.h"
12 #include "ash/common/system/tray/system_tray_delegate.h" 12 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/resources/grit/ash_resources.h" 13 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/resources/vector_icons/vector_icons.h"
14 #include "ash/shell.h" 15 #include "ash/shell.h"
15 #include "base/callback.h" 16 #include "base/callback.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/gfx/paint_vector_icon.h"
18 #include "ui/message_center/message_center.h" 19 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
20 #include "ui/message_center/notification_delegate.h" 21 #include "ui/message_center/notification_delegate.h"
21 22
22 using message_center::Notification; 23 using message_center::Notification;
23 24
24 namespace ash { 25 namespace ash {
25 26
26 const char TraySupervisedUser::kNotificationId[] = 27 const char TraySupervisedUser::kNotificationId[] =
27 "chrome://user/locally-managed"; 28 "chrome://user/locally-managed";
28 29
29 TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray) 30 TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray)
30 : SystemTrayItem(system_tray, UMA_SUPERVISED_USER), 31 : SystemTrayItem(system_tray, UMA_SUPERVISED_USER),
31 tray_view_(NULL), 32 tray_view_(nullptr),
32 status_(LoginStatus::NOT_LOGGED_IN), 33 status_(LoginStatus::NOT_LOGGED_IN),
33 is_user_supervised_(false) { 34 is_user_supervised_(false) {
34 Shell::Get()->system_tray_delegate()->AddCustodianInfoTrayObserver(this); 35 Shell::Get()->system_tray_delegate()->AddCustodianInfoTrayObserver(this);
35 } 36 }
36 37
37 TraySupervisedUser::~TraySupervisedUser() { 38 TraySupervisedUser::~TraySupervisedUser() {
38 // We need the check as on shell destruction delegate is destroyed first. 39 // We need the check as on shell destruction delegate is destroyed first.
39 SystemTrayDelegate* system_tray_delegate = 40 SystemTrayDelegate* system_tray_delegate =
40 Shell::Get()->system_tray_delegate(); 41 Shell::Get()->system_tray_delegate();
41 if (system_tray_delegate) 42 if (system_tray_delegate)
42 system_tray_delegate->RemoveCustodianInfoTrayObserver(this); 43 system_tray_delegate->RemoveCustodianInfoTrayObserver(this);
43 } 44 }
44 45
45 void TraySupervisedUser::UpdateMessage() { 46 void TraySupervisedUser::UpdateMessage() {
46 base::string16 message = 47 base::string16 message =
47 Shell::Get()->system_tray_delegate()->GetSupervisedUserMessage(); 48 Shell::Get()->system_tray_delegate()->GetSupervisedUserMessage();
48 if (tray_view_) 49 if (tray_view_)
49 tray_view_->SetMessage(message); 50 tray_view_->SetMessage(message);
50 if (message_center::MessageCenter::Get()->FindVisibleNotificationById( 51 if (message_center::MessageCenter::Get()->FindVisibleNotificationById(
51 kNotificationId)) 52 kNotificationId))
52 CreateOrUpdateNotification(message); 53 CreateOrUpdateNotification(message);
53 } 54 }
54 55
55 views::View* TraySupervisedUser::CreateDefaultView(LoginStatus status) { 56 views::View* TraySupervisedUser::CreateDefaultView(LoginStatus status) {
56 CHECK(tray_view_ == NULL); 57 DCHECK(!tray_view_);
57 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 58 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
58 if (!delegate->IsUserSupervised()) 59 if (!delegate->IsUserSupervised())
59 return NULL; 60 return nullptr;
60 61
61 tray_view_ = new LabelTrayView(this, GetSupervisedUserIconId()); 62 tray_view_ = new LabelTrayView(this, GetSupervisedUserIcon());
62 UpdateMessage(); 63 UpdateMessage();
63 return tray_view_; 64 return tray_view_;
64 } 65 }
65 66
66 void TraySupervisedUser::DestroyDefaultView() { 67 void TraySupervisedUser::DestroyDefaultView() {
67 tray_view_ = NULL; 68 tray_view_ = nullptr;
68 } 69 }
69 70
70 void TraySupervisedUser::OnViewClicked(views::View* sender) { 71 void TraySupervisedUser::OnViewClicked(views::View* sender) {
71 // TODO(antrim): Find out what should we show in this case. 72 // TODO(antrim): Find out what should we show in this case.
72 } 73 }
73 74
74 void TraySupervisedUser::UpdateAfterLoginStatusChange(LoginStatus status) { 75 void TraySupervisedUser::UpdateAfterLoginStatusChange(LoginStatus status) {
75 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 76 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
76 77
77 bool is_user_supervised = delegate->IsUserSupervised(); 78 bool is_user_supervised = delegate->IsUserSupervised();
78 if (status == status_ && is_user_supervised == is_user_supervised_) 79 if (status == status_ && is_user_supervised == is_user_supervised_)
79 return; 80 return;
80 81
81 if (is_user_supervised && !delegate->IsUserChild() && 82 if (is_user_supervised && !delegate->IsUserChild() &&
82 status_ != LoginStatus::LOCKED && 83 status_ != LoginStatus::LOCKED &&
83 !delegate->GetSupervisedUserManager().empty()) 84 !delegate->GetSupervisedUserManager().empty()) {
84 CreateOrUpdateSupervisedWarningNotification(); 85 CreateOrUpdateSupervisedWarningNotification();
86 }
85 87
86 status_ = status; 88 status_ = status;
87 is_user_supervised_ = is_user_supervised; 89 is_user_supervised_ = is_user_supervised;
88 } 90 }
89 91
90 void TraySupervisedUser::CreateOrUpdateNotification( 92 void TraySupervisedUser::CreateOrUpdateNotification(
91 const base::string16& new_message) { 93 const base::string16& new_message) {
92 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
93 std::unique_ptr<Notification> notification( 94 std::unique_ptr<Notification> notification(
94 message_center::Notification::CreateSystemNotification( 95 message_center::Notification::CreateSystemNotification(
95 kNotificationId, base::string16() /* no title */, new_message, 96 kNotificationId, base::string16() /* no title */, new_message,
96 bundle.GetImageNamed(GetSupervisedUserIconId()), 97 gfx::Image(
98 gfx::CreateVectorIcon(GetSupervisedUserIcon(), kMenuIconColor)),
97 system_notifier::kNotifierSupervisedUser, 99 system_notifier::kNotifierSupervisedUser,
98 base::Closure() /* null callback */)); 100 base::Closure() /* null callback */));
99 message_center::MessageCenter::Get()->AddNotification( 101 message_center::MessageCenter::Get()->AddNotification(
100 std::move(notification)); 102 std::move(notification));
101 } 103 }
102 104
103 void TraySupervisedUser::CreateOrUpdateSupervisedWarningNotification() { 105 void TraySupervisedUser::CreateOrUpdateSupervisedWarningNotification() {
104 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 106 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
105 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); 107 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage());
106 } 108 }
107 109
108 void TraySupervisedUser::OnCustodianInfoChanged() { 110 void TraySupervisedUser::OnCustodianInfoChanged() {
109 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 111 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
110 std::string manager_name = delegate->GetSupervisedUserManager(); 112 std::string manager_name = delegate->GetSupervisedUserManager();
111 if (!manager_name.empty()) { 113 if (!manager_name.empty()) {
112 if (!delegate->IsUserChild() && 114 if (!delegate->IsUserChild() &&
113 !message_center::MessageCenter::Get()->FindVisibleNotificationById( 115 !message_center::MessageCenter::Get()->FindVisibleNotificationById(
114 kNotificationId)) { 116 kNotificationId)) {
115 CreateOrUpdateSupervisedWarningNotification(); 117 CreateOrUpdateSupervisedWarningNotification();
116 } 118 }
117 UpdateMessage(); 119 UpdateMessage();
118 } 120 }
119 } 121 }
120 122
121 int TraySupervisedUser::GetSupervisedUserIconId() const { 123 const gfx::VectorIcon& TraySupervisedUser::GetSupervisedUserIcon() const {
122 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 124 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
123 125
124 // Not intended to be used for non-supervised users. 126 // Not intended to be used for non-supervised users.
125 CHECK(delegate->IsUserSupervised()); 127 DCHECK(delegate->IsUserSupervised());
126 128
127 if (delegate->IsUserChild()) 129 if (delegate->IsUserChild())
128 return IDR_AURA_UBER_TRAY_CHILD_USER; 130 return kSystemMenuChildUserIcon;
129 return IDR_AURA_UBER_TRAY_SUPERVISED_USER; 131 return kSystemMenuSupervisedUserIcon;
130 } 132 }
131 133
132 } // namespace ash 134 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/supervised/tray_supervised_user.h ('k') | ash/common/system/tray/label_tray_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698