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

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

Issue 2929603003: Add RELATIVE_ORIENTATION sensor implementation on macOS to //device/generic_sensor (Closed)
Patch Set: updated IsSignificantlyDifferent() Created 3 years, 6 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_H_ 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 10
(...skipping 23 matching lines...) Expand all
34 virtual void OnSensorReadingChanged() = 0; 34 virtual void OnSensorReadingChanged() = 0;
35 virtual void OnSensorError() = 0; 35 virtual void OnSensorError() = 0;
36 virtual bool IsNotificationSuspended() = 0; 36 virtual bool IsNotificationSuspended() = 0;
37 37
38 protected: 38 protected:
39 virtual ~Client() {} 39 virtual ~Client() {}
40 }; 40 };
41 41
42 virtual mojom::ReportingMode GetReportingMode() = 0; 42 virtual mojom::ReportingMode GetReportingMode() = 0;
43 virtual PlatformSensorConfiguration GetDefaultConfiguration() = 0; 43 virtual PlatformSensorConfiguration GetDefaultConfiguration() = 0;
44 virtual bool StartSensor(
45 const PlatformSensorConfiguration& configuration) = 0;
46 virtual void StopSensor() = 0;
47 virtual bool CheckSensorConfiguration(
48 const PlatformSensorConfiguration& configuration) = 0;
44 49
45 // Can be overriden to return the sensor maximum sampling frequency 50 // Can be overriden to return the sensor maximum sampling frequency
46 // value obtained from the platform if it is available. If platfrom 51 // value obtained from the platform if it is available. If platfrom
47 // does not provide maximum sampling frequency this method must 52 // does not provide maximum sampling frequency this method must
48 // return default frequency. 53 // return default frequency.
49 // The default implementation returns default frequency. 54 // The default implementation returns default frequency.
50 virtual double GetMaximumSupportedFrequency(); 55 virtual double GetMaximumSupportedFrequency();
51 56
52 // Can be overriden to return the sensor minimum sampling frequency. 57 // Can be overriden to return the sensor minimum sampling frequency.
53 // The default implementation returns '1.0 / (60 * 60)', i.e. once per hour. 58 // The default implementation returns '1.0 / (60 * 60)', i.e. once per hour.
54 virtual double GetMinimumSupportedFrequency(); 59 virtual double GetMinimumSupportedFrequency();
55 60
56 mojom::SensorType GetType() const; 61 mojom::SensorType GetType() const;
57 62
58 bool StartListening(Client* client, 63 bool StartListening(Client* client,
59 const PlatformSensorConfiguration& config); 64 const PlatformSensorConfiguration& config);
60 bool StopListening(Client* client, const PlatformSensorConfiguration& config); 65 bool StopListening(Client* client, const PlatformSensorConfiguration& config);
61 66
62 void UpdateSensor(); 67 void UpdateSensor();
63 68
64 void AddClient(Client*); 69 void AddClient(Client*);
65 void RemoveClient(Client*); 70 void RemoveClient(Client*);
66 71
72 bool GetLatestReading(SensorReading* result);
Mikhail 2017/06/21 11:10:00 let's make it virtual, it seems the newly added Pl
juncai 2017/07/20 00:22:16 Not sure why makes it virtual. It should be the sa
73
67 protected: 74 protected:
68 virtual ~PlatformSensor(); 75 virtual ~PlatformSensor();
69 PlatformSensor(mojom::SensorType type, 76 PlatformSensor(mojom::SensorType type,
70 mojo::ScopedSharedBufferMapping mapping, 77 mojo::ScopedSharedBufferMapping mapping,
71 PlatformSensorProvider* provider); 78 PlatformSensorProvider* provider);
72 79
73 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>; 80 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>;
74 using ReadingBuffer = SensorReadingSharedBuffer; 81 using ReadingBuffer = SensorReadingSharedBuffer;
75 82
76 virtual bool UpdateSensorInternal(const ConfigMap& configurations); 83 virtual bool UpdateSensorInternal(const ConfigMap& configurations);
77 virtual bool StartSensor(
78 const PlatformSensorConfiguration& configuration) = 0;
79 virtual void StopSensor() = 0;
80 virtual bool CheckSensorConfiguration(
81 const PlatformSensorConfiguration& configuration) = 0;
82 84
83 // Updates shared buffer with new sensor reading data. 85 // Updates shared buffer with new sensor reading data.
84 // Note: this method is thread-safe. 86 // Note: this method is thread-safe.
85 void UpdateSensorReading(const SensorReading& reading, bool notify_clients); 87 void UpdateSensorReading(const SensorReading& reading, bool notify_clients);
86 88
87 void NotifySensorReadingChanged(); 89 void NotifySensorReadingChanged();
88 void NotifySensorError(); 90 void NotifySensorError();
89 91
90 // For testing purposes. 92 // For testing purposes.
91 const ConfigMap& config_map() const { return config_map_; } 93 const ConfigMap& config_map() const { return config_map_; }
92 94
93 // Task runner that is used by mojo objects for the IPC. 95 // Task runner that is used by mojo objects for the IPC.
94 // If platfrom sensor events are processed on a different 96 // If platfrom sensor events are processed on a different
95 // thread, notifications are forwarded to |task_runner_|. 97 // thread, notifications are forwarded to |task_runner_|.
96 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 98 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
99 base::ObserverList<Client, true> clients_;
97 100
98 private: 101 private:
99 friend class base::RefCountedThreadSafe<PlatformSensor>; 102 friend class base::RefCountedThreadSafe<PlatformSensor>;
100 const mojo::ScopedSharedBufferMapping shared_buffer_mapping_; 103 const mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
101 mojom::SensorType type_; 104 mojom::SensorType type_;
102 base::ObserverList<Client, true> clients_;
103 ConfigMap config_map_; 105 ConfigMap config_map_;
104 PlatformSensorProvider* provider_; 106 PlatformSensorProvider* provider_;
105 base::WeakPtrFactory<PlatformSensor> weak_factory_; 107 base::WeakPtrFactory<PlatformSensor> weak_factory_;
106 DISALLOW_COPY_AND_ASSIGN(PlatformSensor); 108 DISALLOW_COPY_AND_ASSIGN(PlatformSensor);
107 }; 109 };
108 110
109 } // namespace device 111 } // namespace device
110 112
111 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ 113 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698