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

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: 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..93c1434e3912cb1d09ffb240a30ea934fbb2b015 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,16 @@ void BluetoothDispatcher::connectGATT(
device_instance_id.utf8()));
}
+void BluetoothDispatcher::getPrimaryService(
+ const blink::WebString& device_instance_id,
+ const blink::WebString& service_uuid,
Jeffrey Yasskin 2015/05/27 18:36:59 Add a TODO to check that the service_uuid is valid
ortuno 2015/05/27 21:07:45 Done.
+ blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
+ 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 +195,39 @@ 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& uuid) {
+ DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
+ pending_primary_service_requests_.Lookup(request_id)
+ ->onSuccess(new WebBluetoothGATTService(
Jeffrey Yasskin 2015/05/27 18:36:59 Would putting the instance ID in here be more obvi
ortuno 2015/05/27 21:07:45 I don't think it would make that much of a differe
+ 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