OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ |
| 7 |
| 8 #include "device/generic_sensor/platform_sensor_provider.h" |
| 9 |
| 10 namespace base { |
| 11 class Thread; |
| 12 } |
| 13 |
| 14 namespace device { |
| 15 |
| 16 struct SensorDataLinux; |
| 17 class SensorReader; |
| 18 |
| 19 class PlatformSensorProviderLinux : public PlatformSensorProvider { |
| 20 public: |
| 21 PlatformSensorProviderLinux(); |
| 22 ~PlatformSensorProviderLinux() override; |
| 23 |
| 24 static PlatformSensorProviderLinux* GetInstance(); |
| 25 |
| 26 protected: |
| 27 void CreateSensorInternal(mojom::SensorType type, |
| 28 mojo::ScopedSharedBufferMapping mapping, |
| 29 const CreateSensorCallback& callback) override; |
| 30 |
| 31 void AllSensorsRemoved() override; |
| 32 |
| 33 void SetFileTaskRunner( |
| 34 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override; |
| 35 |
| 36 private: |
| 37 void SensorReaderFound( |
| 38 mojom::SensorType type, |
| 39 mojo::ScopedSharedBufferMapping mapping, |
| 40 const PlatformSensorProviderBase::CreateSensorCallback& callback, |
| 41 const SensorDataLinux& data, |
| 42 std::unique_ptr<SensorReader> sensor_reader); |
| 43 |
| 44 // Stops a polling thread if there are no sensors left. Must be called on |
| 45 // a different that polling thread that allows io. |
| 46 void StopPollingThread(); |
| 47 |
| 48 // TODO(maksims): make a separate class Manager that will |
| 49 // create provide sensors with a polling task runner, check sensors existence |
| 50 // and notify provider if a new sensor has appeared and it can be created if a |
| 51 // request comes again for the same sensor. |
| 52 // A use case example: a request for a sensor X comes, manager checks if the |
| 53 // sensor exists on a platform and notifies a provider it is not found. |
| 54 // The provider stores this information into its cache and doesn't try to |
| 55 // create this specific sensor if a request comes. But when, for example, |
| 56 // the sensor X is plugged into a usb port, the manager notices that and |
| 57 // notifies the provider, which updates its cache and starts handling requests |
| 58 // for the sensor X. |
| 59 // |
| 60 // Right now, this thread is used to find sensors files and poll data. |
| 61 std::unique_ptr<base::Thread> polling_thread_; |
| 62 |
| 63 // A task runner that is passed to polling sensors to poll data. |
| 64 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; |
| 65 |
| 66 // Browser's file thread task runner passed from renderer. Used to |
| 67 // stop a polling thread. |
| 68 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux); |
| 71 }; |
| 72 |
| 73 } // namespace device |
| 74 |
| 75 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ |
OLD | NEW |