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

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

Issue 2533793002: [sensors](CrOS/Linux) Implement Sensor device manager for sensors (Closed)
Patch Set: comments Created 4 years 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_provider_base.h" 5 #include "device/generic_sensor/platform_sensor_provider_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" 10 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h"
(...skipping 14 matching lines...) Expand all
25 void PlatformSensorProviderBase::CreateSensor( 25 void PlatformSensorProviderBase::CreateSensor(
26 mojom::SensorType type, 26 mojom::SensorType type,
27 const CreateSensorCallback& callback) { 27 const CreateSensorCallback& callback) {
28 DCHECK(CalledOnValidThread()); 28 DCHECK(CalledOnValidThread());
29 29
30 if (!CreateSharedBufferIfNeeded()) { 30 if (!CreateSharedBufferIfNeeded()) {
31 callback.Run(nullptr); 31 callback.Run(nullptr);
32 return; 32 return;
33 } 33 }
34 34
35 mojo::ScopedSharedBufferMapping mapping = shared_buffer_handle_->MapAtOffset( 35 mojo::ScopedSharedBufferMapping mapping = GetScopedSharedBufferMapping(type);
36 kReadingBufferSize, SensorReadingSharedBuffer::GetOffset(type));
37 if (!mapping) { 36 if (!mapping) {
38 callback.Run(nullptr); 37 callback.Run(nullptr);
39 return; 38 return;
40 } 39 }
41 40
42 auto it = requests_map_.find(type); 41 auto it = requests_map_.find(type);
43 if (it != requests_map_.end()) { 42 if (it != requests_map_.end()) {
44 it->second.push_back(callback); 43 it->second.push_back(callback);
45 } else { // This is the first CreateSensor call. 44 } else { // This is the first CreateSensor call.
46 memset(mapping.get(), 0, kReadingBufferSize); 45 memset(mapping.get(), 0, kReadingBufferSize);
(...skipping 24 matching lines...) Expand all
71 70
72 shared_buffer_handle_ = 71 shared_buffer_handle_ =
73 mojo::SharedBufferHandle::Create(kSharedBufferSizeInBytes); 72 mojo::SharedBufferHandle::Create(kSharedBufferSizeInBytes);
74 return shared_buffer_handle_.is_valid(); 73 return shared_buffer_handle_.is_valid();
75 } 74 }
76 75
77 void PlatformSensorProviderBase::RemoveSensor(mojom::SensorType type) { 76 void PlatformSensorProviderBase::RemoveSensor(mojom::SensorType type) {
78 DCHECK(CalledOnValidThread()); 77 DCHECK(CalledOnValidThread());
79 DCHECK(ContainsKey(sensor_map_, type)); 78 DCHECK(ContainsKey(sensor_map_, type));
80 sensor_map_.erase(type); 79 sensor_map_.erase(type);
80 SensorRemoved(type);
81 81
82 if (sensor_map_.empty()) { 82 if (sensor_map_.empty()) {
83 AllSensorsRemoved(); 83 AllSensorsRemoved();
84 shared_buffer_handle_.reset(); 84 shared_buffer_handle_.reset();
85 } 85 }
86 } 86 }
87 87
88 mojo::ScopedSharedBufferHandle 88 mojo::ScopedSharedBufferHandle
89 PlatformSensorProviderBase::CloneSharedBufferHandle() { 89 PlatformSensorProviderBase::CloneSharedBufferHandle() {
90 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
(...skipping 19 matching lines...) Expand all
110 110
111 // Inform subscribers about the sensor. 111 // Inform subscribers about the sensor.
112 // |sensor| can be nullptr here. 112 // |sensor| can be nullptr here.
113 auto it = requests_map_.find(type); 113 auto it = requests_map_.find(type);
114 for (auto& callback : it->second) 114 for (auto& callback : it->second)
115 callback.Run(sensor); 115 callback.Run(sensor);
116 116
117 requests_map_.erase(type); 117 requests_map_.erase(type);
118 } 118 }
119 119
120 std::vector<mojom::SensorType>
121 PlatformSensorProviderBase::GetPendingRequestTypes() {
122 std::vector<mojom::SensorType> request_types;
123 for (auto const& entry : requests_map_)
124 request_types.push_back(entry.first);
125 return request_types;
126 }
127
128 mojo::ScopedSharedBufferMapping
129 PlatformSensorProviderBase::GetScopedSharedBufferMapping(
Mikhail 2016/12/09 08:15:56 pls rename it to 'MapSharedBufferForType()'
maksims (do not use this acc) 2016/12/09 10:22:42 Done.
130 mojom::SensorType type) {
131 mojo::ScopedSharedBufferMapping mapping = shared_buffer_handle_->MapAtOffset(
132 kReadingBufferSize, SensorReadingSharedBuffer::GetOffset(type));
Mikhail 2016/12/09 08:15:56 memset(mapping.get(), 0, kReadingBufferSize);
maksims (do not use this acc) 2016/12/09 10:22:42 Done.
133 return mapping;
134 }
135
120 } // namespace device 136 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698