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

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: removed unused const 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 "base/memory/weak_ptr.h"
13 #include "chromeos/dbus/power_manager_client.h"
14 #include "device/bluetooth/bluetooth_adapter.h"
15
16 namespace chromeos {
17
18 class BluetoothDevice;
19
20 // 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.
21 // notifications for low battery conditions.
22 class PeripheralBatteryObserver : public PowerManagerClient::Observer,
23 public device::BluetoothAdapter::Observer {
24 public:
25 // This class registers/unregisters itself as an observer in ctor/dtor.
26 PeripheralBatteryObserver();
27 virtual ~PeripheralBatteryObserver();
28
29 void InitializeOnBluetoothReady(
30 scoped_refptr<device::BluetoothAdapter> adapter);
31
32 // PowerManagerClient::Observer implementation.
33 virtual void PeripheralBatteryStatusReceived(const std::string& path,
34 const std::string& name,
35 int level) OVERRIDE;
36
37 // device::BluetoothAdapter::Observer implementation.
38 virtual void DeviceChanged(device::BluetoothAdapter* adapter,
39 device::BluetoothDevice* device) OVERRIDE;
40 virtual void DeviceRemoved(device::BluetoothAdapter* adapter,
41 device::BluetoothDevice* device) OVERRIDE;
42 private:
43 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.
44 public:
45 BatteryInfo() : level_(-1) {}
46 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.
47 base::TimeDelta notification_timestamp,
48 base::TimeDelta update_timestamp)
49 : 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.
50 last_notification_timestamp_(notification_timestamp),
51 last_update_timestamp_(update_timestamp) {
52 }
53
54 const std::string& path() { return path_; }
55
56 const std::string& name() { return name_; }
57 void set_name(const std::string& name) { name_ = name; }
58
59 int level() { return level_; }
60 void set_level(int level) { level_ = level; }
61
62 const base::TimeDelta& last_notification_timestamp() {
63 return last_notification_timestamp_;
64 }
65 void set_notification_timestamp(const base::TimeDelta& timestamp) {
66 last_notification_timestamp_ = timestamp;
67 }
68
69 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.
70 return last_update_timestamp_;
71 }
72 void set_update_timestamp(const base::TimeDelta& timestamp) {
73 last_update_timestamp_ = timestamp;
74 }
75
76 private:
77 // Path to the sysfs entry for this peripheral device battery.
78 std::string path_;
79 // Human readable name for the device. It is changeable.
80 std::string name_;
81 // Battery leve within range [0, 100], and -1 for unknown level.
82 int level_;
83 base::TimeDelta last_notification_timestamp_;
84 base::TimeDelta last_update_timestamp_;
85 };
86
87 void RemoveBattery(const std::string& name);
88 void PostNotification(BatteryInfo* battery);
89
90 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.
91 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
92 scoped_ptr<base::WeakPtrFactory<PeripheralBatteryObserver> > weakptr_factory_;
93
94 DISALLOW_COPY_AND_ASSIGN(PeripheralBatteryObserver);
95 };
96
97 } // namespace chromeos
98
99 #endif // CHROME_BROWSER_CHROMEOS_POWER_PERIPHERAL_BATTERY_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698