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

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

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Pass task runner to PlatformSensor constructor 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(
15 mojo::ScopedSharedBufferMapping mapping, 16 mojom::SensorType type,
16 PlatformSensorProvider* provider) 17 mojo::ScopedSharedBufferMapping mapping,
17 : shared_buffer_mapping_(std::move(mapping)), 18 PlatformSensorProvider* provider,
19 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
20 : task_runner_(task_runner),
21 shared_buffer_mapping_(std::move(mapping)),
18 type_(type), 22 type_(type),
19 provider_(provider), 23 provider_(provider),
20 weak_factory_(this) {} 24 weak_factory_(this) {}
21 25
22 PlatformSensor::~PlatformSensor() { 26 PlatformSensor::~PlatformSensor() {
23 provider_->RemoveSensor(GetType()); 27 provider_->RemoveSensor(GetType());
24 } 28 }
25 29
26 mojom::SensorType PlatformSensor::GetType() const { 30 mojom::SensorType PlatformSensor::GetType() const {
27 return type_; 31 return type_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void PlatformSensor::RemoveClient(Client* client) { 77 void PlatformSensor::RemoveClient(Client* client) {
74 DCHECK(client); 78 DCHECK(client);
75 clients_.RemoveObserver(client); 79 clients_.RemoveObserver(client);
76 auto client_entry = config_map_.find(client); 80 auto client_entry = config_map_.find(client);
77 if (client_entry != config_map_.end()) { 81 if (client_entry != config_map_.end()) {
78 config_map_.erase(client_entry); 82 config_map_.erase(client_entry);
79 UpdateSensorInternal(config_map_); 83 UpdateSensorInternal(config_map_);
80 } 84 }
81 } 85 }
82 86
87 void PlatformSensor::UpdateSensorReading(const SensorReading& reading,
88 bool notify_clients) {
89 ReadingBuffer* buffer =
90 static_cast<ReadingBuffer*>(shared_buffer_mapping_.get());
91 auto& seqlock = buffer->seqlock.value();
92 seqlock.WriteBegin();
93 buffer->reading = reading;
94 seqlock.WriteEnd();
95
96 if (notify_clients)
97 task_runner_->PostTask(
Ken Rockot(use gerrit already) 2016/10/10 16:02:08 I believe this is incorrect. The PlatformSensor in
Reilly Grant (use Gerrit) 2016/10/10 16:30:41 So far it looks like |task_runner_| is always the
Mikhail 2016/10/10 18:29:19 Right, |task_runner_| is PlatformSensor's native t
98 FROM_HERE, base::Bind(&PlatformSensor::NotifySensorReadingChanged,
99 weak_factory_.GetWeakPtr()));
100 }
101
83 void PlatformSensor::NotifySensorReadingChanged() { 102 void PlatformSensor::NotifySensorReadingChanged() {
84 using ClientsList = decltype(clients_); 103 using ClientsList = decltype(clients_);
85 ClientsList::Iterator it(&clients_); 104 ClientsList::Iterator it(&clients_);
86 Client* client; 105 Client* client;
87 while ((client = it.GetNext()) != nullptr) { 106 while ((client = it.GetNext()) != nullptr) {
88 if (!client->IsNotificationSuspended()) 107 if (!client->IsNotificationSuspended())
89 client->OnSensorReadingChanged(); 108 client->OnSensorReadingChanged();
90 } 109 }
91 } 110 }
92 111
(...skipping 17 matching lines...) Expand all
110 129
111 if (!optimal_configuration) { 130 if (!optimal_configuration) {
112 StopSensor(); 131 StopSensor();
113 return true; 132 return true;
114 } 133 }
115 134
116 return StartSensor(*optimal_configuration); 135 return StartSensor(*optimal_configuration);
117 } 136 }
118 137
119 } // namespace device 138 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698