| OLD | NEW |
| 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 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_H_ | 5 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_IMPL2_H_ |
| 6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_ | 6 #define ASH_WM_SESSION_STATE_CONTROLLER_IMPL2_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
| 10 #include "ash/wm/session_state_animator.h" | 10 #include "ash/wm/session_state_animator.h" |
| 11 #include "ash/wm/session_state_controller.h" |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/timer.h" | 15 #include "base/timer.h" |
| 15 #include "ui/aura/root_window_observer.h" | 16 #include "ui/aura/root_window_observer.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class Rect; | 19 class Rect; |
| 19 class Size; | 20 class Size; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| 23 class Layer; | 24 class Layer; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace ash { | 27 namespace ash { |
| 27 | 28 |
| 28 namespace test { | 29 namespace test { |
| 29 class PowerButtonControllerTest; | 30 class PowerButtonControllerTest; |
| 30 } | 31 } |
| 31 | 32 |
| 32 // Performs system-related functions on behalf of SessionStateController. | |
| 33 class ASH_EXPORT SessionStateControllerDelegate { | |
| 34 public: | |
| 35 SessionStateControllerDelegate() {} | |
| 36 virtual ~SessionStateControllerDelegate() {} | |
| 37 | |
| 38 virtual void RequestLockScreen() = 0; | |
| 39 virtual void RequestShutdown() = 0; | |
| 40 | |
| 41 private: | |
| 42 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerDelegate); | |
| 43 }; | |
| 44 | |
| 45 // Displays onscreen animations and locks or suspends the system in response to | 33 // Displays onscreen animations and locks or suspends the system in response to |
| 46 // the power button being pressed or released. | 34 // the power button being pressed or released. |
| 47 class ASH_EXPORT SessionStateController : public aura::RootWindowObserver, | 35 class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController { |
| 48 public ShellObserver { | |
| 49 public: | 36 public: |
| 50 // Amount of time that the power button needs to be held before we lock the | |
| 51 // screen. | |
| 52 static const int kLockTimeoutMs; | |
| 53 | |
| 54 // Amount of time that the power button needs to be held before we shut down. | |
| 55 static const int kShutdownTimeoutMs; | |
| 56 | |
| 57 // Amount of time to wait for our lock requests to be honored before giving | |
| 58 // up. | |
| 59 static const int kLockFailTimeoutMs; | |
| 60 | |
| 61 // When the button has been held continuously from the unlocked state, amount | |
| 62 // of time that we wait after the screen locker window is shown before | |
| 63 // starting the pre-shutdown animation. | |
| 64 static const int kLockToShutdownTimeoutMs; | |
| 65 | |
| 66 // Amount of time taken to scale the snapshot of the screen down to a | |
| 67 // slightly-smaller size once the user starts holding the power button. Used | |
| 68 // for both the pre-lock and pre-shutdown animations. | |
| 69 static const int kSlowCloseAnimMs; | |
| 70 | |
| 71 // Amount of time taken to scale the snapshot of the screen back to its | |
| 72 // original size when the button is released. | |
| 73 static const int kUndoSlowCloseAnimMs; | |
| 74 | |
| 75 // Amount of time taken to scale the snapshot down to a point in the center of | |
| 76 // the screen once the screen has been locked or we've been notified that the | |
| 77 // system is shutting down. | |
| 78 static const int kFastCloseAnimMs; | |
| 79 | |
| 80 // Additional time (beyond kFastCloseAnimMs) to wait after starting the | |
| 81 // fast-close shutdown animation before actually requesting shutdown, to give | |
| 82 // the animation time to finish. | |
| 83 static const int kShutdownRequestDelayMs; | |
| 84 | 37 |
| 85 // Helper class used by tests to access internal state. | 38 // Helper class used by tests to access internal state. |
| 86 class ASH_EXPORT TestApi { | 39 class ASH_EXPORT TestApi { |
| 87 public: | 40 public: |
| 88 explicit TestApi(SessionStateController* controller); | 41 explicit TestApi(SessionStateControllerImpl2* controller); |
| 89 | 42 |
| 90 virtual ~TestApi(); | 43 virtual ~TestApi(); |
| 91 | 44 |
| 92 bool lock_timer_is_running() const { | 45 bool lock_timer_is_running() const { |
| 93 return controller_->lock_timer_.IsRunning(); | 46 return controller_->lock_timer_.IsRunning(); |
| 94 } | 47 } |
| 95 bool lock_fail_timer_is_running() const { | 48 bool lock_fail_timer_is_running() const { |
| 96 return controller_->lock_fail_timer_.IsRunning(); | 49 return controller_->lock_fail_timer_.IsRunning(); |
| 97 } | 50 } |
| 98 bool lock_to_shutdown_timer_is_running() const { | 51 bool lock_to_shutdown_timer_is_running() const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 119 } | 72 } |
| 120 void trigger_shutdown_timeout() { | 73 void trigger_shutdown_timeout() { |
| 121 controller_->OnPreShutdownAnimationTimeout(); | 74 controller_->OnPreShutdownAnimationTimeout(); |
| 122 controller_->pre_shutdown_timer_.Stop(); | 75 controller_->pre_shutdown_timer_.Stop(); |
| 123 } | 76 } |
| 124 void trigger_real_shutdown_timeout() { | 77 void trigger_real_shutdown_timeout() { |
| 125 controller_->OnRealShutdownTimeout(); | 78 controller_->OnRealShutdownTimeout(); |
| 126 controller_->real_shutdown_timer_.Stop(); | 79 controller_->real_shutdown_timer_.Stop(); |
| 127 } | 80 } |
| 128 private: | 81 private: |
| 129 SessionStateController* controller_; // not owned | 82 SessionStateControllerImpl2* controller_; // not owned |
| 130 | 83 |
| 131 DISALLOW_COPY_AND_ASSIGN(TestApi); | 84 DISALLOW_COPY_AND_ASSIGN(TestApi); |
| 132 }; | 85 }; |
| 133 | 86 |
| 134 SessionStateController(); | 87 SessionStateControllerImpl2(); |
| 135 virtual ~SessionStateController(); | 88 virtual ~SessionStateControllerImpl2(); |
| 136 | 89 |
| 137 // RootWindowObserver override: | 90 // RootWindowObserver override: |
| 138 virtual void OnRootWindowHostCloseRequested( | 91 virtual void OnRootWindowHostCloseRequested( |
| 139 const aura::RootWindow* root) OVERRIDE; | 92 const aura::RootWindow* root) OVERRIDE; |
| 140 | 93 |
| 141 // ShellObserver overrides: | 94 // ShellObserver overrides: |
| 142 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | 95 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; |
| 143 virtual void OnAppTerminating() OVERRIDE; | 96 virtual void OnAppTerminating() OVERRIDE; |
| 144 virtual void OnLockStateChanged(bool locked) OVERRIDE; | 97 virtual void OnLockStateChanged(bool locked) OVERRIDE; |
| 145 | 98 |
| 146 void SetDelegate(SessionStateControllerDelegate* delegate); | |
| 147 | |
| 148 // Returns true iff when we're in state when user session can be locked. | 99 // Returns true iff when we're in state when user session can be locked. |
| 149 virtual bool IsEligibleForLock(); | 100 virtual bool IsEligibleForLock() OVERRIDE; |
| 150 | 101 |
| 151 // Returns true if system is locked. | 102 // Returns true if system is locked. |
| 152 virtual bool IsLocked(); | 103 virtual bool IsLocked() OVERRIDE; |
| 153 | 104 |
| 154 // Starts locking (with slow animation) that can be cancelled. | 105 // Starts locking (with slow animation) that can be cancelled. |
| 155 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() | 106 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() |
| 156 // will be called unless CancelShutdown() is called, if |shutdown_after_lock| | 107 // will be called unless CancelShutdownAnimation() is called, if |
| 157 // is true. | 108 // shutdown_after_lock is true. |
| 158 virtual void StartLockAnimation(bool shutdown_after_lock); | 109 virtual void StartLockAnimation(bool shutdown_after_lock) OVERRIDE; |
| 159 | 110 |
| 160 // Starts shutting down (with slow animation) that can be cancelled. | 111 // Starts shutting down (with slow animation) that can be cancelled. |
| 161 virtual void StartShutdownAnimation(); | 112 virtual void StartShutdownAnimation() OVERRIDE; |
| 162 | 113 |
| 163 // Starts usual lock animation, but locks immediately. | 114 // Starts usual lock animation, but locks immediately. |
| 164 // Unlike StartLockAnimation it does no lead to StartShutdownAnimation. | 115 // Unlike StartLockAnimation it does no lead to StartShutdownAnimation. |
| 165 virtual void StartLockAnimationAndLockImmediately(); | 116 virtual void StartLockAnimationAndLockImmediately() OVERRIDE; |
| 166 | 117 |
| 167 // Returns true if we have requested system to lock, but haven't received | 118 // Returns true if we have requested system to lock, but haven't received |
| 168 // confirmation yet. | 119 // confirmation yet. |
| 169 virtual bool LockRequested(); | 120 virtual bool LockRequested() OVERRIDE; |
| 170 | 121 |
| 171 // Returns true if we are shutting down. | 122 // Returns true if we are shutting down. |
| 172 virtual bool ShutdownRequested(); | 123 virtual bool ShutdownRequested() OVERRIDE; |
| 173 | 124 |
| 174 // Returns true if we are within cancellable lock timeframe. | 125 // Returns true if we are within cancellable lock timeframe. |
| 175 virtual bool CanCancelLockAnimation(); | 126 virtual bool CanCancelLockAnimation() OVERRIDE; |
| 176 | 127 |
| 177 // Cancels locking and reverts lock animation. | 128 // Cancels locking and reverts lock animation. |
| 178 virtual void CancelLockAnimation(); | 129 virtual void CancelLockAnimation() OVERRIDE; |
| 179 | |
| 180 // Cancels locking and reverts lock animation with slightly different | |
| 181 // parameters. Seems to be some bug, but refactoring should keep all bugs. | |
| 182 // TODO(antrim): remove this, animations should actually be the same. | |
| 183 virtual void CancelLockWithOtherAnimation(); | |
| 184 | 130 |
| 185 // Returns true if we are within cancellable shutdown timeframe. | 131 // Returns true if we are within cancellable shutdown timeframe. |
| 186 virtual bool CanCancelShutdownAnimation(); | 132 virtual bool CanCancelShutdownAnimation() OVERRIDE; |
| 187 | 133 |
| 188 // Cancels shutting down and reverts shutdown animation. | 134 // Cancels shutting down and reverts shutdown animation. |
| 189 virtual void CancelShutdownAnimation(); | 135 virtual void CancelShutdownAnimation() OVERRIDE; |
| 190 | 136 |
| 191 // Called when Chrome gets a request to display the lock screen. | 137 // Called when Chrome gets a request to display the lock screen. |
| 192 virtual void OnStartingLock(); | 138 virtual void OnStartingLock() OVERRIDE; |
| 193 | 139 |
| 194 // Displays the shutdown animation and requests shutdown when it's done. | 140 // Displays the shutdown animation and requests shutdown when it's done. |
| 195 virtual void RequestShutdown(); | 141 virtual void RequestShutdown() OVERRIDE; |
| 196 | 142 |
| 197 protected: | 143 protected: |
| 198 friend class test::PowerButtonControllerTest; | 144 friend class test::PowerButtonControllerTest; |
| 199 | 145 |
| 200 bool IsLoggedInAsNonGuest() const; | 146 bool IsLoggedInAsNonGuest() const; |
| 201 | 147 |
| 202 private: | 148 private: |
| 203 void RequestShutdownImpl(); | 149 void RequestShutdownImpl(); |
| 204 | 150 |
| 205 // Starts lock timer. | 151 // Starts lock timer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 222 | 168 |
| 223 // Calls RequestShutdownImpl(); | 169 // Calls RequestShutdownImpl(); |
| 224 void OnPreShutdownAnimationTimeout(); | 170 void OnPreShutdownAnimationTimeout(); |
| 225 | 171 |
| 226 // Starts timer for final shutdown animation. | 172 // Starts timer for final shutdown animation. |
| 227 void StartRealShutdownTimer(); | 173 void StartRealShutdownTimer(); |
| 228 | 174 |
| 229 // Requests that the machine be shut down. | 175 // Requests that the machine be shut down. |
| 230 void OnRealShutdownTimeout(); | 176 void OnRealShutdownTimeout(); |
| 231 | 177 |
| 232 // The current login status. | 178 // The current login status, or original login status from before we locked.. |
| 233 user::LoginStatus login_status_; | 179 user::LoginStatus login_status_; |
| 234 | 180 |
| 235 // Original login status from before we locked. LOGGED_IN_NONE if it's not | 181 // Current lock status. |
| 236 // locked. | 182 bool system_is_locked_; |
| 237 user::LoginStatus unlocked_login_status_; | |
| 238 | 183 |
| 239 // Are we in the process of shutting the machine down? | 184 // Are we in the process of shutting the machine down? |
| 240 bool shutting_down_; | 185 bool shutting_down_; |
| 241 | 186 |
| 242 // Indicates whether controller should proceed to (cancellable) shutdown after | 187 // Indicates whether controller should proceed to (cancellable) shutdown after |
| 243 // locking. | 188 // locking. |
| 244 bool shutdown_after_lock_; | 189 bool shutdown_after_lock_; |
| 245 | 190 |
| 246 // Started when the user first presses the power button while in a | 191 // Started when the user first presses the power button while in a |
| 247 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the | 192 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the |
| 248 // screen. | 193 // screen. |
| 249 base::OneShotTimer<SessionStateController> lock_timer_; | 194 base::OneShotTimer<SessionStateControllerImpl2> lock_timer_; |
| 250 | 195 |
| 251 // Started when we request that the screen be locked. When it fires, we | 196 // Started when we request that the screen be locked. When it fires, we |
| 252 // assume that our request got dropped. | 197 // assume that our request got dropped. |
| 253 base::OneShotTimer<SessionStateController> lock_fail_timer_; | 198 base::OneShotTimer<SessionStateControllerImpl2> lock_fail_timer_; |
| 254 | 199 |
| 255 // Started when the screen is locked while the power button is held. Adds a | 200 // Started when the screen is locked while the power button is held. Adds a |
| 256 // delay between the appearance of the lock screen and the beginning of the | 201 // delay between the appearance of the lock screen and the beginning of the |
| 257 // pre-shutdown animation. | 202 // pre-shutdown animation. |
| 258 base::OneShotTimer<SessionStateController> lock_to_shutdown_timer_; | 203 base::OneShotTimer<SessionStateControllerImpl2> lock_to_shutdown_timer_; |
| 259 | 204 |
| 260 // Started when we begin displaying the pre-shutdown animation. When it | 205 // Started when we begin displaying the pre-shutdown animation. When it |
| 261 // fires, we start the shutdown animation and get ready to request shutdown. | 206 // fires, we start the shutdown animation and get ready to request shutdown. |
| 262 base::OneShotTimer<SessionStateController> pre_shutdown_timer_; | 207 base::OneShotTimer<SessionStateControllerImpl2> pre_shutdown_timer_; |
| 263 | 208 |
| 264 // Started when we display the shutdown animation. When it fires, we actually | 209 // Started when we display the shutdown animation. When it fires, we actually |
| 265 // request shutdown. Gives the animation time to complete before Chrome, X, | 210 // request shutdown. Gives the animation time to complete before Chrome, X, |
| 266 // etc. are shut down. | 211 // etc. are shut down. |
| 267 base::OneShotTimer<SessionStateController> real_shutdown_timer_; | 212 base::OneShotTimer<SessionStateControllerImpl2> real_shutdown_timer_; |
| 268 | 213 |
| 269 scoped_ptr<internal::SessionStateAnimator> animator_; | 214 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2); |
| 270 | |
| 271 scoped_ptr<SessionStateControllerDelegate> delegate_; | |
| 272 | |
| 273 DISALLOW_COPY_AND_ASSIGN(SessionStateController); | |
| 274 }; | 215 }; |
| 275 | 216 |
| 276 } // namespace ash | 217 } // namespace ash |
| 277 | 218 |
| 278 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_ | 219 #endif // ASH_WM_SESSION_STATE_CONTROLLER_IMPL2_H_ |
| OLD | NEW |