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

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

Issue 7491083: Implemented nicer battery status (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unitialized ivars Created 9 years, 4 months 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 bc61089487d0fc2bc41ebdff63063344f17c87c6..a26bb485ea5a7d6afd71821dbac0602e9cc3a45e 100644
--- a/chrome/browser/chromeos/cros/power_library.cc
+++ b/chrome/browser/chromeos/cros/power_library.cc
@@ -9,6 +9,7 @@
#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/browser/browser_thread.h"
#include "third_party/cros/chromeos_power.h"
@@ -164,27 +165,88 @@ class PowerLibraryImpl : public PowerLibrary {
class PowerLibraryStubImpl : public PowerLibrary {
achuithb 2011/08/09 18:58:07 Maybe a comment here explaining what you're doing?
DaveMoore 2011/08/12 21:03:11 Done.
public:
- PowerLibraryStubImpl() {}
+ PowerLibraryStubImpl()
+ : discharging_(true),
+ battery_percentage_(20),
+ pause_count_(0) {
+ timer_.Start(
+ base::TimeDelta::FromMilliseconds(100),
+ this,
+ &PowerLibraryStubImpl::Update);
+ }
+
virtual ~PowerLibraryStubImpl() {}
// Begin PowerLibrary implementation.
virtual void Init() OVERRIDE {}
- virtual void AddObserver(Observer* observer) OVERRIDE {}
- virtual void RemoveObserver(Observer* observer) OVERRIDE {}
- virtual bool line_power_on() const OVERRIDE { return false; }
- virtual bool battery_fully_charged() const OVERRIDE { return false; }
- virtual double battery_percentage() const OVERRIDE { return 50.0; }
- virtual bool battery_is_present() const OVERRIDE { return true; }
+ virtual void AddObserver(Observer* observer) OVERRIDE {
+ observers_.AddObserver(observer);
+ }
+
+ virtual void RemoveObserver(Observer* observer) OVERRIDE {
+ observers_.RemoveObserver(observer);
+ }
+
+ virtual bool line_power_on() const OVERRIDE {
+ return !discharging_;
+ }
+
+ virtual bool battery_fully_charged() const OVERRIDE {
+ return battery_percentage_ == 100;
+ }
+
+ virtual double battery_percentage() const OVERRIDE {
+ return battery_percentage_;
+ }
+
+ virtual bool battery_is_present() const OVERRIDE {
+ return true;
+ }
+
virtual base::TimeDelta battery_time_to_empty() const OVERRIDE {
- return base::TimeDelta::FromSeconds(10 * 60);
+ if (battery_percentage_ == 0)
+ return base::TimeDelta::FromSeconds(1);
+ else
+ return (base::TimeDelta::FromHours(3) * battery_percentage_) / 100;
}
+
virtual base::TimeDelta battery_time_to_full() const OVERRIDE {
- return base::TimeDelta::FromSeconds(0);
+ if (battery_percentage_ == 0)
+ return base::TimeDelta::FromSeconds(1);
+ else
+ return base::TimeDelta::FromHours(3) - battery_time_to_empty();
}
+
virtual void EnableScreenLock(bool enable) OVERRIDE {}
virtual void RequestRestart() OVERRIDE {}
virtual void RequestShutdown() OVERRIDE {}
// 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);
+ FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(this));
+ }
achuithb 2011/08/09 18:58:07 newline here?
DaveMoore 2011/08/12 21:03:11 Done.
+ 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