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 #include "base/logging.h" | |
| 6 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 7 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | |
| 8 #include "chromeos/power/power_data_collector.h" | |
|
Daniel Erat
2013/12/11 22:26:47
move this include to the top of the list and separ
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 9 | |
| 10 namespace chromeos { | |
| 11 | |
| 12 // The global PowerDataCollector instance. | |
| 13 static PowerDataCollector* power_data_collector; | |
|
Daniel Erat
2013/12/11 22:26:47
put this in a nested anonymous namespace instead o
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 14 | |
| 15 PowerDataCollector::PowerDataCollector(const bool testing) | |
| 16 : testing_(testing) { | |
| 17 AddRef(); | |
|
Daniel Erat
2013/12/11 22:26:47
delete this
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 18 | |
| 19 if (!testing) { | |
| 20 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
|
Daniel Erat
2013/12/11 22:26:47
i don't think you need this |testing| flag; can't
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 21 } | |
| 22 } | |
| 23 | |
| 24 void PowerDataCollector::ShutdownInstance() { | |
|
Daniel Erat
2013/12/11 22:26:47
(mentioned earlier: put this in the destructor ins
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 25 if (!testing_) { | |
| 26 DBusThreadManager *dbus_manager = DBusThreadManager::Get(); | |
| 27 | |
| 28 // Destroy the power data collector before the DBusThreadManager. | |
| 29 CHECK(dbus_manager); | |
| 30 | |
| 31 dbus_manager->GetPowerManagerClient()->RemoveObserver(this); | |
| 32 } | |
| 33 | |
| 34 Release(); | |
|
Daniel Erat
2013/12/11 22:26:47
delete this
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 35 } | |
| 36 | |
| 37 void PowerDataCollector::PowerChanged( | |
| 38 const power_manager::PowerSupplyProperties& prop) { | |
| 39 PowerSupplySnapshot snapshot = { | |
|
Daniel Erat
2013/12/11 22:26:47
nit: this would be a bit clearer:
PowerSupplySnap
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 40 base::TimeTicks::Now(), | |
| 41 prop.external_power() != | |
| 42 power_manager::PowerSupplyProperties::DISCONNECTED, | |
| 43 prop.battery_percent() | |
| 44 }; | |
| 45 | |
| 46 power_supply_.push_back(snapshot); | |
| 47 } | |
| 48 | |
| 49 void PowerDataCollector::Initialize() { | |
| 50 // Check that power data collector is initialized only after the | |
| 51 // DBusThreadManager is initialized. | |
| 52 CHECK(DBusThreadManager::Get()); | |
| 53 | |
| 54 // Do no allow intializing twice. | |
|
Daniel Erat
2013/12/11 22:26:47
nit: s/no/not/
(but i don't think that this comme
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 55 CHECK(power_data_collector == NULL); | |
| 56 | |
| 57 power_data_collector = new PowerDataCollector(false); | |
| 58 } | |
| 59 | |
| 60 void PowerDataCollector::InitializeTesting() { | |
|
Daniel Erat
2013/12/11 22:26:47
remove this (see above)
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 61 power_data_collector = new PowerDataCollector(true); | |
| 62 } | |
| 63 | |
| 64 PowerDataCollector *PowerDataCollector::Get() { | |
| 65 CHECK(power_data_collector); | |
| 66 | |
| 67 return power_data_collector; | |
| 68 } | |
| 69 | |
| 70 void PowerDataCollector::Shutdown() { | |
| 71 // Shutdown only if initialized. | |
| 72 CHECK(power_data_collector); | |
| 73 | |
| 74 power_data_collector->ShutdownInstance(); | |
| 75 | |
| 76 // NULL it to protect from improper usage after shutdown. | |
|
Daniel Erat
2013/12/11 22:26:47
nit: delete unnecessary comments and blank lines h
Siva Chandra
2013/12/12 00:35:59
Done.
| |
| 77 power_data_collector = NULL; | |
| 78 } | |
| 79 | |
| 80 std::vector<PowerDataCollector::PowerSupplySnapshot> | |
| 81 &PowerDataCollector::GetPowerSupplyData() { | |
| 82 // Do not allow calling this method after shutdown or before initialization. | |
| 83 CHECK(power_data_collector); | |
| 84 | |
| 85 return power_data_collector->power_supply_; | |
|
Daniel Erat
2013/12/11 22:26:47
(see earlier comment about just making this be an
Siva Chandra
2013/12/12 00:35:59
My bad.
Fixed.
| |
| 86 } | |
| 87 | |
| 88 } // namespace chromeos | |
| OLD | NEW |