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..d151dc8cfeb37e561e4f156004f8ef381de66416 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/power/peripheral_battery_observer.h |
| @@ -0,0 +1,98 @@ |
| +// 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/gtest_prod_util.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/test/simple_test_tick_clock.h" |
| +#include "chromeos/dbus/power_manager_client.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| + |
| +namespace chromeos { |
| + |
| +class BluetoothDevice; |
| +class PeripheralBatteryObserverTest; |
| + |
| +// This observer listens for peripheral device battery status and shows |
| +// 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(); |
| + |
| + // 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; |
| + |
| + 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.
|
| + testing_clock_ = clock; |
| + } |
| + |
| + private: |
| + friend class PeripheralBatteryObserverTest; |
| + FRIEND_TEST_ALL_PREFIXES(PeripheralBatteryObserverTest, Basic); |
| + FRIEND_TEST_ALL_PREFIXES(PeripheralBatteryObserverTest, InvalidBatteryInfo); |
| + FRIEND_TEST_ALL_PREFIXES(PeripheralBatteryObserverTest, DeviceRemove); |
| + |
| + struct BatteryInfo { |
| + BatteryInfo() : level(-1) {} |
| + BatteryInfo(const std::string& name, |
| + int level, |
| + base::TimeTicks notification_timestamp) |
| + : name(name), |
| + level(level), |
| + last_notification_timestamp(notification_timestamp) { |
| + } |
| + |
| + // Human readable name for the device. It is changeable. |
| + std::string name; |
| + // 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.
|
| + int level; |
| + base::TimeTicks last_notification_timestamp; |
| + }; |
| + |
| + void InitializeOnBluetoothReady( |
| + scoped_refptr<device::BluetoothAdapter> adapter); |
| + |
| + void RemoveBattery(const std::string& address); |
| + |
| + // Posts a low battery notification with unique id |address|. Returns true |
| + // if the notification is posted, false if not. |
| + bool PostNotification(const std::string& address, const BatteryInfo& battery); |
| + |
| + void CancelNotification(const std::string& address); |
| + |
| + // 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.
|
| + // is the address of the bluetooth device. |
| + std::map<std::string, BatteryInfo> batteries_; |
| + |
| + // PeripheralBatteryObserver is an observer of |bluetooth_adapter_| for |
| + // bluetooth device change/remove events. |
| + scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; |
| + |
| + 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.
|
| + |
| + scoped_ptr<base::WeakPtrFactory<PeripheralBatteryObserver> > weakptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PeripheralBatteryObserver); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_ |