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

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: 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..750befeb5670d92d616472df81dfeb337a788df3
--- /dev/null
+++ b/chrome/browser/chromeos/power/peripheral_battery_observer.h
@@ -0,0 +1,82 @@
+// 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 "chromeos/dbus/power_manager_client.h"
+
+namespace chromeos {
+
+// This observer listens for peripheral device battery status and show
+// notifications for low battery conditions.
+class PeripheralBatteryObserver : public PowerManagerClient::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;
+ private:
+ class BatteryInfo {
+ public:
+ BatteryInfo() : level_(-1) {}
+ BatteryInfo(const std::string& path, const std::string& name, int level,
+ base::TimeDelta notification_timestamp,
+ base::TimeDelta update_timestamp)
+ : path_(path), name_(name), level_(level),
+ 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() {
+ 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 PostNotification(BatteryInfo* battery);
+
+ std::map<std::string, BatteryInfo> batteries_;
+
+ 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