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

Side by Side Diff: ash/wm/session_state_controller.h

Issue 11091023: ash : Decouple power button controller and session state controller. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initialize variable Created 8 years, 2 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_H_
6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_
7
8 #include "ash/ash_export.h"
9 #include "ash/shell_observer.h"
10 #include "ash/wm/session_state_animator.h"
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h"
14 #include "base/timer.h"
15 #include "ui/aura/root_window_observer.h"
16
17 namespace gfx {
18 class Rect;
19 class Size;
20 }
21
22 namespace ui {
23 class Layer;
24 }
25
26 namespace ash {
27
28 namespace test {
29 class PowerButtonControllerTest;
30 }
31
32 namespace internal {
Daniel Erat 2012/10/11 15:08:30 why do you need all of these in the header instead
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 I will have two implementations that would reuse t
Daniel Erat 2012/10/11 16:16:42 please make them be protected static members of th
33 // Amount of time that the power button needs to be held before we lock the
34 // screen.
35 const int kLockTimeoutMs = 400;
36
37 // Amount of time that the power button needs to be held before we shut down.
38 const int kShutdownTimeoutMs = 400;
39
40 // Amount of time to wait for our lock requests to be honored before giving up.
41 const int kLockFailTimeoutMs = 4000;
42
43 // When the button has been held continuously from the unlocked state, amount of
44 // time that we wait after the screen locker window is shown before starting the
45 // pre-shutdown animation.
46 const int kLockToShutdownTimeoutMs = 150;
47
48 // Amount of time taken to scale the snapshot of the screen down to a
49 // slightly-smaller size once the user starts holding the power button. Used
50 // for both the pre-lock and pre-shutdown animations.
51 const int kSlowCloseAnimMs = 400;
52
53 // Amount of time taken to scale the snapshot of the screen back to its original
54 // size when the button is released.
55 const int kUndoSlowCloseAnimMs = 100;
56
57 // Amount of time taken to scale the snapshot down to a point in the center of
58 // the screen once the screen has been locked or we've been notified that the
59 // system is shutting down.
60 const int kFastCloseAnimMs = 150;
61
62 // Additional time (beyond kFastCloseAnimMs) to wait after starting the
63 // fast-close shutdown animation before actually requesting shutdown, to give
64 // the animation time to finish.
65 const int kShutdownRequestDelayMs = 50;
66 }
67
68 // Performs system-related functions on behalf of SessionStateController.
69 class ASH_EXPORT SessionStateControllerDelegate {
70 public:
71 SessionStateControllerDelegate() {}
72 virtual ~SessionStateControllerDelegate() {}
73
74 virtual void RequestLockScreen() = 0;
75 virtual void RequestShutdown() = 0;
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerDelegate);
79 };
80
81 // Displays onscreen animations and locks or suspends the system in response to
82 // the power button being pressed or released.
83 class ASH_EXPORT SessionStateController : public aura::RootWindowObserver,
84 public ShellObserver {
85 public:
86
87 // Helper class used by tests to access internal state.
88 class ASH_EXPORT TestApi {
89 public:
90 explicit TestApi(SessionStateController* controller);
91
92 virtual ~TestApi();
93
94 bool lock_timer_is_running() const {
95 return controller_->lock_timer_.IsRunning();
96 }
97 bool lock_fail_timer_is_running() const {
98 return controller_->lock_fail_timer_.IsRunning();
99 }
100 bool lock_to_shutdown_timer_is_running() const {
101 return controller_->lock_to_shutdown_timer_.IsRunning();
102 }
103 bool shutdown_timer_is_running() const {
104 return controller_->pre_shutdown_timer_.IsRunning();
105 }
106 bool real_shutdown_timer_is_running() const {
107 return controller_->real_shutdown_timer_.IsRunning();
108 }
109
110 void trigger_lock_timeout() {
111 controller_->OnLockTimeout();
112 controller_->lock_timer_.Stop();
113 }
114 void trigger_lock_fail_timeout() {
115 controller_->OnLockFailTimeout();
116 controller_->lock_fail_timer_.Stop();
117 }
118 void trigger_lock_to_shutdown_timeout() {
119 controller_->OnLockToShutdownTimeout();
120 controller_->lock_to_shutdown_timer_.Stop();
121 }
122 void trigger_shutdown_timeout() {
123 controller_->OnPreShutdownAnimationTimeout();
124 controller_->pre_shutdown_timer_.Stop();
125 }
126 void trigger_real_shutdown_timeout() {
127 controller_->OnRealShutdownTimeout();
128 controller_->real_shutdown_timer_.Stop();
129 }
130 private:
131 SessionStateController* controller_; // not owned
132
133 DISALLOW_COPY_AND_ASSIGN(TestApi);
134 };
135
136 SessionStateController();
137 virtual ~SessionStateController();
138
139 void set_delegate(SessionStateControllerDelegate* delegate) {
140 delegate_.reset(delegate);
141 }
142
143 // Returns true iff when we're in state when user session can be locked.
144 virtual bool IsEligibleForLock();
Daniel Erat 2012/10/11 15:08:30 can this and many other similar methods be const?
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Same as above - there would be two actual implemen
145
146 // Returns true if system is locked.
147 virtual bool IsLocked();
148
149 // Starts locking (with slow animation) that can be cancelled.
150 // After locking and |kLockToShutdownTimeoutMs| StartCancellableShutdown()
151 // will be called unless CancelShutdown() is called.
152 virtual void StartCancellableLock();
153
154 // Starts shutting down (with slow animation) that can be cancelled.
155 virtual void StartCancellableShutdown();
156
157 // Starts shutdown that can not be undone.
158 virtual void ShutdownImmediately();
159
160 // Starts usual lock animation, but lock immediately.
161 virtual void StartLockAnimationButLockImmediately();
Daniel Erat 2012/10/11 15:08:30 nit: s/But/And/
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
162
163 // Returns true if we have requested system to lock, but havan't recieved
Daniel Erat 2012/10/11 15:08:30 nit: s/havan't/haven't/
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
164 // confirmation yet.
165 virtual bool IsTryingToLock();
166
167 // Returns true if we are within cancellable lock timeframe or trying to lock.
168 virtual bool IsLocking();
Daniel Erat 2012/10/11 15:08:30 i think that the IsTryingToLock() vs. IsLocking()
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
169
170 // Returns true if we are shutting down.
171 virtual bool IsShuttingDown();
172
173 // Returns true if we are within cancellable lock timeframe.
174 virtual bool CanCancelLock();
175
176 // Cancels locking and reverts lock animation.
177 virtual void CancelLock();
178
179 // Cancels locking and reverts lock animation with slightly different
180 // parameters. Seems to be some bug, but refactoring should keep all bugs.
Daniel Erat 2012/10/11 15:08:30 add a TODO to remove this; put the explanation the
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
181 virtual void CancelLockWithOtherAnimation();
182
183 // Returns true if we are within cancellable shutdown timeframe.
184 virtual bool CanCancelShutdown();
Daniel Erat 2012/10/11 15:08:30 i recommend the same thing here: CanCancelShutdow
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
185
186 // Cancels shutting down and reverts shutdown animation.
187 virtual void CancelShutdown();
188
189
Daniel Erat 2012/10/11 15:08:30 nit: delete extra blank line
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
190 // Called when Chrome gets a request to display the lock screen.
191 virtual void OnStartingLock();
192
193 // Displays the shutdown animation and requests shutdown when it's done.
194 virtual void RequestShutdown();
195
196
Daniel Erat 2012/10/11 15:08:30 nit: delete extra blank line
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
197 // RootWindowObserver override:
198 virtual void OnRootWindowHostCloseRequested(
199 const aura::RootWindow* root) OVERRIDE;
Daniel Erat 2012/10/11 15:08:30 nit: fix indenting
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
200
201 // ShellObserver overrides:
202 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE;
203 virtual void OnAppTerminating() OVERRIDE;
204 virtual void OnLockStateChanged(bool locked) OVERRIDE;
205
206 protected:
207 friend class test::PowerButtonControllerTest;
208
209 bool LoggedInAsNonGuest() const;
210
211
Daniel Erat 2012/10/11 15:08:30 nit: delete extra blank line
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
212 private:
213 void RequestShutdownImpl();
214
215 // Timer stuff.
Daniel Erat 2012/10/11 15:08:30 nit: delete unnecessary comment
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
216
217 // Starts lock timer.
218 void StartLockTimer();
219
220 // Requests that the screen be locked and starts |lock_fail_timer_|.
221 void OnLockTimeout();
222
223 // Reverts the pre-lock animation, reports the error.
224 void OnLockFailTimeout();
225
226 // Starts timer for gap between lock and shutdown.
227 void StartLockToShutdownTimer();
228 // Calls StartCancellableShutdown().
Daniel Erat 2012/10/11 15:08:30 nit: add blank line before this one
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
229 void OnLockToShutdownTimeout();
230
231 // Starts timer for undoable shutdown animation.
232 void StartPreShutdownAnimationTimer();
233 // Calls RequestShutdownImpl();
Daniel Erat 2012/10/11 15:08:30 nit: add blank line before this one
Denis Kuznetsov (DE-MUC) 2012/10/11 16:14:38 Done.
234 void OnPreShutdownAnimationTimeout();
235
236 // Starts timer for final shutdown animation.
237 void StartRealShutdownTimer();
238 // Requests that the machine be shut down.
239 void OnRealShutdownTimeout();
240
241 // The current login status.
242 user::LoginStatus login_status_;
243
244 // Original login status during locked. LOGGED_IN_NONE if it's not locked.
245 user::LoginStatus unlocked_login_status_;
246
247 // Are we in the process of shutting the machine down?
248 bool shutting_down_;
249
250 // Indicates whether controller should proceed to (cancellable) shutdown after
251 // locking.
252 bool shutdown_after_lock_;
253
254 // Started when the user first presses the power button while in a
255 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the
256 // screen.
257 base::OneShotTimer<SessionStateController> lock_timer_;
258
259 // Started when we request that the screen be locked. When it fires, we
260 // assume that our request got dropped.
261 base::OneShotTimer<SessionStateController> lock_fail_timer_;
262
263 // Started when the screen is locked while the power button is held. Adds a
264 // delay between the appearance of the lock screen and the beginning of the
265 // pre-shutdown animation.
266 base::OneShotTimer<SessionStateController> lock_to_shutdown_timer_;
267
268 // Started when we begin displaying the pre-shutdown animation. When it
269 // fires, we start the shutdown animation and get ready to request shutdown.
270 base::OneShotTimer<SessionStateController> pre_shutdown_timer_;
271
272 // Started when we display the shutdown animation. When it fires, we actually
273 // request shutdown. Gives the animation time to complete before Chrome, X,
274 // etc. are shut down.
275 base::OneShotTimer<SessionStateController> real_shutdown_timer_;
276
277 scoped_ptr<internal::SessionStateAnimator> animator_;
278
279 scoped_ptr<SessionStateControllerDelegate> delegate_;
280
281 DISALLOW_COPY_AND_ASSIGN(SessionStateController);
282 };
283
284 } // namespace ash
285
286 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698