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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothAttributeInstanceMap.cpp

Issue 2615093002: Typemap WebBluetoothDeviceId to WTF::String (Closed)
Patch Set: merge master Created 3 years, 11 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 "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 <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 namespace blink { 12 namespace blink {
13 13
14 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( 14 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap(
15 BluetoothDevice* device) 15 BluetoothDevice* device)
16 : m_device(device) {} 16 : m_device(device) {}
17 17
18 BluetoothRemoteGATTService* 18 BluetoothRemoteGATTService*
19 BluetoothAttributeInstanceMap::getOrCreateRemoteGATTService( 19 BluetoothAttributeInstanceMap::getOrCreateRemoteGATTService(
20 const String& serviceInstanceId, 20 mojom::blink::WebBluetoothRemoteGATTServicePtr remoteGATTService,
21 const String& uuid,
22 bool isPrimary, 21 bool isPrimary,
23 const String& deviceInstanceId) { 22 const String& deviceInstanceId) {
23 String serviceInstanceId = remoteGATTService->instance_id;
24 BluetoothRemoteGATTService* service = 24 BluetoothRemoteGATTService* service =
25 m_serviceIdToObject.get(serviceInstanceId); 25 m_serviceIdToObject.get(serviceInstanceId);
26 26
27 if (!service) { 27 if (!service) {
28 service = new BluetoothRemoteGATTService(serviceInstanceId, uuid, isPrimary, 28 service = new BluetoothRemoteGATTService(
29 deviceInstanceId, m_device); 29 std::move(remoteGATTService), isPrimary, deviceInstanceId, m_device);
30 m_serviceIdToObject.add(serviceInstanceId, service); 30 m_serviceIdToObject.add(serviceInstanceId, service);
31 } 31 }
32 32
33 return service; 33 return service;
34 } 34 }
35 35
36 bool BluetoothAttributeInstanceMap::containsService( 36 bool BluetoothAttributeInstanceMap::containsService(
37 const String& serviceInstanceId) { 37 const String& serviceInstanceId) {
38 return m_serviceIdToObject.contains(serviceInstanceId); 38 return m_serviceIdToObject.contains(serviceInstanceId);
39 } 39 }
40 40
41 BluetoothRemoteGATTCharacteristic* 41 BluetoothRemoteGATTCharacteristic*
42 BluetoothAttributeInstanceMap::getOrCreateRemoteGATTCharacteristic( 42 BluetoothAttributeInstanceMap::getOrCreateRemoteGATTCharacteristic(
43 ExecutionContext* context, 43 ExecutionContext* context,
44 const String& characteristicInstanceId,
45 const String& serviceInstanceId, 44 const String& serviceInstanceId,
46 const String& uuid, 45 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr
47 uint32_t characteristicProperties, 46 remoteGATTCharacteristic,
48 BluetoothRemoteGATTService* service) { 47 BluetoothRemoteGATTService* service) {
48 String instanceId = remoteGATTCharacteristic->instance_id;
49 BluetoothRemoteGATTCharacteristic* characteristic = 49 BluetoothRemoteGATTCharacteristic* characteristic =
50 m_characteristicIdToObject.get(characteristicInstanceId); 50 m_characteristicIdToObject.get(instanceId);
51 51
52 if (!characteristic) { 52 if (!characteristic) {
53 characteristic = BluetoothRemoteGATTCharacteristic::create( 53 characteristic = BluetoothRemoteGATTCharacteristic::create(
54 context, characteristicInstanceId, serviceInstanceId, uuid, 54 context, serviceInstanceId, std::move(remoteGATTCharacteristic),
55 characteristicProperties, service, m_device); 55 service, m_device);
56 m_characteristicIdToObject.add(characteristicInstanceId, characteristic); 56 m_characteristicIdToObject.add(instanceId, characteristic);
57 } 57 }
58 58
59 return characteristic; 59 return characteristic;
60 } 60 }
61 61
62 bool BluetoothAttributeInstanceMap::containsCharacteristic( 62 bool BluetoothAttributeInstanceMap::containsCharacteristic(
63 const String& characteristicInstanceId) { 63 const String& characteristicInstanceId) {
64 return m_characteristicIdToObject.contains(characteristicInstanceId); 64 return m_characteristicIdToObject.contains(characteristicInstanceId);
65 } 65 }
66 66
67 void BluetoothAttributeInstanceMap::Clear() { 67 void BluetoothAttributeInstanceMap::Clear() {
68 m_serviceIdToObject.clear(); 68 m_serviceIdToObject.clear();
69 m_characteristicIdToObject.clear(); 69 m_characteristicIdToObject.clear();
70 } 70 }
71 71
72 DEFINE_TRACE(BluetoothAttributeInstanceMap) { 72 DEFINE_TRACE(BluetoothAttributeInstanceMap) {
73 visitor->trace(m_device); 73 visitor->trace(m_device);
74 visitor->trace(m_serviceIdToObject); 74 visitor->trace(m_serviceIdToObject);
75 visitor->trace(m_characteristicIdToObject); 75 visitor->trace(m_characteristicIdToObject);
76 } 76 }
77 77
78 } // namespace blink 78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698