Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_provider_iio.h |
| diff --git a/device/generic_sensor/platform_sensor_provider_iio.h b/device/generic_sensor/platform_sensor_provider_iio.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..06fff1972e19ab3e522c5aa57f439e016170e39c |
| --- /dev/null |
| +++ b/device/generic_sensor/platform_sensor_provider_iio.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_IIO_H_ |
| +#define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_IIO_H_ |
| + |
| +#include "device/generic_sensor/platform_sensor_provider.h" |
| + |
| +namespace base { |
| +class Thread; |
| +} |
| + |
| +namespace device { |
| + |
| +struct SensorDataIio; |
| +class SensorReader; |
| + |
| +class PlatformSensorProviderIio : public PlatformSensorProvider { |
|
timvolodine
2016/10/31 18:28:17
shouldn't the platform-specific implementations li
maksims (do not use this acc)
2016/10/31 19:21:48
chromeos and linux share the same code. that is wh
Reilly Grant (use Gerrit)
2016/10/31 19:33:21
When Chrome OS and Linux share code we generally j
maksims (do not use this acc)
2016/11/01 08:10:31
Done.
|
| + public: |
| + PlatformSensorProviderIio(); |
| + ~PlatformSensorProviderIio() override; |
| + |
| + static PlatformSensorProviderIio* GetInstance(); |
| + |
| + protected: |
| + void CreateSensorInternal(mojom::SensorType type, |
| + mojo::ScopedSharedBufferMapping mapping, |
| + const CreateSensorCallback& callback) override; |
| + |
| + void AllSensorsRemoved() override; |
| + |
| + void SetFileTaskRunner( |
| + scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override; |
| + |
| + private: |
| + void SensorReaderFound( |
| + mojom::SensorType type, |
| + mojo::ScopedSharedBufferMapping mapping, |
| + const PlatformSensorProviderBase::CreateSensorCallback& callback, |
| + const SensorDataIio& data, |
| + std::unique_ptr<SensorReader> sensor_reader); |
| + |
| + // Stops a polling thread if there are no sensors left. |
| + 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. |
| + std::unique_ptr<base::Thread> polling_thread_; |
|
timvolodine
2016/10/31 18:28:17
is this a single thread per renderer or browser? m
maksims (do not use this acc)
2016/10/31 19:21:48
It's a single thread per browser.
|
| + |
| + // A task runner that is passed to polling sensors to poll data. |
| + scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; |
| + |
| + // Browser's file thread task runner passed from renderer. Used to |
| + // stop a polling thread. |
| + scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderIio); |
| +}; |
| + |
| +} // namespace device |
| + |
| +#endif /* DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_IIO_H_ */ |
|
timvolodine
2016/10/31 18:28:17
usually
#endif // DEVICE_GENERIC...
maksims (do not use this acc)
2016/11/01 08:14:08
Done.
|