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

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

Issue 2417533002: [Sensors] Read-only access to the sensors shared buffer from Blink (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 sensor_map_.erase(type); 80 sensor_map_.erase(type);
81 81
82 if (sensor_map_.empty()) 82 if (sensor_map_.empty())
83 shared_buffer_handle_.reset(); 83 shared_buffer_handle_.reset();
84 } 84 }
85 85
86 mojo::ScopedSharedBufferHandle 86 mojo::ScopedSharedBufferHandle
87 PlatformSensorProviderBase::CloneSharedBufferHandle() { 87 PlatformSensorProviderBase::CloneSharedBufferHandle() {
88 DCHECK(CalledOnValidThread()); 88 DCHECK(CalledOnValidThread());
89 CreateSharedBufferIfNeeded(); 89 CreateSharedBufferIfNeeded();
90 return shared_buffer_handle_->Clone(); 90 return shared_buffer_handle_->Clone(
91 mojo::SharedBufferHandle::AccessMode::READ_ONLY);
91 } 92 }
92 93
93 void PlatformSensorProviderBase::NotifySensorCreated( 94 void PlatformSensorProviderBase::NotifySensorCreated(
94 mojom::SensorType type, 95 mojom::SensorType type,
95 scoped_refptr<PlatformSensor> sensor) { 96 scoped_refptr<PlatformSensor> sensor) {
96 DCHECK(CalledOnValidThread()); 97 DCHECK(CalledOnValidThread());
97 DCHECK(!ContainsKey(sensor_map_, type)); 98 DCHECK(!ContainsKey(sensor_map_, type));
98 DCHECK(ContainsKey(requests_map_, type)); 99 DCHECK(ContainsKey(requests_map_, type));
99 100
100 if (sensor) 101 if (sensor)
101 sensor_map_[type] = sensor.get(); 102 sensor_map_[type] = sensor.get();
102 103
103 // Inform subscribers about the sensor. 104 // Inform subscribers about the sensor.
104 // |sensor| can be nullptr here. 105 // |sensor| can be nullptr here.
105 auto it = requests_map_.find(type); 106 auto it = requests_map_.find(type);
106 for (auto& callback : it->second) 107 for (auto& callback : it->second)
107 callback.Run(sensor); 108 callback.Run(sensor);
108 109
109 requests_map_.erase(type); 110 requests_map_.erase(type);
110 } 111 }
111 112
112 } // namespace device 113 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698