Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_reader_linux.h |
| diff --git a/device/generic_sensor/platform_sensor_reader_linux.h b/device/generic_sensor/platform_sensor_reader_linux.h |
| index 755ad2671af5f80937cd470d8f3ac8851d64f733..77477d422043e4eb5258fef9767bb57c9d2f0408 100644 |
| --- a/device/generic_sensor/platform_sensor_reader_linux.h |
| +++ b/device/generic_sensor/platform_sensor_reader_linux.h |
| @@ -5,7 +5,9 @@ |
| #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ |
| #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ |
| +#include "base/callback.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/threading/thread_checker.h" |
| #include "device/generic_sensor/generic_sensor_export.h" |
| namespace base { |
| @@ -14,45 +16,58 @@ class SingleThreadTaskRunner; |
| namespace device { |
| -class PlatformSensorLinux; |
| class PlatformSensorConfiguration; |
| struct SensorInfoLinux; |
| +struct SensorReading; |
| // A generic reader class that can be implemented with two different strategies: |
| -// polling and on trigger. |
| +// polling and on trigger. All methods are not thread-safe and must be called |
| +// on a polling thread that allows I/O. |
| class SensorReader { |
| public: |
| + using UpdateSensorReadingCallback = base::Callback<void(SensorReading)>; |
| + using NotifyReadErrorCallback = base::Callback<void()>; |
| + |
| // Creates a new instance of SensorReader. At the moment, only polling |
| // reader is supported. |
| static std::unique_ptr<SensorReader> Create( |
| const SensorInfoLinux* sensor_device, |
| - PlatformSensorLinux* sensor, |
| - scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner); |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + const UpdateSensorReadingCallback& notify_new_readings_cb, |
| + const NotifyReadErrorCallback& notify_read_error_cb); |
| virtual ~SensorReader(); |
| // Starts fetching data based on strategy this reader has chosen. |
| - // Only polling strategy is supported at the moment. Thread safe. |
| - virtual bool StartFetchingData( |
| + // Only polling strategy is supported at the moment. |
| + virtual void StartFetchingData( |
| const PlatformSensorConfiguration& configuration) = 0; |
| - // Stops fetching data. Thread safe. |
| + // Stops fetching data. |
| virtual void StopFetchingData() = 0; |
| protected: |
| - SensorReader(PlatformSensorLinux* sensor, |
| - scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner); |
| + SensorReader(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + const UpdateSensorReadingCallback& notify_new_readings_cb, |
| + const NotifyReadErrorCallback& notify_read_error_cb); |
| // Notifies |sensor_| about an error. |
| void NotifyReadError(); |
| - // Non-owned pointer to a sensor that created this reader. |
| - PlatformSensorLinux* sensor_; |
| + // In builds with DCHECK enabled checks that methods of this |
| + // and derived classes are called on a right thread. |
| + base::ThreadChecker thread_checker_; |
| - // A task runner that is used to poll data. |
| - scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_; |
| + // Used for notifications about new readings and errors. |
| + // Can be run on any thread, because this callbacks are attached |
| + // to the same MessageLoop where they are created. |
|
Reilly Grant (use Gerrit)
2016/12/16 21:34:42
This comment is out of date because they are no lo
|
| + UpdateSensorReadingCallback notify_new_readings_cb_; |
| + NotifyReadErrorCallback notify_read_error_cb_; |
| // A task runner that belongs to a thread this reader is created on. |
| + scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_; |
|
Reilly Grant (use Gerrit)
2016/12/16 21:34:42
This field is unused.
maksims (do not use this acc)
2016/12/19 09:46:23
Done.
|
| + |
| + // A task runner that is used to report reading updates and errors |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| // Indicates if reading is active. |