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

Unified Diff: chrome/browser/chromeos/cros_power_library.cc

Issue 251099: Refactor cros library code into central location and have the UI elements obs... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « chrome/browser/chromeos/cros_power_library.h ('k') | chrome/browser/chromeos/network_menu_button.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros_power_library.cc
===================================================================
--- chrome/browser/chromeos/cros_power_library.cc (revision 0)
+++ chrome/browser/chromeos/cros_power_library.cc (revision 0)
@@ -0,0 +1,73 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/cros_power_library.h"
+
+#include "base/string_util.h"
+#include "chrome/browser/chromeos/cros_library.h"
+
+CrosPowerLibrary::CrosPowerLibrary() {
+ if (CrosLibrary::loaded()) {
+ power_status_connection_ = chromeos::MonitorPowerStatus(
+ &PowerStatusChangedHandler, this);
+ }
+}
+
+CrosPowerLibrary::~CrosPowerLibrary() {
+ if (CrosLibrary::loaded())
+ chromeos::DisconnectPowerStatus(power_status_connection_);
+}
+
+// static
+CrosPowerLibrary* CrosPowerLibrary::Get() {
+ return Singleton<CrosPowerLibrary>::get();
+}
+
+// static
+bool CrosPowerLibrary::loaded() {
+ return CrosLibrary::loaded();
+}
+
+void CrosPowerLibrary::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void CrosPowerLibrary::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool CrosPowerLibrary::line_power_on() const {
+ return status_.line_power_on;
+}
+
+bool CrosPowerLibrary::battery_fully_charged() const {
+ return status_.line_power_on &&
+ status_.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED;
+}
+
+double CrosPowerLibrary::battery_percentage() const {
+ return status_.battery_percentage;
+}
+
+base::TimeDelta CrosPowerLibrary::battery_time_to_empty() const {
+ return base::TimeDelta::FromSeconds(status_.battery_time_to_empty);
+}
+
+base::TimeDelta CrosPowerLibrary::battery_time_to_full() const {
+ return base::TimeDelta::FromSeconds(status_.battery_time_to_full);
+}
+
+// static
+void CrosPowerLibrary::PowerStatusChangedHandler(void* object,
+ const chromeos::PowerStatus& status) {
+ CrosPowerLibrary* power = static_cast<CrosPowerLibrary*>(object);
+ DLOG(INFO) << "Power" <<
+ " lpo=" << status.line_power_on <<
+ " sta=" << status.battery_state <<
+ " per=" << status.battery_percentage <<
+ " tte=" << status.battery_time_to_empty <<
+ " ttf=" << status.battery_time_to_full;
+ power->status_ = status;
+ FOR_EACH_OBSERVER(Observer, power->observers_, PowerChanged(power));
+}
Property changes on: chrome/browser/chromeos/cros_power_library.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/chromeos/cros_power_library.h ('k') | chrome/browser/chromeos/network_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698