| 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/SensorProviderProxy.h" | 5 #include "modules/sensor/SensorProviderProxy.h" |
| 6 | 6 |
| 7 #include "modules/sensor/SensorProxy.h" | 7 #include "modules/sensor/SensorProxy.h" |
| 8 #include "modules/sensor/SensorReading.h" | |
| 9 #include "platform/mojo/MojoHelper.h" | 8 #include "platform/mojo/MojoHelper.h" |
| 10 #include "public/platform/InterfaceProvider.h" | 9 #include "public/platform/InterfaceProvider.h" |
| 11 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 12 | 11 |
| 13 namespace blink { | 12 namespace blink { |
| 14 | 13 |
| 15 // SensorProviderProxy | 14 // SensorProviderProxy |
| 16 SensorProviderProxy::SensorProviderProxy(LocalFrame& frame) | 15 SensorProviderProxy::SensorProviderProxy(LocalFrame& frame) |
| 17 : Supplement<LocalFrame>(frame) {} | 16 : Supplement<LocalFrame>(frame) {} |
| 18 | 17 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 46 | 45 |
| 47 SensorProviderProxy::~SensorProviderProxy() {} | 46 SensorProviderProxy::~SensorProviderProxy() {} |
| 48 | 47 |
| 49 DEFINE_TRACE(SensorProviderProxy) { | 48 DEFINE_TRACE(SensorProviderProxy) { |
| 50 visitor->trace(m_sensorProxies); | 49 visitor->trace(m_sensorProxies); |
| 51 Supplement<LocalFrame>::trace(visitor); | 50 Supplement<LocalFrame>::trace(visitor); |
| 52 } | 51 } |
| 53 | 52 |
| 54 SensorProxy* SensorProviderProxy::createSensorProxy( | 53 SensorProxy* SensorProviderProxy::createSensorProxy( |
| 55 device::mojom::blink::SensorType type, | 54 device::mojom::blink::SensorType type, |
| 56 Page* page, | 55 Page* page) { |
| 57 std::unique_ptr<SensorReadingFactory> readingFactory) { | |
| 58 DCHECK(!getSensorProxy(type)); | 56 DCHECK(!getSensorProxy(type)); |
| 59 | 57 |
| 60 SensorProxy* sensor = | 58 SensorProxy* sensor = new SensorProxy(type, this, page); |
| 61 new SensorProxy(type, this, page, std::move(readingFactory)); | |
| 62 m_sensorProxies.insert(sensor); | 59 m_sensorProxies.insert(sensor); |
| 63 | 60 |
| 64 return sensor; | 61 return sensor; |
| 65 } | 62 } |
| 66 | 63 |
| 67 SensorProxy* SensorProviderProxy::getSensorProxy( | 64 SensorProxy* SensorProviderProxy::getSensorProxy( |
| 68 device::mojom::blink::SensorType type) { | 65 device::mojom::blink::SensorType type) { |
| 69 for (SensorProxy* sensor : m_sensorProxies) { | 66 for (SensorProxy* sensor : m_sensorProxies) { |
| 70 // TODO(Mikhail) : Hash sensors by type for efficiency. | 67 // TODO(Mikhail) : Hash sensors by type for efficiency. |
| 71 if (sensor->type() == type) | 68 if (sensor->type() == type) |
| 72 return sensor; | 69 return sensor; |
| 73 } | 70 } |
| 74 | 71 |
| 75 return nullptr; | 72 return nullptr; |
| 76 } | 73 } |
| 77 | 74 |
| 78 void SensorProviderProxy::onSensorProviderConnectionError() { | 75 void SensorProviderProxy::onSensorProviderConnectionError() { |
| 79 m_sensorProvider.reset(); | 76 m_sensorProvider.reset(); |
| 80 for (SensorProxy* sensor : m_sensorProxies) | 77 for (SensorProxy* sensor : m_sensorProxies) |
| 81 sensor->handleSensorError(); | 78 sensor->handleSensorError(); |
| 82 } | 79 } |
| 83 | 80 |
| 84 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |