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

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

Issue 10008074: Cancel partial screenshot UI when lock happens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/power_button_controller.h" 5 #include "ash/wm/power_button_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/root_window_event_filter.h" 10 #include "ash/wm/root_window_event_filter.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 269 }
270 return true; 270 return true;
271 } 271 }
272 272
273 bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const { 273 bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const {
274 return controller_->background_layer_.get() && 274 return controller_->background_layer_.get() &&
275 controller_->background_layer_->visible(); 275 controller_->background_layer_->visible();
276 } 276 }
277 277
278 PowerButtonController::PowerButtonController() 278 PowerButtonController::PowerButtonController()
279 : logged_in_(false), 279 : login_status_(user::LOGGED_IN_NONE),
280 is_guest_(false), 280 unlocked_login_status_(user::LOGGED_IN_NONE),
281 locked_(false),
282 power_button_down_(false), 281 power_button_down_(false),
283 lock_button_down_(false), 282 lock_button_down_(false),
284 shutting_down_(false), 283 shutting_down_(false),
285 has_legacy_power_button_( 284 has_legacy_power_button_(
286 CommandLine::ForCurrentProcess()->HasSwitch( 285 CommandLine::ForCurrentProcess()->HasSwitch(
287 switches::kAuraLegacyPowerButton)) { 286 switches::kAuraLegacyPowerButton)) {
288 } 287 }
289 288
290 PowerButtonController::~PowerButtonController() { 289 PowerButtonController::~PowerButtonController() {
291 } 290 }
292 291
293 void PowerButtonController::OnLoginStateChange(bool logged_in, bool is_guest) { 292 void PowerButtonController::OnLoginStateChanged(user::LoginStatus status) {
294 logged_in_ = logged_in; 293 login_status_ = status;
295 is_guest_ = is_guest; 294 unlocked_login_status_ = user::LOGGED_IN_NONE;
296 } 295 }
297 296
298 void PowerButtonController::OnExit() { 297 void PowerButtonController::OnAppTerminating() {
299 // If we hear that Chrome is exiting but didn't request it ourselves, all we 298 // If we hear that Chrome is exiting but didn't request it ourselves, all we
300 // can really hope for is that we'll have time to clear the screen. 299 // can really hope for is that we'll have time to clear the screen.
301 if (!shutting_down_) { 300 if (!shutting_down_) {
302 shutting_down_ = true; 301 shutting_down_ = true;
303 ash::Shell::GetInstance()->root_filter()-> 302 ash::Shell::GetInstance()->root_filter()->
304 set_update_cursor_visibility(false); 303 set_update_cursor_visibility(false);
305 Shell::GetRootWindow()->ShowCursor(false); 304 Shell::GetRootWindow()->ShowCursor(false);
306 ShowBackgroundLayer(); 305 ShowBackgroundLayer();
307 StartAnimation(ALL_CONTAINERS, ANIMATION_HIDE); 306 StartAnimation(ALL_CONTAINERS, ANIMATION_HIDE);
308 } 307 }
309 } 308 }
310 309
311 void PowerButtonController::OnLockStateChange(bool locked) { 310 void PowerButtonController::OnLockStateChanged(bool locked) {
312 if (shutting_down_ || locked_ == locked) 311 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked)
313 return; 312 return;
314 313
315 locked_ = locked; 314 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) {
315 login_status_ = unlocked_login_status_;
316 unlocked_login_status_ = user::LOGGED_IN_NONE;
317 } else {
318 unlocked_login_status_ = login_status_;
319 login_status_ = user::LOGGED_IN_LOCKED;
320 }
321
316 if (locked) { 322 if (locked) {
317 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); 323 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN);
318 lock_timer_.Stop(); 324 lock_timer_.Stop();
319 lock_fail_timer_.Stop(); 325 lock_fail_timer_.Stop();
320 326
321 if (!has_legacy_power_button_ && power_button_down_) { 327 if (!has_legacy_power_button_ && power_button_down_) {
322 lock_to_shutdown_timer_.Stop(); 328 lock_to_shutdown_timer_.Stop();
323 lock_to_shutdown_timer_.Start( 329 lock_to_shutdown_timer_.Start(
324 FROM_HERE, 330 FROM_HERE,
325 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), 331 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs),
326 this, &PowerButtonController::OnLockToShutdownTimeout); 332 this, &PowerButtonController::OnLockToShutdownTimeout);
327 } 333 }
328 } else { 334 } else {
329 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 335 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
330 ANIMATION_RESTORE); 336 ANIMATION_RESTORE);
331 HideBackgroundLayer(); 337 HideBackgroundLayer();
332 } 338 }
333 } 339 }
334 340
335 void PowerButtonController::OnStartingLock() { 341 void PowerButtonController::OnStartingLock() {
336 if (shutting_down_ || locked_) 342 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED)
337 return; 343 return;
338 344
339 // Ensure that the background layer is visible -- if the screen was locked via 345 // Ensure that the background layer is visible -- if the screen was locked via
340 // the wrench menu, we won't have already shown the background as part of the 346 // the wrench menu, we won't have already shown the background as part of the
341 // slow-close animation. 347 // slow-close animation.
342 ShowBackgroundLayer(); 348 ShowBackgroundLayer();
343 349
344 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 350 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
345 ANIMATION_FAST_CLOSE); 351 ANIMATION_FAST_CLOSE);
346 352
347 // Hide the screen locker containers so we can make them fade in later. 353 // Hide the screen locker containers so we can make them fade in later.
348 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); 354 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE);
349 } 355 }
350 356
351 void PowerButtonController::OnPowerButtonEvent( 357 void PowerButtonController::OnPowerButtonEvent(
352 bool down, const base::TimeTicks& timestamp) { 358 bool down, const base::TimeTicks& timestamp) {
353 power_button_down_ = down; 359 power_button_down_ = down;
354 360
355 if (shutting_down_) 361 if (shutting_down_)
356 return; 362 return;
357 363
358 if (has_legacy_power_button_) { 364 if (has_legacy_power_button_) {
359 // If power button releases won't get reported correctly because we're not 365 // If power button releases won't get reported correctly because we're not
360 // running on official hardware, just lock the screen or shut down 366 // running on official hardware, just lock the screen or shut down
361 // immediately. 367 // immediately.
362 if (down) { 368 if (down) {
363 ShowBackgroundLayer(); 369 ShowBackgroundLayer();
364 if (logged_in_as_non_guest() && !locked_) { 370 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) {
365 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 371 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
366 ANIMATION_SLOW_CLOSE); 372 ANIMATION_SLOW_CLOSE);
367 OnLockTimeout(); 373 OnLockTimeout();
368 } else { 374 } else {
369 OnShutdownTimeout(); 375 OnShutdownTimeout();
370 } 376 }
371 } 377 }
372 } else { // !has_legacy_power_button_ 378 } else { // !has_legacy_power_button_
373 if (down) { 379 if (down) {
374 // If we already have a pending request to lock the screen, wait. 380 // If we already have a pending request to lock the screen, wait.
375 if (lock_fail_timer_.IsRunning()) 381 if (lock_fail_timer_.IsRunning())
376 return; 382 return;
377 383
378 if (logged_in_as_non_guest() && !locked_) 384 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED)
379 StartLockTimer(); 385 StartLockTimer();
380 else 386 else
381 StartShutdownTimer(); 387 StartShutdownTimer();
382 } else { // Button is up. 388 } else { // Button is up.
383 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) 389 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning())
384 StartAnimation( 390 StartAnimation(
385 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, 391 (login_status_ == user::LOGGED_IN_LOCKED) ?
392 SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS,
386 ANIMATION_UNDO_SLOW_CLOSE); 393 ANIMATION_UNDO_SLOW_CLOSE);
387 394
388 // Drop the background layer after the undo animation finishes. 395 // Drop the background layer after the undo animation finishes.
389 if (lock_timer_.IsRunning() || 396 if (lock_timer_.IsRunning() ||
390 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest())) { 397 (shutdown_timer_.IsRunning() && !LoggedInAsNonGuest())) {
391 hide_background_layer_timer_.Stop(); 398 hide_background_layer_timer_.Stop();
392 hide_background_layer_timer_.Start( 399 hide_background_layer_timer_.Start(
393 FROM_HERE, 400 FROM_HERE,
394 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), 401 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs),
395 this, &PowerButtonController::HideBackgroundLayer); 402 this, &PowerButtonController::HideBackgroundLayer);
396 } 403 }
397 404
398 lock_timer_.Stop(); 405 lock_timer_.Stop();
399 shutdown_timer_.Stop(); 406 shutdown_timer_.Stop();
400 lock_to_shutdown_timer_.Stop(); 407 lock_to_shutdown_timer_.Stop();
401 } 408 }
402 } 409 }
403 } 410 }
404 411
405 void PowerButtonController::OnLockButtonEvent( 412 void PowerButtonController::OnLockButtonEvent(
406 bool down, const base::TimeTicks& timestamp) { 413 bool down, const base::TimeTicks& timestamp) {
407 lock_button_down_ = down; 414 lock_button_down_ = down;
408 415
409 if (shutting_down_ || !logged_in_as_non_guest()) 416 if (shutting_down_ || !LoggedInAsNonGuest())
410 return; 417 return;
411 418
412 // Bail if we're already locked or are in the process of locking. Also give 419 // Bail if we're already locked or are in the process of locking. Also give
413 // the power button precedence over the lock button (we don't expect both 420 // the power button precedence over the lock button (we don't expect both
414 // buttons to be present, so this is just making sure that we don't do 421 // buttons to be present, so this is just making sure that we don't do
415 // something completely stupid if that assumption changes later). 422 // something completely stupid if that assumption changes later).
416 if (locked_ || lock_fail_timer_.IsRunning() || power_button_down_) 423 if (login_status_ == user::LOGGED_IN_LOCKED ||
424 lock_fail_timer_.IsRunning() || power_button_down_)
417 return; 425 return;
418 426
419 if (down) { 427 if (down) {
420 StartLockTimer(); 428 StartLockTimer();
421 } else { 429 } else {
422 if (lock_timer_.IsRunning()) { 430 if (lock_timer_.IsRunning()) {
423 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 431 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
424 ANIMATION_UNDO_SLOW_CLOSE); 432 ANIMATION_UNDO_SLOW_CLOSE);
425 hide_background_layer_timer_.Stop(); 433 hide_background_layer_timer_.Stop();
426 hide_background_layer_timer_.Start( 434 hide_background_layer_timer_.Start(
427 FROM_HERE, 435 FROM_HERE,
428 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), 436 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs),
429 this, &PowerButtonController::HideBackgroundLayer); 437 this, &PowerButtonController::HideBackgroundLayer);
430 lock_timer_.Stop(); 438 lock_timer_.Stop();
431 } 439 }
432 } 440 }
433 } 441 }
434 442
435 void PowerButtonController::RequestShutdown() { 443 void PowerButtonController::RequestShutdown() {
436 if (!shutting_down_) 444 if (!shutting_down_)
437 StartShutdownAnimationAndRequestShutdown(); 445 StartShutdownAnimationAndRequestShutdown();
438 } 446 }
439 447
440 void PowerButtonController::OnRootWindowResized(const aura::RootWindow* root, 448 void PowerButtonController::OnRootWindowResized(const aura::RootWindow* root,
441 const gfx::Size& new_size) { 449 const gfx::Size& new_size) {
442 if (background_layer_.get()) 450 if (background_layer_.get())
443 background_layer_->SetBounds(gfx::Rect(root->bounds().size())); 451 background_layer_->SetBounds(gfx::Rect(root->bounds().size()));
444 } 452 }
445 453
454 bool PowerButtonController::LoggedInAsNonGuest() const {
455 if (login_status_ == user::LOGGED_IN_NONE)
456 return false;
457 if (login_status_ == user::LOGGED_IN_GUEST)
458 return false;
459 // TODO(mukai): think about kiosk mode.
460 return true;
461 }
462
446 void PowerButtonController::OnLockTimeout() { 463 void PowerButtonController::OnLockTimeout() {
447 delegate_->RequestLockScreen(); 464 delegate_->RequestLockScreen();
448 lock_fail_timer_.Start( 465 lock_fail_timer_.Start(
449 FROM_HERE, 466 FROM_HERE,
450 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), 467 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs),
451 this, &PowerButtonController::OnLockFailTimeout); 468 this, &PowerButtonController::OnLockFailTimeout);
452 } 469 }
453 470
454 void PowerButtonController::OnLockFailTimeout() { 471 void PowerButtonController::OnLockFailTimeout() {
455 DCHECK(!locked_); 472 DCHECK(login_status_ != user::LOGGED_IN_LOCKED);
sky 2012/04/19 15:43:29 DCHECK_NE
Jun Mukai 2012/04/20 07:27:33 Done.
456 LOG(ERROR) << "Screen lock request timed out"; 473 LOG(ERROR) << "Screen lock request timed out";
457 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 474 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
458 ANIMATION_RESTORE); 475 ANIMATION_RESTORE);
459 HideBackgroundLayer(); 476 HideBackgroundLayer();
460 } 477 }
461 478
462 void PowerButtonController::OnLockToShutdownTimeout() { 479 void PowerButtonController::OnLockToShutdownTimeout() {
463 DCHECK(locked_); 480 DCHECK(login_status_ == user::LOGGED_IN_LOCKED);
sky 2012/04/19 15:43:29 DCHECK_EQ
Jun Mukai 2012/04/20 07:27:33 Done.
464 StartShutdownTimer(); 481 StartShutdownTimer();
465 } 482 }
466 483
467 void PowerButtonController::OnShutdownTimeout() { 484 void PowerButtonController::OnShutdownTimeout() {
468 if (!shutting_down_) 485 if (!shutting_down_)
469 StartShutdownAnimationAndRequestShutdown(); 486 StartShutdownAnimationAndRequestShutdown();
470 } 487 }
471 488
472 void PowerButtonController::OnRealShutdownTimeout() { 489 void PowerButtonController::OnRealShutdownTimeout() {
473 DCHECK(shutting_down_); 490 DCHECK(shutting_down_);
(...skipping 21 matching lines...) Expand all
495 } 512 }
496 513
497 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { 514 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() {
498 DCHECK(!shutting_down_); 515 DCHECK(!shutting_down_);
499 shutting_down_ = true; 516 shutting_down_ = true;
500 517
501 ash::Shell::GetInstance()->root_filter()->set_update_cursor_visibility(false); 518 ash::Shell::GetInstance()->root_filter()->set_update_cursor_visibility(false);
502 Shell::GetRootWindow()->ShowCursor(false); 519 Shell::GetRootWindow()->ShowCursor(false);
503 520
504 ShowBackgroundLayer(); 521 ShowBackgroundLayer();
505 if (!logged_in_ || locked_) { 522 if (login_status_ != user::LOGGED_IN_NONE) {
506 // Hide the other containers before starting the animation. 523 // Hide the other containers before starting the animation.
507 // ANIMATION_FAST_CLOSE will make the screen locker windows partially 524 // ANIMATION_FAST_CLOSE will make the screen locker windows partially
508 // transparent, and we don't want the other windows to show through. 525 // transparent, and we don't want the other windows to show through.
509 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 526 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
510 ANIMATION_HIDE); 527 ANIMATION_HIDE);
511 StartAnimation(SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_FAST_CLOSE); 528 StartAnimation(SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_FAST_CLOSE);
512 } else { 529 } else {
513 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE); 530 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE);
514 } 531 }
515 532
(...skipping 18 matching lines...) Expand all
534 root_layer->StackAtBottom(background_layer_.get()); 551 root_layer->StackAtBottom(background_layer_.get());
535 } 552 }
536 background_layer_->SetVisible(true); 553 background_layer_->SetVisible(true);
537 } 554 }
538 555
539 void PowerButtonController::HideBackgroundLayer() { 556 void PowerButtonController::HideBackgroundLayer() {
540 background_layer_.reset(); 557 background_layer_.reset();
541 } 558 }
542 559
543 } // namespace ash 560 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698