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 acde536b9fdccfb3aa2412f8916cd9607841f29c..b9be7fe4153655b3edcfb78d147581b853947687 100644 |
--- a/chrome/browser/chromeos/cros/power_library.cc |
+++ b/chrome/browser/chromeos/cros/power_library.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/chromeos/cros/power_library.h" |
+#include <algorithm> |
+ |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
#include "base/logging.h" |
@@ -21,8 +23,7 @@ class PowerLibraryImpl : public PowerLibrary { |
public: |
PowerLibraryImpl() |
: power_status_connection_(NULL), |
- resume_status_connection_(NULL), |
- status_(chromeos::PowerStatus()) { |
+ resume_status_connection_(NULL) { |
} |
virtual ~PowerLibraryImpl() { |
@@ -53,30 +54,6 @@ class PowerLibraryImpl : public PowerLibrary { |
observers_.RemoveObserver(observer); |
} |
- virtual bool IsLinePowerOn() const OVERRIDE { |
- return status_.line_power_on; |
- } |
- |
- virtual bool IsBatteryFullyCharged() const OVERRIDE { |
- return status_.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED; |
- } |
- |
- virtual double GetBatteryPercentage() const OVERRIDE { |
- return status_.battery_percentage; |
- } |
- |
- virtual bool IsBatteryPresent() const OVERRIDE { |
- return status_.battery_is_present; |
- } |
- |
- virtual base::TimeDelta GetBatteryTimeToEmpty() const OVERRIDE { |
- return base::TimeDelta::FromSeconds(status_.battery_time_to_empty); |
- } |
- |
- virtual base::TimeDelta GetBatteryTimeToFull() const OVERRIDE { |
- return base::TimeDelta::FromSeconds(status_.battery_time_to_full); |
- } |
- |
virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) OVERRIDE { |
// TODO(sidor): Examine if it's really a good idea to use void* as a second |
// argument. |
@@ -129,7 +106,7 @@ class PowerLibraryImpl : public PowerLibrary { |
} |
static void PowerStatusChangedHandler(void* object, |
- const chromeos::PowerStatus& status) { |
+ const PowerStatus& status) { |
PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object); |
power->UpdatePowerStatus(status); |
} |
@@ -139,7 +116,7 @@ class PowerLibraryImpl : public PowerLibrary { |
power->SystemResumed(); |
} |
- void UpdatePowerStatus(const chromeos::PowerStatus& status) { |
+ void UpdatePowerStatus(const PowerStatus& status) { |
// Make sure we run on UI thread. |
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
BrowserThread::PostTask( |
@@ -154,8 +131,7 @@ class PowerLibraryImpl : public PowerLibrary { |
<< " per=" << status.battery_percentage |
<< " tte=" << status.battery_time_to_empty |
<< " ttf=" << status.battery_time_to_full; |
- status_ = status; |
- FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(this)); |
+ FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); |
} |
void SystemResumed() { |
@@ -179,9 +155,6 @@ class PowerLibraryImpl : public PowerLibrary { |
// A reference to the resume alerts. |
chromeos::ResumeConnection resume_status_connection_; |
- // The latest power status. |
- chromeos::PowerStatus status_; |
- |
DISALLOW_COPY_AND_ASSIGN(PowerLibraryImpl); |
}; |
@@ -207,36 +180,6 @@ class PowerLibraryStubImpl : public PowerLibrary { |
observers_.RemoveObserver(observer); |
} |
- virtual bool IsLinePowerOn() const OVERRIDE { |
- return !discharging_; |
- } |
- |
- virtual bool IsBatteryFullyCharged() const OVERRIDE { |
- return battery_percentage_ == 100; |
- } |
- |
- virtual double GetBatteryPercentage() const OVERRIDE { |
- return battery_percentage_; |
- } |
- |
- virtual bool IsBatteryPresent() const OVERRIDE { |
- return true; |
- } |
- |
- virtual base::TimeDelta GetBatteryTimeToEmpty() const OVERRIDE { |
- if (battery_percentage_ == 0) |
- return base::TimeDelta::FromSeconds(1); |
- else |
- return (base::TimeDelta::FromHours(3) * battery_percentage_) / 100; |
- } |
- |
- virtual base::TimeDelta GetBatteryTimeToFull() const OVERRIDE { |
- if (battery_percentage_ == 100) |
- return base::TimeDelta::FromSeconds(1); |
- else |
- return base::TimeDelta::FromHours(3) - GetBatteryTimeToEmpty(); |
- } |
- |
virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) OVERRIDE { |
callback->Run(0); |
delete callback; |
@@ -280,7 +223,16 @@ class PowerLibraryStubImpl : public PowerLibrary { |
} |
} |
battery_percentage_ += (discharging_ ? -1 : 1); |
- FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(this)); |
+ |
+ PowerStatus status; |
+ status.line_power_on = !discharging_; |
+ status.battery_is_present = true; |
+ status.battery_percentage = battery_percentage_; |
+ status.battery_time_to_empty = std::max(1, battery_percentage_ * 180 / 100); |
+ status.battery_time_to_full = std::max(1LL, |
+ 180 - status.battery_time_to_empty); |
stevenjb
2011/10/18 23:08:23
It seems like PowerStatus should just store percen
satorux1
2011/10/19 21:16:55
This is a stub implementation.
PowerStatus data c
|
+ |
+ FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); |
} |
bool discharging_; |