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