| 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 "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "modules/battery/BatteryDispatcher.h" | 10 #include "modules/battery/BatteryDispatcher.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 { | 37 { |
| 38 if (m_state == Pending) | 38 if (m_state == Pending) |
| 39 return m_resolver->promise(); | 39 return m_resolver->promise(); |
| 40 | 40 |
| 41 m_resolver = ScriptPromiseResolver::create(scriptState); | 41 m_resolver = ScriptPromiseResolver::create(scriptState); |
| 42 ScriptPromise promise = m_resolver->promise(); | 42 ScriptPromise promise = m_resolver->promise(); |
| 43 | 43 |
| 44 if (m_state == Resolved) { | 44 if (m_state == Resolved) { |
| 45 // FIXME: Consider returning the same promise in this case. See crbug.co
m/385025. | 45 // FIXME: Consider returning the same promise in this case. See crbug.co
m/385025. |
| 46 m_resolver->resolve(this); | 46 m_resolver->resolve(this); |
| 47 m_resolver = nullptr; | |
| 48 } else if (m_state == NotStarted) { | 47 } else if (m_state == NotStarted) { |
| 49 m_state = Pending; | 48 m_state = Pending; |
| 50 m_hasEventListener = true; | 49 m_hasEventListener = true; |
| 51 startUpdating(); | 50 startUpdating(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 return promise; | 53 return promise; |
| 55 } | 54 } |
| 56 | 55 |
| 57 bool BatteryManager::charging() | 56 bool BatteryManager::charging() |
| (...skipping 21 matching lines...) Expand all Loading... |
| 79 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); | 78 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); |
| 80 ASSERT(m_state != NotStarted); | 79 ASSERT(m_state != NotStarted); |
| 81 | 80 |
| 82 BatteryStatus* oldStatus = m_batteryStatus; | 81 BatteryStatus* oldStatus = m_batteryStatus; |
| 83 m_batteryStatus = BatteryDispatcher::instance().latestData(); | 82 m_batteryStatus = BatteryDispatcher::instance().latestData(); |
| 84 | 83 |
| 85 if (m_state == Pending) { | 84 if (m_state == Pending) { |
| 86 ASSERT(m_resolver); | 85 ASSERT(m_resolver); |
| 87 m_state = Resolved; | 86 m_state = Resolved; |
| 88 m_resolver->resolve(this); | 87 m_resolver->resolve(this); |
| 89 m_resolver = nullptr; | |
| 90 return; | 88 return; |
| 91 } | 89 } |
| 92 | 90 |
| 93 Document* document = toDocument(executionContext()); | 91 Document* document = toDocument(executionContext()); |
| 94 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr
eStopped()) | 92 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr
eStopped()) |
| 95 return; | 93 return; |
| 96 | 94 |
| 97 ASSERT(oldStatus); | 95 ASSERT(oldStatus); |
| 98 | 96 |
| 99 if (m_batteryStatus->charging() != oldStatus->charging()) | 97 if (m_batteryStatus->charging() != oldStatus->charging()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 return m_state == Resolved && hasEventListeners(); | 145 return m_state == Resolved && hasEventListeners(); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void BatteryManager::trace(Visitor* visitor) | 148 void BatteryManager::trace(Visitor* visitor) |
| 151 { | 149 { |
| 152 visitor->trace(m_batteryStatus); | 150 visitor->trace(m_batteryStatus); |
| 153 EventTargetWithInlineData::trace(visitor); | 151 EventTargetWithInlineData::trace(visitor); |
| 154 } | 152 } |
| 155 | 153 |
| 156 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |