Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2198)

Unified Diff: device/generic_sensor/platform_sensor_provider_linux.h

Issue 2480773002: Reland of [sensors] Ambient light sensor implementation for ChromeOS and Linux. (Closed)
Patch Set: remove parenthesis Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..7470cbeb82edcae0c03c4dde49c497cb2c2f8947
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_provider_linux.h
@@ -0,0 +1,75 @@
+// 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_LINUX_H_
+#define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
+
+#include "device/generic_sensor/platform_sensor_provider.h"
+
+namespace base {
+class Thread;
+}
+
+namespace device {
+
+struct SensorDataLinux;
+class SensorReader;
+
+class PlatformSensorProviderLinux : public PlatformSensorProvider {
+ public:
+ PlatformSensorProviderLinux();
+ ~PlatformSensorProviderLinux() override;
+
+ static PlatformSensorProviderLinux* 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 SensorDataLinux& data,
+ std::unique_ptr<SensorReader> sensor_reader);
+
+ // Stops a polling thread if there are no sensors left. Must be called on
+ // a different that polling thread that allows io.
+ 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_;
+
+ // 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(PlatformSensorProviderLinux);
+};
+
+} // namespace device
+
+#endif // DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
« no previous file with comments | « device/generic_sensor/platform_sensor_provider_base.h ('k') | device/generic_sensor/platform_sensor_provider_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698