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

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

Issue 1217983004: bluetooth: browser-side implementation of writeValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Created 5 years, 5 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 2643752506b8bfd013afd956a1216beeb76b7f81..5f8fd80f0535aedf376ec406e060c45d09b56fa1 100644
--- a/content/child/bluetooth/bluetooth_dispatcher.cc
+++ b/content/child/bluetooth/bluetooth_dispatcher.cc
@@ -163,6 +163,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnReadValueSuccess);
IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
OnReadValueError);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess,
+ OnWriteValueSuccess);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError,
+ OnWriteValueError);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
DCHECK(handled) << "Unhandled message:" << msg.type();
@@ -233,6 +237,20 @@ void BluetoothDispatcher::readValue(
characteristic_instance_id.utf8()));
}
+void BluetoothDispatcher::writeValue(
+ const blink::WebString& characteristic_instance_id,
+ const unsigned char* bytes,
+ unsigned byteLength,
+ blink::WebBluetoothWriteValueCallbacks* callbacks) {
+ int request_id = pending_write_value_requests_.Add(callbacks);
+ std::vector<uint8_t> value(byteLength);
Jeffrey Yasskin 2015/07/07 00:31:42 You can initialize this with "std::vector<uint8_t>
+ for (unsigned i = 0; i < byteLength; i++)
+ value[i] = bytes[i];
+
+ Send(new BluetoothHostMsg_WriteValue(
+ CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), value));
+}
+
void BluetoothDispatcher::OnWorkerRunLoopStopped() {
delete this;
}
@@ -404,4 +422,26 @@ void BluetoothDispatcher::OnReadValueError(int thread_id,
pending_read_value_requests_.Remove(request_id);
}
+void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) {
+ DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id;
+
+ pending_write_value_requests_.Lookup(request_id)->onSuccess();
+
+ pending_write_value_requests_.Remove(request_id);
+}
+
+void BluetoothDispatcher::OnWriteValueError(int thread_id,
+ int request_id,
+ BluetoothError error_type,
+ const std::string& error_message) {
+ DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id;
+
+ pending_write_value_requests_.Lookup(request_id)
+ ->onError(
+ new WebBluetoothError(WebBluetoothErrorFromBluetoothError(error_type),
+ WebString::fromUTF8(error_message)));
+
+ pending_write_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