Index: third_party/WebKit/Source/modules/sensor/SensorProxy.h |
diff --git a/third_party/WebKit/Source/modules/sensor/SensorProxy.h b/third_party/WebKit/Source/modules/sensor/SensorProxy.h |
index 4c32534e9ae1a38158f008f63bd99cfdfe4bff11..3243636775cef146e6edd103933ced25ff4c15ad 100644 |
--- a/third_party/WebKit/Source/modules/sensor/SensorProxy.h |
+++ b/third_party/WebKit/Source/modules/sensor/SensorProxy.h |
@@ -6,12 +6,15 @@ |
#define SensorProxy_h |
#include "core/dom/ExceptionCode.h" |
+#include "core/page/PageVisibilityObserver.h" |
#include "device/generic_sensor/public/cpp/sensor_reading.h" |
#include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
#include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
#include "mojo/public/cpp/bindings/binding.h" |
#include "platform/Supplementable.h" |
+#include "platform/Timer.h" |
#include "platform/heap/Handle.h" |
+#include "wtf/Vector.h" |
namespace blink { |
@@ -22,7 +25,9 @@ class SensorReadingFactory; |
// This class wraps 'Sensor' mojo interface and used by multiple |
// JS sensor instances of the same type (within a single frame). |
class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
- public device::mojom::blink::SensorClient { |
+ public device::mojom::blink::SensorClient, |
+ public PageVisibilityObserver { |
+ USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); |
USING_PRE_FINALIZER(SensorProxy, dispose); |
WTF_MAKE_NONCOPYABLE(SensorProxy); |
@@ -32,12 +37,14 @@ class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
// Has valid 'Sensor' binding, {add, remove}Configuration() |
// methods can be called. |
virtual void onSensorInitialized() {} |
- // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). |
+ // Platfrom sensort reading has changed. |
virtual void onSensorReadingChanged() {} |
// An error has occurred. |
virtual void onSensorError(ExceptionCode, |
const String& sanitizedMessage, |
const String& unsanitizedMessage) {} |
+ // Sensor reading change notification is suspended. |
+ virtual void onSuspended() {} |
}; |
~SensorProxy(); |
@@ -54,8 +61,8 @@ class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
void addConfiguration(device::mojom::blink::SensorConfigurationPtr, |
std::unique_ptr<Function<void(bool)>>); |
- void removeConfiguration(device::mojom::blink::SensorConfigurationPtr, |
- std::unique_ptr<Function<void(bool)>>); |
+ |
+ void removeConfiguration(device::mojom::blink::SensorConfigurationPtr); |
void suspend(); |
void resume(); |
@@ -72,31 +79,45 @@ class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
double maximumFrequency() const { return m_maximumFrequency; } |
- // Updates sensor reading from shared buffer. |
- void updateSensorReading(); |
- |
DECLARE_VIRTUAL_TRACE(); |
private: |
friend class SensorProviderProxy; |
SensorProxy(device::mojom::blink::SensorType, |
SensorProviderProxy*, |
+ Page*, |
std::unique_ptr<SensorReadingFactory>); |
+ // Returns true if this instance is using polling timer to |
+ // periodically fetch reading data from shared buffer. |
+ bool usesPollingTimer() const; |
+ |
+ // Updates sensor reading from shared buffer. |
+ void updateSensorReading(); |
// device::mojom::blink::SensorClient overrides. |
void RaiseError() override; |
void SensorReadingChanged() override; |
+ // PageVisibilityObserver overrides. |
+ void pageVisibilityChanged() override; |
+ |
// Generic handler for a fatal error. |
// String parameters are intentionally copied. |
void handleSensorError(ExceptionCode = UnknownError, |
String sanitizedMessage = String(), |
String unsanitizedMessage = String()); |
- |
+ // mojo call callbacks. |
void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, |
device::mojom::blink::SensorClientRequest); |
+ void onAddConfigurationCompleted( |
+ double frequency, |
+ std::unique_ptr<Function<void(bool)>> callback, |
+ bool result); |
+ void onRemoveConfigurationCompleted(double frequency, bool result); |
bool tryReadFromBuffer(device::SensorReading& result); |
+ void updatePollingStatus(); |
+ void onTimerFired(TimerBase*); |
device::mojom::blink::SensorType m_type; |
device::mojom::blink::ReportingMode m_mode; |
@@ -117,6 +138,10 @@ class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
std::unique_ptr<SensorReadingFactory> m_readingFactory; |
double m_maximumFrequency; |
+ // Used for continious reporting mode. |
+ Timer<SensorProxy> m_timer; |
+ WTF::Vector<double> m_frequenciesUsed; |
+ |
using ReadingBuffer = device::SensorReadingSharedBuffer; |
static_assert( |
sizeof(ReadingBuffer) == |