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

Unified Diff: ash/system/date/date_default_view.cc

Issue 811033002: Add device policy to disallow shutdown - ash UI modifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/date/date_default_view.h ('k') | ash/system/tray/default_system_tray_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/date/date_default_view.cc
diff --git a/ash/system/date/date_default_view.cc b/ash/system/date/date_default_view.cc
index 44cb9978d5b595c884bc18c87cb4292b7f1dac60..aa86cc8f8d55163e3b1737df59a623224fa69cbd 100644
--- a/ash/system/date/date_default_view.cc
+++ b/ash/system/date/date_default_view.cc
@@ -30,10 +30,11 @@ const int kPaddingVertical = 19;
namespace ash {
DateDefaultView::DateDefaultView(ash::user::LoginStatus login)
- : help_(NULL),
- shutdown_(NULL),
- lock_(NULL),
- date_view_(NULL) {
+ : help_button_(NULL),
+ shutdown_button_(NULL),
+ lock_button_(NULL),
+ date_view_(NULL),
+ weak_factory_(this) {
SetLayoutManager(new views::FillLayout);
date_view_ = new tray::DateView();
@@ -53,46 +54,52 @@ DateDefaultView::DateDefaultView(ash::user::LoginStatus login)
date_view_->SetAction(TrayDate::SHOW_DATE_SETTINGS);
- help_ = new TrayPopupHeaderButton(this,
- IDR_AURA_UBER_TRAY_HELP,
- IDR_AURA_UBER_TRAY_HELP,
- IDR_AURA_UBER_TRAY_HELP_HOVER,
- IDR_AURA_UBER_TRAY_HELP_HOVER,
- IDS_ASH_STATUS_TRAY_HELP);
- help_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
- view->AddButton(help_);
+ help_button_ = new TrayPopupHeaderButton(
+ this, IDR_AURA_UBER_TRAY_HELP, IDR_AURA_UBER_TRAY_HELP,
+ IDR_AURA_UBER_TRAY_HELP_HOVER, IDR_AURA_UBER_TRAY_HELP_HOVER,
+ IDS_ASH_STATUS_TRAY_HELP);
+ help_button_->SetTooltipText(
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
+ view->AddButton(help_button_);
#if !defined(OS_WIN)
if (login != ash::user::LOGGED_IN_LOCKED) {
- shutdown_ = new TrayPopupHeaderButton(this,
- IDR_AURA_UBER_TRAY_SHUTDOWN,
- IDR_AURA_UBER_TRAY_SHUTDOWN,
- IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
- IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
- IDS_ASH_STATUS_TRAY_SHUTDOWN);
- shutdown_->SetTooltipText(
+ shutdown_button_ = new TrayPopupHeaderButton(
+ this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN,
+ IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
+ IDS_ASH_STATUS_TRAY_SHUTDOWN);
+ shutdown_button_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN));
- view->AddButton(shutdown_);
+ view->AddButton(shutdown_button_);
}
if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) {
- lock_ = new TrayPopupHeaderButton(this,
- IDR_AURA_UBER_TRAY_LOCKSCREEN,
- IDR_AURA_UBER_TRAY_LOCKSCREEN,
- IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
- IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
- IDS_ASH_STATUS_TRAY_LOCK);
- lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
- view->AddButton(lock_);
+ lock_button_ = new TrayPopupHeaderButton(
+ this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN,
+ IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
+ IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK);
+ lock_button_->SetTooltipText(
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
+ view->AddButton(lock_button_);
}
+ SystemTrayDelegate* system_tray_delegate =
+ Shell::GetInstance()->system_tray_delegate();
+ system_tray_delegate->AddShutdownPolicyObserver(this);
+ system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
+ &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
#endif // !defined(OS_WIN)
}
DateDefaultView::~DateDefaultView() {
+ // We need the check as on shell destruction, the delegate is destroyed first.
+ SystemTrayDelegate* system_tray_delegate =
+ Shell::GetInstance()->system_tray_delegate();
+ if (system_tray_delegate)
+ system_tray_delegate->RemoveShutdownPolicyObserver(this);
}
views::View* DateDefaultView::GetHelpButtonView() {
- return help_;
+ return help_button_;
}
tray::DateView* DateDefaultView::GetDateView() {
@@ -107,14 +114,13 @@ void DateDefaultView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
ash::Shell* shell = ash::Shell::GetInstance();
ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate();
- if (sender == help_) {
+ if (sender == help_button_) {
shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP);
tray_delegate->ShowHelp();
- } else if (sender == shutdown_) {
+ } else if (sender == shutdown_button_) {
shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN);
- ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown(
- ash::LockStateController::POWER_OFF);
- } else if (sender == lock_) {
+ ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown();
+ } else if (sender == lock_button_) {
shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN);
tray_delegate->RequestLockScreen();
} else {
@@ -122,4 +128,13 @@ void DateDefaultView::ButtonPressed(views::Button* sender,
}
}
+void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
+ if (!shutdown_button_)
+ return;
+
+ shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16(
+ reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT
+ : IDS_ASH_STATUS_TRAY_SHUTDOWN));
+}
+
} // namespace ash
« no previous file with comments | « ash/system/date/date_default_view.h ('k') | ash/system/tray/default_system_tray_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698