| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/battery/BatteryManager.h" | 6 #include "modules/battery/BatteryManager.h" |
| 7 | 7 |
| 8 #include "RuntimeEnabledFeatures.h" | 8 #include "RuntimeEnabledFeatures.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "modules/battery/BatteryStatus.h" | 10 #include "modules/battery/BatteryStatus.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 { | 27 { |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool BatteryManager::charging() | 30 bool BatteryManager::charging() |
| 31 { | 31 { |
| 32 return m_batteryStatus ? m_batteryStatus->charging() : true; | 32 return m_batteryStatus ? m_batteryStatus->charging() : true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 double BatteryManager::chargingTime() | 35 double BatteryManager::chargingTime() |
| 36 { | 36 { |
| 37 if (!m_batteryStatus || !m_batteryStatus->charging()) | 37 if (!m_batteryStatus) |
| 38 return 0; |
| 39 |
| 40 if (!m_batteryStatus->charging()) |
| 38 return std::numeric_limits<double>::infinity(); | 41 return std::numeric_limits<double>::infinity(); |
| 39 | 42 |
| 43 // The spec requires that if level == 1.0, chargingTime == 0 but this has to |
| 44 // be implement by the backend. Adding this assert will help enforcing it. |
| 45 ASSERT(level() != 1.0 && m_batteryStatus->chargingTime() == 0.0); |
| 46 |
| 40 return m_batteryStatus->chargingTime(); | 47 return m_batteryStatus->chargingTime(); |
| 41 } | 48 } |
| 42 | 49 |
| 43 double BatteryManager::dischargingTime() | 50 double BatteryManager::dischargingTime() |
| 44 { | 51 { |
| 45 if (!m_batteryStatus || m_batteryStatus->charging()) | 52 if (!m_batteryStatus || m_batteryStatus->charging()) |
| 46 return std::numeric_limits<double>::infinity(); | 53 return std::numeric_limits<double>::infinity(); |
| 47 | 54 |
| 48 return m_batteryStatus->dischargingTime(); | 55 return m_batteryStatus->dischargingTime(); |
| 49 } | 56 } |
| 50 | 57 |
| 51 double BatteryManager::level() | 58 double BatteryManager::level() |
| 52 { | 59 { |
| 53 return m_batteryStatus ? m_batteryStatus->level() : 1; | 60 return m_batteryStatus ? m_batteryStatus->level() : 1; |
| 54 } | 61 } |
| 55 | 62 |
| 56 void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr<
BatteryStatus> batteryStatus) | 63 void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr<
BatteryStatus> batteryStatus) |
| 57 { | 64 { |
| 58 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); | 65 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); |
| 59 | 66 |
| 60 m_batteryStatus = batteryStatus; | 67 m_batteryStatus = batteryStatus; |
| 61 dispatchEvent(event); | 68 dispatchEvent(event); |
| 62 } | 69 } |
| 63 | 70 |
| 64 } // namespace WebCore | 71 } // namespace WebCore |
| OLD | NEW |