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

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

Issue 2832903002: cros: Remove supervised user methods from SystemTrayDelegate (Closed)
Patch Set: review 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/system/supervised/tray_supervised_user.h" 5 #include "ash/system/supervised/tray_supervised_user.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/login_status.h"
10 #include "ash/resources/vector_icons/vector_icons.h" 9 #include "ash/resources/vector_icons/vector_icons.h"
11 #include "ash/session/session_controller.h" 10 #include "ash/session/session_controller.h"
12 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/strings/grit/ash_strings.h"
13 #include "ash/system/system_notifier.h" 13 #include "ash/system/system_notifier.h"
14 #include "ash/system/tray/label_tray_view.h" 14 #include "ash/system/tray/label_tray_view.h"
15 #include "ash/system/tray/system_tray_delegate.h"
16 #include "ash/system/tray/tray_constants.h" 15 #include "ash/system/tray/tray_constants.h"
17 #include "base/callback.h" 16 #include "base/callback.h"
18 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/paint_vector_icon.h" 20 #include "ui/gfx/paint_vector_icon.h"
20 #include "ui/message_center/message_center.h" 21 #include "ui/message_center/message_center.h"
21 #include "ui/message_center/notification.h" 22 #include "ui/message_center/notification.h"
22 #include "ui/message_center/notification_delegate.h" 23 #include "ui/message_center/notification_delegate.h"
23 24
25 using base::UTF8ToUTF16;
26 using message_center::MessageCenter;
24 using message_center::Notification; 27 using message_center::Notification;
25 28
26 namespace ash { 29 namespace ash {
30 namespace {
31
32 const gfx::VectorIcon& GetSupervisedUserIcon() {
33 SessionController* session_controller = Shell::Get()->session_controller();
34 DCHECK(session_controller->IsUserSupervised());
35
36 if (session_controller->IsUserChild())
37 return kSystemMenuChildUserIcon;
38
39 return kSystemMenuSupervisedUserIcon;
40 }
41
42 } // namespace
27 43
28 const char TraySupervisedUser::kNotificationId[] = 44 const char TraySupervisedUser::kNotificationId[] =
29 "chrome://user/locally-managed"; 45 "chrome://user/locally-managed";
30 46
31 TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray) 47 TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray)
32 : SystemTrayItem(system_tray, UMA_SUPERVISED_USER), 48 : SystemTrayItem(system_tray, UMA_SUPERVISED_USER),
33 tray_view_(nullptr), 49 scoped_session_observer_(this) {}
34 status_(LoginStatus::NOT_LOGGED_IN),
35 is_user_supervised_(false) {
36 Shell::Get()->system_tray_delegate()->AddCustodianInfoTrayObserver(this);
37 }
38 50
39 TraySupervisedUser::~TraySupervisedUser() { 51 TraySupervisedUser::~TraySupervisedUser() = default;
40 // We need the check as on shell destruction delegate is destroyed first.
41 SystemTrayDelegate* system_tray_delegate =
42 Shell::Get()->system_tray_delegate();
43 if (system_tray_delegate)
44 system_tray_delegate->RemoveCustodianInfoTrayObserver(this);
45 }
46
47 void TraySupervisedUser::UpdateMessage() {
48 base::string16 message =
49 Shell::Get()->system_tray_delegate()->GetSupervisedUserMessage();
50 if (tray_view_)
51 tray_view_->SetMessage(message);
52 if (message_center::MessageCenter::Get()->FindVisibleNotificationById(
53 kNotificationId))
54 CreateOrUpdateNotification(message);
55 }
56 52
57 views::View* TraySupervisedUser::CreateDefaultView(LoginStatus status) { 53 views::View* TraySupervisedUser::CreateDefaultView(LoginStatus status) {
58 DCHECK(!tray_view_);
59 if (!Shell::Get()->session_controller()->IsUserSupervised()) 54 if (!Shell::Get()->session_controller()->IsUserSupervised())
60 return nullptr; 55 return nullptr;
61 56
62 tray_view_ = new LabelTrayView(this, GetSupervisedUserIcon()); 57 LabelTrayView* tray_view =
63 UpdateMessage(); 58 new LabelTrayView(nullptr, GetSupervisedUserIcon());
64 return tray_view_; 59 // The message almost never changes during a session, so we compute it when
60 // the menu is shown. We don't update it while the menu is open.
61 tray_view->SetMessage(GetSupervisedUserMessage());
62 return tray_view;
65 } 63 }
66 64
67 void TraySupervisedUser::DestroyDefaultView() { 65 void TraySupervisedUser::OnUserSessionUpdated(const AccountId& account_id) {
68 tray_view_ = nullptr; 66 // NOTE: This doesn't use OnUserSessionAdded() because the custodian info
67 // isn't available until after the session starts.
68 SessionController* session_controller = Shell::Get()->session_controller();
69 if (!session_controller->IsUserSupervised())
70 return;
71
72 // Get the active user session.
73 DCHECK(session_controller->IsActiveUserSessionStarted());
74 const mojom::UserSession* const user_session =
75 session_controller->GetUserSession(0);
76 DCHECK(user_session);
77
78 // Only respond to updates for the active user.
79 if (user_session->account_id != account_id)
80 return;
81
82 // Show notifications when custodian data first becomes available on login
83 // and if the custodian data changes.
84 if (custodian_email_ == user_session->custodian_email &&
85 second_custodian_email_ == user_session->second_custodian_email) {
86 return;
87 }
88 custodian_email_ = user_session->custodian_email;
89 second_custodian_email_ = user_session->second_custodian_email;
90
91 CreateOrUpdateNotification();
69 } 92 }
70 93
71 void TraySupervisedUser::OnViewClicked(views::View* sender) { 94 void TraySupervisedUser::CreateOrUpdateNotification() {
72 // TODO(antrim): Find out what should we show in this case.
73 }
74
75 void TraySupervisedUser::UpdateAfterLoginStatusChange(LoginStatus status) {
76 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
77 SessionController* session = Shell::Get()->session_controller();
78
79 const bool is_user_supervised = session->IsUserSupervised();
80 if (status == status_ && is_user_supervised == is_user_supervised_)
81 return;
82
83 if (is_user_supervised && !session->IsUserChild() &&
84 status_ != LoginStatus::LOCKED &&
85 !delegate->GetSupervisedUserManager().empty()) {
86 CreateOrUpdateSupervisedWarningNotification();
87 }
88
89 status_ = status;
90 is_user_supervised_ = is_user_supervised;
91 }
92
93 void TraySupervisedUser::CreateOrUpdateNotification(
94 const base::string16& new_message) {
95 std::unique_ptr<Notification> notification( 95 std::unique_ptr<Notification> notification(
96 message_center::Notification::CreateSystemNotification( 96 message_center::Notification::CreateSystemNotification(
97 kNotificationId, base::string16() /* no title */, new_message, 97 kNotificationId, base::string16() /* no title */,
98 GetSupervisedUserMessage(),
98 gfx::Image( 99 gfx::Image(
99 gfx::CreateVectorIcon(GetSupervisedUserIcon(), kMenuIconColor)), 100 gfx::CreateVectorIcon(GetSupervisedUserIcon(), kMenuIconColor)),
100 system_notifier::kNotifierSupervisedUser, 101 system_notifier::kNotifierSupervisedUser,
101 base::Closure() /* null callback */)); 102 base::Closure() /* null callback */));
102 message_center::MessageCenter::Get()->AddNotification( 103 // AddNotification does an update if the notification already exists.
103 std::move(notification)); 104 MessageCenter::Get()->AddNotification(std::move(notification));
104 } 105 }
105 106
106 void TraySupervisedUser::CreateOrUpdateSupervisedWarningNotification() { 107 base::string16 TraySupervisedUser::GetSupervisedUserMessage() const {
107 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 108 base::string16 first_custodian = UTF8ToUTF16(custodian_email_);
108 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); 109 base::string16 second_custodian = UTF8ToUTF16(second_custodian_email_);
109 }
110 110
111 void TraySupervisedUser::OnCustodianInfoChanged() { 111 // Regular supervised user. The "manager" is the first custodian.
112 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 112 if (!Shell::Get()->session_controller()->IsUserChild()) {
113 std::string manager_name = delegate->GetSupervisedUserManager(); 113 return l10n_util::GetStringFUTF16(IDS_ASH_USER_IS_SUPERVISED_BY_NOTICE,
114 if (!manager_name.empty()) { 114 first_custodian);
115 if (!Shell::Get()->session_controller()->IsUserChild() &&
116 !message_center::MessageCenter::Get()->FindVisibleNotificationById(
117 kNotificationId)) {
118 CreateOrUpdateSupervisedWarningNotification();
119 }
120 UpdateMessage();
121 } 115 }
122 }
123 116
124 const gfx::VectorIcon& TraySupervisedUser::GetSupervisedUserIcon() const { 117 // Child supervised user.
125 // Not intended to be used for non-supervised users. 118 if (second_custodian.empty()) {
126 DCHECK(Shell::Get()->session_controller()->IsUserSupervised()); 119 return l10n_util::GetStringFUTF16(
127 120 IDS_ASH_CHILD_USER_IS_MANAGED_BY_ONE_PARENT_NOTICE, first_custodian);
128 if (Shell::Get()->session_controller()->IsUserChild()) 121 }
129 return kSystemMenuChildUserIcon; 122 return l10n_util::GetStringFUTF16(
130 return kSystemMenuSupervisedUserIcon; 123 IDS_ASH_CHILD_USER_IS_MANAGED_BY_TWO_PARENTS_NOTICE, first_custodian,
124 second_custodian);
131 } 125 }
132 126
133 } // namespace ash 127 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698