| 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 "platform/mojo/MojoHelper.h" | 8 #include "platform/mojo/MojoHelper.h" |
| 9 #include "public/platform/InterfaceProvider.h" | 9 #include "public/platform/Connector.h" |
| 10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 11 #include "services/device/public/interfaces/constants.mojom-blink.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 // SensorProviderProxy | 15 // SensorProviderProxy |
| 15 SensorProviderProxy::SensorProviderProxy(LocalFrame& frame) | 16 SensorProviderProxy::SensorProviderProxy(LocalFrame& frame) |
| 16 : Supplement<LocalFrame>(frame) {} | 17 : Supplement<LocalFrame>(frame) {} |
| 17 | 18 |
| 18 void SensorProviderProxy::initializeIfNeeded(LocalFrame* frame) { | 19 void SensorProviderProxy::initializeIfNeeded() { |
| 19 if (isInitialized()) | 20 if (isInitialized()) |
| 20 return; | 21 return; |
| 21 | 22 Platform::current()->connector()->bindInterface( |
| 22 frame->interfaceProvider()->getInterface( | 23 device::mojom::blink::kServiceName, mojo::MakeRequest(&m_sensorProvider)); |
| 23 mojo::MakeRequest(&m_sensorProvider)); | |
| 24 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( | 24 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( |
| 25 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, | 25 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, |
| 26 wrapWeakPersistent(this)))); | 26 wrapWeakPersistent(this)))); |
| 27 } | 27 } |
| 28 | 28 |
| 29 const char* SensorProviderProxy::supplementName() { | 29 const char* SensorProviderProxy::supplementName() { |
| 30 return "SensorProvider"; | 30 return "SensorProvider"; |
| 31 } | 31 } |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { | 34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { |
| 35 DCHECK(frame); | 35 DCHECK(frame); |
| 36 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( | 36 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( |
| 37 Supplement<LocalFrame>::from(*frame, supplementName())); | 37 Supplement<LocalFrame>::from(*frame, supplementName())); |
| 38 if (!providerProxy) { | 38 if (!providerProxy) { |
| 39 providerProxy = new SensorProviderProxy(*frame); | 39 providerProxy = new SensorProviderProxy(*frame); |
| 40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); | 40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); |
| 41 } | 41 } |
| 42 providerProxy->initializeIfNeeded(frame); | 42 providerProxy->initializeIfNeeded(); |
| 43 return providerProxy; | 43 return providerProxy; |
| 44 } | 44 } |
| 45 | 45 |
| 46 SensorProviderProxy::~SensorProviderProxy() {} | 46 SensorProviderProxy::~SensorProviderProxy() {} |
| 47 | 47 |
| 48 DEFINE_TRACE(SensorProviderProxy) { | 48 DEFINE_TRACE(SensorProviderProxy) { |
| 49 visitor->trace(m_sensorProxies); | 49 visitor->trace(m_sensorProxies); |
| 50 Supplement<LocalFrame>::trace(visitor); | 50 Supplement<LocalFrame>::trace(visitor); |
| 51 } | 51 } |
| 52 | 52 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 return nullptr; | 72 return nullptr; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void SensorProviderProxy::onSensorProviderConnectionError() { | 75 void SensorProviderProxy::onSensorProviderConnectionError() { |
| 76 m_sensorProvider.reset(); | 76 m_sensorProvider.reset(); |
| 77 for (SensorProxy* sensor : m_sensorProxies) | 77 for (SensorProxy* sensor : m_sensorProxies) |
| 78 sensor->handleSensorError(); | 78 sensor->handleSensorError(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |