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/memory/weak_ptr.h" | |
| 13 #include "chromeos/dbus/power_manager_client.h" | |
| 14 #include "device/bluetooth/bluetooth_adapter.h" | |
| 15 | |
| 16 namespace chromeos { | |
| 17 | |
| 18 class BluetoothDevice; | |
| 19 | |
| 20 // This observer listens for peripheral device battery status and shows | |
| 21 // notifications for low battery conditions. | |
| 22 class PeripheralBatteryObserver : public PowerManagerClient::Observer, | |
| 23 public device::BluetoothAdapter::Observer { | |
| 24 public: | |
| 25 // This class registers/unregisters itself as an observer in ctor/dtor. | |
| 26 PeripheralBatteryObserver(); | |
| 27 virtual ~PeripheralBatteryObserver(); | |
| 28 | |
| 29 void InitializeOnBluetoothReady( | |
|
Daniel Erat
2013/04/09 02:06:18
can this be private instead of public?
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 30 scoped_refptr<device::BluetoothAdapter> adapter); | |
| 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 private: | |
| 43 struct BatteryInfo { | |
| 44 public: | |
| 45 BatteryInfo() : level_(-1) {} | |
| 46 BatteryInfo(const std::string& name, | |
| 47 int level, | |
| 48 base::TimeTicks notification_timestamp, | |
| 49 base::TimeTicks update_timestamp) | |
| 50 : name_(name), | |
| 51 level_(level), | |
| 52 last_notification_timestamp_(notification_timestamp), | |
| 53 last_update_timestamp_(update_timestamp) { | |
| 54 } | |
| 55 | |
| 56 const std::string& name() const { return name_; } | |
|
Daniel Erat
2013/04/09 02:06:18
you don't need getters and setters now that this i
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 57 void set_name(const std::string& name) { name_ = name; } | |
| 58 | |
| 59 int level() const { return level_; } | |
| 60 void set_level(int level) { level_ = level; } | |
| 61 | |
| 62 const base::TimeTicks& last_notification_timestamp() const { | |
| 63 return last_notification_timestamp_; | |
| 64 } | |
| 65 void set_notification_timestamp(const base::TimeTicks& timestamp) { | |
| 66 last_notification_timestamp_ = timestamp; | |
| 67 } | |
| 68 | |
| 69 const base::TimeTicks& last_update_timestamp() const { | |
| 70 return last_update_timestamp_; | |
| 71 } | |
| 72 void set_update_timestamp(const base::TimeTicks& timestamp) { | |
| 73 last_update_timestamp_ = timestamp; | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 // Human readable name for the device. It is changeable. | |
| 78 std::string name_; | |
|
Daniel Erat
2013/04/09 02:06:18
make these public and remove the trailing undersco
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 79 // Battery leve within range [0, 100], and -1 for unknown level. | |
| 80 int level_; | |
| 81 base::TimeTicks last_notification_timestamp_; | |
| 82 base::TimeTicks last_update_timestamp_; | |
| 83 }; | |
| 84 | |
| 85 bool IsBluetoothHIDBattery(const std::string& path); | |
| 86 std::string ExtractBluetoothAddress(const std::string& path); | |
|
Daniel Erat
2013/04/09 02:06:18
these methods don't look like they need to be clas
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 87 | |
| 88 void RemoveBattery(const std::string& key); | |
| 89 | |
| 90 // Post a low battery notification with unique id |id|, Return true if the | |
|
Daniel Erat
2013/04/09 02:06:18
nit: s/Post/Posts/, s/,/./, s/Return/Returns/
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 91 // noitification is posted, false if not. | |
|
Daniel Erat
2013/04/09 02:06:18
sp: notification
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 92 bool PostNotification(const std::string& id, const BatteryInfo& battery); | |
| 93 | |
| 94 void CancelNotification(const std::string& id); | |
|
Daniel Erat
2013/04/09 02:06:18
please use consistent parameter names instead of '
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 95 | |
| 96 // Record of existing battery infomation. For bluetooh HID device, the key | |
| 97 // is the address of the bluetooth device. | |
| 98 std::map<std::string, BatteryInfo> batteries_; | |
|
Daniel Erat
2013/04/09 02:06:18
nit: add a blank line after this one to set it apa
Yufeng Shen (Slow to review)
2013/04/10 05:54:08
Done.
| |
| 99 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | |
| 100 scoped_ptr<base::WeakPtrFactory<PeripheralBatteryObserver> > weakptr_factory_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(PeripheralBatteryObserver); | |
| 103 }; | |
| 104 | |
| 105 } // namespace chromeos | |
| 106 | |
| 107 #endif // CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ | |
| OLD | NEW |