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/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "chromeos/dbus/power_manager_client.h" | |
| 15 | |
| 16 namespace power_manager { | |
| 17 class PowerSupplyProperties; | |
| 18 } | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 // A class which starts collecting power metrics, like the battery charge, as | |
| 23 // soon as it is initialized via Initialize(). | |
| 24 // | |
| 25 // This class is implemented as a global singleton, initialized after | |
| 26 // DBusThreadManager which it depends on. | |
| 27 class PowerDataCollector : public PowerManagerClient::Observer { | |
| 28 public: | |
| 29 struct PowerSupplySnapshot { | |
| 30 PowerSupplySnapshot(); | |
| 31 | |
| 32 // Time the snapshot was captured. | |
|
stevenjb
2013/12/13 22:28:45
nit: Time when, or Time at which
Siva Chandra
2013/12/13 23:22:39
Done.
| |
| 33 base::TimeTicks time; | |
| 34 | |
| 35 // True if connected to external power at the time of the snapshot. | |
| 36 bool external_power; | |
| 37 | |
| 38 // The battery charge as a percentage of full charge in range [0.0, 100.00]. | |
| 39 double battery_percent; | |
| 40 }; | |
| 41 | |
| 42 const std::vector<PowerSupplySnapshot>& power_supply_data() const { | |
| 43 return power_supply_data_; | |
| 44 } | |
| 45 | |
| 46 // Can be called only after DBusThreadManager is initialized. | |
| 47 static void Initialize(); | |
| 48 | |
| 49 // Can be called only if initialized via Initialize, and before | |
| 50 // DBusThreadManager is destroyed. | |
| 51 static void Shutdown(); | |
| 52 | |
| 53 // Returns the global instance of PowerDataCollector. | |
| 54 static PowerDataCollector* Get(); | |
| 55 | |
| 56 private: | |
| 57 friend class PowerDataCollectorTest; | |
| 58 FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, PowerChanged); | |
| 59 | |
| 60 PowerDataCollector(); | |
| 61 | |
| 62 virtual ~PowerDataCollector(); | |
| 63 | |
| 64 // PowerManagerClient::Observer implementation: | |
| 65 virtual void PowerChanged( | |
| 66 const power_manager::PowerSupplyProperties& prop) OVERRIDE; | |
| 67 | |
| 68 private: | |
| 69 std::vector<PowerSupplySnapshot> power_supply_data_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector); | |
| 72 }; | |
| 73 | |
| 74 } // namespace chromeos | |
| 75 | |
| 76 #endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | |
| OLD | NEW |