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/synchronization/lock.h" | |
|
Daniel Erat
2013/12/11 22:26:47
nit: remove this
Siva Chandra
2013/12/12 00:35:59
Done.
I realize now that I did not remove a lot o
| |
| 12 #include "base/time/time.h" | |
| 13 #include "chromeos/dbus/power_manager_client.h" | |
| 14 | |
| 15 namespace power_manager { | |
| 16 class PowerSupplyProperties; | |
| 17 } | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 // A class which starts collecting power metrics, like the battery charge, as | |
| 22 // soon as it is initialized via Initialize(). | |
| 23 // | |
| 24 // This class is implemented as a global singleton, initialized after | |
| 25 // DBusThreadManager which it depends on. | |
| 26 class PowerDataCollector | |
| 27 : public PowerManagerClient::Observer, | |
| 28 public base::RefCountedThreadSafe<PowerDataCollector> { | |
|
Daniel Erat
2013/12/11 22:26:47
you don't need this, i don't think (as this will o
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 29 public: | |
| 30 struct PowerSupplySnapshot { | |
|
Daniel Erat
2013/12/11 22:26:47
this creates a default c'tor that leaves |external
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 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; | |
| 39 }; | |
| 40 | |
| 41 public: | |
| 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(); | |
|
Daniel Erat
2013/12/11 22:26:47
nit: move '*' to left side of space to match the r
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 51 | |
| 52 // Returns a reference to a vector of power supply data. | |
| 53 std::vector<PowerSupplySnapshot> &GetPowerSupplyData(void); | |
|
Daniel Erat
2013/12/11 22:26:47
nit: make this be a const reference and move '&' t
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 54 | |
| 55 private: | |
| 56 friend class base::RefCountedThreadSafe<PowerDataCollector>; | |
| 57 friend class PowerDataCollectorTest; | |
| 58 FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, AppendPowerSupplySnapshot); | |
| 59 | |
| 60 // When the 'testing' argument is 'true', the instance is created without | |
| 61 // checking for an initialized DBusThreadManager and hence it does not listen | |
| 62 // to any PowerManagerClient notifications. | |
| 63 explicit PowerDataCollector(const bool testing); | |
| 64 | |
| 65 virtual ~PowerDataCollector() {} | |
|
Daniel Erat
2013/12/11 22:26:47
move the destructor implementation to the .cc file
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 66 | |
| 67 // Used in tests. Initializes the PowerDataCollector so that unit tests | |
| 68 // can be performed without depending on the DBusThreadManager. | |
| 69 static void InitializeTesting(); | |
| 70 | |
| 71 void ShutdownInstance(void); | |
|
Daniel Erat
2013/12/11 22:26:47
get rid of this method and just do cleanup in the
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 72 | |
| 73 // PowerManagerClient::Observer implementation: | |
| 74 virtual void PowerChanged( | |
| 75 const power_manager::PowerSupplyProperties& prop) OVERRIDE; | |
| 76 | |
| 77 private: | |
| 78 // Is true for testing instance. | |
| 79 bool testing_; | |
| 80 | |
| 81 std::vector<PowerSupplySnapshot> power_supply_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector); | |
| 84 }; | |
| 85 | |
| 86 } // namespace chromeos | |
| 87 | |
| 88 #endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | |
| OLD | NEW |