Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Unified Diff: chrome/browser/chromeos/power/peripheral_battery_observer.h

Issue 13638018: Add PeripheralBatteryObserver (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: update Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..fb9d92415d4d58a99c0f83ccff4b425fbbdee9d3
--- /dev/null
+++ b/chrome/browser/chromeos/power/peripheral_battery_observer.h
@@ -0,0 +1,107 @@
+// 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 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();
+
+ 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.
+ 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:
+ struct BatteryInfo {
+ public:
+ BatteryInfo() : level_(-1) {}
+ BatteryInfo(const std::string& name,
+ int level,
+ base::TimeTicks notification_timestamp,
+ base::TimeTicks update_timestamp)
+ : name_(name),
+ level_(level),
+ last_notification_timestamp_(notification_timestamp),
+ last_update_timestamp_(update_timestamp) {
+ }
+
+ 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.
+ void set_name(const std::string& name) { name_ = name; }
+
+ int level() const { return level_; }
+ void set_level(int level) { level_ = level; }
+
+ const base::TimeTicks& last_notification_timestamp() const {
+ return last_notification_timestamp_;
+ }
+ void set_notification_timestamp(const base::TimeTicks& timestamp) {
+ last_notification_timestamp_ = timestamp;
+ }
+
+ const base::TimeTicks& last_update_timestamp() const {
+ return last_update_timestamp_;
+ }
+ void set_update_timestamp(const base::TimeTicks& timestamp) {
+ last_update_timestamp_ = timestamp;
+ }
+
+ private:
+ // Human readable name for the device. It is changeable.
+ 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.
+ // Battery leve within range [0, 100], and -1 for unknown level.
+ int level_;
+ base::TimeTicks last_notification_timestamp_;
+ base::TimeTicks last_update_timestamp_;
+ };
+
+ bool IsBluetoothHIDBattery(const std::string& path);
+ 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.
+
+ void RemoveBattery(const std::string& key);
+
+ // 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.
+ // 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.
+ bool PostNotification(const std::string& id, const BatteryInfo& battery);
+
+ 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.
+
+ // Record of existing battery infomation. For bluetooh HID device, the key
+ // is the address of the bluetooth device.
+ 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.
+ 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_

Powered by Google App Engine
This is Rietveld 408576698