| 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 #ifndef BluetoothAttributeInstanceMap_h | 5 #ifndef BluetoothAttributeInstanceMap_h |
| 6 #define BluetoothAttributeInstanceMap_h | 6 #define BluetoothAttributeInstanceMap_h |
| 7 | 7 |
| 8 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" |
| 8 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 9 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 9 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 10 #include "platform/heap/Heap.h" | 11 #include "platform/heap/Heap.h" |
| 11 #include <memory> | 12 #include <memory> |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 class BluetoothDevice; | 16 class BluetoothDevice; |
| 17 class ExecutionContext; |
| 16 class ScriptPromiseResolver; | 18 class ScriptPromiseResolver; |
| 19 |
| 20 struct WebBluetoothRemoteGATTCharacteristicInit; |
| 17 struct WebBluetoothRemoteGATTService; | 21 struct WebBluetoothRemoteGATTService; |
| 18 | 22 |
| 19 // Map that holds all GATT attributes, i.e. BluetoothRemoteGATTService, | 23 // Map that holds all GATT attributes, i.e. BluetoothRemoteGATTService, |
| 20 // BluetoothRemoteGATTCharacteristic, BluetoothRemoteGATTDescriptor, for | 24 // BluetoothRemoteGATTCharacteristic, BluetoothRemoteGATTDescriptor, for |
| 21 // the BluetoothDevice passed in when constructing the object. | 25 // the BluetoothDevice passed in when constructing the object. |
| 22 // Methods in this map are used to create or retrieve these attributes. | 26 // Methods in this map are used to create or retrieve these attributes. |
| 23 class BluetoothAttributeInstanceMap final | 27 class BluetoothAttributeInstanceMap final |
| 24 : public GarbageCollected<BluetoothAttributeInstanceMap> { | 28 : public GarbageCollected<BluetoothAttributeInstanceMap> { |
| 25 public: | 29 public: |
| 26 BluetoothAttributeInstanceMap(BluetoothDevice*); | 30 BluetoothAttributeInstanceMap(BluetoothDevice*); |
| 27 | 31 |
| 28 // Constructs a new BluetoothRemoteGATTService object if there was | 32 // Constructs a new BluetoothRemoteGATTService object if there was |
| 29 // no service with the same instance id and adds it to the map. | 33 // no service with the same instance id and adds it to the map. |
| 30 // Otherwise returns the BluetoothRemoteGATTService object already | 34 // Otherwise returns the BluetoothRemoteGATTService object already |
| 31 // in the map. | 35 // in the map. |
| 32 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( | 36 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( |
| 33 std::unique_ptr<WebBluetoothRemoteGATTService>); | 37 std::unique_ptr<WebBluetoothRemoteGATTService>); |
| 34 | 38 |
| 35 // Returns true if a BluetoothRemoteGATTService with |serviceInstanceId| | 39 // Returns true if a BluetoothRemoteGATTService with |serviceInstanceId| |
| 36 // is in the map. | 40 // is in the map. |
| 37 bool containsService(const String& serviceInstanceId); | 41 bool containsService(const String& serviceInstanceId); |
| 38 | 42 |
| 43 // Constructs a new BluetoothRemoteGATTCharacteristic object if there was no |
| 44 // characteristic with the same instance id and adds it to the map. |
| 45 // Otherwise returns the BluetoothRemoteGATTCharacteristic object already in |
| 46 // the map. |
| 47 BluetoothRemoteGATTCharacteristic* |
| 48 getOrCreateBluetoothRemoteGATTCharacteristic( |
| 49 ExecutionContext*, |
| 50 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, |
| 51 BluetoothRemoteGATTService*); |
| 52 |
| 39 // Removes all Attributes from the map. | 53 // Removes all Attributes from the map. |
| 40 // TODO(crbug.com/654950): Remove characteristics and descriptors when | 54 // TODO(crbug.com/654950): Remove characteristics and descriptors when |
| 41 // implemented. | 55 // implemented. |
| 42 void Clear(); | 56 void Clear(); |
| 43 | 57 |
| 44 DECLARE_VIRTUAL_TRACE(); | 58 DECLARE_VIRTUAL_TRACE(); |
| 45 | 59 |
| 46 private: | 60 private: |
| 47 // BluetoothDevice that owns this map. | 61 // BluetoothDevice that owns this map. |
| 48 Member<BluetoothDevice> m_device; | 62 Member<BluetoothDevice> m_device; |
| 49 // Map of service instance ids to objects. | 63 // Map of service instance ids to objects. |
| 50 HeapHashMap<String, Member<BluetoothRemoteGATTService>> m_serviceIdToObject; | 64 HeapHashMap<String, Member<BluetoothRemoteGATTService>> m_serviceIdToObject; |
| 65 // Map of characteristic instance ids to objects. |
| 66 HeapHashMap<String, Member<BluetoothRemoteGATTCharacteristic>> |
| 67 m_characteristicIdToObject; |
| 51 }; | 68 }; |
| 52 | 69 |
| 53 } // namespace blink | 70 } // namespace blink |
| 54 | 71 |
| 55 #endif // BluetoothAttributeInstanceMap_h | 72 #endif // BluetoothAttributeInstanceMap_h |
| OLD | NEW |