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