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

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

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 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 2016 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_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
7
8 #include <memory>
9
10 #include "ash/ash_export.h"
11 #include "ash/common/shell_observer.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/tick_clock.h"
15 #include "base/time/time.h"
16 #include "base/timer/timer.h"
17 #include "chromeos/dbus/power_manager_client.h"
18 #include "ui/events/devices/input_device_event_observer.h"
19 #include "ui/events/event_handler.h"
20
21 namespace ash {
22
23 class LockStateController;
24
25 // Handles power button events on convertible/tablet device. This class is
26 // instantiated and used in PowerButtonController.
27 class ASH_EXPORT TabletPowerButtonController
28 : public chromeos::PowerManagerClient::Observer,
29 public ShellObserver,
30 public ui::EventHandler,
31 public ui::InputDeviceEventObserver {
32 public:
33 // Helper class used by tablet power button tests to access internal state.
34 class ASH_EXPORT TestApi {
35 public:
36 explicit TestApi(TabletPowerButtonController* controller);
37 ~TestApi();
38
39 // Returns true when |shutdown_timer_| is running.
40 bool ShutdownTimerIsRunning() const;
41
42 // Emulates |shutdown_timer_| timeout.
43 void TriggerShutdownTimeout();
44
45 private:
46 TabletPowerButtonController* controller_; // Not owned.
47
48 DISALLOW_COPY_AND_ASSIGN(TestApi);
49 };
50
51 explicit TabletPowerButtonController(LockStateController* controller);
52 ~TabletPowerButtonController() override;
53
54 // Returns true if power button events should be handled by this class instead
55 // of PowerButtonController.
56 bool ShouldHandlePowerButtonEvents() const;
57
58 // Handles a power button event.
59 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
60
61 // Overridden from chromeos::PowerManagerClient::Observer:
62 void PowerManagerRestarted() override;
63 void BrightnessChanged(int level, bool user_initiated) override;
64 void SuspendDone(const base::TimeDelta& sleep_duration) override;
65
66 // Overridden from ShellObserver:
67 void OnMaximizeModeStarted() override;
68 void OnMaximizeModeEnded() override;
69
70 // Overridden from ui::EventHandler:
71 void OnKeyEvent(ui::KeyEvent* event) override;
72 void OnMouseEvent(ui::MouseEvent* event) override;
73
74 // Overridden from ui::InputDeviceObserver:
75 void OnStylusStateChanged(ui::StylusState state) override;
76
77 // Overrides the tick clock used by |this| for testing.
78 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
79
80 private:
81 // Updates the power manager's backlights-forced-off state and enables or
82 // disables the touchscreen. No-op if |backlights_forced_off_| already equals
83 // |forced_off|.
84 void SetDisplayForcedOff(bool forced_off);
85
86 // Sends a request to powerd to get the backlights forced off state so that
87 // |backlights_forced_off_| can be initialized.
88 void GetInitialBacklightsForcedOff();
89
90 // Initializes |backlights_forced_off_|.
91 void OnGotInitialBacklightsForcedOff(bool is_forced_off);
92
93 // Starts |shutdown_timer_| when the power button is pressed while in
94 // tablet mode.
95 void StartShutdownTimer();
96
97 // Called by |shutdown_timer_| to start the pre-shutdown animation.
98 void OnShutdownTimeout();
99
100 // Locks the screen if the "require password to wake from sleep" pref is set
101 // and locking is possible.
102 void LockScreenIfRequired();
103
104 // True if the brightness level is currently set to off.
105 bool brightness_level_is_zero_ = false;
106
107 // Current forced-off state of backlights.
108 bool backlights_forced_off_ = false;
109
110 // True if the screen was off when the power button was pressed.
111 bool screen_off_when_power_button_down_ = false;
112
113 // Time source for performed action times.
114 std::unique_ptr<base::TickClock> tick_clock_;
115
116 // Saves the most recent timestamp that powerd is resuming from suspend,
117 // updated in SuspendDone().
118 base::TimeTicks last_resume_time_;
119
120 // Saves the most recent timestamp that power button is released.
121 base::TimeTicks last_button_up_time_;
122
123 // True if power button released should force off display.
124 bool force_off_on_button_up_;
125
126 // Started when the tablet power button is pressed and stopped when it's
127 // released. Runs OnShutdownTimeout() to start shutdown.
128 base::OneShotTimer shutdown_timer_;
129
130 LockStateController* controller_; // Not owned.
131
132 base::WeakPtrFactory<TabletPowerButtonController> weak_ptr_factory_;
133
134 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonController);
135 };
136
137 } // namespace ash
138
139 #endif // ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698