| 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 "core/dom/ExecutionContext.h" |
| 7 #include "modules/sensor/SensorProxy.h" | 8 #include "modules/sensor/SensorProxy.h" |
| 8 #include "modules/sensor/SensorReading.h" | 9 #include "modules/sensor/SensorReading.h" |
| 9 #include "platform/mojo/MojoHelper.h" | 10 #include "platform/mojo/MojoHelper.h" |
| 10 #include "public/platform/InterfaceProvider.h" | 11 #include "public/platform/InterfaceProvider.h" |
| 11 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 // SensorProviderProxy | 16 // SensorProviderProxy |
| 16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { | 17 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 SensorProviderProxy::~SensorProviderProxy() {} | 39 SensorProviderProxy::~SensorProviderProxy() {} |
| 39 | 40 |
| 40 DEFINE_TRACE(SensorProviderProxy) { | 41 DEFINE_TRACE(SensorProviderProxy) { |
| 41 visitor->trace(m_sensors); | 42 visitor->trace(m_sensors); |
| 42 Supplement<LocalFrame>::trace(visitor); | 43 Supplement<LocalFrame>::trace(visitor); |
| 43 } | 44 } |
| 44 | 45 |
| 45 SensorProxy* SensorProviderProxy::createSensor( | 46 SensorProxy* SensorProviderProxy::createSensor( |
| 46 device::mojom::blink::SensorType type, | 47 device::mojom::blink::SensorType type, |
| 48 ExecutionContext* context, |
| 47 std::unique_ptr<SensorReadingFactory> readingFactory) { | 49 std::unique_ptr<SensorReadingFactory> readingFactory) { |
| 48 DCHECK(!getSensor(type)); | 50 DCHECK(!getSensor(type)); |
| 49 | 51 |
| 50 SensorProxy* sensor = new SensorProxy(type, this, std::move(readingFactory)); | 52 SensorProxy* sensor = |
| 53 new SensorProxy(type, context, this, std::move(readingFactory)); |
| 51 m_sensors.add(sensor); | 54 m_sensors.add(sensor); |
| 52 | 55 |
| 53 return sensor; | 56 return sensor; |
| 54 } | 57 } |
| 55 | 58 |
| 56 SensorProxy* SensorProviderProxy::getSensor( | 59 SensorProxy* SensorProviderProxy::getSensor( |
| 57 device::mojom::blink::SensorType type) { | 60 device::mojom::blink::SensorType type) { |
| 58 for (SensorProxy* sensor : m_sensors) { | 61 for (SensorProxy* sensor : m_sensors) { |
| 59 // TODO(Mikhail) : Hash sensors by type for efficiency. | 62 // TODO(Mikhail) : Hash sensors by type for efficiency. |
| 60 if (sensor->type() == type) | 63 if (sensor->type() == type) |
| 61 return sensor; | 64 return sensor; |
| 62 } | 65 } |
| 63 | 66 |
| 64 return nullptr; | 67 return nullptr; |
| 65 } | 68 } |
| 66 | 69 |
| 67 void SensorProviderProxy::onSensorProviderConnectionError() { | 70 void SensorProviderProxy::onSensorProviderConnectionError() { |
| 68 if (!Platform::current()) { | 71 if (!Platform::current()) { |
| 69 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 72 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
| 70 return; | 73 return; |
| 71 } | 74 } |
| 72 | 75 |
| 73 m_sensorProvider.reset(); | 76 m_sensorProvider.reset(); |
| 74 for (SensorProxy* sensor : m_sensors) | 77 for (SensorProxy* sensor : m_sensors) |
| 75 sensor->handleSensorError(); | 78 sensor->handleSensorError(); |
| 76 } | 79 } |
| 77 | 80 |
| 78 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |