Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: Source/modules/battery/BatteryManager.cpp

Issue 618673002: Oilpan: reliably track listening PlatformEventControllers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Don't start updating in a stopped context Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 } 34 }
35 35
36 ScriptPromise BatteryManager::startRequest(ScriptState* scriptState) 36 ScriptPromise BatteryManager::startRequest(ScriptState* scriptState)
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 ASSERT(executionContext());
45 // If the context is in a stopped state already, do not start updating.
46 if (m_state == Resolved || executionContext()->activeDOMObjectsAreStopped()) {
45 // FIXME: Consider returning the same promise in this case. See crbug.co m/385025. 47 // FIXME: Consider returning the same promise in this case. See crbug.co m/385025.
48 m_state = Resolved;
46 m_resolver->resolve(this); 49 m_resolver->resolve(this);
47 m_resolver = nullptr; 50 m_resolver = nullptr;
48 } else if (m_state == NotStarted) { 51 } else if (m_state == NotStarted) {
49 m_state = Pending; 52 m_state = Pending;
50 m_hasEventListener = true; 53 m_hasEventListener = true;
51 startUpdating(); 54 startUpdating();
52 } 55 }
53 56
54 return promise; 57 return promise;
55 } 58 }
(...skipping 28 matching lines...) Expand all
84 87
85 if (m_state == Pending) { 88 if (m_state == Pending) {
86 ASSERT(m_resolver); 89 ASSERT(m_resolver);
87 m_state = Resolved; 90 m_state = Resolved;
88 m_resolver->resolve(this); 91 m_resolver->resolve(this);
89 m_resolver = nullptr; 92 m_resolver = nullptr;
90 return; 93 return;
91 } 94 }
92 95
93 Document* document = toDocument(executionContext()); 96 Document* document = toDocument(executionContext());
97 ASSERT(document);
94 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr eStopped()) 98 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr eStopped())
95 return; 99 return;
96 100
97 ASSERT(oldStatus); 101 ASSERT(oldStatus);
98 102
99 if (m_batteryStatus->charging() != oldStatus->charging()) 103 if (m_batteryStatus->charging() != oldStatus->charging())
100 dispatchEvent(Event::create(EventTypeNames::chargingchange)); 104 dispatchEvent(Event::create(EventTypeNames::chargingchange));
101 if (m_batteryStatus->chargingTime() != oldStatus->chargingTime()) 105 if (m_batteryStatus->chargingTime() != oldStatus->chargingTime())
102 dispatchEvent(Event::create(EventTypeNames::chargingtimechange)); 106 dispatchEvent(Event::create(EventTypeNames::chargingtimechange));
103 if (m_batteryStatus->dischargingTime() != oldStatus->dischargingTime()) 107 if (m_batteryStatus->dischargingTime() != oldStatus->dischargingTime())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 bool BatteryManager::hasPendingActivity() const 147 bool BatteryManager::hasPendingActivity() const
144 { 148 {
145 // Prevent V8 from garbage collecting the wrapper object if there are 149 // Prevent V8 from garbage collecting the wrapper object if there are
146 // event listeners attached to it. 150 // event listeners attached to it.
147 return m_state == Resolved && hasEventListeners(); 151 return m_state == Resolved && hasEventListeners();
148 } 152 }
149 153
150 void BatteryManager::trace(Visitor* visitor) 154 void BatteryManager::trace(Visitor* visitor)
151 { 155 {
152 visitor->trace(m_batteryStatus); 156 visitor->trace(m_batteryStatus);
157 PlatformEventController::trace(visitor);
153 EventTargetWithInlineData::trace(visitor); 158 EventTargetWithInlineData::trace(visitor);
154 } 159 }
155 160
156 } // namespace blink 161 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/PlatformEventDispatcher.cpp ('k') | Source/modules/gamepad/NavigatorGamepad.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698