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

Side by Side Diff: services/device/generic_sensor/platform_sensor_provider_base.h

Issue 2898433002: Revert of Move //device/generic_sensor to be part of the internal implementation of the Device Service. (Closed)
Patch Set: Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
(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 SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
6 #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
7
8 #include "base/macros.h"
9
10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_checker.h"
12 #include "services/device/generic_sensor/platform_sensor.h"
13
14 namespace device {
15
16 // Base class that defines factory methods for PlatformSensor creation.
17 // Its implementations must be accessed via GetInstance() method.
18 class PlatformSensorProviderBase {
19 public:
20 using CreateSensorCallback =
21 base::Callback<void(scoped_refptr<PlatformSensor>)>;
22
23 // Creates new instance of PlatformSensor.
24 void CreateSensor(mojom::SensorType type,
25 const CreateSensorCallback& callback);
26
27 // Gets previously created instance of PlatformSensor by sensor type |type|.
28 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type);
29
30 // Shared buffer getters.
31 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle();
32
33 // Returns 'true' if some of sensor instances produced by this provider are
34 // alive; 'false' otherwise.
35 bool HasSensors() const;
36
37 // Implementations might want to override this in order to be able
38 // to read from sensor files. For example, linux does so.
39 virtual void SetFileTaskRunner(
40 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {}
41
42 protected:
43 PlatformSensorProviderBase();
44 virtual ~PlatformSensorProviderBase();
45
46 // Method that must be implemented by platform specific classes.
47 virtual void CreateSensorInternal(mojom::SensorType type,
48 mojo::ScopedSharedBufferMapping mapping,
49 const CreateSensorCallback& callback) = 0;
50
51 // Implementations might override this method to free resources when there
52 // are no sensors left.
53 virtual void AllSensorsRemoved() {}
54
55 void NotifySensorCreated(mojom::SensorType type,
56 scoped_refptr<PlatformSensor> sensor);
57
58 std::vector<mojom::SensorType> GetPendingRequestTypes();
59
60 mojo::ScopedSharedBufferMapping MapSharedBufferForType(
61 mojom::SensorType type);
62
63 THREAD_CHECKER(thread_checker_);
64
65 private:
66 friend class PlatformSensor; // To call RemoveSensor();
67
68 bool CreateSharedBufferIfNeeded();
69 void RemoveSensor(mojom::SensorType type);
70
71 private:
72 using CallbackQueue = std::vector<CreateSensorCallback>;
73
74 std::map<mojom::SensorType, PlatformSensor*> sensor_map_;
75 std::map<mojom::SensorType, CallbackQueue> requests_map_;
76 mojo::ScopedSharedBufferHandle shared_buffer_handle_;
77
78 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase);
79 };
80
81 } // namespace device
82
83 #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698