| Index: third_party/WebKit/Source/modules/sensor/Sensor.cpp
|
| diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.cpp b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
|
| index 57faf7541adba4fe11261d42f7eace3eb949678f..3ff5c78c507e777d5303b7814fdd8cad8b3b5ac6 100644
|
| --- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
|
| +++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
|
| @@ -7,12 +7,13 @@
|
| #include "core/dom/Document.h"
|
| #include "core/dom/ExceptionCode.h"
|
| #include "core/dom/ExecutionContextTask.h"
|
| +#include "core/dom/FrameRequestCallback.h"
|
| #include "core/inspector/ConsoleMessage.h"
|
| #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
|
| #include "modules/sensor/SensorErrorEvent.h"
|
| #include "modules/sensor/SensorProviderProxy.h"
|
| #include "modules/sensor/SensorReading.h"
|
| -#include "modules/sensor/SensorUpdateNotificationStrategy.h"
|
| +#include "modules/sensor/SensorUpdateNotifier.h"
|
|
|
| using namespace device::mojom::blink;
|
|
|
| @@ -164,7 +165,7 @@ void Sensor::initSensorProxyIfNeeded() {
|
| m_sensorProxy = provider->getSensorProxy(m_type);
|
|
|
| if (!m_sensorProxy) {
|
| - m_sensorProxy = provider->createSensorProxy(m_type, document->page(),
|
| + m_sensorProxy = provider->createSensorProxy(m_type, document,
|
| createSensorReadingFactory());
|
| }
|
| }
|
| @@ -182,10 +183,10 @@ void Sensor::onSensorInitialized() {
|
| startListening();
|
| }
|
|
|
| -void Sensor::onSensorReadingChanged() {
|
| +void Sensor::onSensorReadingChanged(double timestamp) {
|
| if (m_state == Sensor::SensorState::Activated) {
|
| DCHECK(m_sensorUpdateNotifier);
|
| - m_sensorUpdateNotifier->onSensorReadingChanged();
|
| + m_sensorUpdateNotifier->onSensorReadingChanged(timestamp);
|
| }
|
| }
|
|
|
| @@ -211,10 +212,11 @@ void Sensor::onStartRequestCompleted(bool result) {
|
| DCHECK(m_configuration);
|
| DCHECK(m_sensorProxy);
|
| auto updateCallback =
|
| - WTF::bind(&Sensor::onSensorUpdateNotification, wrapWeakPersistent(this));
|
| + WTF::bind(&Sensor::notifySensorReadingChanged, wrapWeakPersistent(this));
|
| DCHECK_GT(m_configuration->frequency, 0);
|
| - m_sensorUpdateNotifier = SensorUpdateNotificationStrategy::create(
|
| - m_configuration->frequency, std::move(updateCallback));
|
| + m_sensorUpdateNotifier = SensorUpdateNotifier::create(
|
| + m_configuration->frequency, std::move(updateCallback),
|
| + m_sensorProxy->reportingMode());
|
| updateState(Sensor::SensorState::Activated);
|
| }
|
|
|
| @@ -255,25 +257,6 @@ void Sensor::stopListening() {
|
| m_sensorProxy->removeObserver(this);
|
| }
|
|
|
| -void Sensor::onSensorUpdateNotification() {
|
| - if (m_state != Sensor::SensorState::Activated)
|
| - return;
|
| -
|
| - DCHECK(m_sensorProxy);
|
| - DCHECK(m_sensorProxy->isInitialized());
|
| - DCHECK(m_sensorProxy->sensorReading());
|
| -
|
| - if (getExecutionContext() &&
|
| - m_sensorProxy->sensorReading()->isReadingUpdated(m_storedData)) {
|
| - getExecutionContext()->postTask(
|
| - BLINK_FROM_HERE,
|
| - createSameThreadTask(&Sensor::notifySensorReadingChanged,
|
| - wrapWeakPersistent(this)));
|
| - }
|
| -
|
| - m_storedData = m_sensorProxy->sensorReading()->data();
|
| -}
|
| -
|
| void Sensor::updateState(Sensor::SensorState newState) {
|
| if (newState == m_state)
|
| return;
|
| @@ -308,7 +291,16 @@ void Sensor::onSuspended() {
|
| }
|
|
|
| void Sensor::notifySensorReadingChanged() {
|
| - dispatchEvent(Event::create(EventTypeNames::change));
|
| + if (m_state != Sensor::SensorState::Activated)
|
| + return;
|
| +
|
| + DCHECK(m_sensorProxy);
|
| + DCHECK(m_sensorProxy->sensorReading());
|
| +
|
| + if (m_sensorProxy->sensorReading()->isReadingUpdated(m_storedData)) {
|
| + dispatchEvent(Event::create(EventTypeNames::change));
|
| + m_storedData = m_sensorProxy->sensorReading()->data();
|
| + }
|
| }
|
|
|
| void Sensor::notifyOnActivate() {
|
|
|