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; |
47 } else if (m_state == NotStarted) { | 48 } else if (m_state == NotStarted) { |
48 m_state = Pending; | 49 m_state = Pending; |
49 m_hasEventListener = true; | 50 m_hasEventListener = true; |
50 startUpdating(); | 51 startUpdating(); |
51 } | 52 } |
52 | 53 |
53 return promise; | 54 return promise; |
54 } | 55 } |
55 | 56 |
56 bool BatteryManager::charging() | 57 bool BatteryManager::charging() |
(...skipping 21 matching lines...) Expand all Loading... |
78 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); | 79 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); |
79 ASSERT(m_state != NotStarted); | 80 ASSERT(m_state != NotStarted); |
80 | 81 |
81 BatteryStatus* oldStatus = m_batteryStatus; | 82 BatteryStatus* oldStatus = m_batteryStatus; |
82 m_batteryStatus = BatteryDispatcher::instance().latestData(); | 83 m_batteryStatus = BatteryDispatcher::instance().latestData(); |
83 | 84 |
84 if (m_state == Pending) { | 85 if (m_state == Pending) { |
85 ASSERT(m_resolver); | 86 ASSERT(m_resolver); |
86 m_state = Resolved; | 87 m_state = Resolved; |
87 m_resolver->resolve(this); | 88 m_resolver->resolve(this); |
| 89 m_resolver = nullptr; |
88 return; | 90 return; |
89 } | 91 } |
90 | 92 |
91 Document* document = toDocument(executionContext()); | 93 Document* document = toDocument(executionContext()); |
92 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr
eStopped()) | 94 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr
eStopped()) |
93 return; | 95 return; |
94 | 96 |
95 ASSERT(oldStatus); | 97 ASSERT(oldStatus); |
96 | 98 |
97 if (m_batteryStatus->charging() != oldStatus->charging()) | 99 if (m_batteryStatus->charging() != oldStatus->charging()) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return m_state == Resolved && hasEventListeners(); | 147 return m_state == Resolved && hasEventListeners(); |
146 } | 148 } |
147 | 149 |
148 void BatteryManager::trace(Visitor* visitor) | 150 void BatteryManager::trace(Visitor* visitor) |
149 { | 151 { |
150 visitor->trace(m_batteryStatus); | 152 visitor->trace(m_batteryStatus); |
151 EventTargetWithInlineData::trace(visitor); | 153 EventTargetWithInlineData::trace(visitor); |
152 } | 154 } |
153 | 155 |
154 } // namespace blink | 156 } // namespace blink |
OLD | NEW |