Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Unified Diff: chromeos/power/power_data_collector.h

Issue 101963004: [chromeos] New PowerManagerClient observer to collect power data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove a now unused global constant Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..eee9f98348b1a8603d0b358ef656b0e924c42217
--- /dev/null
+++ b/chromeos/power/power_data_collector.h
@@ -0,0 +1,88 @@
+// 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/synchronization/lock.h"
Daniel Erat 2013/12/11 22:26:47 nit: remove this
Siva Chandra 2013/12/12 00:35:59 Done. I realize now that I did not remove a lot o
+#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,
+ public base::RefCountedThreadSafe<PowerDataCollector> {
Daniel Erat 2013/12/11 22:26:47 you don't need this, i don't think (as this will o
Siva Chandra 2013/12/12 00:35:59 Done.
+ public:
+ struct PowerSupplySnapshot {
Daniel Erat 2013/12/11 22:26:47 this creates a default c'tor that leaves |external
Siva Chandra 2013/12/12 00:35:59 Done.
+ // 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;
+ };
+
+ public:
+ // 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();
Daniel Erat 2013/12/11 22:26:47 nit: move '*' to left side of space to match the r
Siva Chandra 2013/12/12 00:35:59 Done.
+
+ // Returns a reference to a vector of power supply data.
+ std::vector<PowerSupplySnapshot> &GetPowerSupplyData(void);
Daniel Erat 2013/12/11 22:26:47 nit: make this be a const reference and move '&' t
Siva Chandra 2013/12/12 00:35:59 Done.
+
+ private:
+ friend class base::RefCountedThreadSafe<PowerDataCollector>;
+ friend class PowerDataCollectorTest;
+ FRIEND_TEST_ALL_PREFIXES(PowerDataCollectorTest, AppendPowerSupplySnapshot);
+
+ // When the 'testing' argument is 'true', the instance is created without
+ // checking for an initialized DBusThreadManager and hence it does not listen
+ // to any PowerManagerClient notifications.
+ explicit PowerDataCollector(const bool testing);
+
+ virtual ~PowerDataCollector() {}
Daniel Erat 2013/12/11 22:26:47 move the destructor implementation to the .cc file
Siva Chandra 2013/12/12 00:35:59 Done.
+
+ // Used in tests. Initializes the PowerDataCollector so that unit tests
+ // can be performed without depending on the DBusThreadManager.
+ static void InitializeTesting();
+
+ void ShutdownInstance(void);
Daniel Erat 2013/12/11 22:26:47 get rid of this method and just do cleanup in the
Siva Chandra 2013/12/12 00:35:59 Done.
+
+ // PowerManagerClient::Observer implementation:
+ virtual void PowerChanged(
+ const power_manager::PowerSupplyProperties& prop) OVERRIDE;
+
+ private:
+ // Is true for testing instance.
+ bool testing_;
+
+ std::vector<PowerSupplySnapshot> power_supply_;
+
+ DISALLOW_COPY_AND_ASSIGN(PowerDataCollector);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_

Powered by Google App Engine
This is Rietveld 408576698