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

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

Issue 2671933002: Migrate WTF::HashMap::add() to ::insert() (Closed)
Patch Set: rebase, add TODOs Created 3 years, 10 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 mojom::blink::WebBluetoothRemoteGATTServicePtr remoteGATTService, 20 mojom::blink::WebBluetoothRemoteGATTServicePtr remoteGATTService,
21 bool isPrimary, 21 bool isPrimary,
22 const String& deviceInstanceId) { 22 const String& deviceInstanceId) {
23 String serviceInstanceId = remoteGATTService->instance_id; 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( 28 service = new BluetoothRemoteGATTService(
29 std::move(remoteGATTService), isPrimary, deviceInstanceId, m_device); 29 std::move(remoteGATTService), isPrimary, deviceInstanceId, m_device);
30 m_serviceIdToObject.add(serviceInstanceId, service); 30 m_serviceIdToObject.insert(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 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr 44 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr
45 remoteGATTCharacteristic, 45 remoteGATTCharacteristic,
46 BluetoothRemoteGATTService* service) { 46 BluetoothRemoteGATTService* service) {
47 String instanceId = remoteGATTCharacteristic->instance_id; 47 String instanceId = remoteGATTCharacteristic->instance_id;
48 BluetoothRemoteGATTCharacteristic* characteristic = 48 BluetoothRemoteGATTCharacteristic* characteristic =
49 m_characteristicIdToObject.get(instanceId); 49 m_characteristicIdToObject.get(instanceId);
50 50
51 if (!characteristic) { 51 if (!characteristic) {
52 characteristic = BluetoothRemoteGATTCharacteristic::create( 52 characteristic = BluetoothRemoteGATTCharacteristic::create(
53 context, std::move(remoteGATTCharacteristic), service, m_device); 53 context, std::move(remoteGATTCharacteristic), service, m_device);
54 m_characteristicIdToObject.add(instanceId, characteristic); 54 m_characteristicIdToObject.insert(instanceId, characteristic);
55 } 55 }
56 56
57 return characteristic; 57 return characteristic;
58 } 58 }
59 59
60 bool BluetoothAttributeInstanceMap::containsCharacteristic( 60 bool BluetoothAttributeInstanceMap::containsCharacteristic(
61 const String& characteristicInstanceId) { 61 const String& characteristicInstanceId) {
62 return m_characteristicIdToObject.contains(characteristicInstanceId); 62 return m_characteristicIdToObject.contains(characteristicInstanceId);
63 } 63 }
64 64
65 BluetoothRemoteGATTDescriptor* 65 BluetoothRemoteGATTDescriptor*
66 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTDescriptor( 66 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTDescriptor(
67 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor, 67 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor,
68 BluetoothRemoteGATTCharacteristic* characteristic) { 68 BluetoothRemoteGATTCharacteristic* characteristic) {
69 String instanceId = descriptor->instance_id; 69 String instanceId = descriptor->instance_id;
70 BluetoothRemoteGATTDescriptor* result = 70 BluetoothRemoteGATTDescriptor* result =
71 m_descriptorIdToObject.get(instanceId); 71 m_descriptorIdToObject.get(instanceId);
72 72
73 if (result) 73 if (result)
74 return result; 74 return result;
75 75
76 result = 76 result =
77 new BluetoothRemoteGATTDescriptor(std::move(descriptor), characteristic); 77 new BluetoothRemoteGATTDescriptor(std::move(descriptor), characteristic);
78 m_descriptorIdToObject.add(instanceId, result); 78 m_descriptorIdToObject.insert(instanceId, result);
79 return result; 79 return result;
80 } 80 }
81 81
82 bool BluetoothAttributeInstanceMap::containsDescriptor( 82 bool BluetoothAttributeInstanceMap::containsDescriptor(
83 const String& descriptorInstanceId) { 83 const String& descriptorInstanceId) {
84 return m_descriptorIdToObject.contains(descriptorInstanceId); 84 return m_descriptorIdToObject.contains(descriptorInstanceId);
85 } 85 }
86 86
87 void BluetoothAttributeInstanceMap::Clear() { 87 void BluetoothAttributeInstanceMap::Clear() {
88 m_serviceIdToObject.clear(); 88 m_serviceIdToObject.clear();
89 m_characteristicIdToObject.clear(); 89 m_characteristicIdToObject.clear();
90 m_descriptorIdToObject.clear(); 90 m_descriptorIdToObject.clear();
91 } 91 }
92 92
93 DEFINE_TRACE(BluetoothAttributeInstanceMap) { 93 DEFINE_TRACE(BluetoothAttributeInstanceMap) {
94 visitor->trace(m_device); 94 visitor->trace(m_device);
95 visitor->trace(m_serviceIdToObject); 95 visitor->trace(m_serviceIdToObject);
96 visitor->trace(m_characteristicIdToObject); 96 visitor->trace(m_characteristicIdToObject);
97 visitor->trace(m_descriptorIdToObject); 97 visitor->trace(m_descriptorIdToObject);
98 } 98 }
99 99
100 } // namespace blink 100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698