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

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

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

Powered by Google App Engine
This is Rietveld 408576698