Chromium Code Reviews| 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 #ifndef BatteryManager_h | 5 #ifndef BatteryManager_h |
| 6 #define BatteryManager_h | 6 #define BatteryManager_h |
| 7 | 7 |
| 8 #include "bindings/v8/ScriptPromise.h" | |
| 9 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | |
| 8 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
| 9 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 10 #include "core/frame/DeviceEventControllerBase.h" | 12 #include "core/frame/DeviceEventControllerBase.h" |
| 11 #include "modules/EventTargetModules.h" | 13 #include "modules/EventTargetModules.h" |
| 12 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
| 13 | 15 |
| 14 namespace WebCore { | 16 namespace WebCore { |
| 15 | 17 |
| 16 class BatteryStatus; | 18 class BatteryStatus; |
| 17 class Navigator; | |
| 18 | 19 |
| 19 class BatteryManager FINAL : public RefCountedWillBeRefCountedGarbageCollected<B atteryManager>, public ActiveDOMObject, public DeviceEventControllerBase, public EventTargetWithInlineData { | 20 class BatteryManager FINAL : public RefCountedWillBeRefCountedGarbageCollected<B atteryManager>, public ActiveDOMObject, public DeviceEventControllerBase, public EventTargetWithInlineData { |
| 20 REFCOUNTED_EVENT_TARGET(BatteryManager); | 21 REFCOUNTED_EVENT_TARGET(BatteryManager); |
| 21 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BatteryManager); | 22 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BatteryManager); |
| 22 public: | 23 public: |
| 23 virtual ~BatteryManager(); | 24 virtual ~BatteryManager(); |
| 24 static PassRefPtrWillBeRawPtr<BatteryManager> create(ExecutionContext*); | 25 static PassRefPtrWillBeRawPtr<BatteryManager> create(ExecutionContext*); |
| 25 | 26 |
| 27 // Returns a promise object that will be resolved with this BatteryManager. | |
| 28 ScriptPromise startRequest(ScriptState*); | |
| 29 | |
| 26 // EventTarget implementation. | 30 // EventTarget implementation. |
| 27 virtual const WTF::AtomicString& interfaceName() const OVERRIDE { return Eve ntTargetNames::BatteryManager; } | 31 virtual const WTF::AtomicString& interfaceName() const OVERRIDE { return Eve ntTargetNames::BatteryManager; } |
| 28 virtual ExecutionContext* executionContext() const OVERRIDE { return Context LifecycleObserver::executionContext(); } | 32 virtual ExecutionContext* executionContext() const OVERRIDE { return Context LifecycleObserver::executionContext(); } |
| 29 | 33 |
| 30 bool charging(); | 34 bool charging(); |
| 31 double chargingTime(); | 35 double chargingTime(); |
| 32 double dischargingTime(); | 36 double dischargingTime(); |
| 33 double level(); | 37 double level(); |
| 34 | 38 |
| 35 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingchange); | 39 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingchange); |
| 36 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingtimechange); | 40 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingtimechange); |
| 37 DEFINE_ATTRIBUTE_EVENT_LISTENER(dischargingtimechange); | 41 DEFINE_ATTRIBUTE_EVENT_LISTENER(dischargingtimechange); |
| 38 DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange); | 42 DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange); |
| 39 | 43 |
| 40 // Inherited from DeviceEventControllerBase. | 44 // Inherited from DeviceEventControllerBase. |
| 41 virtual void didUpdateData() OVERRIDE; | 45 virtual void didUpdateData() OVERRIDE; |
| 42 virtual void registerWithDispatcher() OVERRIDE; | 46 virtual void registerWithDispatcher() OVERRIDE; |
| 43 virtual void unregisterWithDispatcher() OVERRIDE; | 47 virtual void unregisterWithDispatcher() OVERRIDE; |
| 44 virtual bool hasLastData() OVERRIDE; | 48 virtual bool hasLastData() OVERRIDE; |
| 45 | 49 |
| 46 // ActiveDOMObject implementation. | 50 // ActiveDOMObject implementation. |
| 47 virtual bool canSuspend() const { return true; } | 51 virtual bool canSuspend() const { return true; } |
| 48 virtual void suspend() OVERRIDE; | 52 virtual void suspend() OVERRIDE; |
| 49 virtual void resume() OVERRIDE; | 53 virtual void resume() OVERRIDE; |
| 50 virtual void stop() OVERRIDE; | 54 virtual void stop() OVERRIDE; |
| 51 | 55 |
| 52 private: | 56 private: |
| 57 class ThenFunction; | |
| 58 | |
| 59 enum State { | |
| 60 NotStarted, | |
| 61 Pending, | |
| 62 Resolved, | |
| 63 }; | |
| 64 | |
| 53 explicit BatteryManager(ExecutionContext*); | 65 explicit BatteryManager(ExecutionContext*); |
| 66 void onPromiseResolved(); | |
|
abarth-chromium
2014/06/11 19:44:34
didResolvePromise?
timvolodine
2014/06/12 16:38:45
Done.
| |
| 54 | 67 |
| 68 RefPtr<ScriptPromiseResolverWithContext> m_resolver; | |
| 55 RefPtr<BatteryStatus> m_batteryStatus; | 69 RefPtr<BatteryStatus> m_batteryStatus; |
| 70 State m_state; | |
| 56 }; | 71 }; |
| 57 | 72 |
| 58 } | 73 } |
| 59 | 74 |
| 60 #endif // BatteryManager_h | 75 #endif // BatteryManager_h |
| 61 | 76 |
| OLD | NEW |