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/SensorProxy.h" | 5 #include "modules/sensor/SensorProxy.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "modules/sensor/SensorProviderProxy.h" | 9 #include "modules/sensor/SensorProviderProxy.h" |
10 #include "modules/sensor/SensorReading.h" | 10 #include "modules/sensor/SensorReading.h" |
11 #include "modules/sensor/SensorReadingUpdater.h" | 11 #include "modules/sensor/SensorReadingUpdater.h" |
12 #include "platform/mojo/MojoHelper.h" | 12 #include "platform/mojo/MojoHelper.h" |
13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
14 | 14 |
15 using namespace device::mojom::blink; | 15 using namespace device::mojom::blink; |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 SensorProxy::SensorProxy(SensorType sensorType, | 19 SensorProxy::SensorProxy(SensorType sensorType, |
20 SensorProviderProxy* provider, | 20 SensorProviderProxy* provider, |
21 Document* document, | 21 Page* page, |
22 std::unique_ptr<SensorReadingFactory> readingFactory) | 22 std::unique_ptr<SensorReadingFactory> readingFactory) |
23 : PageVisibilityObserver(document->page()), | 23 : PageVisibilityObserver(page), |
24 m_type(sensorType), | 24 m_type(sensorType), |
25 m_mode(ReportingMode::CONTINUOUS), | 25 m_mode(ReportingMode::CONTINUOUS), |
26 m_provider(provider), | 26 m_provider(provider), |
27 m_clientBinding(this), | 27 m_clientBinding(this), |
28 m_state(SensorProxy::Uninitialized), | 28 m_state(SensorProxy::Uninitialized), |
29 m_suspended(false), | 29 m_suspended(false), |
30 m_document(document), | |
31 m_readingFactory(std::move(readingFactory)), | 30 m_readingFactory(std::move(readingFactory)), |
32 m_maximumFrequency(0.0) {} | 31 m_maximumFrequency(0.0) {} |
33 | 32 |
34 SensorProxy::~SensorProxy() {} | 33 SensorProxy::~SensorProxy() {} |
35 | 34 |
36 void SensorProxy::dispose() { | 35 void SensorProxy::dispose() { |
37 m_clientBinding.Close(); | 36 m_clientBinding.Close(); |
38 } | 37 } |
39 | 38 |
40 DEFINE_TRACE(SensorProxy) { | 39 DEFINE_TRACE(SensorProxy) { |
41 visitor->trace(m_document); | |
42 visitor->trace(m_readingUpdater); | 40 visitor->trace(m_readingUpdater); |
43 visitor->trace(m_reading); | 41 visitor->trace(m_reading); |
44 visitor->trace(m_observers); | 42 visitor->trace(m_observers); |
45 visitor->trace(m_provider); | 43 visitor->trace(m_provider); |
46 PageVisibilityObserver::trace(visitor); | 44 PageVisibilityObserver::trace(visitor); |
47 } | 45 } |
48 | 46 |
49 void SensorProxy::addObserver(Observer* observer) { | 47 void SensorProxy::addObserver(Observer* observer) { |
50 if (!m_observers.contains(observer)) | 48 if (!m_observers.contains(observer)) |
51 m_observers.insert(observer); | 49 m_observers.insert(observer); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 111 |
114 if (isActive()) | 112 if (isActive()) |
115 m_readingUpdater->start(); | 113 m_readingUpdater->start(); |
116 } | 114 } |
117 | 115 |
118 const SensorConfiguration* SensorProxy::defaultConfig() const { | 116 const SensorConfiguration* SensorProxy::defaultConfig() const { |
119 DCHECK(isInitialized()); | 117 DCHECK(isInitialized()); |
120 return m_defaultConfig.get(); | 118 return m_defaultConfig.get(); |
121 } | 119 } |
122 | 120 |
| 121 Document* SensorProxy::document() const { |
| 122 return m_provider->supplementable()->document(); |
| 123 } |
| 124 |
123 void SensorProxy::updateSensorReading() { | 125 void SensorProxy::updateSensorReading() { |
124 DCHECK(isInitialized()); | 126 DCHECK(isInitialized()); |
125 DCHECK(m_readingFactory); | 127 DCHECK(m_readingFactory); |
126 int readAttempts = 0; | 128 int readAttempts = 0; |
127 const int kMaxReadAttemptsCount = 10; | 129 const int kMaxReadAttemptsCount = 10; |
128 device::SensorReading readingData; | 130 device::SensorReading readingData; |
129 while (!tryReadFromBuffer(readingData)) { | 131 while (!tryReadFromBuffer(readingData)) { |
130 if (++readAttempts == kMaxReadAttemptsCount) { | 132 if (++readAttempts == kMaxReadAttemptsCount) { |
131 handleSensorError(); | 133 handleSensorError(); |
132 return; | 134 return; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value(); | 274 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value(); |
273 auto version = seqlock.ReadBegin(); | 275 auto version = seqlock.ReadBegin(); |
274 auto readingData = buffer->reading; | 276 auto readingData = buffer->reading; |
275 if (seqlock.ReadRetry(version)) | 277 if (seqlock.ReadRetry(version)) |
276 return false; | 278 return false; |
277 result = readingData; | 279 result = readingData; |
278 return true; | 280 return true; |
279 } | 281 } |
280 | 282 |
281 } // namespace blink | 283 } // namespace blink |
OLD | NEW |