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

Side by Side Diff: device/generic_sensor/platform_sensor_provider.h

Issue 2144623003: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from Tim and Ken Created 4 years, 4 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 DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_
7
8 #include "base/macros.h"
9
10 #include "base/threading/non_thread_safe.h"
11 #include "device/generic_sensor/platform_sensor.h"
12
13 namespace device {
14
15 // Base class that defines factory methods for PlatformSensor creation.
16 // Its implementations must be accessed via GetInstance() method.
17 class PlatformSensorProvider : public base::NonThreadSafe {
18 public:
19 // Note: returns 'nullptr' if there is no available implementation for
20 // the current platform.
21 static PlatformSensorProvider* GetInstance();
22
23 // Creates new instance of PlatformSensor.
24 scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type,
25 uint64_t size,
26 uint64_t offset);
27
28 // Gets previously created instance of PlatformSensor by sensor type |type|.
29 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type);
30
31 // Shared buffer getters.
32 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle();
33
34 protected:
35 PlatformSensorProvider();
36 virtual ~PlatformSensorProvider();
37
38 // Method that must be implemented by platform specific classes.
39 virtual scoped_refptr<PlatformSensor> CreateSensorInternal(
40 mojom::SensorType type,
41 mojo::ScopedSharedBufferMapping mapping,
42 uint64_t buffer_size) = 0;
43
44 private:
45 friend class PlatformSensor; // To call RemoveSensor();
46
47 bool CreateSharedBufferIfNeeded();
48 void RemoveSensor(mojom::SensorType type);
49
50 private:
51 std::map<mojom::SensorType, PlatformSensor*> sensor_map_;
52 mojo::ScopedSharedBufferHandle shared_buffer_handle_;
53
54 static PlatformSensorProvider* s_instance_;
55 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProvider);
56 };
57
58 } // namespace device
59
60 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698