OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/bluetooth/Bluetooth.h" | 5 #include "modules/bluetooth/Bluetooth.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 wrapPersistent(resolver)))); | 228 wrapPersistent(resolver)))); |
229 return promise; | 229 return promise; |
230 } | 230 } |
231 | 231 |
232 void Bluetooth::AddToConnectedDevicesMap(const String& deviceId, | 232 void Bluetooth::AddToConnectedDevicesMap(const String& deviceId, |
233 BluetoothDevice* device) { | 233 BluetoothDevice* device) { |
234 m_connectedDevices.insert(deviceId, device); | 234 m_connectedDevices.insert(deviceId, device); |
235 } | 235 } |
236 | 236 |
237 void Bluetooth::RemoveFromConnectedDevicesMap(const String& deviceId) { | 237 void Bluetooth::RemoveFromConnectedDevicesMap(const String& deviceId) { |
238 m_connectedDevices.remove(deviceId); | 238 m_connectedDevices.erase(deviceId); |
239 } | 239 } |
240 | 240 |
241 void Bluetooth::RegisterCharacteristicObject( | 241 void Bluetooth::RegisterCharacteristicObject( |
242 const String& characteristicInstanceId, | 242 const String& characteristicInstanceId, |
243 BluetoothRemoteGATTCharacteristic* characteristic) { | 243 BluetoothRemoteGATTCharacteristic* characteristic) { |
244 m_activeCharacteristics.insert(characteristicInstanceId, characteristic); | 244 m_activeCharacteristics.insert(characteristicInstanceId, characteristic); |
245 } | 245 } |
246 | 246 |
247 void Bluetooth::CharacteristicObjectRemoved( | 247 void Bluetooth::CharacteristicObjectRemoved( |
248 const String& characteristicInstanceId) { | 248 const String& characteristicInstanceId) { |
249 m_activeCharacteristics.remove(characteristicInstanceId); | 249 m_activeCharacteristics.erase(characteristicInstanceId); |
250 } | 250 } |
251 | 251 |
252 DEFINE_TRACE(Bluetooth) { | 252 DEFINE_TRACE(Bluetooth) { |
253 visitor->trace(m_deviceInstanceMap); | 253 visitor->trace(m_deviceInstanceMap); |
254 visitor->trace(m_activeCharacteristics); | 254 visitor->trace(m_activeCharacteristics); |
255 visitor->trace(m_connectedDevices); | 255 visitor->trace(m_connectedDevices); |
256 } | 256 } |
257 | 257 |
258 Bluetooth::Bluetooth() : m_clientBinding(this) {} | 258 Bluetooth::Bluetooth() : m_clientBinding(this) {} |
259 | 259 |
260 void Bluetooth::RemoteCharacteristicValueChanged( | 260 void Bluetooth::RemoteCharacteristicValueChanged( |
261 const WTF::String& characteristicInstanceId, | 261 const WTF::String& characteristicInstanceId, |
262 const WTF::Vector<uint8_t>& value) { | 262 const WTF::Vector<uint8_t>& value) { |
263 BluetoothRemoteGATTCharacteristic* characteristic = | 263 BluetoothRemoteGATTCharacteristic* characteristic = |
264 m_activeCharacteristics.at(characteristicInstanceId); | 264 m_activeCharacteristics.at(characteristicInstanceId); |
265 if (characteristic) | 265 if (characteristic) |
266 characteristic->DispatchCharacteristicValueChanged(value); | 266 characteristic->DispatchCharacteristicValueChanged(value); |
267 } | 267 } |
268 | 268 |
269 void Bluetooth::GattServerDisconnected(const WTF::String& deviceId) { | 269 void Bluetooth::GattServerDisconnected(const WTF::String& deviceId) { |
270 BluetoothDevice* device = m_connectedDevices.at(deviceId); | 270 BluetoothDevice* device = m_connectedDevices.at(deviceId); |
271 if (device) { | 271 if (device) { |
272 // Remove device from the map before calling dispatchGattServerDisconnected | 272 // Remove device from the map before calling dispatchGattServerDisconnected |
273 // to avoid removing a device the gattserverdisconnected event handler might | 273 // to avoid removing a device the gattserverdisconnected event handler might |
274 // have re-connected. | 274 // have re-connected. |
275 m_connectedDevices.remove(deviceId); | 275 m_connectedDevices.erase(deviceId); |
276 device->DispatchGattServerDisconnected(); | 276 device->DispatchGattServerDisconnected(); |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 BluetoothDevice* Bluetooth::GetBluetoothDeviceRepresentingDevice( | 280 BluetoothDevice* Bluetooth::GetBluetoothDeviceRepresentingDevice( |
281 mojom::blink::WebBluetoothDevicePtr devicePtr, | 281 mojom::blink::WebBluetoothDevicePtr devicePtr, |
282 ScriptPromiseResolver* resolver) { | 282 ScriptPromiseResolver* resolver) { |
283 WTF::String id = devicePtr->id; | 283 WTF::String id = devicePtr->id; |
284 BluetoothDevice* device = m_deviceInstanceMap.at(id); | 284 BluetoothDevice* device = m_deviceInstanceMap.at(id); |
285 if (!device) { | 285 if (!device) { |
286 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); | 286 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); |
287 auto result = m_deviceInstanceMap.insert(id, device); | 287 auto result = m_deviceInstanceMap.insert(id, device); |
288 DCHECK(result.isNewEntry); | 288 DCHECK(result.isNewEntry); |
289 } | 289 } |
290 return device; | 290 return device; |
291 } | 291 } |
292 | 292 |
293 } // namespace blink | 293 } // namespace blink |
OLD | NEW |