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 "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)); |
17 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( | 18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( |
(...skipping 16 matching lines...) Expand all Loading... | |
34 return result; | 35 return result; |
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::createSensor( |
46 device::mojom::blink::SensorType type, | |
47 std::unique_ptr<SensorReadingFactory> readingFactory) { | |
48 DCHECK(!getSensor(type)); | |
49 | |
50 SensorProxy* sensor = new SensorProxy(type, this, std::move(readingFactory)); | |
51 m_sensors.add(sensor); | |
52 | |
53 return sensor; | |
54 } | |
55 | |
56 SensorProxy* SensorProviderProxy::getSensor( | |
timvolodine
2016/11/07 15:49:19
perhaps easier to just have getSensor with on dema
Mikhail
2016/11/08 09:09:15
This is how it was so far, I decided to split 'get
| |
45 device::mojom::blink::SensorType type) { | 57 device::mojom::blink::SensorType type) { |
46 for (SensorProxy* sensor : m_sensors) { | 58 for (SensorProxy* sensor : m_sensors) { |
47 // TODO(Mikhail) : Hash sensors by type for efficiency. | 59 // TODO(Mikhail) : Hash sensors by type for efficiency. |
48 if (sensor->type() == type) | 60 if (sensor->type() == type) |
49 return sensor; | 61 return sensor; |
50 } | 62 } |
51 | 63 |
52 SensorProxy* sensor = new SensorProxy(type, this); | 64 return nullptr; |
53 m_sensors.add(sensor); | |
54 | |
55 return sensor; | |
56 } | 65 } |
57 | 66 |
58 void SensorProviderProxy::onSensorProviderConnectionError() { | 67 void SensorProviderProxy::onSensorProviderConnectionError() { |
59 if (!Platform::current()) { | 68 if (!Platform::current()) { |
60 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 69 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
61 return; | 70 return; |
62 } | 71 } |
63 | 72 |
64 m_sensorProvider.reset(); | 73 m_sensorProvider.reset(); |
65 for (SensorProxy* sensor : m_sensors) | 74 for (SensorProxy* sensor : m_sensors) |
66 sensor->handleSensorError(); | 75 sensor->handleSensorError(); |
67 } | 76 } |
68 | 77 |
69 } // namespace blink | 78 } // namespace blink |
OLD | NEW |