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" | |
10 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
10 #include "services/device/public/interfaces/constants.mojom-blink.h" | |
11 #include "services/service_manager/public/cpp/connector.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 |
22 frame->interfaceProvider()->getInterface( | 23 Platform::current()->connector()->BindInterface( |
shalamov
2017/03/29 10:24:08
I'm concerned about this change, as we should have
blundell
2017/03/29 10:28:07
Nothing is changing about the granularity of the c
| |
23 mojo::MakeRequest(&m_sensorProvider)); | 24 device::mojom::blink::kServiceName, mojo::MakeRequest(&m_sensorProvider)); |
24 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( | 25 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( |
25 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, | 26 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, |
26 wrapWeakPersistent(this)))); | 27 wrapWeakPersistent(this)))); |
27 } | 28 } |
28 | 29 |
29 const char* SensorProviderProxy::supplementName() { | 30 const char* SensorProviderProxy::supplementName() { |
30 return "SensorProvider"; | 31 return "SensorProvider"; |
31 } | 32 } |
32 | 33 |
33 // static | 34 // static |
34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { | 35 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { |
35 DCHECK(frame); | 36 DCHECK(frame); |
36 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( | 37 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( |
37 Supplement<LocalFrame>::from(*frame, supplementName())); | 38 Supplement<LocalFrame>::from(*frame, supplementName())); |
38 if (!providerProxy) { | 39 if (!providerProxy) { |
39 providerProxy = new SensorProviderProxy(*frame); | 40 providerProxy = new SensorProviderProxy(*frame); |
40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); | 41 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); |
41 } | 42 } |
42 providerProxy->initializeIfNeeded(frame); | 43 providerProxy->initializeIfNeeded(); |
43 return providerProxy; | 44 return providerProxy; |
44 } | 45 } |
45 | 46 |
46 SensorProviderProxy::~SensorProviderProxy() {} | 47 SensorProviderProxy::~SensorProviderProxy() {} |
47 | 48 |
48 DEFINE_TRACE(SensorProviderProxy) { | 49 DEFINE_TRACE(SensorProviderProxy) { |
49 visitor->trace(m_sensorProxies); | 50 visitor->trace(m_sensorProxies); |
50 Supplement<LocalFrame>::trace(visitor); | 51 Supplement<LocalFrame>::trace(visitor); |
51 } | 52 } |
52 | 53 |
(...skipping 19 matching lines...) Expand all Loading... | |
72 return nullptr; | 73 return nullptr; |
73 } | 74 } |
74 | 75 |
75 void SensorProviderProxy::onSensorProviderConnectionError() { | 76 void SensorProviderProxy::onSensorProviderConnectionError() { |
76 m_sensorProvider.reset(); | 77 m_sensorProvider.reset(); |
77 for (SensorProxy* sensor : m_sensorProxies) | 78 for (SensorProxy* sensor : m_sensorProxies) |
78 sensor->handleSensorError(); | 79 sensor->handleSensorError(); |
79 } | 80 } |
80 | 81 |
81 } // namespace blink | 82 } // namespace blink |
OLD | NEW |