OLD | NEW |
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 #include "device/generic_sensor/platform_sensor.h" | 5 #include "device/generic_sensor/platform_sensor.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" |
9 #include "device/generic_sensor/platform_sensor_provider.h" | 10 #include "device/generic_sensor/platform_sensor_provider.h" |
10 #include "device/generic_sensor/public/cpp/platform_sensor_configuration.h" | 11 #include "device/generic_sensor/public/cpp/platform_sensor_configuration.h" |
11 | 12 |
12 namespace device { | 13 namespace device { |
13 | 14 |
14 PlatformSensor::PlatformSensor(mojom::SensorType type, | 15 PlatformSensor::PlatformSensor(mojom::SensorType type, |
15 mojo::ScopedSharedBufferMapping mapping, | 16 mojo::ScopedSharedBufferMapping mapping, |
16 PlatformSensorProvider* provider) | 17 PlatformSensorProvider* provider) |
17 : shared_buffer_mapping_(std::move(mapping)), | 18 : shared_buffer_mapping_(std::move(mapping)), |
18 type_(type), | 19 type_(type), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 void PlatformSensor::RemoveClient(Client* client) { | 74 void PlatformSensor::RemoveClient(Client* client) { |
74 DCHECK(client); | 75 DCHECK(client); |
75 clients_.RemoveObserver(client); | 76 clients_.RemoveObserver(client); |
76 auto client_entry = config_map_.find(client); | 77 auto client_entry = config_map_.find(client); |
77 if (client_entry != config_map_.end()) { | 78 if (client_entry != config_map_.end()) { |
78 config_map_.erase(client_entry); | 79 config_map_.erase(client_entry); |
79 UpdateSensorInternal(config_map_); | 80 UpdateSensorInternal(config_map_); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
| 84 void PlatformSensor::UpdateSensorReading(const mojom::SensorReading& reading) { |
| 85 ReadingBuffer* buffer = |
| 86 static_cast<ReadingBuffer*>(shared_buffer_mapping_.get()); |
| 87 buffer->seqlock.WriteBegin(); |
| 88 buffer->data = reading; |
| 89 buffer->seqlock.WriteEnd(); |
| 90 } |
| 91 |
83 void PlatformSensor::NotifySensorReadingChanged() { | 92 void PlatformSensor::NotifySensorReadingChanged() { |
84 using ClientsList = decltype(clients_); | 93 using ClientsList = decltype(clients_); |
85 ClientsList::Iterator it(&clients_); | 94 ClientsList::Iterator it(&clients_); |
86 Client* client; | 95 Client* client; |
87 while ((client = it.GetNext()) != nullptr) { | 96 while ((client = it.GetNext()) != nullptr) { |
88 if (!client->IsNotificationSuspended()) | 97 if (!client->IsNotificationSuspended()) |
89 client->OnSensorReadingChanged(); | 98 client->OnSensorReadingChanged(); |
90 } | 99 } |
91 } | 100 } |
92 | 101 |
(...skipping 17 matching lines...) Expand all Loading... |
110 | 119 |
111 if (!optimal_configuration) { | 120 if (!optimal_configuration) { |
112 StopSensor(); | 121 StopSensor(); |
113 return true; | 122 return true; |
114 } | 123 } |
115 | 124 |
116 return StartSensor(*optimal_configuration); | 125 return StartSensor(*optimal_configuration); |
117 } | 126 } |
118 | 127 |
119 } // namespace device | 128 } // namespace device |
OLD | NEW |