Index: device/generic_sensor/platform_sensor_provider_linux.h |
diff --git a/device/generic_sensor/platform_sensor_provider_linux.h b/device/generic_sensor/platform_sensor_provider_linux.h |
index 7470cbeb82edcae0c03c4dde49c497cb2c2f8947..bcef25d56a501b1b1460b5e754877b75899efd43 100644 |
--- a/device/generic_sensor/platform_sensor_provider_linux.h |
+++ b/device/generic_sensor/platform_sensor_provider_linux.h |
@@ -8,22 +8,32 @@ |
#include "device/generic_sensor/platform_sensor_provider.h" |
namespace base { |
+template <typename T> |
+struct DefaultSingletonTraits; |
class Thread; |
} |
namespace device { |
-struct SensorDataLinux; |
-class SensorReader; |
+struct SensorDeviceLinux; |
+class SensorDeviceManager; |
+class SensorDeviceService; |
-class PlatformSensorProviderLinux : public PlatformSensorProvider { |
+class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderLinux |
+ : public PlatformSensorProvider { |
public: |
- PlatformSensorProviderLinux(); |
- ~PlatformSensorProviderLinux() override; |
+ using SensorAttachedCallback = base::Callback<void(mojom::SensorType)>; |
static PlatformSensorProviderLinux* GetInstance(); |
+ // Provides SensorDeviceManager with a mock service used for testing, because |
+ // there might not be sensors on a testing system. |
+ void SetSensorDeviceServiceForTesting( |
+ std::unique_ptr<SensorDeviceService> device); |
+ |
protected: |
+ ~PlatformSensorProviderLinux() override; |
+ |
void CreateSensorInternal(mojom::SensorType type, |
mojo::ScopedSharedBufferMapping mapping, |
const CreateSensorCallback& callback) override; |
@@ -34,37 +44,34 @@ class PlatformSensorProviderLinux : public PlatformSensorProvider { |
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override; |
private: |
- void SensorReaderFound( |
+ friend struct base::DefaultSingletonTraits<PlatformSensorProviderLinux>; |
+ |
+ PlatformSensorProviderLinux(); |
+ |
+ void SensorDeviceFound( |
mojom::SensorType type, |
mojo::ScopedSharedBufferMapping mapping, |
const PlatformSensorProviderBase::CreateSensorCallback& callback, |
- const SensorDataLinux& data, |
- std::unique_ptr<SensorReader> sensor_reader); |
+ SensorDeviceLinux* sensor_device); |
+ |
+ bool StartPollingThread(); |
// Stops a polling thread if there are no sensors left. Must be called on |
- // a different that polling thread that allows io. |
+ // a different than the polling thread which allows I/O. |
void StopPollingThread(); |
- // TODO(maksims): make a separate class Manager that will |
- // create provide sensors with a polling task runner, check sensors existence |
- // and notify provider if a new sensor has appeared and it can be created if a |
- // request comes again for the same sensor. |
- // A use case example: a request for a sensor X comes, manager checks if the |
- // sensor exists on a platform and notifies a provider it is not found. |
- // The provider stores this information into its cache and doesn't try to |
- // create this specific sensor if a request comes. But when, for example, |
- // the sensor X is plugged into a usb port, the manager notices that and |
- // notifies the provider, which updates its cache and starts handling requests |
- // for the sensor X. |
- // |
- // Right now, this thread is used to find sensors files and poll data. |
+ void InitializeSensorDeviceManager(); |
+ |
+ // A thread that is used by sensor readers in case of polling strategy. |
std::unique_ptr<base::Thread> polling_thread_; |
- // A task runner that is passed to polling sensors to poll data. |
- scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; |
+ // This manager is being used to get |SensorDeviceLinux|, which represents |
+ // all the information of a concrete sensor provided by OS. |
+ std::unique_ptr<SensorDeviceManager> sensor_device_manager_; |
- // Browser's file thread task runner passed from renderer. Used to |
- // stop a polling thread. |
+ // Browser's file thread task runner passed from renderer. Used by this |
+ // provider to stop a polling thread and passed to a manager that |
+ // runs a linux device monitor service on this task runner. |
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux); |