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

Side by Side Diff: ash/wm/power_button_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: 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
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_POWER_BUTTON_CONTROLLER_H_ 5 #ifndef ASH_WM_POWER_BUTTON_CONTROLLER_H_
6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ 6 #define ASH_WM_POWER_BUTTON_CONTROLLER_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"
Daniel Erat 2012/10/09 17:28:55 remove this if it isn't needed
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
10 #include "ash/wm/session_state_animator.h" 10 #include "ash/wm/session_state_animator.h"
Daniel Erat 2012/10/09 17:28:55 remove this if it isn't needed
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
Daniel Erat 2012/10/09 17:28:55 remove this if it isn't needed
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
Daniel Erat 2012/10/09 17:28:55 remove this if it isn't needed
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
15 #include "ui/aura/root_window_observer.h" 15 #include "ui/aura/root_window_observer.h"
Daniel Erat 2012/10/09 17:28:55 remove this if it isn't needed
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
16 16
17 namespace gfx { 17 namespace gfx {
18 class Rect; 18 class Rect;
19 class Size; 19 class Size;
20 } 20 }
21 21
22 namespace ui { 22 namespace ui {
23 class Layer; 23 class Layer;
24 } 24 }
25 25
26
Nikita (slow) 2012/10/09 18:30:06 nit: drop extra empty line
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
26 namespace ash { 27 namespace ash {
27 28
28 // Performs system-related functions on behalf of PowerButtonController. 29 namespace test {
29 class ASH_EXPORT PowerButtonControllerDelegate { 30 class PowerButtonControllerTest;
30 public: 31 }
31 PowerButtonControllerDelegate() {}
32 virtual ~PowerButtonControllerDelegate() {}
33 32
34 virtual void RequestLockScreen() = 0; 33 class SessionStateController;
35 virtual void RequestShutdown() = 0;
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate);
39 };
40 34
41 // Displays onscreen animations and locks or suspends the system in response to 35 // Displays onscreen animations and locks or suspends the system in response to
42 // the power button being pressed or released. 36 // the power button being pressed or released.
43 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, 37 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver {
Daniel Erat 2012/10/09 17:28:55 do you still need RootWindowObserver?
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
44 public ShellObserver {
45 public: 38 public:
46 39
47 // Helper class used by tests to access internal state. 40 PowerButtonController(SessionStateController* controller);
Nikita (slow) 2012/10/09 18:30:06 Add explicit http://google-styleguide.googlecode.c
Denis Kuznetsov (DE-MUC) 2012/10/11 11:37:12 Done.
48 class ASH_EXPORT TestApi {
49 public:
50 explicit TestApi(PowerButtonController* controller);
51
52 virtual ~TestApi();
53
54 bool lock_timer_is_running() const {
55 return controller_->lock_timer_.IsRunning();
56 }
57 bool lock_fail_timer_is_running() const {
58 return controller_->lock_fail_timer_.IsRunning();
59 }
60 bool lock_to_shutdown_timer_is_running() const {
61 return controller_->lock_to_shutdown_timer_.IsRunning();
62 }
63 bool shutdown_timer_is_running() const {
64 return controller_->shutdown_timer_.IsRunning();
65 }
66 bool real_shutdown_timer_is_running() const {
67 return controller_->real_shutdown_timer_.IsRunning();
68 }
69 bool hide_black_layer_timer_is_running() const {
70 return animator_api_->hide_black_layer_timer_is_running();
71 }
72
73 void trigger_lock_timeout() {
74 controller_->OnLockTimeout();
75 controller_->lock_timer_.Stop();
76 }
77 void trigger_lock_fail_timeout() {
78 controller_->OnLockFailTimeout();
79 controller_->lock_fail_timer_.Stop();
80 }
81 void trigger_lock_to_shutdown_timeout() {
82 controller_->OnLockToShutdownTimeout();
83 controller_->lock_to_shutdown_timer_.Stop();
84 }
85 void trigger_shutdown_timeout() {
86 controller_->OnShutdownTimeout();
87 controller_->shutdown_timer_.Stop();
88 }
89 void trigger_real_shutdown_timeout() {
90 controller_->OnRealShutdownTimeout();
91 controller_->real_shutdown_timer_.Stop();
92 }
93 void TriggerHideBlackLayerTimeout() {
94 animator_api_->TriggerHideBlackLayerTimeout();
95 }
96
97 // Returns true if containers of a given |container_mask|
98 // were last animated with |type| (probably; the analysis is fairly ad-hoc).
99 // |container_mask| is a bitfield of a Container.
100 bool ContainersAreAnimated(int container_mask,
101 internal::SessionStateAnimator::AnimationType type) const {
102 return animator_api_->ContainersAreAnimated(container_mask, type);
103 }
104
105 // Returns true if |black_layer_| is non-NULL and visible.
106 bool BlackLayerIsVisible() {
107 return animator_api_->BlackLayerIsVisible();
108 }
109
110 // Returns |black_layer_|'s bounds, or an empty rect if the layer is
111 // NULL.
112 gfx::Rect GetBlackLayerBounds() const {
113 return animator_api_->GetBlackLayerBounds();
114 }
115
116 private:
117 PowerButtonController* controller_; // not owned
118
119 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_;
120
121 DISALLOW_COPY_AND_ASSIGN(TestApi);
122 };
123
124 PowerButtonController();
125 virtual ~PowerButtonController(); 41 virtual ~PowerButtonController();
126 42
127 void set_delegate(PowerButtonControllerDelegate* delegate) {
128 delegate_.reset(delegate);
129 }
130
131 void set_has_legacy_power_button_for_test(bool legacy) { 43 void set_has_legacy_power_button_for_test(bool legacy) {
132 has_legacy_power_button_ = legacy; 44 has_legacy_power_button_ = legacy;
133 } 45 }
134 46
135 // Called when the current screen brightness changes. 47 // Called when the current screen brightness changes.
136 void OnScreenBrightnessChanged(double percent); 48 void OnScreenBrightnessChanged(double percent);
137 49
138 // Called when Chrome gets a request to display the lock screen.
139 void OnStartingLock();
140
141 // Called when the power or lock buttons are pressed or released. 50 // Called when the power or lock buttons are pressed or released.
142 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); 51 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
143 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); 52 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp);
144 53
145 // Displays the shutdown animation and requests shutdown when it's done.
146 void RequestShutdown();
147
148 virtual void OnRootWindowHostCloseRequested(
149 const aura::RootWindow* root) OVERRIDE;
150
151 // ShellObserver overrides:
152 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE;
153 virtual void OnAppTerminating() OVERRIDE;
154 virtual void OnLockStateChanged(bool locked) OVERRIDE;
155
156 private: 54 private:
157 bool LoggedInAsNonGuest() const; 55 friend class test::PowerButtonControllerTest;
158
159 // Requests that the screen be locked and starts |lock_fail_timer_|.
160 void OnLockTimeout();
161
162 // Aborts the pre-lock animation.
163 void OnLockFailTimeout();
164
165 // Displays the pre-shutdown animation and starts |shutdown_timer_|.
166 void OnLockToShutdownTimeout();
167
168 // Calls StartShutdownAnimationAndRequestShutdown().
169 void OnShutdownTimeout();
170
171 // Requests that the machine be shut down.
172 void OnRealShutdownTimeout();
173
174 // Puts us into the pre-lock or pre-shutdown state.
175 void StartLockTimer();
176 void StartShutdownTimer();
177
178 // Displays the shutdown animation and starts |real_shutdown_timer_|.
179 void StartShutdownAnimationAndRequestShutdown();
180
181 scoped_ptr<PowerButtonControllerDelegate> delegate_;
182
183 // The current login status.
184 user::LoginStatus login_status_;
185
186 // Original login status during locked. LOGGED_IN_NONE if it's not locked.
187 user::LoginStatus unlocked_login_status_;
188 56
189 // Are the power or lock buttons currently held? 57 // Are the power or lock buttons currently held?
190 bool power_button_down_; 58 bool power_button_down_;
191 bool lock_button_down_; 59 bool lock_button_down_;
192 60
193 // Is the screen currently turned off? 61 // Is the screen currently turned off?
194 bool screen_is_off_; 62 bool screen_is_off_;
195 63
196 // Are we in the process of shutting the machine down?
197 bool shutting_down_;
198
199 // Was a command-line switch set telling us that we're running on hardware 64 // Was a command-line switch set telling us that we're running on hardware
200 // that misreports power button releases? 65 // that misreports power button releases?
201 bool has_legacy_power_button_; 66 bool has_legacy_power_button_;
202 67
203 // Started when the user first presses the power button while in a 68 SessionStateController* controller_; // Not owned.
204 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the
205 // screen.
206 base::OneShotTimer<PowerButtonController> lock_timer_;
207
208 // Started when we request that the screen be locked. When it fires, we
209 // assume that our request got dropped.
210 base::OneShotTimer<PowerButtonController> lock_fail_timer_;
211
212 // Started when the screen is locked while the power button is held. Adds a
213 // delay between the appearance of the lock screen and the beginning of the
214 // pre-shutdown animation.
215 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_;
216
217 // Started when we begin displaying the pre-shutdown animation. When it
218 // fires, we start the shutdown animation and get ready to request shutdown.
219 base::OneShotTimer<PowerButtonController> shutdown_timer_;
220
221 // Started when we display the shutdown animation. When it fires, we actually
222 // request shutdown. Gives the animation time to complete before Chrome, X,
223 // etc. are shut down.
224 base::OneShotTimer<PowerButtonController> real_shutdown_timer_;
225
226 scoped_ptr<internal::SessionStateAnimator> animator_;
227 69
228 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); 70 DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
229 }; 71 };
230 72
231 } // namespace ash 73 } // namespace ash
232 74
233 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ 75 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698