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

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

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 #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 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
19 shared_buffer_mapping_(std::move(mapping)),
18 type_(type), 20 type_(type),
19 provider_(provider), 21 provider_(provider),
20 weak_factory_(this) {} 22 weak_factory_(this) {}
21 23
22 PlatformSensor::~PlatformSensor() { 24 PlatformSensor::~PlatformSensor() {
23 provider_->RemoveSensor(GetType()); 25 provider_->RemoveSensor(GetType());
24 } 26 }
25 27
26 mojom::SensorType PlatformSensor::GetType() const { 28 mojom::SensorType PlatformSensor::GetType() const {
27 return type_; 29 return type_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void PlatformSensor::RemoveClient(Client* client) { 75 void PlatformSensor::RemoveClient(Client* client) {
74 DCHECK(client); 76 DCHECK(client);
75 clients_.RemoveObserver(client); 77 clients_.RemoveObserver(client);
76 auto client_entry = config_map_.find(client); 78 auto client_entry = config_map_.find(client);
77 if (client_entry != config_map_.end()) { 79 if (client_entry != config_map_.end()) {
78 config_map_.erase(client_entry); 80 config_map_.erase(client_entry);
79 UpdateSensorInternal(config_map_); 81 UpdateSensorInternal(config_map_);
80 } 82 }
81 } 83 }
82 84
85 void PlatformSensor::UpdateSensorReading(const SensorReading& reading,
86 bool notify_clients) {
87 ReadingBuffer* buffer =
88 static_cast<ReadingBuffer*>(shared_buffer_mapping_.get());
89 auto& seqlock = buffer->seqlock.value();
90 seqlock.WriteBegin();
91 buffer->reading = reading;
92 seqlock.WriteEnd();
93
94 if (notify_clients)
95 task_runner_->PostTask(
96 FROM_HERE, base::Bind(&PlatformSensor::NotifySensorReadingChanged,
97 weak_factory_.GetWeakPtr()));
98 }
99
83 void PlatformSensor::NotifySensorReadingChanged() { 100 void PlatformSensor::NotifySensorReadingChanged() {
84 using ClientsList = decltype(clients_); 101 using ClientsList = decltype(clients_);
85 ClientsList::Iterator it(&clients_); 102 ClientsList::Iterator it(&clients_);
86 Client* client; 103 Client* client;
87 while ((client = it.GetNext()) != nullptr) { 104 while ((client = it.GetNext()) != nullptr) {
88 if (!client->IsNotificationSuspended()) 105 if (!client->IsNotificationSuspended())
89 client->OnSensorReadingChanged(); 106 client->OnSensorReadingChanged();
90 } 107 }
91 } 108 }
92 109
(...skipping 17 matching lines...) Expand all
110 127
111 if (!optimal_configuration) { 128 if (!optimal_configuration) {
112 StopSensor(); 129 StopSensor();
113 return true; 130 return true;
114 } 131 }
115 132
116 return StartSensor(*optimal_configuration); 133 return StartSensor(*optimal_configuration);
117 } 134 }
118 135
119 } // namespace device 136 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor.h ('k') | device/generic_sensor/platform_sensor_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698