OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/power/power_data_collector.h" | 5 #include "chrome/browser/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 |
11 namespace chromeos { | 11 namespace chromeos { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // The global PowerDataCollector instance. | 15 // The global PowerDataCollector instance. |
16 PowerDataCollector* g_power_data_collector = NULL; | 16 PowerDataCollector* g_power_data_collector = NULL; |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 const int PowerDataCollector::kSampleTimeLimitSec = 24 * 60 * 60; | 20 const int PowerDataCollector::kSampleTimeLimitSec = 24 * 60 * 60; |
21 | 21 |
22 // static | 22 // static |
23 void PowerDataCollector::Initialize() { | 23 void PowerDataCollector::Initialize() { |
24 // Check that power data collector is initialized only after the | 24 // Check that power data collector is initialized only after the |
25 // DBusThreadManager is initialized. | 25 // DBusThreadManager is initialized. |
26 CHECK(DBusThreadManager::Get()); | 26 CHECK(DBusThreadManager::Get()); |
27 CHECK(g_power_data_collector == NULL); | 27 CHECK(g_power_data_collector == NULL); |
28 g_power_data_collector = new PowerDataCollector(); | 28 g_power_data_collector = new PowerDataCollector(true); |
| 29 } |
| 30 |
| 31 void PowerDataCollector::InitializeForTesting() { |
| 32 CHECK(DBusThreadManager::Get()); |
| 33 CHECK(g_power_data_collector == NULL); |
| 34 g_power_data_collector = new PowerDataCollector(false); |
29 } | 35 } |
30 | 36 |
31 // static | 37 // static |
32 void PowerDataCollector::Shutdown() { | 38 void PowerDataCollector::Shutdown() { |
33 // Shutdown only if initialized. | 39 // Shutdown only if initialized. |
34 CHECK(g_power_data_collector); | 40 CHECK(g_power_data_collector); |
35 delete g_power_data_collector; | 41 delete g_power_data_collector; |
36 g_power_data_collector = NULL; | 42 g_power_data_collector = NULL; |
37 } | 43 } |
38 | 44 |
(...skipping 14 matching lines...) Expand all Loading... |
53 AddSample(&power_supply_data_, sample); | 59 AddSample(&power_supply_data_, sample); |
54 } | 60 } |
55 | 61 |
56 void PowerDataCollector::SystemResumed(const base::TimeDelta& sleep_duration) { | 62 void PowerDataCollector::SystemResumed(const base::TimeDelta& sleep_duration) { |
57 SystemResumedSample sample; | 63 SystemResumedSample sample; |
58 sample.time = base::Time::Now(); | 64 sample.time = base::Time::Now(); |
59 sample.sleep_duration = sleep_duration; | 65 sample.sleep_duration = sleep_duration; |
60 AddSample(&system_resumed_data_, sample); | 66 AddSample(&system_resumed_data_, sample); |
61 } | 67 } |
62 | 68 |
63 PowerDataCollector::PowerDataCollector() { | 69 PowerDataCollector::PowerDataCollector(const bool start_cpu_data_collector) { |
64 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 70 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 71 if (start_cpu_data_collector) |
| 72 cpu_data_collector_.Start(); |
65 } | 73 } |
66 | 74 |
67 PowerDataCollector::~PowerDataCollector() { | 75 PowerDataCollector::~PowerDataCollector() { |
68 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); | 76 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
69 CHECK(dbus_manager); | 77 CHECK(dbus_manager); |
70 dbus_manager->GetPowerManagerClient()->RemoveObserver(this); | 78 dbus_manager->GetPowerManagerClient()->RemoveObserver(this); |
71 } | 79 } |
72 | 80 |
73 PowerDataCollector::PowerSupplySample::PowerSupplySample() | 81 PowerDataCollector::PowerSupplySample::PowerSupplySample() |
74 : external_power(false), | 82 : external_power(false), |
75 battery_percent(0.0), | 83 battery_percent(0.0), |
76 battery_discharge_rate(0.0) { | 84 battery_discharge_rate(0.0) { |
77 } | 85 } |
78 | 86 |
79 PowerDataCollector::SystemResumedSample::SystemResumedSample() { | 87 PowerDataCollector::SystemResumedSample::SystemResumedSample() { |
80 } | 88 } |
81 | 89 |
82 } // namespace chromeos | 90 } // namespace chromeos |
OLD | NEW |