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_IIO_H_ | |
6 #define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_IIO_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 SensorDataIio; | |
17 class SensorReader; | |
18 | |
19 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.
| |
20 public: | |
21 PlatformSensorProviderIio(); | |
22 ~PlatformSensorProviderIio() override; | |
23 | |
24 static PlatformSensorProviderIio* 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 SensorDataIio& data, | |
42 std::unique_ptr<SensorReader> sensor_reader); | |
43 | |
44 // Stops a polling thread if there are no sensors left. | |
45 void StopPollingThread(); | |
46 | |
47 // TODO(maksims): make a separate class Manager that will | |
48 // create provide sensors with a polling task runner, check sensors existence | |
49 // and notify provider if a new sensor has appeared and it can be created if a | |
50 // request comes again for the same sensor. | |
51 // A use case example: a request for a sensor X comes, manager checks if the | |
52 // sensor exists on a platform and notifies a provider it is not found. | |
53 // The provider stores this information into its cache and doesn't try to | |
54 // create this specific sensor if a request comes. But when, for example, | |
55 // the sensor X is plugged into a usb port, the manager notices that and | |
56 // notifies the provider, which updates its cache and starts handling requests | |
57 // for the sensor X. | |
58 // | |
59 // Right now, this thread is used to find sensors files and poll data. | |
60 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.
| |
61 | |
62 // A task runner that is passed to polling sensors to poll data. | |
63 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; | |
64 | |
65 // Browser's file thread task runner passed from renderer. Used to | |
66 // stop a polling thread. | |
67 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderIio); | |
70 }; | |
71 | |
72 } // namespace device | |
73 | |
74 #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.
| |
OLD | NEW |