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 "core/dom/ExecutionContext.h" |
7 #include "modules/sensor/SensorProxy.h" | 8 #include "modules/sensor/SensorProxy.h" |
8 #include "platform/mojo/MojoHelper.h" | 9 #include "platform/mojo/MojoHelper.h" |
9 #include "public/platform/InterfaceProvider.h" | 10 #include "public/platform/InterfaceProvider.h" |
10 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.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 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); | 17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); |
(...skipping 18 matching lines...) Expand all Loading... |
35 } | 36 } |
36 | 37 |
37 SensorProviderProxy::~SensorProviderProxy() {} | 38 SensorProviderProxy::~SensorProviderProxy() {} |
38 | 39 |
39 DEFINE_TRACE(SensorProviderProxy) { | 40 DEFINE_TRACE(SensorProviderProxy) { |
40 visitor->trace(m_sensors); | 41 visitor->trace(m_sensors); |
41 Supplement<LocalFrame>::trace(visitor); | 42 Supplement<LocalFrame>::trace(visitor); |
42 } | 43 } |
43 | 44 |
44 SensorProxy* SensorProviderProxy::getOrCreateSensor( | 45 SensorProxy* SensorProviderProxy::getOrCreateSensor( |
45 device::mojom::blink::SensorType type) { | 46 device::mojom::blink::SensorType type, |
| 47 ExecutionContext* context) { |
46 for (SensorProxy* sensor : m_sensors) { | 48 for (SensorProxy* sensor : m_sensors) { |
47 // TODO(Mikhail) : Hash sensors by type for efficiency. | 49 // TODO(Mikhail) : Hash sensors by type for efficiency. |
48 if (sensor->type() == type) | 50 if (sensor->type() == type) |
49 return sensor; | 51 return sensor; |
50 } | 52 } |
51 | 53 |
52 SensorProxy* sensor = new SensorProxy(type, this); | 54 SensorProxy* sensor = new SensorProxy(type, context, this); |
53 m_sensors.add(sensor); | 55 m_sensors.add(sensor); |
54 | 56 |
55 return sensor; | 57 return sensor; |
56 } | 58 } |
57 | 59 |
58 void SensorProviderProxy::onSensorProviderConnectionError() { | 60 void SensorProviderProxy::onSensorProviderConnectionError() { |
59 if (!Platform::current()) { | 61 if (!Platform::current()) { |
60 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 62 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
61 return; | 63 return; |
62 } | 64 } |
63 | 65 |
64 m_sensorProvider.reset(); | 66 m_sensorProvider.reset(); |
65 for (SensorProxy* sensor : m_sensors) | 67 for (SensorProxy* sensor : m_sensors) |
66 sensor->handleSensorError(); | 68 sensor->handleSensorError(); |
67 } | 69 } |
68 | 70 |
69 } // namespace blink | 71 } // namespace blink |
OLD | NEW |