OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/sensor/SensorReadingUpdater.h" | 5 #include "modules/sensor/SensorReadingUpdater.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 8 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
9 #include "modules/sensor/SensorProxy.h" | 9 #include "modules/sensor/SensorProxy.h" |
10 #include "wtf/CurrentTime.h" | 10 #include "wtf/CurrentTime.h" |
11 | 11 |
12 using device::mojom::blink::ReportingMode; | 12 using device::mojom::blink::ReportingMode; |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 SensorReadingUpdater::SensorReadingUpdater(SensorProxy* sensorProxy) | 16 SensorReadingUpdater::SensorReadingUpdater(SensorProxy* sensorProxy) |
17 : m_sensorProxy(sensorProxy), m_hasPendingAnimationFrameTask(false) {} | 17 : m_sensorProxy(sensorProxy), m_hasPendingAnimationFrameTask(false) {} |
18 | 18 |
19 void SensorReadingUpdater::enqueueAnimationFrameTask() { | 19 void SensorReadingUpdater::enqueueAnimationFrameTask() { |
20 if (!m_document || m_document->isDetached()) { | |
haraken
2017/01/25 18:20:06
Will the following work?
- Make SensorReadingUpda
Mikhail
2017/01/26 06:19:59
As far as I see, ContextClient contains ExecutionC
| |
21 // If the document has detached the scheduled callbacks | |
22 // will never be called. | |
23 m_hasPendingAnimationFrameTask = false; | |
24 m_document = m_sensorProxy->document(); | |
haraken
2017/01/25 18:20:06
Can we set m_document in SensorReadingUpdater's co
Mikhail
2017/01/26 06:19:59
Done.
| |
25 if (!m_document) | |
26 return; | |
27 } | |
28 | |
20 if (m_hasPendingAnimationFrameTask) | 29 if (m_hasPendingAnimationFrameTask) |
21 return; | 30 return; |
22 | 31 |
23 auto callback = WTF::bind(&SensorReadingUpdater::onAnimationFrame, | 32 auto callback = WTF::bind(&SensorReadingUpdater::onAnimationFrame, |
24 wrapWeakPersistent(this)); | 33 wrapWeakPersistent(this)); |
25 m_sensorProxy->document()->enqueueAnimationFrameTask(std::move(callback)); | 34 m_document->enqueueAnimationFrameTask(std::move(callback)); |
26 m_hasPendingAnimationFrameTask = true; | 35 m_hasPendingAnimationFrameTask = true; |
27 } | 36 } |
28 | 37 |
29 void SensorReadingUpdater::start() { | 38 void SensorReadingUpdater::start() { |
30 enqueueAnimationFrameTask(); | 39 enqueueAnimationFrameTask(); |
31 } | 40 } |
32 | 41 |
33 void SensorReadingUpdater::onAnimationFrame() { | 42 void SensorReadingUpdater::onAnimationFrame() { |
34 m_hasPendingAnimationFrameTask = false; | 43 m_hasPendingAnimationFrameTask = false; |
35 onAnimationFrameInternal(); | 44 onAnimationFrameInternal(); |
36 } | 45 } |
37 | 46 |
38 DEFINE_TRACE(SensorReadingUpdater) { | 47 DEFINE_TRACE(SensorReadingUpdater) { |
48 visitor->trace(m_document); | |
39 visitor->trace(m_sensorProxy); | 49 visitor->trace(m_sensorProxy); |
40 } | 50 } |
41 | 51 |
42 class SensorReadingUpdaterContinuous : public SensorReadingUpdater { | 52 class SensorReadingUpdaterContinuous : public SensorReadingUpdater { |
43 public: | 53 public: |
44 explicit SensorReadingUpdaterContinuous(SensorProxy* sensorProxy) | 54 explicit SensorReadingUpdaterContinuous(SensorProxy* sensorProxy) |
45 : SensorReadingUpdater(sensorProxy) {} | 55 : SensorReadingUpdater(sensorProxy) {} |
46 | 56 |
47 DEFINE_INLINE_VIRTUAL_TRACE() { SensorReadingUpdater::trace(visitor); } | 57 DEFINE_INLINE_VIRTUAL_TRACE() { SensorReadingUpdater::trace(visitor); } |
48 | 58 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 | 113 |
104 // static | 114 // static |
105 SensorReadingUpdater* SensorReadingUpdater::create(SensorProxy* proxy, | 115 SensorReadingUpdater* SensorReadingUpdater::create(SensorProxy* proxy, |
106 ReportingMode mode) { | 116 ReportingMode mode) { |
107 if (mode == ReportingMode::CONTINUOUS) | 117 if (mode == ReportingMode::CONTINUOUS) |
108 return new SensorReadingUpdaterContinuous(proxy); | 118 return new SensorReadingUpdaterContinuous(proxy); |
109 return new SensorReadingUpdaterOnChange(proxy); | 119 return new SensorReadingUpdaterOnChange(proxy); |
110 } | 120 } |
111 | 121 |
112 } // namespace blink | 122 } // namespace blink |
OLD | NEW |