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

Unified Diff: content/renderer/bluetooth/web_bluetooth_impl.cc

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: Remove macos restriction 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/bluetooth/web_bluetooth_impl.cc
diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc
index c518ef6720c4f7172be312ab724807fe63a2881d..41163e92a11e9d2b621711c119b5af1c8352a48a 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -21,6 +21,7 @@
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDeviceInit.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristicInit.h"
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTDescriptorInit.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceOptions.h"
@@ -112,7 +113,7 @@ void WebBluetoothImpl::getCharacteristics(
base::Passed(base::WrapUnique(callbacks))));
}
-void WebBluetoothImpl::readValue(
+void WebBluetoothImpl::characteristicReadValue(
const blink::WebString& characteristic_instance_id,
blink::WebBluetoothReadValueCallbacks* callbacks) {
GetWebBluetoothService().RemoteCharacteristicReadValue(
@@ -121,7 +122,7 @@ void WebBluetoothImpl::readValue(
base::Passed(base::WrapUnique(callbacks))));
}
-void WebBluetoothImpl::writeValue(
+void WebBluetoothImpl::characteristicWriteValue(
const blink::WebString& characteristic_instance_id,
const blink::WebVector<uint8_t>& value,
blink::WebBluetoothWriteValueCallbacks* callbacks) {
@@ -153,6 +154,25 @@ void WebBluetoothImpl::stopNotifications(
base::Passed(base::WrapUnique(callbacks))));
}
+void WebBluetoothImpl::getDescriptors(
+ const blink::WebString& characteristic_instance_id,
+ int32_t quantity,
+ const blink::WebString& descriptors_uuid,
+ blink::WebBluetoothGetDescriptorsCallbacks* callbacks) {
+ DCHECK(blink::mojom::IsKnownEnumValue(
+ static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity)));
+
+ GetWebBluetoothService().RemoteCharacteristicGetDescriptors(
+ mojo::String::From(characteristic_instance_id),
+ static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity),
+ descriptors_uuid.isEmpty()
+ ? base::nullopt
+ : base::make_optional(device::BluetoothUUID(descriptors_uuid.utf8())),
+ base::Bind(&WebBluetoothImpl::OnGetDescriptorsComplete,
+ base::Unretained(this), characteristic_instance_id,
+ base::Passed(base::WrapUnique(callbacks))));
+}
+
void WebBluetoothImpl::characteristicObjectRemoved(
const blink::WebString& characteristic_instance_id,
blink::WebBluetoothRemoteGATTCharacteristic* characteristic) {
@@ -267,6 +287,29 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete(
}
}
+void WebBluetoothImpl::OnGetDescriptorsComplete(
+ const blink::WebString& characteristic_instance_id,
+ std::unique_ptr<blink::WebBluetoothGetDescriptorsCallbacks> callbacks,
+ blink::mojom::WebBluetoothResult result,
+ base::Optional<
+ std::vector<blink::mojom::WebBluetoothRemoteGATTDescriptorPtr>>
+ descriptors) {
+ if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
+ DCHECK(descriptors);
+ // TODO(dcheng): This WebVector should use smart pointers.
+ blink::WebVector<blink::WebBluetoothRemoteGATTDescriptorInit*>
+ promise_descriptors(descriptors->size());
+ for (size_t i = 0; i < descriptors->size(); i++) {
+ promise_descriptors[i] = new blink::WebBluetoothRemoteGATTDescriptorInit(
+ blink::WebString::fromUTF8(descriptors.value()[i]->instance_id),
+ blink::WebString::fromUTF8(descriptors.value()[i]->uuid));
+ }
+ callbacks->onSuccess(promise_descriptors);
+ } else {
+ callbacks->onError(ToInt32(result));
+ }
+}
+
void WebBluetoothImpl::OnReadValueComplete(
std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
blink::mojom::WebBluetoothResult result,

Powered by Google App Engine
This is Rietveld 408576698