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

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

Issue 2504523002: [Reland-fixing asan failure] Tablet-like power button behavior on Convertible/Tablet ChromeOS devic… (Closed)
Patch Set: fix asan test failure Created 4 years, 1 month 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
« no previous file with comments | « ash/BUILD.gn ('k') | ash/system/chromeos/power/tablet_power_button_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/tick_clock.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "chromeos/dbus/power_manager_client.h"
17 #include "ui/events/devices/input_device_event_observer.h"
18 #include "ui/events/event_handler.h"
19
20 namespace ash {
21
22 class LockStateController;
23
24 // Handles power button events on convertible/tablet device. This class is
25 // instantiated and used in PowerButtonController.
26 class ASH_EXPORT TabletPowerButtonController
27 : public chromeos::PowerManagerClient::Observer,
28 public ui::EventHandler,
29 public ui::InputDeviceEventObserver {
30 public:
31 // Helper class used by tablet power button tests to access internal state.
32 class ASH_EXPORT TestApi {
33 public:
34 explicit TestApi(TabletPowerButtonController* controller);
35 ~TestApi();
36
37 // Returns true when |shutdown_timer_| is running.
38 bool ShutdownTimerIsRunning() const;
39
40 // Emulates |shutdown_timer_| timeout.
41 void TriggerShutdownTimeout();
42
43 private:
44 TabletPowerButtonController* controller_; // Not owned.
45
46 DISALLOW_COPY_AND_ASSIGN(TestApi);
47 };
48
49 explicit TabletPowerButtonController(LockStateController* controller);
50 ~TabletPowerButtonController() override;
51
52 // Returns true if power button events should be handled by this class instead
53 // of PowerButtonController.
54 bool ShouldHandlePowerButtonEvents() const;
55
56 // Handles a power button event.
57 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
58
59 // Overridden from chromeos::PowerManagerClient::Observer:
60 void PowerManagerRestarted() override;
61 void BrightnessChanged(int level, bool user_initiated) override;
62 void SuspendDone(const base::TimeDelta& sleep_duration) override;
63
64 // Overridden from ui::EventHandler:
65 void OnKeyEvent(ui::KeyEvent* event) override;
66 void OnMouseEvent(ui::MouseEvent* event) override;
67
68 // Overridden from ui::InputDeviceObserver:
69 void OnStylusStateChanged(ui::StylusState state) override;
70
71 // Overrides the tick clock used by |this| for testing.
72 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
73
74 private:
75 // Set backlights to |forced_off| if they aren't already.
76 void SetBacklightsForcedOff(bool forced_off);
77
78 // Sends a request to powerd to get the backlights forced off state so that
79 // |backlights_forced_off_| can be initialized.
80 void GetInitialBacklightsForcedOff();
81
82 // Initializes |backlights_forced_off_|.
83 void OnGotInitialBacklightsForcedOff(bool is_forced_off);
84
85 // Starts |shutdown_timer_| when the power button is pressed while in
86 // tablet mode.
87 void StartShutdownTimer();
88
89 // Called by |shutdown_timer_| to start the pre-shutdown animation.
90 void OnShutdownTimeout();
91
92 // Locks the screen if the "require password to wake from sleep" pref is set
93 // and locking is possible.
94 void LockScreenIfRequired();
95
96 // True if the brightness level is currently set to off.
97 bool brightness_level_is_zero_ = false;
98
99 // Current forced-off state of backlights.
100 bool backlights_forced_off_ = false;
101
102 // True if the screen was off when the power button was pressed.
103 bool screen_off_when_power_button_down_ = false;
104
105 // Time source for performed action times.
106 std::unique_ptr<base::TickClock> tick_clock_;
107
108 // Saves the most recent timestamp that powerd is resuming from suspend,
109 // updated in SuspendDone().
110 base::TimeTicks last_resume_time_;
111
112 // Started when the tablet power button is pressed and stopped when it's
113 // released. Runs OnShutdownTimeout() to start shutdown.
114 base::OneShotTimer shutdown_timer_;
115
116 LockStateController* controller_; // Not owned.
117
118 base::WeakPtrFactory<TabletPowerButtonController> weak_ptr_factory_;
119
120 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonController);
121 };
122
123 } // namespace ash
124
125 #endif // ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ash/BUILD.gn ('k') | ash/system/chromeos/power/tablet_power_button_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698