1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef ASH_WM_LOCK_STATE_CONTROLLER_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define ASH_WM_LOCK_STATE_CONTROLLER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_export.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_observer.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/wm/lock_state_observer.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/session_state_animator.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/weak_ptr.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/observer_list.h"
16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/timer/timer.h"
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_tree_host_observer.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Rect;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Size;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Layer;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test {
324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class LockStateControllerTest;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PowerButtonControllerTest;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Performs system-related functions on behalf of LockStateController.
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ASH_EXPORT LockStateControllerDelegate {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  LockStateControllerDelegate() {}
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual ~LockStateControllerDelegate() {}
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RequestLockScreen() = 0;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RequestShutdown() = 0;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(LockStateControllerDelegate);
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Displays onscreen animations and locks or suspends the system in response to
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the power button being pressed or released.
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Lock workflow:
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Entry points:
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//  * StartLockAnimation (bool shutdown after lock) - starts lock that can be
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//    cancelled.
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci//  * StartLockAnimationAndLockImmediately (bool shutdown after lock) - starts
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci//    uninterruptible lock animation.
574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// This leads to call of either StartImmediatePreLockAnimation or
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// StartCancellablePreLockAnimation. Once they complete
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// PreLockAnimationFinished is called, and system lock is requested.
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Once system locks and lock UI is created, OnLockStateChanged is called, and
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// StartPostLockAnimation is called. In PostLockAnimationFinished two
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// things happen : EVENT_LOCK_ANIMATION_FINISHED notification is sent (it
634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// triggers third part of animation within lock UI), and check for continuing to
644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// shutdown is made.
654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//
664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Unlock workflow:
674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// WebUI does first part of animation, and calls OnLockScreenHide(callback) that
684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// triggers StartUnlockAnimationBeforeUIDestroyed(callback). Once callback is
694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// called at the end of the animation, lock UI is deleted, system unlocks, and
704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// OnLockStateChanged is called. It leads to
714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// StartUnlockAnimationAfterUIDestroyed.
72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ASH_EXPORT LockStateController : public aura::WindowTreeHostObserver,
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                       public ShellObserver {
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Amount of time that the power button needs to be held before we lock the
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // screen.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kLockTimeoutMs;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Amount of time that the power button needs to be held before we shut down.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kShutdownTimeoutMs;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Amount of time to wait for our lock requests to be honored before giving
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // up.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kLockFailTimeoutMs;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When the button has been held continuously from the unlocked state, amount
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of time that we wait after the screen locker window is shown before
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // starting the pre-shutdown animation.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kLockToShutdownTimeoutMs;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Additional time (beyond kFastCloseAnimMs) to wait after starting the
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // fast-close shutdown animation before actually requesting shutdown, to give
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the animation time to finish.
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kShutdownRequestDelayMs;
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Helper class used by tests to access internal state.
974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class ASH_EXPORT TestApi {
984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)   public:
994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    explicit TestApi(LockStateController* controller);
1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    virtual ~TestApi();
1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool lock_fail_timer_is_running() const {
1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return controller_->lock_fail_timer_.IsRunning();
1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool lock_to_shutdown_timer_is_running() const {
1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return controller_->lock_to_shutdown_timer_.IsRunning();
1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool shutdown_timer_is_running() const {
1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return controller_->pre_shutdown_timer_.IsRunning();
1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool real_shutdown_timer_is_running() const {
1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return controller_->real_shutdown_timer_.IsRunning();
1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool is_animating_lock() const {
1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return controller_->animating_lock_;
1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool is_lock_cancellable() const {
1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return controller_->CanCancelLockAnimation();
1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    void trigger_lock_fail_timeout() {
1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->OnLockFailTimeout();
1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->lock_fail_timer_.Stop();
1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    void trigger_lock_to_shutdown_timeout() {
1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->OnLockToShutdownTimeout();
1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->lock_to_shutdown_timer_.Stop();
1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    void trigger_shutdown_timeout() {
1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->OnPreShutdownAnimationTimeout();
1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->pre_shutdown_timer_.Stop();
1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    void trigger_real_shutdown_timeout() {
1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->OnRealShutdownTimeout();
1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      controller_->real_shutdown_timer_.Stop();
1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)   private:
1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    LockStateController* controller_;  // not owned
1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(TestApi);
1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  };
1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  LockStateController();
146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual ~LockStateController();
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void SetDelegate(scoped_ptr<LockStateControllerDelegate> delegate);
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void AddObserver(LockStateObserver* observer);
1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void RemoveObserver(LockStateObserver* observer);
1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool HasObserver(LockStateObserver* observer);
1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Starts locking (with slow animation) that can be cancelled.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation()
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be called unless CancelShutdownAnimation() is called, if
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |shutdown_after_lock| is true.
1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartLockAnimation(bool shutdown_after_lock);
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Starts shutting down (with slow animation) that can be cancelled.
1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartShutdownAnimation();
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Starts usual lock animation, but locks immediately.  After locking and
1641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // |kLockToShutdownTimeoutMs| StartShutdownAnimation() will be called unless
1651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // CancelShutdownAnimation() is called, if  |shutdown_after_lock| is true.
1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void StartLockAnimationAndLockImmediately(bool shutdown_after_lock);
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we have requested system to lock, but haven't received
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // confirmation yet.
1704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool LockRequested();
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we are shutting down.
1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool ShutdownRequested();
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we are within cancellable lock timeframe.
1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool CanCancelLockAnimation();
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels locking and reverts lock animation.
1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void CancelLockAnimation();
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we are within cancellable shutdown timeframe.
1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool CanCancelShutdownAnimation();
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels shutting down and reverts shutdown animation.
1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void CancelShutdownAnimation();
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when Chrome gets a request to display the lock screen.
1884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void OnStartingLock();
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Displays the shutdown animation and requests shutdown when it's done.
1914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void RequestShutdown();
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when ScreenLocker is ready to close, but not yet destroyed.
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Can be used to display "hiding" animations on unlock.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |callback| will be called when all animations are done.
1964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void OnLockScreenHide(base::Closure& callback);
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets up the callback that should be called once lock animation is finished.
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback is guaranteed to be called once and then discarded.
2000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  void SetLockScreenDisplayedCallback(const base::Closure& callback);
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
202a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // aura::WindowTreeHostObserver override:
203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE;
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // ShellObserver overrides:
2064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE;
2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void OnAppTerminating() OVERRIDE;
2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void OnLockStateChanged(bool locked) OVERRIDE;
2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void set_animator_for_test(SessionStateAnimator* animator) {
2111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    animator_.reset(animator);
2121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
2131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private:
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class test::PowerButtonControllerTest;
2164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  friend class test::LockStateControllerTest;
2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  struct UnlockedStateProperties {
2194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool background_is_hidden;
2204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  };
2214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Reverts the pre-lock animation, reports the error.
2234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void OnLockFailTimeout();
2244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Starts timer for gap between lock and shutdown.
2264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartLockToShutdownTimer();
2274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Calls StartShutdownAnimation().
2294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void OnLockToShutdownTimeout();
2304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Starts timer for undoable shutdown animation.
2324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartPreShutdownAnimationTimer();
2334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Calls StartRealShutdownTimer().
2354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void OnPreShutdownAnimationTimeout();
2364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Starts timer for final shutdown animation.
2384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // If |with_animation_time| is true, it will also include time of "fade to
2394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // white" shutdown animation.
2404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartRealShutdownTimer(bool with_animation_time);
2414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Requests that the machine be shut down.
2434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void OnRealShutdownTimeout();
2444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Starts shutdown animation that can be cancelled and starts pre-shutdown
2464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // timer.
2474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartCancellableShutdownAnimation();
2484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // If |request_lock_on_completion| is true, a lock request will be sent
2504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // after the pre-lock animation completes.  (The pre-lock animation is
2514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // also displayed in response to already-in-progress lock requests; in
2524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // these cases an additional lock request is undesirable.)
2534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartImmediatePreLockAnimation(bool request_lock_on_completion);
2544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartCancellablePreLockAnimation();
2554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void CancelPreLockAnimation();
2564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartPostLockAnimation();
2574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // This method calls |callback| when animation completes.
2584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartUnlockAnimationBeforeUIDestroyed(base::Closure &callback);
2594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StartUnlockAnimationAfterUIDestroyed();
2604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // These methods are called when corresponding animation completes.
2624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void LockAnimationCancelled();
2634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void PreLockAnimationFinished(bool request_lock);
2644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void PostLockAnimationFinished();
2654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void UnlockAnimationAfterUIDestroyedFinished();
2664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Stores properties of UI that have to be temporarily modified while locking.
2684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void StoreUnlockedProperties();
2694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void RestoreUnlockedProperties();
2704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Fades in background layer with |speed| if it was hidden in unlocked state.
2724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void AnimateBackgroundAppearanceIfNecessary(
273c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ash::SessionStateAnimator::AnimationSpeed speed,
2741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      SessionStateAnimator::AnimationSequence* animation_sequence);
2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Fades out background layer with |speed| if it was hidden in unlocked state.
2774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void AnimateBackgroundHidingIfNecessary(
278c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ash::SessionStateAnimator::AnimationSpeed speed,
2791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      SessionStateAnimator::AnimationSequence* animation_sequence);
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
281c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_ptr<SessionStateAnimator> animator_;
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<LockStateControllerDelegate> delegate_;
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ObserverList<LockStateObserver> observers_;
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The current login status, or original login status from before we locked.
2884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  user::LoginStatus login_status_;
2894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Current lock status.
2914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool system_is_locked_;
2924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Are we in the process of shutting the machine down?
2944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool shutting_down_;
2954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Indicates whether controller should proceed to (cancellable) shutdown after
2974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // locking.
2984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool shutdown_after_lock_;
2994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Indicates that controller displays lock animation.
3014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool animating_lock_;
3024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Indicates that lock animation can be undone.
3044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool can_cancel_lock_animation_;
3054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<UnlockedStateProperties> unlocked_properties_;
3074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Started when we request that the screen be locked.  When it fires, we
3094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // assume that our request got dropped.
3104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::OneShotTimer<LockStateController> lock_fail_timer_;
3114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Started when the screen is locked while the power button is held.  Adds a
3134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // delay between the appearance of the lock screen and the beginning of the
3144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // pre-shutdown animation.
3154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::OneShotTimer<LockStateController> lock_to_shutdown_timer_;
3164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Started when we begin displaying the pre-shutdown animation.  When it
3184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // fires, we start the shutdown animation and get ready to request shutdown.
3194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::OneShotTimer<LockStateController> pre_shutdown_timer_;
3204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Started when we display the shutdown animation.  When it fires, we actually
3224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // request shutdown.  Gives the animation time to complete before Chrome, X,
3234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // etc. are shut down.
3244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::OneShotTimer<LockStateController> real_shutdown_timer_;
3254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::Closure lock_screen_displayed_callback_;
3274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
328a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::WeakPtrFactory<LockStateController> weak_ptr_factory_;
329a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(LockStateController);
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // ASH_WM_LOCK_STATE_CONTROLLER_H_
336