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

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

Issue 627593003: Adding infrastructure for possibility of changing manager names for the supervised accounts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Weak pointers removed. Created 6 years, 2 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/chromeos/supervised/tray_supervised_user.h" 5 #include "ash/system/chromeos/supervised/tray_supervised_user.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/chromeos/label_tray_view.h" 8 #include "ash/system/chromeos/label_tray_view.h"
9 #include "ash/system/system_notifier.h" 9 #include "ash/system/system_notifier.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/system_tray_notifier.h" 11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "ash/system/tray/tray_notification_view.h" 12 #include "ash/system/tray/tray_notification_view.h"
13 #include "ash/system/user/login_status.h" 13 #include "ash/system/user/login_status.h"
14 #include "base/bind.h"
14 #include "base/callback.h" 15 #include "base/callback.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "grit/ash_resources.h" 17 #include "grit/ash_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.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), 31 : SystemTrayItem(system_tray),
31 tray_view_(NULL), 32 tray_view_(NULL),
32 status_(ash::user::LOGGED_IN_NONE), 33 status_(ash::user::LOGGED_IN_NONE),
33 is_user_supervised_(false) { 34 is_user_supervised_(false) {
35 Shell::GetInstance()->system_tray_delegate()->AddObserver(this);
34 } 36 }
35 37
36 TraySupervisedUser::~TraySupervisedUser() { 38 TraySupervisedUser::~TraySupervisedUser() {
39 Shell::GetInstance()->system_tray_delegate()->RemoveObserver(this);
37 } 40 }
38 41
39 void TraySupervisedUser::UpdateMessage() { 42 void TraySupervisedUser::UpdateMessage() {
40 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> 43 base::string16 message = Shell::GetInstance()->system_tray_delegate()->
41 GetSupervisedUserMessage(); 44 GetSupervisedUserMessage();
42 if (tray_view_) 45 if (tray_view_)
43 tray_view_->SetMessage(message); 46 tray_view_->SetMessage(message);
44 if (message_center::MessageCenter::Get()->FindVisibleNotificationById( 47 if (message_center::MessageCenter::Get()->FindVisibleNotificationById(
45 kNotificationId)) 48 kNotificationId))
46 CreateOrUpdateNotification(message); 49 CreateOrUpdateNotification(message);
(...skipping 21 matching lines...) Expand all
68 71
69 void TraySupervisedUser::UpdateAfterLoginStatusChange( 72 void TraySupervisedUser::UpdateAfterLoginStatusChange(
70 user::LoginStatus status) { 73 user::LoginStatus status) {
71 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); 74 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
72 75
73 bool is_user_supervised = delegate->IsUserSupervised(); 76 bool is_user_supervised = delegate->IsUserSupervised();
74 if (status == status_ && is_user_supervised == is_user_supervised_) 77 if (status == status_ && is_user_supervised == is_user_supervised_)
75 return; 78 return;
76 79
77 if (is_user_supervised && 80 if (is_user_supervised &&
78 status_ != ash::user::LOGGED_IN_LOCKED) { 81 status_ != ash::user::LOGGED_IN_LOCKED &&
79 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); 82 !delegate->GetSupervisedUserManager().empty())
80 } 83 CreateOrUpdateSupervisedWarningNotification();
84
81 status_ = status; 85 status_ = status;
82 is_user_supervised_ = is_user_supervised; 86 is_user_supervised_ = is_user_supervised;
83 } 87 }
84 88
85 void TraySupervisedUser::CreateOrUpdateNotification( 89 void TraySupervisedUser::CreateOrUpdateNotification(
86 const base::string16& new_message) { 90 const base::string16& new_message) {
87 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 91 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
88 scoped_ptr<Notification> notification( 92 scoped_ptr<Notification> notification(
89 message_center::Notification::CreateSystemNotification( 93 message_center::Notification::CreateSystemNotification(
90 kNotificationId, 94 kNotificationId,
91 base::string16() /* no title */, 95 base::string16() /* no title */,
92 new_message, 96 new_message,
93 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SUPERVISED_USER), 97 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SUPERVISED_USER),
94 system_notifier::kNotifierSupervisedUser, 98 system_notifier::kNotifierSupervisedUser,
95 base::Closure() /* null callback */)); 99 base::Closure() /* null callback */));
96 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 100 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
97 } 101 }
98 102
103 void TraySupervisedUser::CreateOrUpdateSupervisedWarningNotification() {
104 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
105 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage());
106 }
107
108 void TraySupervisedUser::OnCustodianInfoChanged() {
109 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
110 std::string manager_name = delegate->GetSupervisedUserManager();
111 if (!manager_name.empty()) {
112 if (!message_center::MessageCenter::Get()->FindVisibleNotificationById(
113 kNotificationId))
114 CreateOrUpdateSupervisedWarningNotification();
115 UpdateMessage();
116 }
117 }
118
99 } // namespace ash 119 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698