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

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

Issue 2615093002: Typemap WebBluetoothDeviceId to WTF::String (Closed)
Patch Set: typemap WebBluetoothDeviceId to WTF::String 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 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/BluetoothRemoteGATTService.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTService.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
11 #include "core/inspector/ConsoleMessage.h" 11 #include "core/inspector/ConsoleMessage.h"
12 #include "modules/bluetooth/Bluetooth.h" 12 #include "modules/bluetooth/Bluetooth.h"
13 #include "modules/bluetooth/BluetoothError.h" 13 #include "modules/bluetooth/BluetoothError.h"
14 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" 14 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h"
15 #include "modules/bluetooth/BluetoothUUID.h" 15 #include "modules/bluetooth/BluetoothUUID.h"
16 #include "wtf/PtrUtil.h" 16 #include "wtf/PtrUtil.h"
17 #include <memory>
18 #include <utility> 17 #include <utility>
19 18
20 namespace blink { 19 namespace blink {
21 20
22 namespace { 21 namespace {
23 22
24 const char kGATTServerDisconnected[] = 23 const char kGATTServerDisconnected[] =
25 "GATT Server disconnected while retrieving characteristics."; 24 "GATT Server disconnected while retrieving characteristics.";
26 const char kGATTServerNotConnected[] = 25 const char kGATTServerNotConnected[] =
27 "GATT Server is disconnected. Cannot retrieve characteristics."; 26 "GATT Server is disconnected. Cannot retrieve characteristics.";
28 const char kInvalidService[] = 27 const char kInvalidService[] =
29 "Service is no longer valid. Remember to retrieve the service again after " 28 "Service is no longer valid. Remember to retrieve the service again after "
30 "reconnecting."; 29 "reconnecting.";
31 30
32 } // namespace 31 } // namespace
33 32
34 BluetoothRemoteGATTService::BluetoothRemoteGATTService( 33 BluetoothRemoteGATTService::BluetoothRemoteGATTService(
35 const String& serviceInstanceId, 34 mojom::blink::WebBluetoothRemoteGATTServicePtr service,
36 const String& uuid,
37 bool isPrimary, 35 bool isPrimary,
38 const String& deviceInstanceId, 36 const String& deviceInstanceId,
39 BluetoothDevice* device) 37 BluetoothDevice* device)
40 : m_serviceInstanceId(serviceInstanceId), 38 : m_service(std::move(service)),
41 m_uuid(uuid),
42 m_isPrimary(isPrimary), 39 m_isPrimary(isPrimary),
43 m_deviceInstanceId(deviceInstanceId), 40 m_deviceInstanceId(deviceInstanceId),
44 m_device(device) {} 41 m_device(device) {}
45 42
46 DEFINE_TRACE(BluetoothRemoteGATTService) { 43 DEFINE_TRACE(BluetoothRemoteGATTService) {
47 visitor->trace(m_device); 44 visitor->trace(m_device);
48 } 45 }
49 46
50 // Callback that allows us to resolve the promise with a single Characteristic 47 // Callback that allows us to resolve the promise with a single Characteristic
51 // or with a vector owning the characteristics. 48 // or with a vector owning the characteristics.
(...skipping 15 matching lines...) Expand all
67 DOMException::create(NetworkError, kGATTServerDisconnected)); 64 DOMException::create(NetworkError, kGATTServerDisconnected));
68 return; 65 return;
69 } 66 }
70 67
71 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { 68 if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
72 DCHECK(characteristics); 69 DCHECK(characteristics);
73 70
74 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { 71 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) {
75 DCHECK_EQ(1u, characteristics->size()); 72 DCHECK_EQ(1u, characteristics->size());
76 resolver->resolve(device()->getOrCreateRemoteGATTCharacteristic( 73 resolver->resolve(device()->getOrCreateRemoteGATTCharacteristic(
77 resolver->getExecutionContext(), 74 resolver->getExecutionContext(), serviceInstanceId,
78 characteristics.value()[0]->instance_id, serviceInstanceId, 75 std::move(characteristics.value()[0]), this));
79 characteristics.value()[0]->uuid,
80 characteristics.value()[0]->properties, this));
81 return; 76 return;
82 } 77 }
83 78
84 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> gattCharacteristics; 79 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> gattCharacteristics;
85 gattCharacteristics.reserveInitialCapacity(characteristics->size()); 80 gattCharacteristics.reserveInitialCapacity(characteristics->size());
86 for (const auto& characteristic : characteristics.value()) { 81 for (auto& characteristic : characteristics.value()) {
87 gattCharacteristics.append(device()->getOrCreateRemoteGATTCharacteristic( 82 gattCharacteristics.append(device()->getOrCreateRemoteGATTCharacteristic(
88 resolver->getExecutionContext(), characteristic->instance_id, 83 resolver->getExecutionContext(), serviceInstanceId,
89 serviceInstanceId, characteristic->uuid, characteristic->properties, 84 std::move(characteristic), this));
90 this));
91 } 85 }
92 resolver->resolve(gattCharacteristics); 86 resolver->resolve(gattCharacteristics);
93 } else { 87 } else {
94 resolver->reject(BluetoothError::take(resolver, result)); 88 resolver->reject(BluetoothError::take(resolver, result));
95 } 89 }
96 } 90 }
97 91
98 ScriptPromise BluetoothRemoteGATTService::getCharacteristic( 92 ScriptPromise BluetoothRemoteGATTService::getCharacteristic(
99 ScriptState* scriptState, 93 ScriptState* scriptState,
100 const StringOrUnsignedLong& characteristic, 94 const StringOrUnsignedLong& characteristic,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ScriptState* scriptState, 128 ScriptState* scriptState,
135 mojom::blink::WebBluetoothGATTQueryQuantity quantity, 129 mojom::blink::WebBluetoothGATTQueryQuantity quantity,
136 const String& characteristicsUUID) { 130 const String& characteristicsUUID) {
137 // We always check that the device is connected. 131 // We always check that the device is connected.
138 if (!device()->gatt()->connected()) { 132 if (!device()->gatt()->connected()) {
139 return ScriptPromise::rejectWithDOMException( 133 return ScriptPromise::rejectWithDOMException(
140 scriptState, 134 scriptState,
141 DOMException::create(NetworkError, kGATTServerNotConnected)); 135 DOMException::create(NetworkError, kGATTServerNotConnected));
142 } 136 }
143 137
144 if (!device()->isValidService(m_serviceInstanceId)) { 138 if (!device()->isValidService(m_service->instance_id)) {
145 return ScriptPromise::rejectWithDOMException( 139 return ScriptPromise::rejectWithDOMException(
146 scriptState, DOMException::create(InvalidStateError, kInvalidService)); 140 scriptState, DOMException::create(InvalidStateError, kInvalidService));
147 } 141 }
148 142
149 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 143 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
150 ScriptPromise promise = resolver->promise(); 144 ScriptPromise promise = resolver->promise();
151 device()->gatt()->AddToActiveAlgorithms(resolver); 145 device()->gatt()->AddToActiveAlgorithms(resolver);
152 146
153 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); 147 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service();
154 148
155 WTF::Optional<String> uuid = WTF::nullopt; 149 WTF::Optional<String> uuid = WTF::nullopt;
156 if (!characteristicsUUID.isEmpty()) 150 if (!characteristicsUUID.isEmpty())
157 uuid = characteristicsUUID; 151 uuid = characteristicsUUID;
158 service->RemoteServiceGetCharacteristics( 152 service->RemoteServiceGetCharacteristics(
159 m_serviceInstanceId, quantity, uuid, 153 m_service->instance_id, quantity, uuid,
160 convertToBaseCallback( 154 convertToBaseCallback(
161 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, 155 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback,
162 wrapPersistent(this), m_serviceInstanceId, quantity, 156 wrapPersistent(this), m_service->instance_id, quantity,
163 wrapPersistent(resolver)))); 157 wrapPersistent(resolver))));
164 158
165 return promise; 159 return promise;
166 } 160 }
167 161
168 } // namespace blink 162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698