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

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

Issue 1723723002: bluetooth: Implement Service.getCharacteristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Clean up Created 4 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/bluetooth/bluetooth_dispatcher.cc
diff --git a/content/renderer/bluetooth/bluetooth_dispatcher.cc b/content/renderer/bluetooth/bluetooth_dispatcher.cc
index d24a056ca7abbcf1d8272746d5ecc463b3c33a5a..9c56a66451a0ec47fe364a09f13a419d64fc9e82 100644
--- a/content/renderer/bluetooth/bluetooth_dispatcher.cc
+++ b/content/renderer/bluetooth/bluetooth_dispatcher.cc
@@ -65,6 +65,17 @@ struct BluetoothCharacteristicRequest {
scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks;
};
+struct BluetoothCharacteristicsRequest {
+ BluetoothCharacteristicsRequest(
+ blink::WebString service_instance_id,
+ blink::WebBluetoothGetCharacteristicsCallbacks* callbacks)
+ : service_instance_id(service_instance_id), callbacks(callbacks) {}
+ ~BluetoothCharacteristicsRequest() {}
+
+ blink::WebString service_instance_id;
+ scoped_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks;
+};
+
// Struct that holds a pending WriteValue request.
struct BluetoothWriteValueRequest {
BluetoothWriteValueRequest(const blink::WebVector<uint8_t>& value,
@@ -179,6 +190,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnGetCharacteristicSuccess);
IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError,
OnGetCharacteristicError);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess,
+ OnGetCharacteristicsSuccess);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError,
+ OnGetCharacteristicsError);
IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess,
OnReadValueSuccess);
IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
@@ -269,6 +284,18 @@ void BluetoothDispatcher::getCharacteristic(
service_instance_id.utf8(), characteristic_uuid.utf8()));
}
+void BluetoothDispatcher::getCharacteristics(
+ int frame_routing_id,
+ const blink::WebString& service_instance_id,
+ const blink::WebString& characteristic_uuid,
+ blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) {
+ int request_id = pending_characteristics_requests_.Add(
+ new BluetoothCharacteristicsRequest(service_instance_id, callbacks));
+ Send(new BluetoothHostMsg_GetCharacteristics(
+ CurrentWorkerId(), request_id, frame_routing_id,
+ service_instance_id.utf8(), characteristic_uuid.utf8()));
+}
+
void BluetoothDispatcher::readValue(
int frame_routing_id,
const blink::WebString& characteristic_instance_id,
@@ -677,6 +704,45 @@ void BluetoothDispatcher::OnGetCharacteristicError(int thread_id,
pending_characteristic_requests_.Remove(request_id);
}
+void BluetoothDispatcher::OnGetCharacteristicsSuccess(
+ int thread_id,
+ int request_id,
+ const std::vector<std::string>& characteristics_instance_ids,
+ const std::vector<std::string>& characteristics_uuids,
+ const std::vector<uint32_t>& characteristics_properties) {
+ DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id;
+
+ BluetoothCharacteristicsRequest* request =
+ pending_characteristics_requests_.Lookup(request_id);
+
+ WebVector<WebBluetoothRemoteGATTCharacteristicInit*>* characteristics =
+ new WebVector<WebBluetoothRemoteGATTCharacteristicInit*>(
+ characteristics_instance_ids.size());
+
+ for (size_t i = 0; i < characteristics_instance_ids.size(); i++) {
+ (*characteristics)[i] = new WebBluetoothRemoteGATTCharacteristicInit(
Jeffrey Yasskin 2016/02/24 23:20:29 I'm sad that we wind up with raw pointers in this
ortuno 2016/02/25 23:08:27 WebPassOwnPtr is move only. WebVector doesn't supp
Jeffrey Yasskin 2016/02/25 23:46:57 Oh, I see. WebPassOwnPtr doesn't have an assignmen
+ WebString::fromUTF8(characteristics_instance_ids[i]),
+ request->service_instance_id,
Jeffrey Yasskin 2016/02/24 23:20:29 Nit: I'd put the service instance ID first, so the
ortuno 2016/02/25 23:08:27 Done.
+ WebString::fromUTF8(characteristics_uuids[i]),
+ characteristics_properties[i]);
+ }
+
+ request->callbacks->onSuccess(blink::adoptWebPtr(characteristics));
+
+ pending_characteristics_requests_.Lookup(request_id);
+}
+
+void BluetoothDispatcher::OnGetCharacteristicsError(int thread_id,
+ int request_id,
+ WebBluetoothError error) {
+ DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id;
+
+ pending_characteristics_requests_.Lookup(request_id)
+ ->callbacks->onError(WebBluetoothError(error));
+
+ pending_characteristics_requests_.Remove(request_id);
+}
+
void BluetoothDispatcher::OnReadValueSuccess(
int thread_id,
int request_id,

Powered by Google App Engine
This is Rietveld 408576698