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/SensorProxy.h" | 5 #include "modules/sensor/SensorProxy.h" |
6 | 6 |
7 #include "core/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
8 #include "modules/permissions/PermissionUtils.h" | |
8 #include "modules/sensor/SensorProviderProxy.h" | 9 #include "modules/sensor/SensorProviderProxy.h" |
9 #include "modules/sensor/SensorReading.h" | 10 #include "modules/sensor/SensorReading.h" |
11 #include "platform/UserGestureIndicator.h" | |
10 #include "platform/mojo/MojoHelper.h" | 12 #include "platform/mojo/MojoHelper.h" |
13 #include "platform/weborigin/SecurityOrigin.h" | |
11 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
12 | 15 |
13 using namespace device::mojom::blink; | 16 using namespace device::mojom::blink; |
14 | 17 |
15 namespace blink { | 18 namespace blink { |
16 | 19 |
20 using mojom::blink::PermissionName; | |
21 using mojom::blink::PermissionService; | |
22 using mojom::blink::PermissionStatus; | |
23 | |
17 SensorProxy::SensorProxy(SensorType sensorType, | 24 SensorProxy::SensorProxy(SensorType sensorType, |
25 PermissionService* permissionService, | |
26 RefPtr<SecurityOrigin> origin, | |
18 SensorProviderProxy* provider, | 27 SensorProviderProxy* provider, |
19 std::unique_ptr<SensorReadingFactory> readingFactory) | 28 std::unique_ptr<SensorReadingFactory> readingFactory) |
20 : m_type(sensorType), | 29 : m_type(sensorType), |
21 m_mode(ReportingMode::CONTINUOUS), | 30 m_mode(ReportingMode::CONTINUOUS), |
22 m_provider(provider), | 31 m_provider(provider), |
23 m_clientBinding(this), | 32 m_clientBinding(this), |
24 m_state(SensorProxy::Uninitialized), | 33 m_state(SensorProxy::Uninitialized), |
25 m_suspended(false), | 34 m_suspended(false), |
26 m_readingFactory(std::move(readingFactory)), | 35 m_readingFactory(std::move(readingFactory)), |
27 m_maximumFrequency(0.0) {} | 36 m_maximumFrequency(0.0), |
37 m_permissionStatus(PermissionStatus::ASK), | |
38 m_permissionService(permissionService), | |
39 m_securityOrigin(std::move(origin)) {} | |
40 | |
41 void SensorProxy::onPermissionUpdate(PermissionStatus status) { | |
42 if (m_permissionStatus != status) { | |
43 m_permissionStatus = status; | |
44 if (!isInitialized()) | |
Mikhail
2016/11/18 12:37:43
so, any external permission changes could initiate
riju_
2016/11/21 11:23:28
Acknowledged.
| |
45 initialize(); | |
46 } | |
47 | |
48 // If permission is revoked, throw error. | |
49 if (m_permissionStatus != PermissionStatus::GRANTED) | |
50 handleSensorError(NotAllowedError, "Permission not granted."); | |
Mikhail
2016/11/18 12:37:42
what it if we in the middle of initialization, or
riju_
2016/11/21 11:23:28
Acknowledged.
| |
51 | |
52 // Keep listening to changes. | |
53 m_permissionService->GetNextPermissionChange( | |
54 createPermissionDescriptor(PermissionName::SENSORS), m_securityOrigin, | |
55 m_permissionStatus, | |
56 convertToBaseCallback(WTF::bind(&SensorProxy::onPermissionUpdate, | |
57 wrapWeakPersistent(this)))); | |
58 } | |
28 | 59 |
29 SensorProxy::~SensorProxy() {} | 60 SensorProxy::~SensorProxy() {} |
30 | 61 |
31 void SensorProxy::dispose() { | 62 void SensorProxy::dispose() { |
32 m_clientBinding.Close(); | 63 m_clientBinding.Close(); |
33 } | 64 } |
34 | 65 |
35 DEFINE_TRACE(SensorProxy) { | 66 DEFINE_TRACE(SensorProxy) { |
36 visitor->trace(m_reading); | 67 visitor->trace(m_reading); |
37 visitor->trace(m_observers); | 68 visitor->trace(m_observers); |
(...skipping 11 matching lines...) Expand all Loading... | |
49 | 80 |
50 void SensorProxy::initialize() { | 81 void SensorProxy::initialize() { |
51 if (m_state != Uninitialized) | 82 if (m_state != Uninitialized) |
52 return; | 83 return; |
53 | 84 |
54 if (!m_provider->sensorProvider()) { | 85 if (!m_provider->sensorProvider()) { |
55 handleSensorError(); | 86 handleSensorError(); |
56 return; | 87 return; |
57 } | 88 } |
58 | 89 |
59 m_state = Initializing; | |
60 auto callback = convertToBaseCallback( | 90 auto callback = convertToBaseCallback( |
61 WTF::bind(&SensorProxy::onSensorCreated, wrapWeakPersistent(this))); | 91 WTF::bind(&SensorProxy::onSensorCreated, wrapWeakPersistent(this))); |
62 m_provider->sensorProvider()->GetSensor(m_type, mojo::GetProxy(&m_sensor), | 92 |
63 callback); | 93 switch (m_permissionStatus) { |
94 case PermissionStatus::ASK: | |
95 // Request permission. | |
96 m_permissionService->RequestPermission( | |
97 createPermissionDescriptor(PermissionName::SENSORS), m_securityOrigin, | |
98 UserGestureIndicator::processingUserGesture(), | |
99 convertToBaseCallback(WTF::bind(&SensorProxy::onPermissionUpdate, | |
100 wrapPersistent(this)))); | |
Mikhail
2016/11/18 12:37:43
why to hold proxy instance alive until onPermissio
riju_
2016/11/21 11:23:28
Done.
| |
101 break; | |
102 case PermissionStatus::DENIED: | |
103 handleSensorError(NotAllowedError, "Permission not granted."); | |
104 break; | |
105 case PermissionStatus::GRANTED: | |
106 m_state = Initializing; | |
107 m_provider->sensorProvider()->GetSensor(m_type, mojo::GetProxy(&m_sensor), | |
108 callback); | |
109 break; | |
110 default: | |
111 NOTREACHED(); | |
112 } | |
64 } | 113 } |
65 | 114 |
66 void SensorProxy::addConfiguration( | 115 void SensorProxy::addConfiguration( |
67 SensorConfigurationPtr configuration, | 116 SensorConfigurationPtr configuration, |
68 std::unique_ptr<Function<void(bool)>> callback) { | 117 std::unique_ptr<Function<void(bool)>> callback) { |
69 DCHECK(isInitialized()); | 118 DCHECK(isInitialized()); |
70 m_sensor->AddConfiguration(std::move(configuration), | 119 m_sensor->AddConfiguration(std::move(configuration), |
71 convertToBaseCallback(std::move(callback))); | 120 convertToBaseCallback(std::move(callback))); |
72 } | 121 } |
73 | 122 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value(); | 251 const device::OneWriterSeqLock& seqlock = buffer->seqlock.value(); |
203 auto version = seqlock.ReadBegin(); | 252 auto version = seqlock.ReadBegin(); |
204 auto readingData = buffer->reading; | 253 auto readingData = buffer->reading; |
205 if (seqlock.ReadRetry(version)) | 254 if (seqlock.ReadRetry(version)) |
206 return false; | 255 return false; |
207 result = readingData; | 256 result = readingData; |
208 return true; | 257 return true; |
209 } | 258 } |
210 | 259 |
211 } // namespace blink | 260 } // namespace blink |
OLD | NEW |