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

Side by Side Diff: chromeos/power/power_data_collector.h

Issue 101963004: [chromeos] New PowerManagerClient observer to collect power data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address the various comments about location etc. Created 7 years 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 | Annotate | Revision Log
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 CHROMEOS_DBUS_POWER_DATA_COLLECTOR_H_
Daniel Erat 2013/12/11 01:06:52 nit: update these to reflect the new path (don't f
Siva Chandra 2013/12/11 20:32:02 Done.
6 #define CHROMEOS_DBUS_POWER_DATA_COLLECTOR_H_
7
8 #include <vector>
9
10 #include "base/gtest_prod_util.h"
11 #include "base/synchronization/lock.h"
12 #include "chromeos/dbus/power_manager_client.h"
13
14 namespace power_manager {
15 class PowerSupplyProperties;
16 }
17
18 namespace chromeos {
19
20 // A class which starts collecting power metrics, like the battery charge, as
21 // soon as it is initialized via Initialize().
22 //
23 // The constructor for this class is private as we want only a single global
24 // instance to be created via Initialize(). Also, Initialize() should be called
25 // only after the DBusThreadManager is initialized. The single global instance
26 // should be destroyed via Shutdown(), and before the DBusThreadManager is
27 // shutdown.
28 class PowerDataCollector
29 : public PowerManagerClient::Observer,
30 public base::RefCountedThreadSafe<PowerDataCollector> {
31 public:
32 struct PowerSupplySnapshot {
33 // Generated by Time::ToInternalValue.
34 int64 time;
Daniel Erat 2013/12/11 01:06:52 why not just use base::TimeTicks here? the interna
Siva Chandra 2013/12/11 20:32:02 Done. How does one convert time ticks to human un
Daniel Erat 2013/12/11 20:59:20 base::TimeDelta is a class that represents an inte
35
36 // true if connected to externel power at the time of the snapshot.
Daniel Erat 2013/12/11 01:06:52 nit: s/externel/external/
Siva Chandra 2013/12/11 20:32:02 Done.
37 bool external_power;
38
39 // The battery charge as a percentage of full charge in range [0.0, 100.00].
40 double battery_charge;
41 };
42
43 public:
44 // Can be called only after DBusThreadManager is initialized.
45 static void Initialize();
46
47 // Can be called only if initialized via Initialize, and before
48 // DBusThreadManager is destroyed.
49 static void Shutdown();
50
51 // Call this when processing the power supply data got from
Daniel Erat 2013/12/11 01:06:52 nit: s/got/received/
Siva Chandra 2013/12/11 20:32:02 Done.
52 // GetPowerSupplyData. Call UnlockPowerSupplyData after done with processing.
53 static void LockPowerSupplyData(void);
Daniel Erat 2013/12/11 01:06:52 this lock/unlock mechanism seems error-prone. why
Siva Chandra 2013/12/11 20:32:02 Why is it error-prone?
Daniel Erat 2013/12/11 20:59:20 it is easy for a caller to acquire the lock and la
54
55 // Returns a reference to a vector of power supply data. Invoke this function
56 // after locking the data with LockPowerSupplyData, and unlock after done
57 // processing the data with UnlockPowerSupplyData.
58 static std::vector<PowerSupplySnapshot> &GetPowerSupplyData(void);
Daniel Erat 2013/12/11 01:06:52 instead of having a bunch of static methods, i thi
Siva Chandra 2013/12/11 20:32:02 Done.
59
60 // Call this after done with processing the power supply data got from
61 // &GetPowerSupplyData.
62 static void UnlockPowerSupplyData(void);
63
64 private:
65 friend class base::RefCountedThreadSafe<PowerDataCollector>;
66 friend class PowerDataCollectorTest;
67 FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, AppendPowerSupplySnapshot);
68
69 // When the 'testing' argument is 'true', the instance is created without
70 // checking for an initialized DBusThreadManager and hence it does not listen
71 // to any PowerManagerClient notifications.
72 explicit PowerDataCollector(const bool testing);
73
74 virtual ~PowerDataCollector() {}
75
76 // Used in tests. Initializes the PowerDataCollector so that unit tests
77 // can be performed without depending on the DBusThreadManager.
78 static void InitializeTesting();
79
80 // Used in tests. Returns the global instance of PowerDataCollector.
81 static PowerDataCollector *Get();
82
83 virtual void PowerChanged(const power_manager::PowerSupplyProperties& prop);
Daniel Erat 2013/12/11 01:06:52 list virtual methods after other methods, add "//
Siva Chandra 2013/12/11 20:32:02 Done.
84 void AppendPowerSupplySnapshot(const PowerSupplySnapshot& snapshot);
85 void Shutdown_Instance(void);
Daniel Erat 2013/12/11 01:06:52 google c++ naming style would be ShutdownInstance
Siva Chandra 2013/12/11 20:32:02 Done.
86
87 // Is true for testing instance.
88 bool testing_;
89
90 base::Lock power_supply_lock_;
91 std::vector<PowerSupplySnapshot> power_supply_;
92
93 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector);
94 };
95
96 } // namespace chromeos
97
98 #endif // CHROMEOS_DBUS_POWER_DATA_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698