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 |
| 33 // static |
27 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { | 34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { |
28 DCHECK(frame); | 35 DCHECK(frame); |
29 SensorProviderProxy* result = static_cast<SensorProviderProxy*>( | 36 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( |
30 Supplement<LocalFrame>::from(*frame, supplementName())); | 37 Supplement<LocalFrame>::from(*frame, supplementName())); |
31 if (!result) { | 38 if (!providerProxy) { |
32 result = new SensorProviderProxy(frame); | 39 providerProxy = new SensorProviderProxy(frame); |
33 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result); | 40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); |
34 } | 41 } |
35 return result; | 42 |
| 43 if (!providerProxy->isInitialized()) |
| 44 providerProxy->initialize(frame); |
| 45 |
| 46 return providerProxy; |
36 } | 47 } |
37 | 48 |
38 SensorProviderProxy::~SensorProviderProxy() {} | 49 SensorProviderProxy::~SensorProviderProxy() {} |
39 | 50 |
40 DEFINE_TRACE(SensorProviderProxy) { | 51 DEFINE_TRACE(SensorProviderProxy) { |
41 visitor->trace(m_sensorProxies); | 52 visitor->trace(m_sensorProxies); |
42 Supplement<LocalFrame>::trace(visitor); | 53 Supplement<LocalFrame>::trace(visitor); |
43 } | 54 } |
44 | 55 |
45 SensorProxy* SensorProviderProxy::createSensorProxy( | 56 SensorProxy* SensorProviderProxy::createSensorProxy( |
(...skipping 25 matching lines...) Expand all Loading... |
71 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 82 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
72 return; | 83 return; |
73 } | 84 } |
74 | 85 |
75 m_sensorProvider.reset(); | 86 m_sensorProvider.reset(); |
76 for (SensorProxy* sensor : m_sensorProxies) | 87 for (SensorProxy* sensor : m_sensorProxies) |
77 sensor->handleSensorError(); | 88 sensor->handleSensorError(); |
78 } | 89 } |
79 | 90 |
80 } // namespace blink | 91 } // namespace blink |
OLD | NEW |