summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorsivachandra@chromium.org <sivachandra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 04:53:51 +0000
committersivachandra@chromium.org <sivachandra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 04:53:51 +0000
commit879eb06ab4f02da130e490bee7a5532392c5649a (patch)
tree28dd110da6a0b4c98c3452632bf50b5874f3f3c7 /chromeos
parenta5ac474f2dd210ce87a1a4652ddbd9937bc9dc07 (diff)
downloadchromium_src-879eb06ab4f02da130e490bee7a5532392c5649a.zip
chromium_src-879eb06ab4f02da130e490bee7a5532392c5649a.tar.gz
chromium_src-879eb06ab4f02da130e490bee7a5532392c5649a.tar.bz2
[chromeos] Move files from chromeos/power to chrome/browser/chromeos/power
This is being done so that content::BrowserThread can be used in PowerDataCollector, which is required for future changes. BUG=312956,335816 TBR=arv Review URL: https://codereview.chromium.org/153153002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp3
-rw-r--r--chromeos/power/power_data_collector.cc82
-rw-r--r--chromeos/power/power_data_collector.h115
-rw-r--r--chromeos/power/power_data_collector_unittest.cc88
4 files changed, 0 insertions, 288 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 33cc695..3922ba0 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -320,8 +320,6 @@
'network/shill_property_util.h',
'network/dhcp_proxy_script_fetcher_chromeos.cc',
'network/dhcp_proxy_script_fetcher_chromeos.h',
- 'power/power_data_collector.cc',
- 'power/power_data_collector.h',
'process_proxy/process_output_watcher.cc',
'process_proxy/process_output_watcher.h',
'process_proxy/process_proxy.cc',
@@ -521,7 +519,6 @@
'network/onc/onc_validator_unittest.cc',
'network/shill_property_handler_unittest.cc',
'network/shill_property_util_unittest.cc',
- 'power/power_data_collector_unittest.cc',
'process_proxy/process_output_watcher_unittest.cc',
'process_proxy/process_proxy_unittest.cc',
'system/name_value_pairs_parser_unittest.cc',
diff --git a/chromeos/power/power_data_collector.cc b/chromeos/power/power_data_collector.cc
deleted file mode 100644
index 8d1811b..0000000
--- a/chromeos/power/power_data_collector.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 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.
-
-#include "chromeos/power/power_data_collector.h"
-
-#include "base/logging.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
-
-namespace chromeos {
-
-namespace {
-
-// The global PowerDataCollector instance.
-PowerDataCollector* g_power_data_collector = NULL;
-
-} // namespace
-
-const int PowerDataCollector::kSampleTimeLimitSec = 24 * 60 * 60;
-
-// static
-void PowerDataCollector::Initialize() {
- // Check that power data collector is initialized only after the
- // DBusThreadManager is initialized.
- CHECK(DBusThreadManager::Get());
- CHECK(g_power_data_collector == NULL);
- g_power_data_collector = new PowerDataCollector();
-}
-
-// static
-void PowerDataCollector::Shutdown() {
- // Shutdown only if initialized.
- CHECK(g_power_data_collector);
- delete g_power_data_collector;
- g_power_data_collector = NULL;
-}
-
-// static
-PowerDataCollector* PowerDataCollector::Get() {
- CHECK(g_power_data_collector);
- return g_power_data_collector;
-}
-
-void PowerDataCollector::PowerChanged(
- const power_manager::PowerSupplyProperties& prop) {
- PowerSupplySample sample;
- sample.time = base::Time::Now();
- sample.external_power = (prop.external_power() !=
- power_manager::PowerSupplyProperties::DISCONNECTED);
- sample.battery_percent = prop.battery_percent();
- sample.battery_discharge_rate = prop.battery_discharge_rate();
- AddSample(&power_supply_data_, sample);
-}
-
-void PowerDataCollector::SystemResumed(const base::TimeDelta& sleep_duration) {
- SystemResumedSample sample;
- sample.time = base::Time::Now();
- sample.sleep_duration = sleep_duration;
- AddSample(&system_resumed_data_, sample);
-}
-
-PowerDataCollector::PowerDataCollector() {
- DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
-}
-
-PowerDataCollector::~PowerDataCollector() {
- DBusThreadManager* dbus_manager = DBusThreadManager::Get();
- CHECK(dbus_manager);
- dbus_manager->GetPowerManagerClient()->RemoveObserver(this);
-}
-
-PowerDataCollector::PowerSupplySample::PowerSupplySample()
- : external_power(false),
- battery_percent(0.0),
- battery_discharge_rate(0.0) {
-}
-
-PowerDataCollector::SystemResumedSample::SystemResumedSample() {
-}
-
-} // namespace chromeos
diff --git a/chromeos/power/power_data_collector.h b/chromeos/power/power_data_collector.h
deleted file mode 100644
index f57a0e9..0000000
--- a/chromeos/power/power_data_collector.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 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 <deque>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/time/time.h"
-#include "chromeos/chromeos_export.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 CHROMEOS_EXPORT PowerDataCollector : public PowerManagerClient::Observer {
- public:
- struct PowerSupplySample {
- PowerSupplySample();
-
- // Time when the sample was captured. We use base::Time instead of
- // base::TimeTicks because the latter does not advance when the system is
- // suspended.
- base::Time time;
-
- // True if connected to external power at the time of the sample.
- bool external_power;
-
- // The battery charge as a percentage of full charge in range [0.0, 100.00].
- double battery_percent;
-
- // The battery discharge rate in W. Positive if the battery is being
- // discharged and negative if it's being charged.
- double battery_discharge_rate;
- };
-
- struct SystemResumedSample {
- SystemResumedSample();
-
- // Time when the system resumed.
- base::Time time;
-
- // The duration for which the system was in sleep/suspend state.
- base::TimeDelta sleep_duration;
- };
-
- const std::deque<PowerSupplySample>& power_supply_data() const {
- return power_supply_data_;
- }
-
- const std::deque<SystemResumedSample>& system_resumed_data() const {
- return system_resumed_data_;
- }
-
- // 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();
-
- // PowerManagerClient::Observer implementation:
- virtual void PowerChanged(
- const power_manager::PowerSupplyProperties& prop) OVERRIDE;
- virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE;
-
- // Only those power data samples which fall within the last
- // |kSampleTimeLimitSec| are stored in memory.
- static const int kSampleTimeLimitSec;
-
- private:
- PowerDataCollector();
-
- virtual ~PowerDataCollector();
-
- std::deque<PowerSupplySample> power_supply_data_;
- std::deque<SystemResumedSample> system_resumed_data_;
-
- DISALLOW_COPY_AND_ASSIGN(PowerDataCollector);
-};
-
-// Adds |sample| to |sample_deque|.
-// It dumps samples |PowerDataCollector::kSampleTimeLimitSec| or more older than
-// |sample|.
-template <typename SampleType>
-void AddSample(std::deque<SampleType>* sample_queue, const SampleType& sample) {
- while (!sample_queue->empty()) {
- const SampleType& first = sample_queue->front();
- if (sample.time - first.time >
- base::TimeDelta::FromSeconds(PowerDataCollector::kSampleTimeLimitSec)) {
- sample_queue->pop_front();
- } else {
- break;
- }
- }
- sample_queue->push_back(sample);
-}
-
-} // namespace chromeos
-
-#endif // CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_
diff --git a/chromeos/power/power_data_collector_unittest.cc b/chromeos/power/power_data_collector_unittest.cc
deleted file mode 100644
index ac38038..0000000
--- a/chromeos/power/power_data_collector_unittest.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 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.
-
-#include "chromeos/power/power_data_collector.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/fake_dbus_thread_manager.h"
-#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace chromeos {
-
-class PowerDataCollectorTest : public testing::Test {
- public:
- PowerDataCollectorTest() : power_data_collector_(NULL) {}
- virtual ~PowerDataCollectorTest() {}
-
- virtual void SetUp() OVERRIDE {
- FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
- fake_dbus_thread_manager->SetFakeClients();
- DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
- PowerDataCollector::Initialize();
- power_data_collector_ = PowerDataCollector::Get();
- }
-
- virtual void TearDown() OVERRIDE {
- PowerDataCollector::Shutdown();
- DBusThreadManager::Shutdown();
- power_data_collector_ = NULL;
- }
-
- protected:
- PowerDataCollector* power_data_collector_;
-};
-
-TEST_F(PowerDataCollectorTest, PowerChanged) {
- power_manager::PowerSupplyProperties prop1, prop2;
-
- prop1.set_external_power(power_manager::PowerSupplyProperties::DISCONNECTED);
- prop1.set_battery_percent(20.00);
- power_data_collector_->PowerChanged(prop1);
- const std::deque<PowerDataCollector::PowerSupplySample>& data1 =
- power_data_collector_->power_supply_data();
- ASSERT_EQ(static_cast<size_t>(1), data1.size());
- EXPECT_DOUBLE_EQ(prop1.battery_percent(), data1[0].battery_percent);
- EXPECT_FALSE(data1[0].external_power);
-
- prop2.set_external_power(power_manager::PowerSupplyProperties::AC);
- prop2.set_battery_percent(100.00);
- power_data_collector_->PowerChanged(prop2);
- const std::deque<PowerDataCollector::PowerSupplySample>& data2 =
- power_data_collector_->power_supply_data();
- ASSERT_EQ(static_cast<size_t>(2), data2.size());
- EXPECT_DOUBLE_EQ(prop2.battery_percent(), data2[1].battery_percent);
- EXPECT_TRUE(data2[1].external_power);
-}
-
-TEST_F(PowerDataCollectorTest, SystemResumed) {
- power_data_collector_->SystemResumed(base::TimeDelta::FromSeconds(10));
- const std::deque<PowerDataCollector::SystemResumedSample>& data1 =
- power_data_collector_->system_resumed_data();
- ASSERT_EQ(static_cast<size_t>(1), data1.size());
- ASSERT_EQ(static_cast<int64>(10), data1[0].sleep_duration.InSeconds());
-
- power_data_collector_->SystemResumed(base::TimeDelta::FromSeconds(20));
- const std::deque<PowerDataCollector::SystemResumedSample>& data2 =
- power_data_collector_->system_resumed_data();
- ASSERT_EQ(static_cast<size_t>(2), data2.size());
- ASSERT_EQ(static_cast<int64>(20), data2[1].sleep_duration.InSeconds());
-}
-
-TEST_F(PowerDataCollectorTest, AddSample) {
- std::deque<PowerDataCollector::PowerSupplySample> sample_deque;
- PowerDataCollector::PowerSupplySample sample1, sample2;
- sample1.time = base::Time::FromInternalValue(1000);
- sample2.time = sample1.time +
- base::TimeDelta::FromSeconds(PowerDataCollector::kSampleTimeLimitSec + 1);
-
- AddSample(&sample_deque, sample1);
- ASSERT_EQ(static_cast<size_t>(1), sample_deque.size());
-
- AddSample(&sample_deque, sample2);
- ASSERT_EQ(static_cast<size_t>(1), sample_deque.size());
- EXPECT_EQ(sample2.time.ToInternalValue(),
- sample_deque[0].time.ToInternalValue());
-}
-
-} // namespace chromeos