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

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

Issue 1149883011: bluetooth: Browser-side implementation of readValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-get-characteristic-initial
Patch Set: Fix merge conflicts Created 5 years, 6 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
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/child/bluetooth/web_bluetooth_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/bluetooth/bluetooth_dispatcher.cc
diff --git a/content/child/bluetooth/bluetooth_dispatcher.cc b/content/child/bluetooth/bluetooth_dispatcher.cc
index 74358255246f5460610f28a1260ba32ec48ab3c1..5d78f6537d4adbd4a4e91a37ea996c2fac65ab8f 100644
--- a/content/child/bluetooth/bluetooth_dispatcher.cc
+++ b/content/child/bluetooth/bluetooth_dispatcher.cc
@@ -22,6 +22,7 @@ using blink::WebBluetoothError;
using blink::WebBluetoothGATTCharacteristic;
using blink::WebBluetoothGATTRemoteServer;
using blink::WebBluetoothGATTService;
+using blink::WebBluetoothReadValueCallbacks;
using blink::WebBluetoothRequestDeviceCallbacks;
using blink::WebString;
using blink::WebVector;
@@ -144,6 +145,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnGetCharacteristicSuccess);
IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError,
OnGetCharacteristicError);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess,
+ OnReadValueSuccess);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
+ OnReadValueError);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
DCHECK(handled) << "Unhandled message:" << msg.type();
@@ -187,6 +192,14 @@ void BluetoothDispatcher::getCharacteristic(
characteristic_uuid.utf8()));
}
+void BluetoothDispatcher::readValue(
+ const blink::WebString& characteristic_instance_id,
+ blink::WebBluetoothReadValueCallbacks* callbacks) {
+ int request_id = pending_read_value_requests_.Add(callbacks);
+ Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id,
+ characteristic_instance_id.utf8()));
+}
+
void BluetoothDispatcher::OnWorkerRunLoopStopped() {
delete this;
}
@@ -317,4 +330,32 @@ void BluetoothDispatcher::OnGetCharacteristicError(int thread_id,
pending_characteristic_requests_.Remove(request_id);
}
+void BluetoothDispatcher::OnReadValueSuccess(
+ int thread_id,
+ int request_id,
+ const std::vector<uint8_t>& value) {
+ DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
+
+ // WebArrayBuffer is not accessible from Source/modules so we pass a
+ // WebVector instead.
+ pending_read_value_requests_.Lookup(request_id)
+ ->onSuccess(new WebVector<uint8_t>(value));
+
+ pending_read_value_requests_.Remove(request_id);
+}
+
+void BluetoothDispatcher::OnReadValueError(int thread_id,
+ int request_id,
+ BluetoothError error_type) {
+ DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
+
+ pending_read_value_requests_.Lookup(request_id)
+ ->onError(new WebBluetoothError(
+ // TODO(ortuno): Return more descriptive error messages.
+ // http://crbug.com/490419
+ WebBluetoothErrorFromBluetoothError(error_type), ""));
+
+ pending_read_value_requests_.Remove(request_id);
+}
+
} // namespace content
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/child/bluetooth/web_bluetooth_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698