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

Unified Diff: chrome/browser/chromeos/cros/power_library.cc

Issue 8271024: chromeos: Add power supply info reading capability (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 9 years, 1 month 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: chrome/browser/chromeos/cros/power_library.cc
diff --git a/chrome/browser/chromeos/cros/power_library.cc b/chrome/browser/chromeos/cros/power_library.cc
index f091e216334449dac6ea3d4458cbe4c0628d0dab..ca3de978ec461bdffe41f36ba542b0bce0c7b0c0 100644
--- a/chrome/browser/chromeos/cros/power_library.cc
+++ b/chrome/browser/chromeos/cros/power_library.cc
@@ -11,8 +11,6 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/observer_list.h"
-#include "base/time.h"
-#include "base/timer.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/cros/chromeos_power.h"
@@ -25,15 +23,10 @@ namespace chromeos {
class PowerLibraryImpl : public PowerLibrary {
public:
PowerLibraryImpl()
- : power_status_connection_(NULL),
- resume_status_connection_(NULL) {
+ : resume_status_connection_(NULL) {
}
virtual ~PowerLibraryImpl() {
- if (power_status_connection_) {
- chromeos::DisconnectPowerStatus(power_status_connection_);
- power_status_connection_ = NULL;
- }
if (resume_status_connection_) {
chromeos::DisconnectResume(resume_status_connection_);
resume_status_connection_ = NULL;
@@ -43,8 +36,6 @@ class PowerLibraryImpl : public PowerLibrary {
// Begin PowerLibrary implementation.
virtual void Init() OVERRIDE {
DCHECK(CrosLibrary::Get()->libcros_loaded());
- power_status_connection_ =
- chromeos::MonitorPowerStatus(&PowerStatusChangedHandler, this);
resume_status_connection_ =
chromeos::MonitorResume(&SystemResumedHandler, this);
}
@@ -82,12 +73,6 @@ class PowerLibraryImpl : public PowerLibrary {
chromeos::RequestShutdown();
}
- virtual void RequestStatusUpdate() OVERRIDE {
- // TODO(stevenjb): chromeos::RetrievePowerInformation has been deprecated;
- // we should add a mechanism to immediately request an update, probably
- // when we migrate the DBus code from libcros to here.
- }
-
// End PowerLibrary implementation.
private:
@@ -110,40 +95,11 @@ class PowerLibraryImpl : public PowerLibrary {
delete notify;
}
- static void PowerStatusChangedHandler(
- void* object, const chromeos::PowerStatus& power_status) {
- // TODO(sque): this is a temporary copy-over from libcros. Soon libcros
- // will be removed and this will not be necessary.
- PowerSupplyStatus status;
- status.line_power_on = power_status.line_power_on;
- status.battery_is_present = power_status.battery_is_present;
- status.battery_is_full =
- (power_status.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED);
- status.battery_seconds_to_empty = power_status.battery_time_to_empty;
- status.battery_seconds_to_full = power_status.battery_time_to_full;
- status.battery_percentage = power_status.battery_percentage;
-
- PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object);
- power->UpdatePowerStatus(status);
- }
-
static void SystemResumedHandler(void* object) {
PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object);
power->SystemResumed();
}
- void UpdatePowerStatus(const PowerSupplyStatus& status) {
- // Called from PowerStatusChangedHandler, a libcros callback which
- // should always run on UI thread.
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- DVLOG(1) << "Power line_power_on = " << status.line_power_on
- << " percentage = " << status.battery_percentage
- << " seconds_to_empty = " << status.battery_seconds_to_empty
- << " seconds_to_full = " << status.battery_seconds_to_full;
- FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status));
- }
-
void SystemResumed() {
// Called from SystemResumedHandler, a libcros callback which should
// always run on UI thread.
@@ -153,10 +109,6 @@ class PowerLibraryImpl : public PowerLibrary {
ObserverList<Observer> observers_;
- // A reference to the power battery API, to allow callbacks when the battery
- // status changes.
- chromeos::PowerStatusConnection power_status_connection_;
-
// A reference to the resume alerts.
chromeos::ResumeConnection resume_status_connection_;
@@ -167,10 +119,7 @@ class PowerLibraryImpl : public PowerLibrary {
// fully charged and fully depleted states.
class PowerLibraryStubImpl : public PowerLibrary {
public:
- PowerLibraryStubImpl()
- : discharging_(true),
- battery_percentage_(80),
- pause_count_(0) {
+ PowerLibraryStubImpl() {
}
virtual ~PowerLibraryStubImpl() {}
@@ -196,56 +145,9 @@ class PowerLibraryStubImpl : public PowerLibrary {
virtual void RequestShutdown() OVERRIDE {}
- virtual void RequestStatusUpdate() OVERRIDE {
- if (!timer_.IsRunning()) {
- timer_.Start(
- FROM_HERE,
- base::TimeDelta::FromMilliseconds(100),
- this,
- &PowerLibraryStubImpl::Update);
- } else {
- timer_.Stop();
- }
- }
-
// End PowerLibrary implementation.
-
private:
- void Update() {
- // We pause at 0 and 100% so that it's easier to check those conditions.
- if (pause_count_ > 1) {
- pause_count_--;
- return;
- }
-
- if (battery_percentage_ == 0 || battery_percentage_ == 100) {
- if (pause_count_) {
- pause_count_ = 0;
- discharging_ = !discharging_;
- } else {
- pause_count_ = 20;
- return;
- }
- }
- battery_percentage_ += (discharging_ ? -1 : 1);
-
- PowerSupplyStatus status;
- status.line_power_on = !discharging_;
- status.battery_is_present = true;
- status.battery_percentage = battery_percentage_;
- status.battery_seconds_to_empty =
- std::max(1, battery_percentage_ * 180 / 100);
- status.battery_seconds_to_full =
- std::max(static_cast<int64>(1), 180 - status.battery_seconds_to_empty);
-
- FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status));
- }
-
- bool discharging_;
- int battery_percentage_;
- int pause_count_;
ObserverList<Observer> observers_;
- base::RepeatingTimer<PowerLibraryStubImpl> timer_;
};
// static

Powered by Google App Engine
This is Rietveld 408576698