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

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

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

Powered by Google App Engine
This is Rietveld 408576698