Chromium Code Reviews| 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" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 // SensorProviderProxy | 15 // SensorProviderProxy |
| 16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { | 16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { |
| 17 initialize(frame); | |
| 18 } | |
| 19 | |
| 20 void SensorProviderProxy::initialize(LocalFrame* frame) { | |
| 21 DCHECK(!isInitialized()); | |
| 22 | |
| 17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); | 23 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); |
| 18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( | 24 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( |
| 19 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, | 25 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, |
| 20 wrapWeakPersistent(this)))); | 26 wrapWeakPersistent(this)))); |
| 21 } | 27 } |
| 22 | 28 |
| 23 const char* SensorProviderProxy::supplementName() { | 29 const char* SensorProviderProxy::supplementName() { |
| 24 return "SensorProvider"; | 30 return "SensorProvider"; |
| 25 } | 31 } |
| 26 | 32 |
| 27 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { | 33 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { |
|
Reilly Grant (use Gerrit)
2016/11/28 19:40:33
nit: This function should have a "// static" marke
shalamov
2016/11/29 09:02:23
Done.
| |
| 28 DCHECK(frame); | 34 DCHECK(frame); |
| 29 SensorProviderProxy* result = static_cast<SensorProviderProxy*>( | 35 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( |
| 30 Supplement<LocalFrame>::from(*frame, supplementName())); | 36 Supplement<LocalFrame>::from(*frame, supplementName())); |
| 31 if (!result) { | 37 if (!providerProxy) { |
| 32 result = new SensorProviderProxy(frame); | 38 providerProxy = new SensorProviderProxy(frame); |
| 33 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result); | 39 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); |
| 34 } | 40 } |
| 35 return result; | 41 |
| 42 if (!providerProxy->isInitialized()) | |
| 43 providerProxy->initialize(frame); | |
| 44 | |
| 45 return providerProxy; | |
| 36 } | 46 } |
| 37 | 47 |
| 38 SensorProviderProxy::~SensorProviderProxy() {} | 48 SensorProviderProxy::~SensorProviderProxy() {} |
| 39 | 49 |
| 40 DEFINE_TRACE(SensorProviderProxy) { | 50 DEFINE_TRACE(SensorProviderProxy) { |
| 41 visitor->trace(m_sensorProxies); | 51 visitor->trace(m_sensorProxies); |
| 42 Supplement<LocalFrame>::trace(visitor); | 52 Supplement<LocalFrame>::trace(visitor); |
| 43 } | 53 } |
| 44 | 54 |
| 45 SensorProxy* SensorProviderProxy::createSensorProxy( | 55 SensorProxy* SensorProviderProxy::createSensorProxy( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 71 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 81 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
| 72 return; | 82 return; |
| 73 } | 83 } |
| 74 | 84 |
| 75 m_sensorProvider.reset(); | 85 m_sensorProvider.reset(); |
| 76 for (SensorProxy* sensor : m_sensorProxies) | 86 for (SensorProxy* sensor : m_sensorProxies) |
| 77 sensor->handleSensorError(); | 87 sensor->handleSensorError(); |
| 78 } | 88 } |
| 79 | 89 |
| 80 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |