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

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

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

Powered by Google App Engine
This is Rietveld 408576698