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

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

Issue 2434073002: [sensors] PlatformSensorProvider implementations are notified when there are no sensor instances (Closed)
Patch Set: [sensors] PlatformSensorProvider implementations are notified when there are no sensor instances 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_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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 shared_buffer_handle_ = 72 shared_buffer_handle_ =
73 mojo::SharedBufferHandle::Create(kSharedBufferSizeInBytes); 73 mojo::SharedBufferHandle::Create(kSharedBufferSizeInBytes);
74 return shared_buffer_handle_.is_valid(); 74 return shared_buffer_handle_.is_valid();
75 } 75 }
76 76
77 void PlatformSensorProviderBase::RemoveSensor(mojom::SensorType type) { 77 void PlatformSensorProviderBase::RemoveSensor(mojom::SensorType type) {
78 DCHECK(CalledOnValidThread()); 78 DCHECK(CalledOnValidThread());
79 DCHECK(ContainsKey(sensor_map_, type)); 79 DCHECK(ContainsKey(sensor_map_, type));
80 sensor_map_.erase(type); 80 sensor_map_.erase(type);
81 81
82 if (sensor_map_.empty()) 82 if (sensor_map_.empty()) {
83 AllSensorsRemoved();
83 shared_buffer_handle_.reset(); 84 shared_buffer_handle_.reset();
85 }
84 } 86 }
85 87
86 mojo::ScopedSharedBufferHandle 88 mojo::ScopedSharedBufferHandle
87 PlatformSensorProviderBase::CloneSharedBufferHandle() { 89 PlatformSensorProviderBase::CloneSharedBufferHandle() {
88 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
89 CreateSharedBufferIfNeeded(); 91 CreateSharedBufferIfNeeded();
90 return shared_buffer_handle_->Clone(); 92 return shared_buffer_handle_->Clone();
91 } 93 }
92 94
93 void PlatformSensorProviderBase::NotifySensorCreated( 95 void PlatformSensorProviderBase::NotifySensorCreated(
94 mojom::SensorType type, 96 mojom::SensorType type,
95 scoped_refptr<PlatformSensor> sensor) { 97 scoped_refptr<PlatformSensor> sensor) {
96 DCHECK(CalledOnValidThread()); 98 DCHECK(CalledOnValidThread());
97 DCHECK(!ContainsKey(sensor_map_, type)); 99 DCHECK(!ContainsKey(sensor_map_, type));
98 DCHECK(ContainsKey(requests_map_, type)); 100 DCHECK(ContainsKey(requests_map_, type));
99 101
100 if (sensor) 102 if (sensor)
101 sensor_map_[type] = sensor.get(); 103 sensor_map_[type] = sensor.get();
102 104
103 // Inform subscribers about the sensor. 105 // Inform subscribers about the sensor.
104 // |sensor| can be nullptr here. 106 // |sensor| can be nullptr here.
105 auto it = requests_map_.find(type); 107 auto it = requests_map_.find(type);
106 for (auto& callback : it->second) 108 for (auto& callback : it->second)
107 callback.Run(sensor); 109 callback.Run(sensor);
108 110
109 requests_map_.erase(type); 111 requests_map_.erase(type);
110 } 112 }
111 113
112 } // namespace device 114 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698