Chromium Code Reviews| 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 Page* page, | 28 Page* page, |
| 20 std::unique_ptr<SensorReadingFactory> readingFactory) | 29 std::unique_ptr<SensorReadingFactory> readingFactory) |
| 21 : PageVisibilityObserver(page), | 30 : PageVisibilityObserver(page), |
| 22 m_type(sensorType), | 31 m_type(sensorType), |
| 23 m_mode(ReportingMode::CONTINUOUS), | 32 m_mode(ReportingMode::CONTINUOUS), |
| 24 m_provider(provider), | 33 m_provider(provider), |
| 25 m_clientBinding(this), | 34 m_clientBinding(this), |
| 26 m_state(SensorProxy::Uninitialized), | 35 m_state(SensorProxy::Uninitialized), |
| 27 m_suspended(false), | 36 m_suspended(false), |
| 28 m_readingFactory(std::move(readingFactory)), | 37 m_readingFactory(std::move(readingFactory)), |
| 29 m_maximumFrequency(0.0), | 38 m_maximumFrequency(0.0), |
| 30 m_timer(this, &SensorProxy::onTimerFired) {} | 39 m_timer(this, &SensorProxy::onTimerFired), |
| 40 m_permissionStatus(PermissionStatus::ASK), | |
| 41 m_permissionService(permissionService), | |
| 42 m_securityOrigin(std::move(origin)) {} | |
| 43 | |
| 44 void SensorProxy::onPermissionUpdate(PermissionStatus status) { | |
| 45 if (m_state == Uninitialized) | |
| 46 return; | |
| 47 | |
| 48 if (m_permissionStatus != status) | |
| 49 m_permissionStatus = status; | |
|
Mikhail
2016/11/28 20:07:53
Think m_permissionStatus is not needed as not used
riju_
2016/11/29 07:19:47
Because I wanted to make sure that, whenever Senso
shalamov
2016/11/29 08:29:10
I agree with Mikhail, this line of code and member
Mikhail
2016/11/29 08:46:29
mm.. how does it help to make sure it is always in
| |
| 50 | |
| 51 switch (status) { | |
| 52 case mojom::blink::PermissionStatus::DENIED: | |
| 53 handleSensorError(NotAllowedError, "Permission denied."); | |
| 54 return; | |
| 55 case mojom::blink::PermissionStatus::ASK: | |
| 56 handleSensorError(NotAllowedError, "Permission revoked."); | |
| 57 break; | |
|
Mikhail
2016/11/28 20:07:53
why not return here?
riju_
2016/11/29 07:19:47
Because if it is ASK, I would still like to subscr
Mikhail
2016/11/29 08:46:29
This subscription is meaningless as error handler
| |
| 58 case mojom::blink::PermissionStatus::GRANTED: | |
| 59 if (isInitializing()) { | |
| 60 m_state = Initialized; | |
| 61 for (Observer* observer : m_observers) | |
| 62 observer->onSensorInitialized(); | |
| 63 } | |
| 64 break; | |
| 65 default: | |
| 66 NOTREACHED(); | |
| 67 } | |
| 68 | |
| 69 // Keep listening to changes. | |
| 70 m_permissionService->GetNextPermissionChange( | |
| 71 createPermissionDescriptor(PermissionName::SENSORS), m_securityOrigin, | |
| 72 m_permissionStatus, | |
| 73 convertToBaseCallback(WTF::bind(&SensorProxy::onPermissionUpdate, | |
| 74 wrapWeakPersistent(this)))); | |
| 75 } | |
| 31 | 76 |
| 32 SensorProxy::~SensorProxy() {} | 77 SensorProxy::~SensorProxy() {} |
| 33 | 78 |
| 34 void SensorProxy::dispose() { | 79 void SensorProxy::dispose() { |
| 35 m_clientBinding.Close(); | 80 m_clientBinding.Close(); |
| 36 } | 81 } |
| 37 | 82 |
| 38 DEFINE_TRACE(SensorProxy) { | 83 DEFINE_TRACE(SensorProxy) { |
| 39 visitor->trace(m_reading); | 84 visitor->trace(m_reading); |
| 40 visitor->trace(m_observers); | 85 visitor->trace(m_observers); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 | 265 |
| 221 m_maximumFrequency = params->maximum_frequency; | 266 m_maximumFrequency = params->maximum_frequency; |
| 222 DCHECK(m_maximumFrequency <= SensorConfiguration::kMaxAllowedFrequency); | 267 DCHECK(m_maximumFrequency <= SensorConfiguration::kMaxAllowedFrequency); |
| 223 | 268 |
| 224 auto errorCallback = | 269 auto errorCallback = |
| 225 WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this), | 270 WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this), |
| 226 UnknownError, String("Internal error"), String()); | 271 UnknownError, String("Internal error"), String()); |
| 227 m_sensor.set_connection_error_handler( | 272 m_sensor.set_connection_error_handler( |
| 228 convertToBaseCallback(std::move(errorCallback))); | 273 convertToBaseCallback(std::move(errorCallback))); |
| 229 | 274 |
| 230 m_state = Initialized; | 275 // Request permission. |
| 231 for (Observer* observer : m_observers) | 276 m_permissionService->RequestPermission( |
| 232 observer->onSensorInitialized(); | 277 createPermissionDescriptor(PermissionName::SENSORS), m_securityOrigin, |
| 278 UserGestureIndicator::processingUserGesture(), | |
| 279 convertToBaseCallback(WTF::bind(&SensorProxy::onPermissionUpdate, | |
| 280 wrapWeakPersistent(this)))); | |
| 233 } | 281 } |
| 234 | 282 |
| 235 void SensorProxy::onAddConfigurationCompleted( | 283 void SensorProxy::onAddConfigurationCompleted( |
| 236 double frequency, | 284 double frequency, |
| 237 std::unique_ptr<Function<void(bool)>> callback, | 285 std::unique_ptr<Function<void(bool)>> callback, |
| 238 bool result) { | 286 bool result) { |
| 239 if (usesPollingTimer() && result) { | 287 if (usesPollingTimer() && result) { |
| 240 m_frequenciesUsed.append(frequency); | 288 m_frequenciesUsed.append(frequency); |
| 241 updatePollingStatus(); | 289 updatePollingStatus(); |
| 242 } | 290 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 updateSensorReading(); | 341 updateSensorReading(); |
| 294 m_timer.startRepeating(repeatInterval, BLINK_FROM_HERE); | 342 m_timer.startRepeating(repeatInterval, BLINK_FROM_HERE); |
| 295 } | 343 } |
| 296 } | 344 } |
| 297 | 345 |
| 298 void SensorProxy::onTimerFired(TimerBase*) { | 346 void SensorProxy::onTimerFired(TimerBase*) { |
| 299 updateSensorReading(); | 347 updateSensorReading(); |
| 300 } | 348 } |
| 301 | 349 |
| 302 } // namespace blink | 350 } // namespace blink |
| OLD | NEW |