Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "modules/bluetooth/BluetoothAttributeInstanceMap.h" | 5 #include "modules/bluetooth/BluetoothAttributeInstanceMap.h" |
| 6 | 6 |
| 7 #include "modules/bluetooth/BluetoothDevice.h" | 7 #include "modules/bluetooth/BluetoothDevice.h" |
| 8 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 8 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 9 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic Init.h" | 9 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic Init.h" |
| 10 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTDescriptorInit .h" | |
| 11 | |
| 10 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" | 12 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" |
| 11 #include <memory> | 13 #include <memory> |
| 12 #include <utility> | 14 #include <utility> |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( | 18 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( |
| 17 BluetoothDevice* device) | 19 BluetoothDevice* device) |
| 18 : m_device(device) {} | 20 : m_device(device) {} |
| 19 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 58 } |
| 57 | 59 |
| 58 return characteristic; | 60 return characteristic; |
| 59 } | 61 } |
| 60 | 62 |
| 61 bool BluetoothAttributeInstanceMap::containsCharacteristic( | 63 bool BluetoothAttributeInstanceMap::containsCharacteristic( |
| 62 const String& characteristicInstanceId) { | 64 const String& characteristicInstanceId) { |
| 63 return m_characteristicIdToObject.contains(characteristicInstanceId); | 65 return m_characteristicIdToObject.contains(characteristicInstanceId); |
| 64 } | 66 } |
| 65 | 67 |
| 68 BluetoothRemoteGATTDescriptor* | |
| 69 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTDescriptor( | |
| 70 std::unique_ptr<WebBluetoothRemoteGATTDescriptorInit> webDescriptor, | |
| 71 BluetoothRemoteGATTCharacteristic* characteristic) { | |
| 72 String descriptorInstanceId = webDescriptor->descriptorInstanceID; | |
| 73 | |
| 74 BluetoothRemoteGATTDescriptor* descriptor = | |
| 75 m_descriptorIdToObject.get(descriptorInstanceId); | |
| 76 | |
| 77 if (descriptor) | |
| 78 return descriptor; | |
| 79 | |
| 80 if (!webDescriptor) | |
|
ortuno
2016/12/08 05:42:52
Just DCHECK. I don't think this will ever be calle
dougt
2016/12/08 08:35:59
Done.
| |
| 81 return nullptr; | |
| 82 | |
| 83 descriptor = new BluetoothRemoteGATTDescriptor(std::move(webDescriptor), | |
| 84 characteristic); | |
| 85 m_descriptorIdToObject.add(descriptorInstanceId, descriptor); | |
| 86 | |
| 87 return descriptor; | |
| 88 } | |
| 89 | |
| 90 bool BluetoothAttributeInstanceMap::containsDescriptor( | |
| 91 const String& descriptorInstanceId) { | |
| 92 return m_descriptorIdToObject.contains(descriptorInstanceId); | |
| 93 } | |
| 94 | |
| 66 void BluetoothAttributeInstanceMap::Clear() { | 95 void BluetoothAttributeInstanceMap::Clear() { |
| 67 m_serviceIdToObject.clear(); | 96 m_serviceIdToObject.clear(); |
| 68 m_characteristicIdToObject.clear(); | 97 m_characteristicIdToObject.clear(); |
| 98 m_descriptorIdToObject.clear(); | |
| 69 } | 99 } |
| 70 | 100 |
| 71 DEFINE_TRACE(BluetoothAttributeInstanceMap) { | 101 DEFINE_TRACE(BluetoothAttributeInstanceMap) { |
| 72 visitor->trace(m_device); | 102 visitor->trace(m_device); |
| 73 visitor->trace(m_serviceIdToObject); | 103 visitor->trace(m_serviceIdToObject); |
| 74 visitor->trace(m_characteristicIdToObject); | 104 visitor->trace(m_characteristicIdToObject); |
| 105 visitor->trace(m_descriptorIdToObject); | |
| 75 } | 106 } |
| 76 | 107 |
| 77 } // namespace blink | 108 } // namespace blink |
| OLD | NEW |