Chromium Code Reviews| 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..a9e18d62d45a9c81094557a0326987f1982c9190 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); |
| } |
| @@ -64,14 +55,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); |
|
satorux1
2011/11/03 23:38:47
Why this function is changed? The change does not
Simon Que
2011/11/04 22:35:31
Done.
|
| } |
| virtual void RequestRestart() OVERRIDE { |
| @@ -87,7 +75,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. |
|
satorux1
2011/11/03 23:38:47
Please move the comments to power_manager_client.c
Simon Que
2011/11/04 22:35:31
Done.
|
| } |
| - |
| // End PowerLibrary implementation. |
| private: |
| @@ -110,53 +97,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)); |
| + |
|
satorux1
2011/11/03 23:38:47
Let's not add a blank line here.
Simon Que
2011/11/04 22:35:31
Done.
|
| 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_; |
| @@ -167,10 +122,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 +148,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 |