Chromium Code Reviews| Index: chrome/browser/chromeos/power/peripheral_battery_observer.h |
| diff --git a/chrome/browser/chromeos/power/peripheral_battery_observer.h b/chrome/browser/chromeos/power/peripheral_battery_observer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec42f7b338175748eda76f2815a8c57f6040244d |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/power/peripheral_battery_observer.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chromeos/dbus/power_manager_client.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| + |
| +namespace chromeos { |
| + |
| +class BluetoothDevice; |
| + |
| +// This observer listens for peripheral device battery status and show |
|
Daniel Erat
2013/04/06 01:52:34
nit: s/show/shows/
Yufeng Shen (Slow to review)
2013/04/09 00:45:08
Done.
|
| +// notifications for low battery conditions. |
| +class PeripheralBatteryObserver : public PowerManagerClient::Observer, |
| + public device::BluetoothAdapter::Observer { |
| + public: |
| + // This class registers/unregisters itself as an observer in ctor/dtor. |
| + PeripheralBatteryObserver(); |
| + virtual ~PeripheralBatteryObserver(); |
| + |
| + void InitializeOnBluetoothReady( |
| + scoped_refptr<device::BluetoothAdapter> adapter); |
| + |
| + // PowerManagerClient::Observer implementation. |
| + virtual void PeripheralBatteryStatusReceived(const std::string& path, |
| + const std::string& name, |
| + int level) OVERRIDE; |
| + |
| + // device::BluetoothAdapter::Observer implementation. |
| + virtual void DeviceChanged(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + virtual void DeviceRemoved(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + private: |
| + class BatteryInfo { |
|
Daniel Erat
2013/04/06 01:52:34
this should probably be a struct instead of a clas
Yufeng Shen (Slow to review)
2013/04/09 00:45:08
Done.
|
| + public: |
| + BatteryInfo() : level_(-1) {} |
| + BatteryInfo(const std::string& path, const std::string& name, int level, |
|
Daniel Erat
2013/04/06 01:52:34
nit: one parameter per line if they don't all fit
Yufeng Shen (Slow to review)
2013/04/09 00:45:08
Done.
|
| + base::TimeDelta notification_timestamp, |
| + base::TimeDelta update_timestamp) |
| + : path_(path), name_(name), level_(level), |
|
Daniel Erat
2013/04/06 01:52:34
one member per line
Yufeng Shen (Slow to review)
2013/04/09 00:45:08
Done.
|
| + last_notification_timestamp_(notification_timestamp), |
| + last_update_timestamp_(update_timestamp) { |
| + } |
| + |
| + const std::string& path() { return path_; } |
| + |
| + const std::string& name() { return name_; } |
| + void set_name(const std::string& name) { name_ = name; } |
| + |
| + int level() { return level_; } |
| + void set_level(int level) { level_ = level; } |
| + |
| + const base::TimeDelta& last_notification_timestamp() { |
| + return last_notification_timestamp_; |
| + } |
| + void set_notification_timestamp(const base::TimeDelta& timestamp) { |
| + last_notification_timestamp_ = timestamp; |
| + } |
| + |
| + const base::TimeDelta& last_update_timestamp() { |
|
Daniel Erat
2013/04/06 01:52:34
a TimeDelta isn't a timestamp. use base::TimeTick
Yufeng Shen (Slow to review)
2013/04/09 00:45:08
Done.
|
| + return last_update_timestamp_; |
| + } |
| + void set_update_timestamp(const base::TimeDelta& timestamp) { |
| + last_update_timestamp_ = timestamp; |
| + } |
| + |
| + private: |
| + // Path to the sysfs entry for this peripheral device battery. |
| + std::string path_; |
| + // Human readable name for the device. It is changeable. |
| + std::string name_; |
| + // Battery leve within range [0, 100], and -1 for unknown level. |
| + int level_; |
| + base::TimeDelta last_notification_timestamp_; |
| + base::TimeDelta last_update_timestamp_; |
| + }; |
| + |
| + void RemoveBattery(const std::string& name); |
| + void PostNotification(BatteryInfo* battery); |
| + |
| + std::map<std::string, BatteryInfo> batteries_; |
|
Daniel Erat
2013/04/06 01:52:34
add a comment describing what the key is here
Yufeng Shen (Slow to review)
2013/04/09 00:45:08
Done.
|
| + scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; |
| + scoped_ptr<base::WeakPtrFactory<PeripheralBatteryObserver> > weakptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PeripheralBatteryObserver); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ |