Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_POWER_POWER_DATA_COLLECTOR_H_ | |
| 6 #define CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/time/time.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 // This class is implemented as a global singleton, initialized after | |
| 24 // DBusThreadManager which it depends on. | |
| 25 class PowerDataCollector | |
| 26 : public PowerManagerClient::Observer { | |
|
Daniel Erat
2013/12/12 01:31:52
nit: just move this up to the end of the previous
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 27 public: | |
| 28 struct PowerSupplySnapshot { | |
| 29 PowerSupplySnapshot(); | |
| 30 | |
| 31 // Time the snapshot was captured. | |
| 32 base::TimeTicks time; | |
| 33 | |
| 34 // True if connected to external power at the time of the snapshot. | |
| 35 bool external_power; | |
| 36 | |
| 37 // The battery charge as a percentage of full charge in range [0.0, 100.00]. | |
| 38 double battery_charge; | |
|
Daniel Erat
2013/12/12 01:31:52
nit: rename this to |battery_percent| as in PowerS
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 39 }; | |
| 40 | |
| 41 public: | |
|
Daniel Erat
2013/12/12 01:31:52
nit: remove this; there's already a public access
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 42 // Can be called only after DBusThreadManager is initialized. | |
| 43 static void Initialize(); | |
| 44 | |
| 45 // Can be called only if initialized via Initialize, and before | |
| 46 // DBusThreadManager is destroyed. | |
| 47 static void Shutdown(); | |
| 48 | |
| 49 // Returns the global instance of PowerDataCollector. | |
| 50 static PowerDataCollector* Get(); | |
| 51 | |
| 52 // Returns a reference to a vector of power supply data. | |
|
Daniel Erat
2013/12/12 01:31:52
nit: remove unnecessary comment. accessors also us
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 53 const std::vector<PowerSupplySnapshot>& power_supply_data(void) const { | |
|
Daniel Erat
2013/12/12 01:31:52
remove void argument
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 54 return power_supply_data_; | |
| 55 } | |
| 56 | |
| 57 private: | |
| 58 friend class base::RefCountedThreadSafe<PowerDataCollector>; | |
|
Daniel Erat
2013/12/12 01:31:52
remove this
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 59 friend class PowerDataCollectorTest; | |
| 60 FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, PowerChanged); | |
| 61 | |
| 62 explicit PowerDataCollector(); | |
|
Daniel Erat
2013/12/12 01:31:52
remove 'explicit'
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 63 | |
| 64 virtual ~PowerDataCollector(); | |
| 65 | |
| 66 // Used in tests. Initializes the PowerDataCollector so that unit tests | |
| 67 // can be performed without depending on the DBusThreadManager. | |
| 68 static void InitializeTesting(); | |
|
Daniel Erat
2013/12/12 01:31:52
nit: remove this
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 69 | |
| 70 // PowerManagerClient::Observer implementation: | |
| 71 virtual void PowerChanged( | |
| 72 const power_manager::PowerSupplyProperties& prop) OVERRIDE; | |
|
Daniel Erat
2013/12/12 01:31:52
probably safest to include base/compiler_specific.
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 73 | |
| 74 private: | |
| 75 std::vector<PowerSupplySnapshot> power_supply_data_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector); | |
|
Daniel Erat
2013/12/12 01:31:52
i'd include base/basictypes.h as well for this mac
Siva Chandra
2013/12/13 22:10:39
Done.
Siva Chandra
2013/12/13 22:10:39
Done.
| |
| 78 }; | |
| 79 | |
| 80 } // namespace chromeos | |
| 81 | |
| 82 #endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | |
| OLD | NEW |