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

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

Issue 1861013005: bluetooth: Move GetCharacteristic(s) over to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-read-value
Patch Set: Address palmer's comments Created 4 years, 8 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 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 4dc301f448a5f18c42ba9885e61d22d010933e6f..990563976b0dc123068402a08101d6d92b3ba0b4 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -14,6 +14,7 @@
#include "ipc/ipc_message.h"
#include "mojo/public/cpp/bindings/array.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic.h"
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristicInit.h"
namespace content {
@@ -52,20 +53,18 @@ void WebBluetoothImpl::getPrimaryService(
callbacks);
}
-void WebBluetoothImpl::getCharacteristic(
- const blink::WebString& service_instance_id,
- const blink::WebString& characteristics_uuid,
- blink::WebBluetoothGetCharacteristicCallbacks* callbacks) {
- GetDispatcher()->getCharacteristic(frame_routing_id_, service_instance_id,
- characteristics_uuid, callbacks);
-}
-
void WebBluetoothImpl::getCharacteristics(
const blink::WebString& service_instance_id,
- const blink::WebString& characteristic_uuid,
+ blink::mojom::WebBluetoothGATTQueryQuantity quantity,
+ const blink::WebString& characteristics_uuid,
blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) {
- GetDispatcher()->getCharacteristics(frame_routing_id_, service_instance_id,
- characteristic_uuid, callbacks);
+ GetWebBluetoothService().RemoteServiceGetCharacteristics(
+ mojo::String::From(service_instance_id), quantity,
+ characteristics_uuid.isEmpty() ? nullptr
+ : mojo::String::From(characteristics_uuid),
+ base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete,
+ base::Unretained(this), service_instance_id,
+ base::Passed(base::WrapUnique(callbacks))));
}
void WebBluetoothImpl::readValue(
@@ -137,6 +136,31 @@ void WebBluetoothImpl::RemoteCharacteristicValueChanged(
value.PassStorage()));
}
+void WebBluetoothImpl::OnGetCharacteristicsComplete(
+ const blink::WebString& service_instance_id,
+ std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
+ blink::mojom::WebBluetoothError error,
+ mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
+ characteristics) {
+ if (error == blink::mojom::WebBluetoothError::SUCCESS) {
+ // TODO(dcheng): This WebVector should use smart pointers.
+ blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*>
+ promise_characteristics(characteristics.size());
+
+ for (size_t i = 0; i < characteristics.size(); i++) {
+ promise_characteristics[i] =
+ new blink::WebBluetoothRemoteGATTCharacteristicInit(
+ service_instance_id,
+ blink::WebString::fromUTF8(characteristics[i]->instance_id),
+ blink::WebString::fromUTF8(characteristics[i]->uuid),
+ characteristics[i]->properties);
+ }
+ callbacks->onSuccess(promise_characteristics);
+ } else {
+ callbacks->onError(error);
+ }
+}
+
void WebBluetoothImpl::OnReadValueComplete(
std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
blink::mojom::WebBluetoothError error,

Powered by Google App Engine
This is Rietveld 408576698