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

Side by Side Diff: ash/system/chromeos/power/tablet_power_button_controller.cc

Issue 2664683002: ash: Drop the immediately following power button released induced forcing off request (Closed)
Patch Set: better comments Created 3 years, 10 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 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 17 matching lines...) Expand all
28 // TODO(derat): This is currently set to a high value to work around delays in 28 // TODO(derat): This is currently set to a high value to work around delays in
29 // powerd's reports of button-up events when the preceding button-down event 29 // powerd's reports of button-up events when the preceding button-down event
30 // turns the display on. Set it to a lower value once powerd no longer blocks on 30 // turns the display on. Set it to a lower value once powerd no longer blocks on
31 // asking Chrome to turn the display on: http://crbug.com/685734 31 // asking Chrome to turn the display on: http://crbug.com/685734
32 constexpr int kShutdownWhenScreenOffTimeoutMs = 2000; 32 constexpr int kShutdownWhenScreenOffTimeoutMs = 2000;
33 33
34 // Amount of time since last SuspendDone() that power button event needs to be 34 // Amount of time since last SuspendDone() that power button event needs to be
35 // ignored. 35 // ignored.
36 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; 36 constexpr int kIgnorePowerButtonAfterResumeMs = 2000;
37 37
38 // Amount of time since last power button released that power button released
39 // event for forcing off needs to be ignored.
40 constexpr int kIgnoreReleasedAfterLastOneMs = 500;
Daniel Erat 2017/01/30 17:55:00 nit: kIgnoreRepeatedButtonUpMs or something simila
Qiang(Joe) Xu 2017/01/30 19:35:43 done, thanks!
41
38 // Returns true if device is a convertible/tablet device, otherwise false. 42 // Returns true if device is a convertible/tablet device, otherwise false.
39 bool IsTabletModeSupported() { 43 bool IsTabletModeSupported() {
40 MaximizeModeController* maximize_mode_controller = 44 MaximizeModeController* maximize_mode_controller =
41 WmShell::Get()->maximize_mode_controller(); 45 WmShell::Get()->maximize_mode_controller();
42 return maximize_mode_controller && 46 return maximize_mode_controller &&
43 maximize_mode_controller->CanEnterMaximizeMode(); 47 maximize_mode_controller->CanEnterMaximizeMode();
44 } 48 }
45 49
46 // Returns true if device is currently in tablet/maximize mode, otherwise false. 50 // Returns true if device is currently in tablet/maximize mode, otherwise false.
47 bool IsTabletModeActive() { 51 bool IsTabletModeActive() {
(...skipping 18 matching lines...) Expand all
66 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { 70 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() {
67 DCHECK(ShutdownTimerIsRunning()); 71 DCHECK(ShutdownTimerIsRunning());
68 controller_->OnShutdownTimeout(); 72 controller_->OnShutdownTimeout();
69 controller_->shutdown_timer_.Stop(); 73 controller_->shutdown_timer_.Stop();
70 } 74 }
71 75
72 TabletPowerButtonController::TabletPowerButtonController( 76 TabletPowerButtonController::TabletPowerButtonController(
73 LockStateController* controller) 77 LockStateController* controller)
74 : tick_clock_(new base::DefaultTickClock()), 78 : tick_clock_(new base::DefaultTickClock()),
75 last_resume_time_(base::TimeTicks()), 79 last_resume_time_(base::TimeTicks()),
80 last_released_time_(base::TimeTicks()),
Daniel Erat 2017/01/30 17:55:00 i don't think you need to initialize this member a
Qiang(Joe) Xu 2017/01/30 19:35:44 Done.
76 force_off_on_button_up_(true), 81 force_off_on_button_up_(true),
77 controller_(controller), 82 controller_(controller),
78 weak_ptr_factory_(this) { 83 weak_ptr_factory_(this) {
79 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( 84 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
80 this); 85 this);
81 WmShell::Get()->AddShellObserver(this); 86 WmShell::Get()->AddShellObserver(this);
82 // TODO(mash): Provide a way for this class to observe stylus events: 87 // TODO(mash): Provide a way for this class to observe stylus events:
83 // http://crbug.com/682460 88 // http://crbug.com/682460
84 if (ui::InputDeviceManager::HasInstance()) 89 if (ui::InputDeviceManager::HasInstance())
85 ui::InputDeviceManager::GetInstance()->AddObserver(this); 90 ui::InputDeviceManager::GetInstance()->AddObserver(this);
(...skipping 26 matching lines...) Expand all
112 // that woke the system. Avoid forcing off display just after resuming to 117 // that woke the system. Avoid forcing off display just after resuming to
113 // ensure that we don't turn the display off in response to the events. 118 // ensure that we don't turn the display off in response to the events.
114 if (timestamp - last_resume_time_ <= 119 if (timestamp - last_resume_time_ <=
115 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { 120 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) {
116 force_off_on_button_up_ = false; 121 force_off_on_button_up_ = false;
117 } 122 }
118 screen_off_when_power_button_down_ = brightness_level_is_zero_; 123 screen_off_when_power_button_down_ = brightness_level_is_zero_;
119 SetDisplayForcedOff(false); 124 SetDisplayForcedOff(false);
120 StartShutdownTimer(); 125 StartShutdownTimer();
121 } else { 126 } else {
127 // When power button is released, cancel shutdown animation whenever it is
128 // still cancellable.
129 if (controller_->CanCancelShutdownAnimation())
130 controller_->CancelShutdownAnimation();
131
Daniel Erat 2017/01/30 17:55:00 might be a little cleaner to do something like thi
Qiang(Joe) Xu 2017/01/30 19:35:43 Done.
132 // Drop the very adjacent power button released event for forcing off.
Daniel Erat 2017/01/30 17:55:00 maybe: // Ignore the event if it comes too soon
Qiang(Joe) Xu 2017/01/30 19:35:43 Done.
133 if (timestamp - last_released_time_ <=
134 base::TimeDelta::FromMilliseconds(kIgnoreReleasedAfterLastOneMs)) {
135 last_released_time_ = tick_clock_->NowTicks();
136 shutdown_timer_.Stop();
137 return;
138 }
139 last_released_time_ = tick_clock_->NowTicks();
140
122 if (shutdown_timer_.IsRunning()) { 141 if (shutdown_timer_.IsRunning()) {
123 shutdown_timer_.Stop(); 142 shutdown_timer_.Stop();
124 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { 143 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) {
125 SetDisplayForcedOff(true); 144 SetDisplayForcedOff(true);
126 LockScreenIfRequired(); 145 LockScreenIfRequired();
127 } 146 }
128 } 147 }
129
130 // When power button is released, cancel shutdown animation whenever it is
131 // still cancellable.
132 if (controller_->CanCancelShutdownAnimation())
133 controller_->CancelShutdownAnimation();
134 } 148 }
135 } 149 }
136 150
137 void TabletPowerButtonController::PowerManagerRestarted() { 151 void TabletPowerButtonController::PowerManagerRestarted() {
138 chromeos::DBusThreadManager::Get() 152 chromeos::DBusThreadManager::Get()
139 ->GetPowerManagerClient() 153 ->GetPowerManagerClient()
140 ->SetBacklightsForcedOff(backlights_forced_off_); 154 ->SetBacklightsForcedOff(backlights_forced_off_);
141 } 155 }
142 156
143 void TabletPowerButtonController::BrightnessChanged(int level, 157 void TabletPowerButtonController::BrightnessChanged(int level,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 WmShell::Get()->GetSessionStateDelegate(); 257 WmShell::Get()->GetSessionStateDelegate();
244 if (session_state_delegate->ShouldLockScreenAutomatically() && 258 if (session_state_delegate->ShouldLockScreenAutomatically() &&
245 session_state_delegate->CanLockScreen() && 259 session_state_delegate->CanLockScreen() &&
246 !session_state_delegate->IsUserSessionBlocked() && 260 !session_state_delegate->IsUserSessionBlocked() &&
247 !controller_->LockRequested()) { 261 !controller_->LockRequested()) {
248 session_state_delegate->LockScreen(); 262 session_state_delegate->LockScreen();
249 } 263 }
250 } 264 }
251 265
252 } // namespace ash 266 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698