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 #include "chromeos/power/power_data_collector.h" | 5 #include "chromeos/power/power_data_collector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 return g_power_data_collector; | 42 return g_power_data_collector; |
43 } | 43 } |
44 | 44 |
45 void PowerDataCollector::PowerChanged( | 45 void PowerDataCollector::PowerChanged( |
46 const power_manager::PowerSupplyProperties& prop) { | 46 const power_manager::PowerSupplyProperties& prop) { |
47 PowerSupplySnapshot snapshot; | 47 PowerSupplySnapshot snapshot; |
48 snapshot.time = base::TimeTicks::Now(); | 48 snapshot.time = base::TimeTicks::Now(); |
49 snapshot.external_power = (prop.external_power() != | 49 snapshot.external_power = (prop.external_power() != |
50 power_manager::PowerSupplyProperties::DISCONNECTED); | 50 power_manager::PowerSupplyProperties::DISCONNECTED); |
51 snapshot.battery_percent = prop.battery_percent(); | 51 snapshot.battery_percent = prop.battery_percent(); |
52 snapshot.battery_discharge_rate = prop.battery_discharge_rate(); | |
52 AddSnapshot(snapshot); | 53 AddSnapshot(snapshot); |
53 } | 54 } |
54 | 55 |
55 PowerDataCollector::PowerDataCollector() { | 56 PowerDataCollector::PowerDataCollector() { |
56 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 57 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
57 } | 58 } |
58 | 59 |
59 PowerDataCollector::~PowerDataCollector() { | 60 PowerDataCollector::~PowerDataCollector() { |
60 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); | 61 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
61 CHECK(dbus_manager); | 62 CHECK(dbus_manager); |
62 dbus_manager->GetPowerManagerClient()->RemoveObserver(this); | 63 dbus_manager->GetPowerManagerClient()->RemoveObserver(this); |
63 } | 64 } |
64 | 65 |
65 void PowerDataCollector::AddSnapshot(const PowerSupplySnapshot& snapshot) { | 66 void PowerDataCollector::AddSnapshot(const PowerSupplySnapshot& snapshot) { |
66 while (!power_supply_data_.empty()) { | 67 while (!power_supply_data_.empty()) { |
67 const PowerSupplySnapshot& first = power_supply_data_.front(); | 68 const PowerSupplySnapshot& first = power_supply_data_.front(); |
68 if (snapshot.time - first.time > | 69 if (snapshot.time - first.time > |
69 base::TimeDelta::FromSeconds(kSampleTimeLimitSec)) { | 70 base::TimeDelta::FromSeconds(kSampleTimeLimitSec)) { |
70 power_supply_data_.pop_front(); | 71 power_supply_data_.pop_front(); |
71 } else { | 72 } else { |
72 break; | 73 break; |
73 } | 74 } |
74 } | 75 } |
75 power_supply_data_.push_back(snapshot); | 76 power_supply_data_.push_back(snapshot); |
76 } | 77 } |
77 | 78 |
78 PowerDataCollector::PowerSupplySnapshot::PowerSupplySnapshot() | 79 PowerDataCollector::PowerSupplySnapshot::PowerSupplySnapshot() |
79 : time(base::TimeTicks::Now()), | 80 : time(base::TimeTicks::Now()), |
80 external_power(false), | 81 external_power(false), |
81 battery_percent(0) { | 82 battery_percent(0) { |
Daniel Erat
2014/01/16 18:06:38
initialize battery_discharge_rate to 0.0 here
| |
82 } | 83 } |
83 | 84 |
84 } // namespace chromeos | 85 } // namespace chromeos |
OLD | NEW |