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" | |
8 #include "modules/permissions/PermissionUtils.h" | |
7 #include "modules/sensor/SensorProxy.h" | 9 #include "modules/sensor/SensorProxy.h" |
8 #include "modules/sensor/SensorReading.h" | 10 #include "modules/sensor/SensorReading.h" |
9 #include "platform/mojo/MojoHelper.h" | 11 #include "platform/mojo/MojoHelper.h" |
10 #include "public/platform/InterfaceProvider.h" | 12 #include "public/platform/InterfaceProvider.h" |
11 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
12 | 14 |
13 namespace blink { | 15 namespace blink { |
14 | 16 |
15 // SensorProviderProxy | 17 // SensorProviderProxy |
16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { | 18 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { |
(...skipping 18 matching lines...) Expand all Loading... | |
35 return result; | 37 return result; |
36 } | 38 } |
37 | 39 |
38 SensorProviderProxy::~SensorProviderProxy() {} | 40 SensorProviderProxy::~SensorProviderProxy() {} |
39 | 41 |
40 DEFINE_TRACE(SensorProviderProxy) { | 42 DEFINE_TRACE(SensorProviderProxy) { |
41 visitor->trace(m_sensors); | 43 visitor->trace(m_sensors); |
42 Supplement<LocalFrame>::trace(visitor); | 44 Supplement<LocalFrame>::trace(visitor); |
43 } | 45 } |
44 | 46 |
47 void SensorProviderProxy::onPermissionServiceConnectionError() { | |
48 if (!Platform::current()) { | |
49 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | |
50 return; | |
51 } | |
52 | |
53 m_permissionService.reset(); | |
54 for (SensorProxy* sensor : m_sensors) { | |
55 sensor->handleSensorError(SecurityError, | |
56 "Permission service not available."); | |
57 } | |
58 } | |
59 | |
45 SensorProxy* SensorProviderProxy::createSensor( | 60 SensorProxy* SensorProviderProxy::createSensor( |
46 device::mojom::blink::SensorType type, | 61 device::mojom::blink::SensorType type, |
62 ExecutionContext* context, | |
47 std::unique_ptr<SensorReadingFactory> readingFactory) { | 63 std::unique_ptr<SensorReadingFactory> readingFactory) { |
48 DCHECK(!getSensor(type)); | 64 DCHECK(!getSensor(type)); |
49 | 65 |
50 SensorProxy* sensor = new SensorProxy(type, this, std::move(readingFactory)); | 66 // Get permission service. |
51 m_sensors.add(sensor); | 67 if (!m_permissionService && |
68 connectToPermissionService(context, | |
69 mojo::GetProxy(&m_permissionService))) { | |
70 m_permissionService.set_connection_error_handler(convertToBaseCallback( | |
71 WTF::bind(&SensorProviderProxy::onPermissionServiceConnectionError, | |
72 wrapWeakPersistent(this)))); | |
52 | 73 |
53 return sensor; | 74 RefPtr<SecurityOrigin> origin = context->getSecurityOrigin(); |
75 DCHECK(origin); | |
76 SensorProxy* sensor = | |
77 new SensorProxy(type, m_permissionService.get(), origin, this, | |
78 std::move(readingFactory)); | |
79 m_sensors.add(sensor); | |
80 return sensor; | |
81 } | |
82 | |
83 return nullptr; | |
Mikhail
2016/11/18 12:37:42
createSensor should not return nullptr, if there i
riju_
2016/11/21 11:23:28
OK, reusing onSensorProviderConnectionError for pe
| |
54 } | 84 } |
55 | 85 |
56 SensorProxy* SensorProviderProxy::getSensor( | 86 SensorProxy* SensorProviderProxy::getSensor( |
57 device::mojom::blink::SensorType type) { | 87 device::mojom::blink::SensorType type) { |
58 for (SensorProxy* sensor : m_sensors) { | 88 for (SensorProxy* sensor : m_sensors) { |
59 // TODO(Mikhail) : Hash sensors by type for efficiency. | 89 // TODO(Mikhail) : Hash sensors by type for efficiency. |
60 if (sensor->type() == type) | 90 if (sensor->type() == type) |
61 return sensor; | 91 return sensor; |
62 } | 92 } |
63 | 93 |
64 return nullptr; | 94 return nullptr; |
65 } | 95 } |
66 | 96 |
67 void SensorProviderProxy::onSensorProviderConnectionError() { | 97 void SensorProviderProxy::onSensorProviderConnectionError() { |
68 if (!Platform::current()) { | 98 if (!Platform::current()) { |
69 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 99 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
70 return; | 100 return; |
71 } | 101 } |
72 | 102 |
73 m_sensorProvider.reset(); | 103 m_sensorProvider.reset(); |
74 for (SensorProxy* sensor : m_sensors) | 104 for (SensorProxy* sensor : m_sensors) |
75 sensor->handleSensorError(); | 105 sensor->handleSensorError(); |
76 } | 106 } |
77 | 107 |
78 } // namespace blink | 108 } // namespace blink |
OLD | NEW |