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

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

Issue 2434073002: [sensors] PlatformSensorProvider implementations are notified when there are no sensor instances (Closed)
Patch Set: rebased 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 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"
(...skipping 13 matching lines...) Expand all
24 // Creates new instance of PlatformSensor. 24 // Creates new instance of PlatformSensor.
25 void CreateSensor(mojom::SensorType type, 25 void CreateSensor(mojom::SensorType type,
26 const CreateSensorCallback& callback); 26 const CreateSensorCallback& callback);
27 27
28 // Gets previously created instance of PlatformSensor by sensor type |type|. 28 // Gets previously created instance of PlatformSensor by sensor type |type|.
29 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type); 29 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type);
30 30
31 // Shared buffer getters. 31 // Shared buffer getters.
32 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle(); 32 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle();
33 33
34 // Returns 'true' if some of sensor instances produced by this provider are
35 // alive; 'false' otherwise.
36 bool HasSensors() const;
37
34 protected: 38 protected:
35 PlatformSensorProviderBase(); 39 PlatformSensorProviderBase();
36 virtual ~PlatformSensorProviderBase(); 40 virtual ~PlatformSensorProviderBase();
37 41
38 // Method that must be implemented by platform specific classes. 42 // Method that must be implemented by platform specific classes.
39 virtual void CreateSensorInternal(mojom::SensorType type, 43 virtual void CreateSensorInternal(mojom::SensorType type,
40 mojo::ScopedSharedBufferMapping mapping, 44 mojo::ScopedSharedBufferMapping mapping,
41 const CreateSensorCallback& callback) = 0; 45 const CreateSensorCallback& callback) = 0;
42 46
47 // Implementations might override this method to free resources when there
48 // are no sensors left.
49 virtual void AllSensorsRemoved() {}
50
43 private: 51 private:
44 friend class PlatformSensor; // To call RemoveSensor(); 52 friend class PlatformSensor; // To call RemoveSensor();
45 53
46 bool CreateSharedBufferIfNeeded(); 54 bool CreateSharedBufferIfNeeded();
47 void RemoveSensor(mojom::SensorType type); 55 void RemoveSensor(mojom::SensorType type);
48 void NotifySensorCreated(mojom::SensorType type, 56 void NotifySensorCreated(mojom::SensorType type,
49 scoped_refptr<PlatformSensor> sensor); 57 scoped_refptr<PlatformSensor> sensor);
50 58
51 private: 59 private:
52 using CallbackQueue = std::vector<CreateSensorCallback>; 60 using CallbackQueue = std::vector<CreateSensorCallback>;
53 61
54 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; 62 std::map<mojom::SensorType, PlatformSensor*> sensor_map_;
55 std::map<mojom::SensorType, CallbackQueue> requests_map_; 63 std::map<mojom::SensorType, CallbackQueue> requests_map_;
56 mojo::ScopedSharedBufferHandle shared_buffer_handle_; 64 mojo::ScopedSharedBufferHandle shared_buffer_handle_;
57 65
58 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); 66 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase);
59 }; 67 };
60 68
61 } // namespace device 69 } // namespace device
62 70
63 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ 71 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/fake_platform_sensor_provider.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