OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef DEVICE_BATTERY_BATTERY_STATUS_MANAGER_LINUX_H_ | 4 #ifndef DEVICE_BATTERY_BATTERY_STATUS_MANAGER_LINUX_H_ |
5 #define DEVICE_BATTERY_BATTERY_STATUS_MANAGER_LINUX_H_ | 5 #define DEVICE_BATTERY_BATTERY_STATUS_MANAGER_LINUX_H_ |
6 | 6 |
7 #include "device/battery/battery_export.h" | 7 #include "device/battery/battery_export.h" |
8 #include "device/battery/battery_status.mojom.h" | 8 #include "device/battery/battery_status.mojom.h" |
| 9 #include "device/battery/battery_status_manager.h" |
9 | 10 |
10 namespace base { | 11 namespace dbus { |
11 class DictionaryValue; | 12 class Bus; |
12 } | 13 } // namespace dbus |
13 | 14 |
14 namespace device { | 15 namespace device { |
15 | 16 |
16 // UPowerDeviceState reflects the possible UPower.Device.State values, | 17 // UPowerDeviceState reflects the possible UPower.Device.State values, |
17 // see upower.freedesktop.org/docs/Device.html#Device:State. | 18 // see upower.freedesktop.org/docs/Device.html#Device:State. |
18 enum UPowerDeviceState { | 19 enum UPowerDeviceState { |
19 UPOWER_DEVICE_STATE_UNKNOWN = 0, | 20 UPOWER_DEVICE_STATE_UNKNOWN = 0, |
20 UPOWER_DEVICE_STATE_CHARGING = 1, | 21 UPOWER_DEVICE_STATE_CHARGING = 1, |
21 UPOWER_DEVICE_STATE_DISCHARGING = 2, | 22 UPOWER_DEVICE_STATE_DISCHARGING = 2, |
22 UPOWER_DEVICE_STATE_EMPTY = 3, | 23 UPOWER_DEVICE_STATE_EMPTY = 3, |
23 UPOWER_DEVICE_STATE_FULL = 4, | 24 UPOWER_DEVICE_STATE_FULL = 4, |
24 UPOWER_DEVICE_STATE_PENDING_CHARGE = 5, | 25 UPOWER_DEVICE_STATE_PENDING_CHARGE = 5, |
25 UPOWER_DEVICE_STATE_PENDING_DISCHARGE = 6, | 26 UPOWER_DEVICE_STATE_PENDING_DISCHARGE = 6, |
26 }; | 27 }; |
27 | 28 |
28 // Returns the BatteryStatus computed using the provided dictionary. | 29 // UPowerDeviceType reflects the possible UPower.Device.Type values, |
29 DEVICE_BATTERY_EXPORT BatteryStatus ComputeWebBatteryStatus( | 30 // see upower.freedesktop.org/docs/Device.html#Device:Type. |
30 const base::DictionaryValue& dictionary); | 31 enum UPowerDeviceType { |
| 32 UPOWER_DEVICE_TYPE_UNKNOWN = 0, |
| 33 UPOWER_DEVICE_TYPE_LINE_POWER = 1, |
| 34 UPOWER_DEVICE_TYPE_BATTERY = 2, |
| 35 UPOWER_DEVICE_TYPE_UPS = 3, |
| 36 UPOWER_DEVICE_TYPE_MONITOR = 4, |
| 37 UPOWER_DEVICE_TYPE_MOUSE = 5, |
| 38 UPOWER_DEVICE_TYPE_KEYBOARD = 6, |
| 39 UPOWER_DEVICE_TYPE_PDA = 7, |
| 40 UPOWER_DEVICE_TYPE_PHONE = 8, |
| 41 }; |
| 42 |
| 43 // Creates a notification thread and delegates Start/Stop calls to it. |
| 44 class DEVICE_BATTERY_EXPORT BatteryStatusManagerLinux |
| 45 : public BatteryStatusManager { |
| 46 public: |
| 47 explicit BatteryStatusManagerLinux( |
| 48 const BatteryStatusService::BatteryUpdateCallback& callback); |
| 49 ~BatteryStatusManagerLinux() override; |
| 50 |
| 51 private: |
| 52 friend class BatteryStatusManagerLinuxTest; |
| 53 class BatteryStatusNotificationThread; |
| 54 |
| 55 // BatteryStatusManager: |
| 56 bool StartListeningBatteryChange() override; |
| 57 void StopListeningBatteryChange() override; |
| 58 |
| 59 // Starts the notifier thread if not already started and returns true on |
| 60 // success. |
| 61 bool StartNotifierThreadIfNecessary(); |
| 62 base::Thread* GetNotifierThreadForTesting(); |
| 63 |
| 64 static std::unique_ptr<BatteryStatusManagerLinux> CreateForTesting( |
| 65 const BatteryStatusService::BatteryUpdateCallback& callback, |
| 66 dbus::Bus* bus); |
| 67 |
| 68 BatteryStatusService::BatteryUpdateCallback callback_; |
| 69 std::unique_ptr<BatteryStatusNotificationThread> notifier_thread_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(BatteryStatusManagerLinux); |
| 72 }; |
31 | 73 |
32 } // namespace device | 74 } // namespace device |
33 | 75 |
34 #endif // DEVICE_BATTERY_BATTERY_STATUS_MANAGER_LINUX_H_ | 76 #endif // DEVICE_BATTERY_BATTERY_STATUS_MANAGER_LINUX_H_ |
OLD | NEW |