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