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

Side by Side Diff: content/renderer/bluetooth/web_bluetooth_impl.cc

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: Removing BDH_INVALID_DESCRIPTOR_ID Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/bluetooth/web_bluetooth_impl.h" 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/optional.h" 12 #include "base/optional.h"
13 #include "content/child/mojo/type_converters.h" 13 #include "content/child/mojo/type_converters.h"
14 #include "content/child/thread_safe_sender.h" 14 #include "content/child/thread_safe_sender.h"
15 #include "content/common/bluetooth/web_bluetooth_device_id.h" 15 #include "content/common/bluetooth/web_bluetooth_device_id.h"
16 #include "content/renderer/bluetooth/bluetooth_type_converters.h" 16 #include "content/renderer/bluetooth/bluetooth_type_converters.h"
17 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
18 #include "mojo/public/cpp/bindings/array.h" 18 #include "mojo/public/cpp/bindings/array.h"
19 #include "services/service_manager/public/cpp/interface_provider.h" 19 #include "services/service_manager/public/cpp/interface_provider.h"
20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic eInit.h" 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic eInit.h"
22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h"
23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h" 23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h"
24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTDescriptorInit.h"
24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h" 25 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h"
25 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h" 26 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
26 27
27 namespace content { 28 namespace content {
28 29
29 namespace { 30 namespace {
30 31
31 // Blink can't use non-blink mojo enums like blink::mojom::WebBluetoothResult, 32 // Blink can't use non-blink mojo enums like blink::mojom::WebBluetoothResult,
32 // so we pass it as an int32 across the boundary. 33 // so we pass it as an int32 across the boundary.
33 int32_t ToInt32(blink::mojom::WebBluetoothResult result) { 34 int32_t ToInt32(blink::mojom::WebBluetoothResult result) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity), 106 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity),
106 characteristics_uuid.isEmpty() 107 characteristics_uuid.isEmpty()
107 ? base::nullopt 108 ? base::nullopt
108 : base::make_optional( 109 : base::make_optional(
109 device::BluetoothUUID(characteristics_uuid.utf8())), 110 device::BluetoothUUID(characteristics_uuid.utf8())),
110 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete, 111 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete,
111 base::Unretained(this), service_instance_id, 112 base::Unretained(this), service_instance_id,
112 base::Passed(base::WrapUnique(callbacks)))); 113 base::Passed(base::WrapUnique(callbacks))));
113 } 114 }
114 115
115 void WebBluetoothImpl::readValue( 116 void WebBluetoothImpl::characteristicReadValue(
116 const blink::WebString& characteristic_instance_id, 117 const blink::WebString& characteristic_instance_id,
117 blink::WebBluetoothReadValueCallbacks* callbacks) { 118 blink::WebBluetoothReadValueCallbacks* callbacks) {
118 GetWebBluetoothService().RemoteCharacteristicReadValue( 119 GetWebBluetoothService().RemoteCharacteristicReadValue(
119 mojo::String::From(characteristic_instance_id), 120 mojo::String::From(characteristic_instance_id),
120 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), 121 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this),
121 base::Passed(base::WrapUnique(callbacks)))); 122 base::Passed(base::WrapUnique(callbacks))));
122 } 123 }
123 124
124 void WebBluetoothImpl::writeValue( 125 void WebBluetoothImpl::characteristicWriteValue(
125 const blink::WebString& characteristic_instance_id, 126 const blink::WebString& characteristic_instance_id,
126 const blink::WebVector<uint8_t>& value, 127 const blink::WebVector<uint8_t>& value,
127 blink::WebBluetoothWriteValueCallbacks* callbacks) { 128 blink::WebBluetoothWriteValueCallbacks* callbacks) {
128 GetWebBluetoothService().RemoteCharacteristicWriteValue( 129 GetWebBluetoothService().RemoteCharacteristicWriteValue(
129 mojo::String::From(characteristic_instance_id), 130 mojo::String::From(characteristic_instance_id),
130 mojo::Array<uint8_t>::From(value), 131 mojo::Array<uint8_t>::From(value),
131 base::Bind(&WebBluetoothImpl::OnWriteValueComplete, 132 base::Bind(&WebBluetoothImpl::OnWriteValueComplete,
132 base::Unretained(this), value, 133 base::Unretained(this), value,
133 base::Passed(base::WrapUnique(callbacks)))); 134 base::Passed(base::WrapUnique(callbacks))));
134 } 135 }
(...skipping 11 matching lines...) Expand all
146 void WebBluetoothImpl::stopNotifications( 147 void WebBluetoothImpl::stopNotifications(
147 const blink::WebString& characteristic_instance_id, 148 const blink::WebString& characteristic_instance_id,
148 blink::WebBluetoothNotificationsCallbacks* callbacks) { 149 blink::WebBluetoothNotificationsCallbacks* callbacks) {
149 GetWebBluetoothService().RemoteCharacteristicStopNotifications( 150 GetWebBluetoothService().RemoteCharacteristicStopNotifications(
150 mojo::String::From(characteristic_instance_id), 151 mojo::String::From(characteristic_instance_id),
151 base::Bind(&WebBluetoothImpl::OnStopNotificationsComplete, 152 base::Bind(&WebBluetoothImpl::OnStopNotificationsComplete,
152 base::Unretained(this), 153 base::Unretained(this),
153 base::Passed(base::WrapUnique(callbacks)))); 154 base::Passed(base::WrapUnique(callbacks))));
154 } 155 }
155 156
157 void WebBluetoothImpl::getDescriptors(
158 const blink::WebString& characteristic_instance_id,
159 int32_t quantity,
160 const blink::WebString& descriptors_uuid,
161 blink::WebBluetoothGetDescriptorsCallbacks* callbacks) {
162 DCHECK(blink::mojom::IsKnownEnumValue(
163 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity)));
164
165 GetWebBluetoothService().RemoteCharacteristicGetDescriptors(
166 mojo::String::From(characteristic_instance_id),
167 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity),
168 descriptors_uuid.isEmpty()
169 ? base::nullopt
170 : base::make_optional(device::BluetoothUUID(descriptors_uuid.utf8())),
171 base::Bind(&WebBluetoothImpl::OnGetDescriptorsComplete,
172 base::Unretained(this), characteristic_instance_id,
173 base::Passed(base::WrapUnique(callbacks))));
174 }
175
156 void WebBluetoothImpl::characteristicObjectRemoved( 176 void WebBluetoothImpl::characteristicObjectRemoved(
157 const blink::WebString& characteristic_instance_id, 177 const blink::WebString& characteristic_instance_id,
158 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { 178 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) {
159 active_characteristics_.erase(characteristic_instance_id.utf8()); 179 active_characteristics_.erase(characteristic_instance_id.utf8());
160 } 180 }
161 181
162 void WebBluetoothImpl::registerCharacteristicObject( 182 void WebBluetoothImpl::registerCharacteristicObject(
163 const blink::WebString& characteristic_instance_id, 183 const blink::WebString& characteristic_instance_id,
164 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { 184 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) {
165 // TODO(ortuno): After the Bluetooth Tree is implemented, there will 185 // TODO(ortuno): After the Bluetooth Tree is implemented, there will
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 characteristics.value()[i]->instance_id), 280 characteristics.value()[i]->instance_id),
261 blink::WebString::fromUTF8(characteristics.value()[i]->uuid), 281 blink::WebString::fromUTF8(characteristics.value()[i]->uuid),
262 characteristics.value()[i]->properties); 282 characteristics.value()[i]->properties);
263 } 283 }
264 callbacks->onSuccess(promise_characteristics); 284 callbacks->onSuccess(promise_characteristics);
265 } else { 285 } else {
266 callbacks->onError(ToInt32(result)); 286 callbacks->onError(ToInt32(result));
267 } 287 }
268 } 288 }
269 289
290 void WebBluetoothImpl::OnGetDescriptorsComplete(
291 const blink::WebString& characteristic_instance_id,
292 std::unique_ptr<blink::WebBluetoothGetDescriptorsCallbacks> callbacks,
293 blink::mojom::WebBluetoothResult result,
294 base::Optional<
295 std::vector<blink::mojom::WebBluetoothRemoteGATTDescriptorPtr>>
296 descriptors) {
297 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
298 DCHECK(descriptors);
299 // TODO(dcheng): This WebVector should use smart pointers.
dcheng 2016/12/09 08:17:57 Hmm =)
dougt 2016/12/09 19:20:06 Acknowledged. Also see: OnGetPrimaryServicesCompl
300 blink::WebVector<blink::WebBluetoothRemoteGATTDescriptorInit*>
301 promise_descriptors(descriptors->size());
302 for (size_t i = 0; i < descriptors->size(); i++) {
303 promise_descriptors[i] = new blink::WebBluetoothRemoteGATTDescriptorInit(
304 blink::WebString::fromUTF8(descriptors.value()[i]->instance_id),
305 blink::WebString::fromUTF8(descriptors.value()[i]->uuid));
306 }
307 callbacks->onSuccess(promise_descriptors);
308 } else {
309 callbacks->onError(ToInt32(result));
310 }
311 }
312
270 void WebBluetoothImpl::OnReadValueComplete( 313 void WebBluetoothImpl::OnReadValueComplete(
271 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, 314 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
272 blink::mojom::WebBluetoothResult result, 315 blink::mojom::WebBluetoothResult result,
273 const base::Optional<std::vector<uint8_t>>& value) { 316 const base::Optional<std::vector<uint8_t>>& value) {
274 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { 317 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
275 DCHECK(value); 318 DCHECK(value);
276 callbacks->onSuccess(value.value()); 319 callbacks->onSuccess(value.value());
277 } else { 320 } else {
278 callbacks->onError(ToInt32(result)); 321 callbacks->onError(ToInt32(result));
279 } 322 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Create an associated interface ptr and pass it to the WebBluetoothService 363 // Create an associated interface ptr and pass it to the WebBluetoothService
321 // so that it can send us events without us prompting. 364 // so that it can send us events without us prompting.
322 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 365 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
323 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 366 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
324 web_bluetooth_service_->SetClient(std::move(ptr_info)); 367 web_bluetooth_service_->SetClient(std::move(ptr_info));
325 } 368 }
326 return *web_bluetooth_service_; 369 return *web_bluetooth_service_;
327 } 370 }
328 371
329 } // namespace content 372 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698