| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/cros_power_library.h" |
| 6 |
| 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/chromeos/cros_library.h" |
| 9 |
| 10 CrosPowerLibrary::CrosPowerLibrary() { |
| 11 if (CrosLibrary::loaded()) { |
| 12 power_status_connection_ = chromeos::MonitorPowerStatus( |
| 13 &PowerStatusChangedHandler, this); |
| 14 } |
| 15 } |
| 16 |
| 17 CrosPowerLibrary::~CrosPowerLibrary() { |
| 18 if (CrosLibrary::loaded()) |
| 19 chromeos::DisconnectPowerStatus(power_status_connection_); |
| 20 } |
| 21 |
| 22 // static |
| 23 CrosPowerLibrary* CrosPowerLibrary::Get() { |
| 24 return Singleton<CrosPowerLibrary>::get(); |
| 25 } |
| 26 |
| 27 // static |
| 28 bool CrosPowerLibrary::loaded() { |
| 29 return CrosLibrary::loaded(); |
| 30 } |
| 31 |
| 32 void CrosPowerLibrary::AddObserver(Observer* observer) { |
| 33 observers_.AddObserver(observer); |
| 34 } |
| 35 |
| 36 void CrosPowerLibrary::RemoveObserver(Observer* observer) { |
| 37 observers_.RemoveObserver(observer); |
| 38 } |
| 39 |
| 40 bool CrosPowerLibrary::line_power_on() const { |
| 41 return status_.line_power_on; |
| 42 } |
| 43 |
| 44 bool CrosPowerLibrary::battery_fully_charged() const { |
| 45 return status_.line_power_on && |
| 46 status_.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED; |
| 47 } |
| 48 |
| 49 double CrosPowerLibrary::battery_percentage() const { |
| 50 return status_.battery_percentage; |
| 51 } |
| 52 |
| 53 base::TimeDelta CrosPowerLibrary::battery_time_to_empty() const { |
| 54 return base::TimeDelta::FromSeconds(status_.battery_time_to_empty); |
| 55 } |
| 56 |
| 57 base::TimeDelta CrosPowerLibrary::battery_time_to_full() const { |
| 58 return base::TimeDelta::FromSeconds(status_.battery_time_to_full); |
| 59 } |
| 60 |
| 61 // static |
| 62 void CrosPowerLibrary::PowerStatusChangedHandler(void* object, |
| 63 const chromeos::PowerStatus& status) { |
| 64 CrosPowerLibrary* power = static_cast<CrosPowerLibrary*>(object); |
| 65 DLOG(INFO) << "Power" << |
| 66 " lpo=" << status.line_power_on << |
| 67 " sta=" << status.battery_state << |
| 68 " per=" << status.battery_percentage << |
| 69 " tte=" << status.battery_time_to_empty << |
| 70 " ttf=" << status.battery_time_to_full; |
| 71 power->status_ = status; |
| 72 FOR_EACH_OBSERVER(Observer, power->observers_, PowerChanged(power)); |
| 73 } |
| OLD | NEW |