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 "modules/battery/BatteryDispatcher.h" | 8 #include "modules/battery/BatteryDispatcher.h" |
9 #include "modules/battery/BatteryStatus.h" | 9 #include "modules/battery/BatteryStatus.h" |
10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
11 | 11 |
12 namespace WebCore { | 12 namespace WebCore { |
13 | 13 |
14 PassRefPtrWillBeRawPtr<BatteryManager> BatteryManager::create(ExecutionContext* context) | 14 PassRefPtrWillBeRawPtr<BatteryManager> BatteryManager::create(ExecutionContext* context) |
15 { | 15 { |
16 RefPtrWillBeRawPtr<BatteryManager> batteryManager(adoptRefWillBeRefCountedGa rbageCollected(new BatteryManager(context))); | 16 RefPtrWillBeRawPtr<BatteryManager> batteryManager(adoptRefWillBeRefCountedGa rbageCollected(new BatteryManager(context))); |
17 batteryManager->suspendIfNeeded(); | 17 batteryManager->suspendIfNeeded(); |
18 return batteryManager.release(); | 18 return batteryManager.release(); |
19 } | 19 } |
20 | 20 |
21 BatteryManager::~BatteryManager() | 21 BatteryManager::~BatteryManager() |
22 { | 22 { |
23 stopUpdating(); | 23 stopUpdating(); |
haraken
2014/06/19 10:59:16
This calls unregisterWithDispatcher(), which remov
| |
24 } | 24 } |
25 | 25 |
26 BatteryManager::BatteryManager(ExecutionContext* context) | 26 BatteryManager::BatteryManager(ExecutionContext* context) |
27 : ActiveDOMObject(context) | 27 : ActiveDOMObject(context) |
28 , DeviceEventControllerBase(toDocument(context)->page()) | 28 , DeviceEventControllerBase(toDocument(context)->page()) |
29 , m_batteryStatus(BatteryStatus::create()) | 29 , m_batteryStatus(BatteryStatus::create()) |
30 , m_state(NotStarted) | 30 , m_state(NotStarted) |
31 { | 31 { |
32 } | 32 } |
33 | 33 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 double BatteryManager::level() | 69 double BatteryManager::level() |
70 { | 70 { |
71 return m_batteryStatus->level(); | 71 return m_batteryStatus->level(); |
72 } | 72 } |
73 | 73 |
74 void BatteryManager::didUpdateData() | 74 void BatteryManager::didUpdateData() |
75 { | 75 { |
76 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); | 76 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled()); |
77 ASSERT(m_state != NotStarted); | 77 ASSERT(m_state != NotStarted); |
78 | 78 |
79 RefPtr<BatteryStatus> oldStatus = m_batteryStatus; | 79 RefPtrWillBeRawPtr<BatteryStatus> oldStatus = m_batteryStatus; |
80 m_batteryStatus = BatteryDispatcher::instance().latestData(); | 80 m_batteryStatus = BatteryDispatcher::instance().latestData(); |
81 | 81 |
82 #if !ENABLE(OILPAN) | |
82 // BatteryDispatcher also holds a reference to m_batteryStatus. | 83 // BatteryDispatcher also holds a reference to m_batteryStatus. |
83 ASSERT(m_batteryStatus->refCount() > 1); | 84 ASSERT(m_batteryStatus->refCount() > 1); |
85 #endif | |
84 | 86 |
85 if (m_state == Pending) { | 87 if (m_state == Pending) { |
86 ASSERT(m_resolver); | 88 ASSERT(m_resolver); |
87 m_state = Resolved; | 89 m_state = Resolved; |
88 m_resolver->resolve(this); | 90 m_resolver->resolve(this); |
89 return; | 91 return; |
90 } | 92 } |
91 | 93 |
92 Document* document = toDocument(executionContext()); | 94 Document* document = toDocument(executionContext()); |
93 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr eStopped()) | 95 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr eStopped()) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 m_hasEventListener = true; | 133 m_hasEventListener = true; |
132 startUpdating(); | 134 startUpdating(); |
133 } | 135 } |
134 | 136 |
135 void BatteryManager::stop() | 137 void BatteryManager::stop() |
136 { | 138 { |
137 m_hasEventListener = false; | 139 m_hasEventListener = false; |
138 stopUpdating(); | 140 stopUpdating(); |
139 } | 141 } |
140 | 142 |
143 void BatteryManager::trace(Visitor* visitor) | |
144 { | |
145 visitor->trace(m_batteryStatus); | |
146 EventTargetWithInlineData::trace(visitor); | |
147 } | |
148 | |
141 } // namespace WebCore | 149 } // namespace WebCore |
OLD | NEW |