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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/date/date_default_view.h" 5 #include "ash/system/date/date_default_view.h"
6 6
7 #include "ash/metrics/user_metrics_recorder.h" 7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/session/session_state_delegate.h" 8 #include "ash/session/session_state_delegate.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/date/date_view.h" 10 #include "ash/system/date/date_view.h"
(...skipping 12 matching lines...) Expand all
23 23
24 namespace { 24 namespace {
25 25
26 const int kPaddingVertical = 19; 26 const int kPaddingVertical = 19;
27 27
28 } // namespace 28 } // namespace
29 29
30 namespace ash { 30 namespace ash {
31 31
32 DateDefaultView::DateDefaultView(ash::user::LoginStatus login) 32 DateDefaultView::DateDefaultView(ash::user::LoginStatus login)
33 : help_(NULL), 33 : help_button_(NULL),
34 shutdown_(NULL), 34 shutdown_button_(NULL),
35 lock_(NULL), 35 lock_button_(NULL),
36 date_view_(NULL) { 36 date_view_(NULL),
37 weak_factory_(this) {
37 SetLayoutManager(new views::FillLayout); 38 SetLayoutManager(new views::FillLayout);
38 39
39 date_view_ = new tray::DateView(); 40 date_view_ = new tray::DateView();
40 date_view_->SetBorder(views::Border::CreateEmptyBorder( 41 date_view_->SetBorder(views::Border::CreateEmptyBorder(
41 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); 42 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0));
42 SpecialPopupRow* view = new SpecialPopupRow(); 43 SpecialPopupRow* view = new SpecialPopupRow();
43 view->SetContent(date_view_); 44 view->SetContent(date_view_);
44 AddChildView(view); 45 AddChildView(view);
45 46
46 bool userAddingRunning = ash::Shell::GetInstance() 47 bool userAddingRunning = ash::Shell::GetInstance()
47 ->session_state_delegate() 48 ->session_state_delegate()
48 ->IsInSecondaryLoginScreen(); 49 ->IsInSecondaryLoginScreen();
49 50
50 if (login == user::LOGGED_IN_LOCKED || 51 if (login == user::LOGGED_IN_LOCKED ||
51 login == user::LOGGED_IN_NONE || userAddingRunning) 52 login == user::LOGGED_IN_NONE || userAddingRunning)
52 return; 53 return;
53 54
54 date_view_->SetAction(TrayDate::SHOW_DATE_SETTINGS); 55 date_view_->SetAction(TrayDate::SHOW_DATE_SETTINGS);
55 56
56 help_ = new TrayPopupHeaderButton(this, 57 help_button_ = new TrayPopupHeaderButton(
57 IDR_AURA_UBER_TRAY_HELP, 58 this, IDR_AURA_UBER_TRAY_HELP, IDR_AURA_UBER_TRAY_HELP,
58 IDR_AURA_UBER_TRAY_HELP, 59 IDR_AURA_UBER_TRAY_HELP_HOVER, IDR_AURA_UBER_TRAY_HELP_HOVER,
59 IDR_AURA_UBER_TRAY_HELP_HOVER, 60 IDS_ASH_STATUS_TRAY_HELP);
60 IDR_AURA_UBER_TRAY_HELP_HOVER, 61 help_button_->SetTooltipText(
61 IDS_ASH_STATUS_TRAY_HELP); 62 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
62 help_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP)); 63 view->AddButton(help_button_);
63 view->AddButton(help_);
64 64
65 #if !defined(OS_WIN) 65 #if !defined(OS_WIN)
66 if (login != ash::user::LOGGED_IN_LOCKED) { 66 if (login != ash::user::LOGGED_IN_LOCKED) {
67 shutdown_ = new TrayPopupHeaderButton(this, 67 shutdown_button_ = new TrayPopupHeaderButton(
68 IDR_AURA_UBER_TRAY_SHUTDOWN, 68 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN,
69 IDR_AURA_UBER_TRAY_SHUTDOWN, 69 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
70 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, 70 IDS_ASH_STATUS_TRAY_SHUTDOWN);
71 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, 71 shutdown_button_->SetTooltipText(
72 IDS_ASH_STATUS_TRAY_SHUTDOWN);
73 shutdown_->SetTooltipText(
74 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); 72 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN));
75 view->AddButton(shutdown_); 73 view->AddButton(shutdown_button_);
76 } 74 }
77 75
78 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { 76 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) {
79 lock_ = new TrayPopupHeaderButton(this, 77 lock_button_ = new TrayPopupHeaderButton(
80 IDR_AURA_UBER_TRAY_LOCKSCREEN, 78 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN,
81 IDR_AURA_UBER_TRAY_LOCKSCREEN, 79 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
82 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, 80 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK);
83 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, 81 lock_button_->SetTooltipText(
84 IDS_ASH_STATUS_TRAY_LOCK); 82 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
85 lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); 83 view->AddButton(lock_button_);
86 view->AddButton(lock_);
87 } 84 }
85 SystemTrayDelegate* system_tray_delegate =
86 Shell::GetInstance()->system_tray_delegate();
87 system_tray_delegate->AddShutdownPolicyObserver(this);
88 system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
89 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
88 #endif // !defined(OS_WIN) 90 #endif // !defined(OS_WIN)
89 } 91 }
90 92
91 DateDefaultView::~DateDefaultView() { 93 DateDefaultView::~DateDefaultView() {
94 // We need the check as on shell destruction, the delegate is destroyed first.
95 SystemTrayDelegate* system_tray_delegate =
96 Shell::GetInstance()->system_tray_delegate();
97 if (system_tray_delegate)
98 system_tray_delegate->RemoveShutdownPolicyObserver(this);
92 } 99 }
93 100
94 views::View* DateDefaultView::GetHelpButtonView() { 101 views::View* DateDefaultView::GetHelpButtonView() {
95 return help_; 102 return help_button_;
96 } 103 }
97 104
98 tray::DateView* DateDefaultView::GetDateView() { 105 tray::DateView* DateDefaultView::GetDateView() {
99 return date_view_; 106 return date_view_;
100 } 107 }
101 108
102 const tray::DateView* DateDefaultView::GetDateView() const { 109 const tray::DateView* DateDefaultView::GetDateView() const {
103 return date_view_; 110 return date_view_;
104 } 111 }
105 112
106 void DateDefaultView::ButtonPressed(views::Button* sender, 113 void DateDefaultView::ButtonPressed(views::Button* sender,
107 const ui::Event& event) { 114 const ui::Event& event) {
108 ash::Shell* shell = ash::Shell::GetInstance(); 115 ash::Shell* shell = ash::Shell::GetInstance();
109 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); 116 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate();
110 if (sender == help_) { 117 if (sender == help_button_) {
111 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); 118 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP);
112 tray_delegate->ShowHelp(); 119 tray_delegate->ShowHelp();
113 } else if (sender == shutdown_) { 120 } else if (sender == shutdown_button_) {
114 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); 121 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN);
115 ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown( 122 ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown();
116 ash::LockStateController::POWER_OFF); 123 } else if (sender == lock_button_) {
117 } else if (sender == lock_) {
118 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); 124 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN);
119 tray_delegate->RequestLockScreen(); 125 tray_delegate->RequestLockScreen();
120 } else { 126 } else {
121 NOTREACHED(); 127 NOTREACHED();
122 } 128 }
123 } 129 }
124 130
131 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
132 if (!shutdown_button_)
133 return;
134
135 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16(
136 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT
137 : IDS_ASH_STATUS_TRAY_SHUTDOWN));
138 }
139
125 } // namespace ash 140 } // namespace ash
OLDNEW
« 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