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

Side by Side Diff: ash/wm/lock_state_controller.cc

Issue 776093004: Add device policy to disallow shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: modifications suggested by stevenjb Created 6 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/wm/lock_state_controller.h" 5 #include "ash/wm/lock_state_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/accessibility_delegate.h" 10 #include "ash/accessibility_delegate.h"
11 #include "ash/ash_switches.h" 11 #include "ash/ash_switches.h"
12 #include "ash/cancel_mode.h" 12 #include "ash/cancel_mode.h"
13 #include "ash/metrics/user_metrics_recorder.h" 13 #include "ash/metrics/user_metrics_recorder.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/shell_delegate.h" 15 #include "ash/shell_delegate.h"
16 #include "ash/shell_window_ids.h" 16 #include "ash/shell_window_ids.h"
17 #include "ash/wm/session_state_animator.h" 17 #include "ash/wm/session_state_animator.h"
18 #include "ash/wm/session_state_animator_impl.h" 18 #include "ash/wm/session_state_animator_impl.h"
19 #include "base/bind.h"
19 #include "base/bind_helpers.h" 20 #include "base/bind_helpers.h"
20 #include "base/command_line.h" 21 #include "base/command_line.h"
22 #include "base/location.h"
23 #include "base/logging.h"
21 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
22 #include "base/timer/timer.h" 25 #include "base/timer/timer.h"
23 #include "ui/aura/window_tree_host.h" 26 #include "ui/aura/window_tree_host.h"
24 #include "ui/views/controls/menu/menu_controller.h" 27 #include "ui/views/controls/menu/menu_controller.h"
25 #include "ui/wm/core/compound_event_filter.h" 28 #include "ui/wm/core/compound_event_filter.h"
26 29
27 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
28 #include "base/sys_info.h" 31 #include "base/sys_info.h"
29 #include "media/audio/sounds/sounds_manager.h" 32 #include "media/audio/sounds/sounds_manager.h"
30 #endif 33 #endif
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 160 }
158 161
159 void LockStateController::OnStartingLock() { 162 void LockStateController::OnStartingLock() {
160 if (shutting_down_ || system_is_locked_) 163 if (shutting_down_ || system_is_locked_)
161 return; 164 return;
162 if (animating_lock_) 165 if (animating_lock_)
163 return; 166 return;
164 StartImmediatePreLockAnimation(false /* request_lock_on_completion */); 167 StartImmediatePreLockAnimation(false /* request_lock_on_completion */);
165 } 168 }
166 169
167 void LockStateController::RequestShutdown() { 170 void LockStateController::RequestShutdown(ShutdownMode mode) {
168 if (shutting_down_) 171 if (shutting_down_)
169 return; 172 return;
170 173
171 shutting_down_ = true; 174 shutting_down_ = true;
172 175
173 Shell* shell = ash::Shell::GetInstance(); 176 Shell* shell = ash::Shell::GetInstance();
174 shell->cursor_manager()->HideCursor(); 177 shell->cursor_manager()->HideCursor();
175 shell->cursor_manager()->LockCursor(); 178 shell->cursor_manager()->LockCursor();
176 179
177 animator_->StartAnimation( 180 animator_->StartAnimation(
178 SessionStateAnimator::ROOT_CONTAINER, 181 SessionStateAnimator::ROOT_CONTAINER,
179 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, 182 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS,
180 SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 183 SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
181 StartRealShutdownTimer(true); 184 StartRealShutdownTimer(true, mode);
182 } 185 }
183 186
184 void LockStateController::OnLockScreenHide( 187 void LockStateController::OnLockScreenHide(
185 base::Callback<void(void)>& callback) { 188 base::Callback<void(void)>& callback) {
186 StartUnlockAnimationBeforeUIDestroyed(callback); 189 StartUnlockAnimationBeforeUIDestroyed(callback);
187 } 190 }
188 191
189 void LockStateController::SetLockScreenDisplayedCallback( 192 void LockStateController::SetLockScreenDisplayedCallback(
190 const base::Closure& callback) { 193 const base::Closure& callback) {
191 lock_screen_displayed_callback_ = callback; 194 lock_screen_displayed_callback_ = callback;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 &LockStateController::OnPreShutdownAnimationTimeout); 265 &LockStateController::OnPreShutdownAnimationTimeout);
263 } 266 }
264 267
265 void LockStateController::OnPreShutdownAnimationTimeout() { 268 void LockStateController::OnPreShutdownAnimationTimeout() {
266 VLOG(1) << "OnPreShutdownAnimationTimeout"; 269 VLOG(1) << "OnPreShutdownAnimationTimeout";
267 shutting_down_ = true; 270 shutting_down_ = true;
268 271
269 Shell* shell = ash::Shell::GetInstance(); 272 Shell* shell = ash::Shell::GetInstance();
270 shell->cursor_manager()->HideCursor(); 273 shell->cursor_manager()->HideCursor();
271 274
272 StartRealShutdownTimer(false); 275 StartRealShutdownTimer(false, POWER_OFF);
273 } 276 }
274 277
275 void LockStateController::StartRealShutdownTimer(bool with_animation_time) { 278 void LockStateController::StartRealShutdownTimer(bool with_animation_time,
279 ShutdownMode shutdown_mode) {
276 base::TimeDelta duration = 280 base::TimeDelta duration =
277 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); 281 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs);
278 if (with_animation_time) { 282 if (with_animation_time) {
279 duration += 283 duration +=
280 animator_->GetDuration(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 284 animator_->GetDuration(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
281 } 285 }
282 286
283 #if defined(OS_CHROMEOS) 287 #if defined(OS_CHROMEOS)
284 const AccessibilityDelegate* const delegate = 288 const AccessibilityDelegate* const delegate =
285 Shell::GetInstance()->accessibility_delegate(); 289 Shell::GetInstance()->accessibility_delegate();
286 base::TimeDelta sound_duration = delegate->PlayShutdownSound(); 290 base::TimeDelta sound_duration = delegate->PlayShutdownSound();
287 sound_duration = 291 sound_duration =
288 std::min(sound_duration, 292 std::min(sound_duration,
289 base::TimeDelta::FromMilliseconds(kMaxShutdownSoundDurationMs)); 293 base::TimeDelta::FromMilliseconds(kMaxShutdownSoundDurationMs));
290 duration = std::max(duration, sound_duration); 294 duration = std::max(duration, sound_duration);
291 #endif 295 #endif
292 296
293 real_shutdown_timer_.Start( 297 real_shutdown_timer_.Start(
294 FROM_HERE, duration, this, &LockStateController::OnRealShutdownTimeout); 298 FROM_HERE, duration, base::Bind(&LockStateController::OnRealPowerTimeout,
299 base::Unretained(this), shutdown_mode));
295 } 300 }
296 301
297 void LockStateController::OnRealShutdownTimeout() { 302 void LockStateController::OnRealPowerTimeout(ShutdownMode shutdown_mode) {
298 VLOG(1) << "OnRealShutdownTimeout";
bartfab (slow) 2014/12/08 16:49:44 Why did you remove this?
cschuet (SLOW) 2014/12/08 18:57:04 Removed by accident. Restored.
299 DCHECK(shutting_down_); 303 DCHECK(shutting_down_);
300 #if defined(OS_CHROMEOS) 304 #if defined(OS_CHROMEOS)
301 if (!base::SysInfo::IsRunningOnChromeOS()) { 305 if (!base::SysInfo::IsRunningOnChromeOS()) {
302 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 306 ShellDelegate* delegate = Shell::GetInstance()->delegate();
303 if (delegate) { 307 if (delegate) {
304 delegate->Exit(); 308 delegate->Exit();
305 return; 309 return;
306 } 310 }
307 } 311 }
308 #endif 312 #endif
309 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 313 if (shutdown_mode == POWER_OFF) {
310 UMA_ACCEL_SHUT_DOWN_POWER_BUTTON); 314 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
311 delegate_->RequestShutdown(); 315 UMA_ACCEL_SHUT_DOWN_POWER_BUTTON);
316 delegate_->RequestShutdown();
bartfab (slow) 2014/12/08 16:49:44 Nit: If you return here, you can save yourself the
cschuet (SLOW) 2014/12/08 18:57:04 Done.
317 } else {
318 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
319 UMA_ACCEL_RESTART_POWER_BUTTON);
320 delegate_->RequestRestart();
321 }
312 } 322 }
313 323
314 void LockStateController::StartCancellableShutdownAnimation() { 324 void LockStateController::StartCancellableShutdownAnimation() {
315 Shell* shell = ash::Shell::GetInstance(); 325 Shell* shell = ash::Shell::GetInstance();
316 // Hide cursor, but let it reappear if the mouse moves. 326 // Hide cursor, but let it reappear if the mouse moves.
317 shell->cursor_manager()->HideCursor(); 327 shell->cursor_manager()->HideCursor();
318 328
319 animator_->StartAnimation( 329 animator_->StartAnimation(
320 SessionStateAnimator::ROOT_CONTAINER, 330 SessionStateAnimator::ROOT_CONTAINER,
321 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, 331 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 if (unlocked_properties_.get() && 575 if (unlocked_properties_.get() &&
566 unlocked_properties_->background_is_hidden) { 576 unlocked_properties_->background_is_hidden) {
567 animation_sequence->StartAnimation( 577 animation_sequence->StartAnimation(
568 SessionStateAnimator::DESKTOP_BACKGROUND, 578 SessionStateAnimator::DESKTOP_BACKGROUND,
569 SessionStateAnimator::ANIMATION_FADE_OUT, 579 SessionStateAnimator::ANIMATION_FADE_OUT,
570 speed); 580 speed);
571 } 581 }
572 } 582 }
573 583
574 } // namespace ash 584 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698