OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/chromeos/power/tablet_power_button_controller.h" | 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
6 | 6 |
7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shell_delegate.h" | 9 #include "ash/common/shell_delegate.h" |
10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/wm/lock_state_controller.h" | 13 #include "ash/wm/lock_state_controller.h" |
14 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "ui/events/devices/input_device_manager.h" | 16 #include "ui/events/devices/input_device_manager.h" |
17 #include "ui/events/devices/stylus_state.h" | 17 #include "ui/events/devices/stylus_state.h" |
18 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Amount of time the power button must be held to start the pre-shutdown | 24 // Amount of time the power button must be held to start the pre-shutdown |
25 // animation when in tablet mode. | 25 // animation when in tablet mode. |
26 constexpr int kShutdownTimeoutMs = 1000; | 26 constexpr int kShutdownTimeoutMs = 1000; |
27 | 27 |
28 // Amount of time that locking screen needs to be waited to start the actual | |
Daniel Erat
2017/01/11 23:09:06
this comment is a bit confusing. is it more like:
Qiang(Joe) Xu
2017/01/12 00:04:45
That is not right. This cl is about: "after set di
| |
29 // locking screen. | |
30 constexpr int kLockScreenTimeoutMs = 1000; | |
31 | |
28 // Amount of time since last SuspendDone() that power button event needs to be | 32 // Amount of time since last SuspendDone() that power button event needs to be |
29 // ignored. | 33 // ignored. |
30 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; | 34 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; |
31 | 35 |
32 // Returns true if device is a convertible/tablet device or has | 36 // Returns true if device is a convertible/tablet device or has |
33 // kAshEnableTouchViewTesting in test, otherwise false. | 37 // kAshEnableTouchViewTesting in test, otherwise false. |
34 bool IsTabletModeSupported() { | 38 bool IsTabletModeSupported() { |
35 MaximizeModeController* maximize_mode_controller = | 39 MaximizeModeController* maximize_mode_controller = |
36 WmShell::Get()->maximize_mode_controller(); | 40 WmShell::Get()->maximize_mode_controller(); |
37 return maximize_mode_controller && | 41 return maximize_mode_controller && |
(...skipping 19 matching lines...) Expand all Loading... | |
57 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { | 61 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { |
58 return controller_->shutdown_timer_.IsRunning(); | 62 return controller_->shutdown_timer_.IsRunning(); |
59 } | 63 } |
60 | 64 |
61 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { | 65 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { |
62 DCHECK(ShutdownTimerIsRunning()); | 66 DCHECK(ShutdownTimerIsRunning()); |
63 controller_->OnShutdownTimeout(); | 67 controller_->OnShutdownTimeout(); |
64 controller_->shutdown_timer_.Stop(); | 68 controller_->shutdown_timer_.Stop(); |
65 } | 69 } |
66 | 70 |
71 bool TabletPowerButtonController::TestApi::LockScreenTimerIsRunning() const { | |
72 return controller_->lock_screen_timer_.IsRunning(); | |
73 } | |
74 | |
75 void TabletPowerButtonController::TestApi::TriggerLockScreenTimeout() { | |
76 DCHECK(LockScreenTimerIsRunning()); | |
77 controller_->OnLockScreenTimeout(); | |
78 controller_->lock_screen_timer_.Stop(); | |
79 } | |
80 | |
67 TabletPowerButtonController::TabletPowerButtonController( | 81 TabletPowerButtonController::TabletPowerButtonController( |
68 LockStateController* controller) | 82 LockStateController* controller) |
69 : tick_clock_(new base::DefaultTickClock()), | 83 : tick_clock_(new base::DefaultTickClock()), |
70 last_resume_time_(base::TimeTicks()), | 84 last_resume_time_(base::TimeTicks()), |
71 force_off_on_button_up_(true), | 85 force_off_on_button_up_(true), |
72 controller_(controller), | 86 controller_(controller), |
73 weak_ptr_factory_(this) { | 87 weak_ptr_factory_(this) { |
74 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 88 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
75 this); | 89 this); |
76 WmShell::Get()->AddShellObserver(this); | 90 WmShell::Get()->AddShellObserver(this); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 backlights_forced_off_ = forced_off; | 213 backlights_forced_off_ = forced_off; |
200 | 214 |
201 ShellDelegate* delegate = WmShell::Get()->delegate(); | 215 ShellDelegate* delegate = WmShell::Get()->delegate(); |
202 delegate->SetTouchscreenEnabledInPrefs(!forced_off, | 216 delegate->SetTouchscreenEnabledInPrefs(!forced_off, |
203 true /* use_local_state */); | 217 true /* use_local_state */); |
204 delegate->UpdateTouchscreenStatusFromPrefs(); | 218 delegate->UpdateTouchscreenStatusFromPrefs(); |
205 | 219 |
206 // Send an a11y alert. | 220 // Send an a11y alert. |
207 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( | 221 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( |
208 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); | 222 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); |
223 | |
224 // Reset |lock_screen_timer_| when display is not set to forced off since | |
Daniel Erat
2017/01/11 23:09:06
this doesn't feel like the right place for this co
Qiang(Joe) Xu
2017/01/12 00:04:45
Agree that we should put it in all the places wher
| |
225 // under this case, |lock_screen_timer_| should not timeout. | |
Daniel Erat
2017/01/11 23:09:06
nit: s/timeout/time out/ ("time out" is verb, "tim
Qiang(Joe) Xu
2017/01/12 00:04:45
done by removing.
| |
226 if (!forced_off) | |
227 lock_screen_timer_.Stop(); | |
Qiang(Joe) Xu
2017/01/11 22:17:06
Moved here: since besides two quick power button t
| |
209 } | 228 } |
210 | 229 |
211 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { | 230 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { |
212 chromeos::DBusThreadManager::Get() | 231 chromeos::DBusThreadManager::Get() |
213 ->GetPowerManagerClient() | 232 ->GetPowerManagerClient() |
214 ->GetBacklightsForcedOff(base::Bind( | 233 ->GetBacklightsForcedOff(base::Bind( |
215 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, | 234 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, |
216 weak_ptr_factory_.GetWeakPtr())); | 235 weak_ptr_factory_.GetWeakPtr())); |
217 } | 236 } |
218 | 237 |
(...skipping 12 matching lines...) Expand all Loading... | |
231 controller_->StartShutdownAnimation(); | 250 controller_->StartShutdownAnimation(); |
232 } | 251 } |
233 | 252 |
234 void TabletPowerButtonController::LockScreenIfRequired() { | 253 void TabletPowerButtonController::LockScreenIfRequired() { |
235 SessionStateDelegate* session_state_delegate = | 254 SessionStateDelegate* session_state_delegate = |
236 WmShell::Get()->GetSessionStateDelegate(); | 255 WmShell::Get()->GetSessionStateDelegate(); |
237 if (session_state_delegate->ShouldLockScreenAutomatically() && | 256 if (session_state_delegate->ShouldLockScreenAutomatically() && |
238 session_state_delegate->CanLockScreen() && | 257 session_state_delegate->CanLockScreen() && |
239 !session_state_delegate->IsUserSessionBlocked() && | 258 !session_state_delegate->IsUserSessionBlocked() && |
240 !controller_->LockRequested()) { | 259 !controller_->LockRequested()) { |
241 session_state_delegate->LockScreen(); | 260 StartLockScreenTimer(); |
242 } | 261 } |
243 } | 262 } |
244 | 263 |
264 void TabletPowerButtonController::StartLockScreenTimer() { | |
265 lock_screen_timer_.Start( | |
Daniel Erat
2017/01/11 23:09:06
mind moving this into LockScreenIfRequired since i
Qiang(Joe) Xu
2017/01/12 00:04:45
Done.
| |
266 FROM_HERE, base::TimeDelta::FromMilliseconds(kLockScreenTimeoutMs), this, | |
267 &TabletPowerButtonController::OnLockScreenTimeout); | |
268 } | |
269 | |
270 void TabletPowerButtonController::OnLockScreenTimeout() { | |
271 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); | |
272 } | |
273 | |
245 } // namespace ash | 274 } // namespace ash |
OLD | NEW |