Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/test/simple_test_tick_clock.h" | |
| 15 #include "chromeos/dbus/power_manager_client.h" | |
| 16 #include "device/bluetooth/bluetooth_adapter.h" | |
| 17 | |
| 18 namespace chromeos { | |
| 19 | |
| 20 class BluetoothDevice; | |
| 21 class PeripheralBatteryObserverTest; | |
| 22 | |
| 23 // This observer listens for peripheral device battery status and shows | |
| 24 // notifications for low battery conditions. | |
| 25 class PeripheralBatteryObserver : public PowerManagerClient::Observer, | |
| 26 public device::BluetoothAdapter::Observer { | |
| 27 public: | |
| 28 // This class registers/unregisters itself as an observer in ctor/dtor. | |
| 29 PeripheralBatteryObserver(); | |
| 30 virtual ~PeripheralBatteryObserver(); | |
| 31 | |
| 32 // PowerManagerClient::Observer implementation. | |
| 33 virtual void PeripheralBatteryStatusReceived(const std::string& path, | |
| 34 const std::string& name, | |
| 35 int level) OVERRIDE; | |
| 36 | |
| 37 // device::BluetoothAdapter::Observer implementation. | |
| 38 virtual void DeviceChanged(device::BluetoothAdapter* adapter, | |
| 39 device::BluetoothDevice* device) OVERRIDE; | |
| 40 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, | |
| 41 device::BluetoothDevice* device) OVERRIDE; | |
| 42 | |
| 43 void SetClockForTesting(base::SimpleTestTickClock* clock) { | |
|
Daniel Erat
2013/04/10 12:58:21
nit: move above virtual methods and rename to set_
Yufeng Shen (Slow to review)
2013/04/10 18:13:46
Done.
| |
| 44 testing_clock_ = clock; | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 friend class PeripheralBatteryObserverTest; | |
| 49 FRIEND_TEST_ALL_PREFIXES(PeripheralBatteryObserverTest, Basic); | |
| 50 FRIEND_TEST_ALL_PREFIXES(PeripheralBatteryObserverTest, InvalidBatteryInfo); | |
| 51 FRIEND_TEST_ALL_PREFIXES(PeripheralBatteryObserverTest, DeviceRemove); | |
| 52 | |
| 53 struct BatteryInfo { | |
| 54 BatteryInfo() : level(-1) {} | |
| 55 BatteryInfo(const std::string& name, | |
| 56 int level, | |
| 57 base::TimeTicks notification_timestamp) | |
| 58 : name(name), | |
| 59 level(level), | |
| 60 last_notification_timestamp(notification_timestamp) { | |
| 61 } | |
| 62 | |
| 63 // Human readable name for the device. It is changeable. | |
| 64 std::string name; | |
| 65 // Battery leve within range [0, 100], and -1 for unknown level. | |
|
Daniel Erat
2013/04/10 12:58:21
s/leve/level/
Yufeng Shen (Slow to review)
2013/04/10 18:13:46
Done.
| |
| 66 int level; | |
| 67 base::TimeTicks last_notification_timestamp; | |
| 68 }; | |
| 69 | |
| 70 void InitializeOnBluetoothReady( | |
| 71 scoped_refptr<device::BluetoothAdapter> adapter); | |
| 72 | |
| 73 void RemoveBattery(const std::string& address); | |
| 74 | |
| 75 // Posts a low battery notification with unique id |address|. Returns true | |
| 76 // if the notification is posted, false if not. | |
| 77 bool PostNotification(const std::string& address, const BatteryInfo& battery); | |
| 78 | |
| 79 void CancelNotification(const std::string& address); | |
| 80 | |
| 81 // Record of existing battery infomation. For bluetooh HID device, the key | |
|
Daniel Erat
2013/04/10 12:58:21
s/bluetooh/bluetooth/
Yufeng Shen (Slow to review)
2013/04/10 18:13:46
Done.
| |
| 82 // is the address of the bluetooth device. | |
| 83 std::map<std::string, BatteryInfo> batteries_; | |
| 84 | |
| 85 // PeripheralBatteryObserver is an observer of |bluetooth_adapter_| for | |
| 86 // bluetooth device change/remove events. | |
| 87 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | |
| 88 | |
| 89 base::SimpleTestTickClock* testing_clock_; | |
|
Daniel Erat
2013/04/10 12:58:21
nit: add a comment saying that this pointer is uno
Yufeng Shen (Slow to review)
2013/04/10 18:13:46
Done.
| |
| 90 | |
| 91 scoped_ptr<base::WeakPtrFactory<PeripheralBatteryObserver> > weakptr_factory_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(PeripheralBatteryObserver); | |
| 94 }; | |
| 95 | |
| 96 } // namespace chromeos | |
| 97 | |
| 98 #endif // CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ | |
| OLD | NEW |