Chromium Code Reviews| Index: Source/modules/battery/BatteryManager.cpp |
| diff --git a/Source/modules/battery/BatteryManager.cpp b/Source/modules/battery/BatteryManager.cpp |
| index aae81bcf1448b25da6e871ea668cfcd90650432e..a3e3294a365b4e360c919d8fbde8fb75aed78b9c 100644 |
| --- a/Source/modules/battery/BatteryManager.cpp |
| +++ b/Source/modules/battery/BatteryManager.cpp |
| @@ -7,6 +7,7 @@ |
| #include "RuntimeEnabledFeatures.h" |
| #include "core/events/Event.h" |
| +#include "modules/battery/BatteryDispatcher.h" |
| #include "modules/battery/BatteryStatus.h" |
| #include <limits> |
| @@ -14,7 +15,9 @@ namespace WebCore { |
| PassRefPtrWillBeRawPtr<BatteryManager> BatteryManager::create(ExecutionContext* context) |
| { |
| - return adoptRefWillBeRefCountedGarbageCollected(new BatteryManager(context)); |
| + RefPtr<BatteryManager> batteryManager(adoptRefWillBeRefCountedGarbageCollected(new BatteryManager(context))); |
|
sof
2014/04/07 12:52:44
Use RefPtrWillBeRawPtr<> instead of RefPtr<>.
|
| + batteryManager->suspendIfNeeded(); |
| + return batteryManager.release(); |
| } |
| BatteryManager::~BatteryManager() |
| @@ -22,9 +25,13 @@ BatteryManager::~BatteryManager() |
| } |
| BatteryManager::BatteryManager(ExecutionContext* context) |
| - : ContextLifecycleObserver(context) |
| + : ActiveDOMObject(context) |
| + , DeviceSensorEventController(*toDocument(context)) |
| , m_batteryStatus(nullptr) |
| { |
| + // Need to figure out a way to startUpdating only afters EventListeners are added: didAddEventListener? |
| + m_hasEventListener = true; |
| + startUpdating(); |
|
timvolodine
2014/04/02 14:24:51
yeah this is a bit tricky. Think it's generally ok
Srini
2014/04/02 17:25:36
The spec mentions a default value when the battery
|
| } |
| bool BatteryManager::charging() |
| @@ -53,7 +60,7 @@ double BatteryManager::level() |
| return m_batteryStatus ? m_batteryStatus->level() : 1; |
|
timvolodine
2014/04/03 13:48:16
Also batteryStatus appears to be stored twice in b
|
| } |
| -void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr<BatteryStatus> batteryStatus) |
| +void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassRefPtr<BatteryStatus> batteryStatus) |
|
sof
2014/04/07 12:52:44
Change PassRefPtr<Event> to PassRefPtrWillBeRawPtr
|
| { |
| ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); |
| @@ -61,4 +68,49 @@ void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr< |
| dispatchEvent(event); |
| } |
| +void BatteryManager::registerWithDispatcher() |
| +{ |
| + BatteryDispatcher::instance().addClient(this); |
| +} |
| + |
| +void BatteryManager::unregisterWithDispatcher() |
| +{ |
| + BatteryDispatcher::instance().removeClient(this); |
| +} |
| + |
| +bool BatteryManager::hasLastData() |
| +{ |
| + /* Battery Manager sends the event itself */ |
| + return false; |
| +} |
| + |
| +PassRefPtr<Event> BatteryManager::getLastEvent() |
|
sof
2014/04/07 12:52:44
Change this to PassRefPtrWillBeRawPtr<Event>
|
| +{ |
| + // This is called only when hasLastData() is true. |
| + ASSERT_NOT_REACHED(); |
| + return nullptr; |
| +} |
| + |
| +bool BatteryManager::isNullEvent(Event*) |
| +{ |
| + // This is called only when hasLastData() is true. |
| + ASSERT_NOT_REACHED(); |
| + return false; |
| +} |
| + |
| +void BatteryManager::suspend() |
| +{ |
| + stopUpdating(); |
| +} |
| + |
| +void BatteryManager::resume() |
| +{ |
| + startUpdating(); |
| +} |
| + |
| +void BatteryManager::stop() |
| +{ |
| + stopUpdating(); |
| +} |
| + |
| } // namespace WebCore |