| 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 10983e536031c1e402926cf5d228125eda73d297..ab75720007602745482a3090cc8baf39fb320d7a 100644
|
| --- a/device/generic_sensor/platform_sensor_reader_linux.h
|
| +++ b/device/generic_sensor/platform_sensor_reader_linux.h
|
| @@ -5,7 +5,11 @@
|
| #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/memory/weak_ptr.h"
|
| +#include "base/threading/thread_checker.h"
|
| +#include "device/generic_sensor/generic_sensor_export.h"
|
|
|
| namespace base {
|
| class SingleThreadTaskRunner;
|
| @@ -13,45 +17,49 @@ class SingleThreadTaskRunner;
|
|
|
| namespace device {
|
|
|
| -class PlatformSensorLinux;
|
| class PlatformSensorConfiguration;
|
| +class PlatformSensorLinux;
|
| struct SensorInfoLinux;
|
|
|
| // 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:
|
| // 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);
|
| + base::WeakPtr<PlatformSensorLinux> sensor,
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
|
|
| 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(base::WeakPtr<PlatformSensorLinux> sensor,
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
|
|
| // 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_;
|
| + // A sensor that this reader is owned by and notifies about errors and
|
| + // readings to.
|
| + base::WeakPtr<PlatformSensorLinux> sensor_;
|
|
|
| - // A task runner that belongs to a thread this reader is created on.
|
| + // A task runner that is used to report about new readings and errors
|
| + // to a |sensor_|.
|
| scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
|
|
| // Indicates if reading is active.
|
|
|