Chromium Code Reviews| Index: chromeos/power/power_data_collector.h |
| diff --git a/chromeos/power/power_data_collector.h b/chromeos/power/power_data_collector.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6c1c1f27ba479b6161e9dced9bc9320a03e94a64 |
| --- /dev/null |
| +++ b/chromeos/power/power_data_collector.h |
| @@ -0,0 +1,82 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ |
| +#define CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/gtest_prod_util.h" |
| +#include "base/time/time.h" |
| +#include "chromeos/dbus/power_manager_client.h" |
| + |
| +namespace power_manager { |
| +class PowerSupplyProperties; |
| +} |
| + |
| +namespace chromeos { |
| + |
| +// A class which starts collecting power metrics, like the battery charge, as |
| +// soon as it is initialized via Initialize(). |
| +// |
| +// This class is implemented as a global singleton, initialized after |
| +// DBusThreadManager which it depends on. |
| +class PowerDataCollector |
| + : 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.
|
| + public: |
| + struct PowerSupplySnapshot { |
| + PowerSupplySnapshot(); |
| + |
| + // Time the snapshot was captured. |
| + base::TimeTicks time; |
| + |
| + // True if connected to external power at the time of the snapshot. |
| + bool external_power; |
| + |
| + // The battery charge as a percentage of full charge in range [0.0, 100.00]. |
| + 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.
|
| + }; |
| + |
| + 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.
|
| + // Can be called only after DBusThreadManager is initialized. |
| + static void Initialize(); |
| + |
| + // Can be called only if initialized via Initialize, and before |
| + // DBusThreadManager is destroyed. |
| + static void Shutdown(); |
| + |
| + // Returns the global instance of PowerDataCollector. |
| + static PowerDataCollector* Get(); |
| + |
| + // 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.
|
| + 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.
|
| + return power_supply_data_; |
| + } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PowerDataCollector>; |
|
Daniel Erat
2013/12/12 01:31:52
remove this
Siva Chandra
2013/12/13 22:10:39
Done.
|
| + friend class PowerDataCollectorTest; |
| + FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, PowerChanged); |
| + |
| + explicit PowerDataCollector(); |
|
Daniel Erat
2013/12/12 01:31:52
remove 'explicit'
Siva Chandra
2013/12/13 22:10:39
Done.
|
| + |
| + virtual ~PowerDataCollector(); |
| + |
| + // Used in tests. Initializes the PowerDataCollector so that unit tests |
| + // can be performed without depending on the DBusThreadManager. |
| + static void InitializeTesting(); |
|
Daniel Erat
2013/12/12 01:31:52
nit: remove this
Siva Chandra
2013/12/13 22:10:39
Done.
|
| + |
| + // PowerManagerClient::Observer implementation: |
| + virtual void PowerChanged( |
| + 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.
|
| + |
| + private: |
| + std::vector<PowerSupplySnapshot> power_supply_data_; |
| + |
| + 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.
|
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ |