Chromium Code Reviews| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { | 61 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { |
| 62 DCHECK(ShutdownTimerIsRunning()); | 62 DCHECK(ShutdownTimerIsRunning()); |
| 63 controller_->OnShutdownTimeout(); | 63 controller_->OnShutdownTimeout(); |
| 64 controller_->shutdown_timer_.Stop(); | 64 controller_->shutdown_timer_.Stop(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 TabletPowerButtonController::TabletPowerButtonController( | 67 TabletPowerButtonController::TabletPowerButtonController( |
| 68 LockStateController* controller) | 68 LockStateController* controller) |
| 69 : tick_clock_(new base::DefaultTickClock()), | 69 : tick_clock_(new base::DefaultTickClock()), |
| 70 last_resume_time_(base::TimeTicks()), | 70 last_resume_time_(base::TimeTicks()), |
| 71 force_off_on_button_up_(true), | |
| 71 controller_(controller), | 72 controller_(controller), |
| 72 weak_ptr_factory_(this) { | 73 weak_ptr_factory_(this) { |
| 73 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 74 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 74 this); | 75 this); |
| 75 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 76 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| 76 Shell::GetInstance()->PrependPreTargetHandler(this); | 77 Shell::GetInstance()->PrependPreTargetHandler(this); |
| 77 | 78 |
| 78 GetInitialBacklightsForcedOff(); | 79 GetInitialBacklightsForcedOff(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 TabletPowerButtonController::~TabletPowerButtonController() { | 82 TabletPowerButtonController::~TabletPowerButtonController() { |
| 82 Shell::GetInstance()->RemovePreTargetHandler(this); | 83 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 83 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 84 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| 84 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 85 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 85 this); | 86 this); |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool TabletPowerButtonController::ShouldHandlePowerButtonEvents() const { | 89 bool TabletPowerButtonController::ShouldHandlePowerButtonEvents() const { |
| 89 return IsTabletModeSupported(); | 90 return IsTabletModeSupported(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void TabletPowerButtonController::OnPowerButtonEvent( | 93 void TabletPowerButtonController::OnPowerButtonEvent( |
| 93 bool down, | 94 bool down, |
| 94 const base::TimeTicks& timestamp) { | 95 const base::TimeTicks& timestamp) { |
| 95 // When the system resumes in response to the power button being pressed, | |
| 96 // Chrome receives powerd's SuspendDone signal and notification that the | |
| 97 // backlight has been turned back on before seeing the power button events | |
| 98 // that woke the system. Ignore events just after resuming to ensure that we | |
| 99 // don't turn the screen off in response to the events. | |
| 100 // | |
| 101 // TODO(warx): pressing power button should also StartShutdownTimer() in this | |
| 102 // case. Reorganize the code to support that. | |
| 103 if (timestamp - last_resume_time_ <= | |
| 104 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { | |
| 105 // If backlights are forced off, stop forcing off because resuming system | |
| 106 // doesn't handle this. | |
| 107 if (down && backlights_forced_off_) | |
| 108 SetDisplayForcedOff(false); | |
| 109 return; | |
| 110 } | |
| 111 | |
| 112 if (down) { | 96 if (down) { |
| 97 force_off_on_button_up_ = true; | |
| 98 // When the system resumes in response to the power button being pressed, | |
| 99 // Chrome receives powerd's SuspendDone signal and notification that the | |
| 100 // baclight has been turned back on before seeing the power button events | |
|
Daniel Erat
2016/12/05 22:08:09
nit: s/baclight/backlight/
Qiang(Joe) Xu
2016/12/05 22:38:29
Done.
| |
| 101 // that woke the system. Ignore forcing off display just after resuming to | |
|
Daniel Erat
2016/12/05 22:08:09
nit: s/Ignore/Avoid/
Qiang(Joe) Xu
2016/12/05 22:38:29
Done.
| |
| 102 // ensure that we don't turn the display off in response to the events. | |
| 103 if (timestamp - last_resume_time_ <= | |
| 104 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { | |
| 105 force_off_on_button_up_ = false; | |
| 106 } | |
| 113 screen_off_when_power_button_down_ = brightness_level_is_zero_; | 107 screen_off_when_power_button_down_ = brightness_level_is_zero_; |
| 114 SetDisplayForcedOff(false); | 108 SetDisplayForcedOff(false); |
| 115 StartShutdownTimer(); | 109 StartShutdownTimer(); |
| 116 } else { | 110 } else { |
| 117 if (shutdown_timer_.IsRunning()) { | 111 if (shutdown_timer_.IsRunning()) { |
| 118 shutdown_timer_.Stop(); | 112 shutdown_timer_.Stop(); |
| 119 if (!screen_off_when_power_button_down_) { | 113 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { |
| 120 SetDisplayForcedOff(true); | 114 SetDisplayForcedOff(true); |
| 121 LockScreenIfRequired(); | 115 LockScreenIfRequired(); |
| 122 } | 116 } |
| 123 } | 117 } |
| 124 screen_off_when_power_button_down_ = false; | |
|
Qiang(Joe) Xu
2016/12/05 19:33:59
feel this is not needed, as it is always updated i
Daniel Erat
2016/12/05 22:08:09
yep, i agree
| |
| 125 | 118 |
| 126 // When power button is released, cancel shutdown animation whenever it is | 119 // When power button is released, cancel shutdown animation whenever it is |
| 127 // still cancellable. | 120 // still cancellable. |
| 128 if (controller_->CanCancelShutdownAnimation()) | 121 if (controller_->CanCancelShutdownAnimation()) |
| 129 controller_->CancelShutdownAnimation(); | 122 controller_->CancelShutdownAnimation(); |
| 130 } | 123 } |
| 131 } | 124 } |
| 132 | 125 |
| 133 void TabletPowerButtonController::PowerManagerRestarted() { | 126 void TabletPowerButtonController::PowerManagerRestarted() { |
| 134 chromeos::DBusThreadManager::Get() | 127 chromeos::DBusThreadManager::Get() |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 WmShell::Get()->GetSessionStateDelegate(); | 222 WmShell::Get()->GetSessionStateDelegate(); |
| 230 if (session_state_delegate->ShouldLockScreenAutomatically() && | 223 if (session_state_delegate->ShouldLockScreenAutomatically() && |
| 231 session_state_delegate->CanLockScreen() && | 224 session_state_delegate->CanLockScreen() && |
| 232 !session_state_delegate->IsUserSessionBlocked() && | 225 !session_state_delegate->IsUserSessionBlocked() && |
| 233 !controller_->LockRequested()) { | 226 !controller_->LockRequested()) { |
| 234 session_state_delegate->LockScreen(); | 227 session_state_delegate->LockScreen(); |
| 235 } | 228 } |
| 236 } | 229 } |
| 237 | 230 |
| 238 } // namespace ash | 231 } // namespace ash |
| OLD | NEW |