OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/sensor/SensorProviderProxy.h" |
| 6 |
| 7 #include "core/frame/LocalFrame.h" |
| 8 #include "modules/sensor/SensorProxy.h" |
| 9 #include "platform/mojo/MojoHelper.h" |
| 10 #include "public/platform/InterfaceProvider.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 // SensorProviderProxy |
| 15 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) |
| 16 { |
| 17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); |
| 18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback(WTF::bin
d(&SensorProviderProxy::onSensorProviderConnectionError, wrapWeakPersistent(this
)))); |
| 19 } |
| 20 |
| 21 const char* SensorProviderProxy::supplementName() |
| 22 { |
| 23 return "SensorProvider"; |
| 24 } |
| 25 |
| 26 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) |
| 27 { |
| 28 DCHECK(frame); |
| 29 SensorProviderProxy* result = static_cast<SensorProviderProxy*>(Supplement<L
ocalFrame>::from(*frame, supplementName())); |
| 30 if (!result) { |
| 31 result = new SensorProviderProxy(frame); |
| 32 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result); |
| 33 } |
| 34 return result; |
| 35 } |
| 36 |
| 37 SensorProviderProxy::~SensorProviderProxy() |
| 38 { |
| 39 } |
| 40 |
| 41 DEFINE_TRACE(SensorProviderProxy) |
| 42 { |
| 43 visitor->trace(m_sensors); |
| 44 Supplement<LocalFrame>::trace(visitor); |
| 45 } |
| 46 |
| 47 SensorProxy* SensorProviderProxy::getOrCreateSensor(device::mojom::blink::Sensor
Type type) |
| 48 { |
| 49 for (SensorProxy* sensor : m_sensors) { |
| 50 // TODO(Mikhail) : Hash sensors by type for efficiency. |
| 51 if (sensor->type() == type) |
| 52 return sensor; |
| 53 } |
| 54 |
| 55 SensorProxy* sensor = new SensorProxy(type, this); |
| 56 m_sensors.add(sensor); |
| 57 |
| 58 return sensor; |
| 59 } |
| 60 |
| 61 void SensorProviderProxy::onSensorProviderConnectionError() |
| 62 { |
| 63 m_sensorProvider.reset(); |
| 64 for (SensorProxy* sensor : m_sensors) |
| 65 sensor->handleSensorError(); |
| 66 } |
| 67 |
| 68 } // namespace blink |
OLD | NEW |