| 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 01aeb4b50643853fb73d87d8f29bc69ef4aff899..a4f69820e293f69e99d40660924078cd2da381e3 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"
|
| @@ -23,15 +21,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;
|
| @@ -41,8 +34,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);
|
| }
|
| @@ -62,14 +53,11 @@ class PowerLibraryImpl : public PowerLibrary {
|
| }
|
|
|
| virtual void EnableScreenLock(bool enable) OVERRIDE {
|
| - // Called when the screen preference is changed, which should always
|
| - // run on UI thread.
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // Post the task to FILE thread as chromeos::EnableScreenLock
|
| + // Make sure we run on FILE thread because chromeos::EnableScreenLock
|
| // would write power manager config file to disk.
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - base::Bind(&PowerLibraryImpl::DoEnableScreenLock, enable));
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| +
|
| + chromeos::EnableScreenLock(enable);
|
| }
|
|
|
| virtual void RequestRestart() OVERRIDE {
|
| @@ -85,7 +73,6 @@ class PowerLibraryImpl : public PowerLibrary {
|
| // 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:
|
| @@ -108,53 +95,21 @@ 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.
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| FOR_EACH_OBSERVER(Observer, observers_, SystemResumed());
|
| }
|
|
|
| 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_;
|
|
|
| @@ -165,10 +120,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() {}
|
| @@ -194,56 +146,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
|
|
|