| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | 5 #ifndef CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ |
| 6 #define CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | 6 #define CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
| 14 #include "chromeos/dbus/power_manager_client.h" | 15 #include "chromeos/dbus/power_manager_client.h" |
| 15 | 16 |
| 16 namespace power_manager { | 17 namespace power_manager { |
| 17 class PowerSupplyProperties; | 18 class PowerSupplyProperties; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 | 22 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 // Time when the snapshot was captured. | 33 // Time when the snapshot was captured. |
| 33 base::TimeTicks time; | 34 base::TimeTicks time; |
| 34 | 35 |
| 35 // True if connected to external power at the time of the snapshot. | 36 // True if connected to external power at the time of the snapshot. |
| 36 bool external_power; | 37 bool external_power; |
| 37 | 38 |
| 38 // The battery charge as a percentage of full charge in range [0.0, 100.00]. | 39 // The battery charge as a percentage of full charge in range [0.0, 100.00]. |
| 39 double battery_percent; | 40 double battery_percent; |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 const std::vector<PowerSupplySnapshot>& power_supply_data() const { | 43 const std::deque<PowerSupplySnapshot>& power_supply_data() const { |
| 43 return power_supply_data_; | 44 return power_supply_data_; |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Can be called only after DBusThreadManager is initialized. | 47 // Can be called only after DBusThreadManager is initialized. |
| 47 static void Initialize(); | 48 static void Initialize(); |
| 48 | 49 |
| 49 // Can be called only if initialized via Initialize, and before | 50 // Can be called only if initialized via Initialize, and before |
| 50 // DBusThreadManager is destroyed. | 51 // DBusThreadManager is destroyed. |
| 51 static void Shutdown(); | 52 static void Shutdown(); |
| 52 | 53 |
| 53 // Returns the global instance of PowerDataCollector. | 54 // Returns the global instance of PowerDataCollector. |
| 54 static PowerDataCollector* Get(); | 55 static PowerDataCollector* Get(); |
| 55 | 56 |
| 56 // PowerManagerClient::Observer implementation: | 57 // PowerManagerClient::Observer implementation: |
| 57 virtual void PowerChanged( | 58 virtual void PowerChanged( |
| 58 const power_manager::PowerSupplyProperties& prop) OVERRIDE; | 59 const power_manager::PowerSupplyProperties& prop) OVERRIDE; |
| 59 | 60 |
| 61 // Only those power data samples which fall within the last |
| 62 // |kSampleTimeLimitSec| are stored in memory. |
| 63 static const int kSampleTimeLimitSec; |
| 64 |
| 60 private: | 65 private: |
| 66 FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, AddSnapshot); |
| 67 |
| 61 PowerDataCollector(); | 68 PowerDataCollector(); |
| 62 | 69 |
| 63 virtual ~PowerDataCollector(); | 70 virtual ~PowerDataCollector(); |
| 64 | 71 |
| 65 std::vector<PowerSupplySnapshot> power_supply_data_; | 72 // Adds a snapshot to |power_supply_data_|. |
| 73 // It dumps snapshots |kSampleTimeLimitSec| or more older than |snapshot|. |
| 74 void AddSnapshot(const PowerSupplySnapshot& snapshot); |
| 75 |
| 76 std::deque<PowerSupplySnapshot> power_supply_data_; |
| 66 | 77 |
| 67 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector); | 78 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector); |
| 68 }; | 79 }; |
| 69 | 80 |
| 70 } // namespace chromeos | 81 } // namespace chromeos |
| 71 | 82 |
| 72 #endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ | 83 #endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ |
| OLD | NEW |