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

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

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Test compilation fix + comment from Ken Created 4 years, 2 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 9
10 #include "base/threading/non_thread_safe.h" 10 #include "base/threading/non_thread_safe.h"
11 #include "device/generic_sensor/platform_sensor.h" 11 #include "device/generic_sensor/platform_sensor.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 // Base class that defines factory methods for PlatformSensor creation. 15 // Base class that defines factory methods for PlatformSensor creation.
16 // Its implementations must be accessed via GetInstance() method. 16 // Its implementations must be accessed via GetInstance() method.
17 class PlatformSensorProviderBase : public base::NonThreadSafe { 17 class PlatformSensorProviderBase : public base::NonThreadSafe {
18 public: 18 public:
19 using CreateSensorCallback = 19 using CreateSensorCallback =
20 base::Callback<void(scoped_refptr<PlatformSensor>)>; 20 base::Callback<void(scoped_refptr<PlatformSensor>)>;
21 21
22 // Creates new instance of PlatformSensor. 22 // Creates new instance of PlatformSensor.
23 void CreateSensor(mojom::SensorType type, 23 void CreateSensor(mojom::SensorType type,
24 uint64_t size,
25 uint64_t offset,
26 const CreateSensorCallback& callback); 24 const CreateSensorCallback& callback);
27 25
28 // Gets previously created instance of PlatformSensor by sensor type |type|. 26 // Gets previously created instance of PlatformSensor by sensor type |type|.
29 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type); 27 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type);
30 28
31 // Shared buffer getters. 29 // Shared buffer getters.
32 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle(); 30 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle();
33 31
34 protected: 32 protected:
35 PlatformSensorProviderBase(); 33 PlatformSensorProviderBase();
36 virtual ~PlatformSensorProviderBase(); 34 virtual ~PlatformSensorProviderBase();
37 35
38 // Method that must be implemented by platform specific classes. 36 // Method that must be implemented by platform specific classes.
39 virtual void CreateSensorInternal(mojom::SensorType type, 37 virtual void CreateSensorInternal(mojom::SensorType type,
40 mojo::ScopedSharedBufferMapping mapping, 38 mojo::ScopedSharedBufferMapping mapping,
41 uint64_t buffer_size,
42 const CreateSensorCallback& callback) = 0; 39 const CreateSensorCallback& callback) = 0;
43 40
44 private: 41 private:
45 friend class PlatformSensor; // To call RemoveSensor(); 42 friend class PlatformSensor; // To call RemoveSensor();
46 43
47 bool CreateSharedBufferIfNeeded(); 44 bool CreateSharedBufferIfNeeded();
48 void RemoveSensor(mojom::SensorType type); 45 void RemoveSensor(mojom::SensorType type);
49 void NotifySensorCreated(mojom::SensorType type, 46 void NotifySensorCreated(mojom::SensorType type,
50 scoped_refptr<PlatformSensor> sensor); 47 scoped_refptr<PlatformSensor> sensor);
51 48
52 private: 49 private:
53 using CallbackQueue = std::vector<CreateSensorCallback>; 50 using CallbackQueue = std::vector<CreateSensorCallback>;
54 51
55 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; 52 std::map<mojom::SensorType, PlatformSensor*> sensor_map_;
56 std::map<mojom::SensorType, CallbackQueue> requests_map_; 53 std::map<mojom::SensorType, CallbackQueue> requests_map_;
57 mojo::ScopedSharedBufferHandle shared_buffer_handle_; 54 mojo::ScopedSharedBufferHandle shared_buffer_handle_;
58 55
59 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); 56 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase);
60 }; 57 };
61 58
62 } // namespace device 59 } // namespace device
63 60
64 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ 61 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor_provider_android.cc ('k') | device/generic_sensor/platform_sensor_provider_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698