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); | 17 : Supplement<LocalFrame>(frame) {} |
haraken
2017/01/06 12:46:55
This is not needed because it's called at line 43.
| |
18 } | |
19 | 18 |
20 void SensorProviderProxy::initialize(LocalFrame* frame) { | 19 void SensorProviderProxy::initializeIfNeeded(LocalFrame* frame) { |
21 DCHECK(!isInitialized()); | 20 if (isInitialized()) |
21 return; | |
22 | 22 |
23 frame->interfaceProvider()->getInterface( | 23 frame->interfaceProvider()->getInterface( |
24 mojo::MakeRequest(&m_sensorProvider)); | 24 mojo::MakeRequest(&m_sensorProvider)); |
25 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( | 25 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( |
26 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, | 26 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, |
27 wrapWeakPersistent(this)))); | 27 wrapWeakPersistent(this)))); |
28 } | 28 } |
29 | 29 |
30 const char* SensorProviderProxy::supplementName() { | 30 const char* SensorProviderProxy::supplementName() { |
31 return "SensorProvider"; | 31 return "SensorProvider"; |
32 } | 32 } |
33 | 33 |
34 // static | 34 // static |
35 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { | 35 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { |
36 DCHECK(frame); | 36 DCHECK(frame); |
37 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( | 37 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( |
38 Supplement<LocalFrame>::from(*frame, supplementName())); | 38 Supplement<LocalFrame>::from(*frame, supplementName())); |
39 if (!providerProxy) { | 39 if (!providerProxy) { |
40 providerProxy = new SensorProviderProxy(frame); | 40 providerProxy = new SensorProviderProxy(*frame); |
41 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); | 41 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); |
42 } | 42 } |
43 | 43 providerProxy->initializeIfNeeded(frame); |
44 if (!providerProxy->isInitialized()) | |
45 providerProxy->initialize(frame); | |
46 | |
47 return providerProxy; | 44 return providerProxy; |
48 } | 45 } |
49 | 46 |
50 SensorProviderProxy::~SensorProviderProxy() {} | 47 SensorProviderProxy::~SensorProviderProxy() {} |
51 | 48 |
52 DEFINE_TRACE(SensorProviderProxy) { | 49 DEFINE_TRACE(SensorProviderProxy) { |
53 visitor->trace(m_sensorProxies); | 50 visitor->trace(m_sensorProxies); |
54 Supplement<LocalFrame>::trace(visitor); | 51 Supplement<LocalFrame>::trace(visitor); |
55 } | 52 } |
56 | 53 |
(...skipping 26 matching lines...) Expand all Loading... | |
83 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 80 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
84 return; | 81 return; |
85 } | 82 } |
86 | 83 |
87 m_sensorProvider.reset(); | 84 m_sensorProvider.reset(); |
88 for (SensorProxy* sensor : m_sensorProxies) | 85 for (SensorProxy* sensor : m_sensorProxies) |
89 sensor->handleSensorError(); | 86 sensor->handleSensorError(); |
90 } | 87 } |
91 | 88 |
92 } // namespace blink | 89 } // namespace blink |
OLD | NEW |