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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 "chromeos/dbus/power_manager_client.h"
13
14 namespace chromeos {
15
16 // This observer listens for peripheral device battery status and show
17 // notifications for low battery conditions.
18 class PeripheralBatteryObserver : public PowerManagerClient::Observer {
19 public:
20 // This class registers/unregisters itself as an observer in ctor/dtor.
21 PeripheralBatteryObserver();
22 virtual ~PeripheralBatteryObserver();
23
24 // PowerManagerClient::Observer implementation.
25 virtual void PeripheralBatteryStatusReceived(const std::string& path,
26 const std::string& name,
27 int level) OVERRIDE;
28 private:
29 class BatteryInfo {
30 public:
31 BatteryInfo() : level_(-1) {}
32 BatteryInfo(const std::string& path, const std::string& name, int level,
33 base::TimeDelta notification_timestamp,
34 base::TimeDelta update_timestamp)
35 : path_(path), name_(name), level_(level),
36 last_notification_timestamp_(notification_timestamp),
37 last_update_timestamp_(update_timestamp) {
38 }
39
40 const std::string& path() { return path_; }
41
42 const std::string& name() { return name_; }
43 void set_name(const std::string& name) { name_ = name; }
44
45 int level() { return level_; }
46 void set_level(int level) { level_ = level; }
47
48 const base::TimeDelta& last_notification_timestamp() {
49 return last_notification_timestamp_;
50 }
51 void set_notification_timestamp(const base::TimeDelta& timestamp) {
52 last_notification_timestamp_ = timestamp;
53 }
54
55 const base::TimeDelta& last_update_timestamp() {
56 return last_update_timestamp_;
57 }
58 void set_update_timestamp(const base::TimeDelta& timestamp) {
59 last_update_timestamp_ = timestamp;
60 }
61
62 private:
63 // Path to the sysfs entry for this peripheral device battery.
64 std::string path_;
65 // Human readable name for the device. It is changeable.
66 std::string name_;
67 // Battery leve within range [0, 100], and -1 for unknown level.
68 int level_;
69 base::TimeDelta last_notification_timestamp_;
70 base::TimeDelta last_update_timestamp_;
71 };
72
73 void PostNotification(BatteryInfo* battery);
74
75 std::map<std::string, BatteryInfo> batteries_;
76
77 DISALLOW_COPY_AND_ASSIGN(PeripheralBatteryObserver);
78 };
79
80 } // namespace chromeos
81
82 #endif // CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698