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 #ifndef SensorPollingStrategy_h | 5 #ifndef SensorPollingStrategy_h |
6 #define SensorPollingStrategy_h | 6 #define SensorPollingStrategy_h |
7 | 7 |
8 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" | 8 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
| 9 #include "platform/Timer.h" |
9 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
10 #include "wtf/Functional.h" | 11 #include "wtf/Functional.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 // This class provides different polling behaviour depending on | 15 // This class provides different polling behaviour depending on |
15 // the given 'ReportingMode': | 16 // the given 'ReportingMode': |
16 // - for 'CONTINUOUS' mode the polling function is invoked periodically | 17 // - for 'CONTINUOUS' mode the polling function is invoked periodically |
17 // with the given frequency (on timer event). | 18 // with the given polling period (on timer event). |
18 // - for 'ONCHANGE' mode the polling function is invoked only after client | 19 // - for 'ONCHANGE' mode the polling function is invoked only after client |
19 // calls 'onSensorReadingChanged()' however considering the given frequency: | 20 // calls 'onSensorReadingChanged()' however considering the given polling peri
od: |
20 // guaranteed not to be called more often than expected. | 21 // guaranteed not to be called more often than expected. |
21 class SensorPollingStrategy { | 22 class SensorPollingStrategy { |
22 public: | 23 public: |
23 static std::unique_ptr<SensorPollingStrategy> create(double frequency, std::
unique_ptr<Function<void()>> pollFunc, device::mojom::blink::ReportingMode); | 24 static std::unique_ptr<SensorPollingStrategy> create(double pollingPeriod, s
td::unique_ptr<Function<void()>> pollFunc, device::mojom::blink::ReportingMode); |
24 | 25 |
25 virtual void onSensorReadingChanged() {} | 26 virtual void onSensorReadingChanged() {} |
26 virtual void startPolling() = 0; | 27 virtual void startPolling() = 0; |
27 virtual void stopPolling() = 0; | 28 virtual void stopPolling() = 0; |
28 | 29 |
29 virtual ~SensorPollingStrategy() {} | 30 virtual ~SensorPollingStrategy(); |
| 31 |
| 32 protected: |
| 33 SensorPollingStrategy(double pollingPeriod, std::unique_ptr<Function<void()>
>); |
| 34 virtual void pollForData(TimerBase*) = 0; |
| 35 |
| 36 double m_pollingPeriod; |
| 37 std::unique_ptr<Function<void()>> m_pollFunc; |
| 38 Timer<SensorPollingStrategy> m_timer; |
30 }; | 39 }; |
31 | 40 |
32 } // namespace blink | 41 } // namespace blink |
33 | 42 |
34 #endif // SensorPollingStrategy_h | 43 #endif // SensorPollingStrategy_h |
OLD | NEW |