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

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

Issue 1159523002: bluetooth: Browser side partial implementation of getPrimaryService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address jyasskin comments Created 5 years, 7 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/child/bluetooth/bluetooth_dispatcher.cc
diff --git a/content/child/bluetooth/bluetooth_dispatcher.cc b/content/child/bluetooth/bluetooth_dispatcher.cc
index 576fa8dde52826cdbcbe0235eba9cd41ade778e0..50a33579773e36cdbda19a4759f9e66c6c342bec 100644
--- a/content/child/bluetooth/bluetooth_dispatcher.cc
+++ b/content/child/bluetooth/bluetooth_dispatcher.cc
@@ -13,11 +13,13 @@
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevice.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTRemoteServer.h"
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTService.h"
using blink::WebBluetoothConnectGATTCallbacks;
using blink::WebBluetoothDevice;
using blink::WebBluetoothError;
using blink::WebBluetoothGATTRemoteServer;
+using blink::WebBluetoothGATTService;
using blink::WebBluetoothRequestDeviceCallbacks;
using blink::WebString;
using blink::WebVector;
@@ -102,6 +104,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError);
IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess);
IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess,
+ OnGetPrimaryServiceSuccess);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError,
+ OnGetPrimaryServiceError);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
DCHECK(handled) << "Unhandled message:" << msg.type();
@@ -121,6 +127,17 @@ void BluetoothDispatcher::connectGATT(
device_instance_id.utf8()));
}
+void BluetoothDispatcher::getPrimaryService(
+ const blink::WebString& device_instance_id,
+ const blink::WebString& service_uuid,
+ blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
+ // TODO(ortuno): Check that service_uuid is a valid UUID.
+ int request_id = pending_primary_service_requests_.Add(callbacks);
+ Send(new BluetoothHostMsg_GetPrimaryService(CurrentWorkerId(), request_id,
+ device_instance_id.utf8(),
+ service_uuid.utf8()));
+}
+
void BluetoothDispatcher::OnWorkerRunLoopStopped() {
delete this;
}
@@ -179,4 +196,40 @@ void BluetoothDispatcher::OnConnectGATTError(int thread_id,
pending_connect_requests_.Remove(request_id);
}
+void BluetoothDispatcher::OnGetPrimaryServiceSuccess(
+ int thread_id,
+ int request_id,
+ const std::string& device_instance_id,
+ const std::string& service_instance_id,
+ const std::string& uuid) {
+ DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
+ pending_primary_service_requests_.Lookup(request_id)
+ ->onSuccess(new WebBluetoothGATTService(
+ WebString::fromUTF8(service_instance_id), WebString::fromUTF8(uuid),
+ true /* isPrimary */, WebString::fromUTF8(device_instance_id)));
+ pending_primary_service_requests_.Remove(request_id);
+}
+
+void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id,
+ int request_id,
+ BluetoothError error_type) {
+ DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
+
+ // Since we couldn't find the service return null. See Step 3 of
+ // getPrimaryService algorithm:
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattremoteserver-getprimaryservice
+ if (error_type == BluetoothError::NOT_FOUND) {
+ pending_primary_service_requests_.Lookup(request_id)->onSuccess(nullptr);
+ pending_primary_service_requests_.Remove(request_id);
+ return;
+ }
+
+ pending_primary_service_requests_.Lookup(request_id)
+ ->onError(new WebBluetoothError(
+ // TODO(ortuno): Return more descriptive error messages.
+ // http://crbug.com/490419
+ WebBluetoothErrorFromBluetoothError(error_type), ""));
+ pending_primary_service_requests_.Remove(request_id);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698