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

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

Issue 2832903002: cros: Remove supervised user methods from SystemTrayDelegate (Closed)
Patch Set: ready 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
xiyuan 2017/04/21 23:14:35 nit: OnUserSessionUpdated could be called even whe
James Cook 2017/04/24 17:47:25 Done.
78 // Show notifications when custodian data first becomes available on login
79 // and if the custodian data changes.
80 if (custodian_email_ == user_session->custodian_email &&
81 second_custodian_email_ == user_session->second_custodian_email) {
82 return;
83 }
84 custodian_email_ = user_session->custodian_email;
85 second_custodian_email_ = user_session->second_custodian_email;
86
87 CreateOrUpdateNotification();
69 } 88 }
70 89
71 void TraySupervisedUser::OnViewClicked(views::View* sender) { 90 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( 91 std::unique_ptr<Notification> notification(
96 message_center::Notification::CreateSystemNotification( 92 message_center::Notification::CreateSystemNotification(
97 kNotificationId, base::string16() /* no title */, new_message, 93 kNotificationId, base::string16() /* no title */,
94 GetSupervisedUserMessage(),
98 gfx::Image( 95 gfx::Image(
99 gfx::CreateVectorIcon(GetSupervisedUserIcon(), kMenuIconColor)), 96 gfx::CreateVectorIcon(GetSupervisedUserIcon(), kMenuIconColor)),
100 system_notifier::kNotifierSupervisedUser, 97 system_notifier::kNotifierSupervisedUser,
101 base::Closure() /* null callback */)); 98 base::Closure() /* null callback */));
102 message_center::MessageCenter::Get()->AddNotification( 99 // AddNotification does an update if the notification already exists.
103 std::move(notification)); 100 MessageCenter::Get()->AddNotification(std::move(notification));
104 } 101 }
105 102
106 void TraySupervisedUser::CreateOrUpdateSupervisedWarningNotification() { 103 base::string16 TraySupervisedUser::GetSupervisedUserMessage() const {
107 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 104 base::string16 first_custodian = UTF8ToUTF16(custodian_email_);
108 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); 105 base::string16 second_custodian = UTF8ToUTF16(second_custodian_email_);
109 }
110 106
111 void TraySupervisedUser::OnCustodianInfoChanged() { 107 // Regular supervised user. The "manager" is the first custodian.
112 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 108 if (!Shell::Get()->session_controller()->IsUserChild()) {
113 std::string manager_name = delegate->GetSupervisedUserManager(); 109 return l10n_util::GetStringFUTF16(IDS_ASH_USER_IS_SUPERVISED_BY_NOTICE,
114 if (!manager_name.empty()) { 110 first_custodian);
115 if (!Shell::Get()->session_controller()->IsUserChild() &&
116 !message_center::MessageCenter::Get()->FindVisibleNotificationById(
117 kNotificationId)) {
118 CreateOrUpdateSupervisedWarningNotification();
119 }
120 UpdateMessage();
121 } 111 }
122 }
123 112
124 const gfx::VectorIcon& TraySupervisedUser::GetSupervisedUserIcon() const { 113 // Child supervised user.
125 // Not intended to be used for non-supervised users. 114 if (second_custodian.empty()) {
126 DCHECK(Shell::Get()->session_controller()->IsUserSupervised()); 115 return l10n_util::GetStringFUTF16(
127 116 IDS_ASH_CHILD_USER_IS_MANAGED_BY_ONE_PARENT_NOTICE, first_custodian);
128 if (Shell::Get()->session_controller()->IsUserChild()) 117 }
129 return kSystemMenuChildUserIcon; 118 return l10n_util::GetStringFUTF16(
130 return kSystemMenuSupervisedUserIcon; 119 IDS_ASH_CHILD_USER_IS_MANAGED_BY_TWO_PARENTS_NOTICE, first_custodian,
120 second_custodian);
131 } 121 }
132 122
133 } // namespace ash 123 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698