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..40e5bef012b41e871bf33a229fc5290b7492ac2a 100644 |
--- a/content/child/bluetooth/bluetooth_dispatcher.cc |
+++ b/content/child/bluetooth/bluetooth_dispatcher.cc |
@@ -13,15 +13,32 @@ |
#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; |
+struct BluetoothPrimaryServiceRequest { |
+ BluetoothPrimaryServiceRequest( |
+ blink::WebString device_instance_id, |
+ blink::WebString service_uuid, |
+ blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) |
+ : device_instance_id(device_instance_id), |
+ service_uuid(service_uuid), |
+ callbacks(callbacks) {} |
+ ~BluetoothPrimaryServiceRequest() {} |
+ |
+ blink::WebString device_instance_id; |
+ blink::WebString service_uuid; |
+ scoped_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks; |
+}; |
+ |
namespace content { |
namespace { |
@@ -102,6 +119,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 +142,18 @@ void BluetoothDispatcher::connectGATT( |
device_instance_id.utf8())); |
} |
+void BluetoothDispatcher::getPrimaryService( |
+ const blink::WebString& device_instance_id, |
+ const blink::WebString& service_uuid, |
+ blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { |
+ int request_id = |
+ pending_primary_service_requests_.Add(new BluetoothPrimaryServiceRequest( |
+ device_instance_id, service_uuid, callbacks)); |
+ Send(new BluetoothHostMsg_GetPrimaryService(CurrentWorkerId(), request_id, |
+ device_instance_id.utf8(), |
+ service_uuid.utf8())); |
+} |
+ |
void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
delete this; |
} |
@@ -179,4 +212,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& service_instance_id) { |
+ DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; |
+ BluetoothPrimaryServiceRequest* request = |
+ pending_primary_service_requests_.Lookup(request_id); |
+ request->callbacks->onSuccess(new WebBluetoothGATTService( |
+ WebString::fromUTF8(service_instance_id), request->service_uuid, |
+ true /* isPrimary */, request->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) |
+ ->callbacks->onSuccess(nullptr); |
+ pending_primary_service_requests_.Remove(request_id); |
+ return; |
+ } |
+ |
+ pending_primary_service_requests_.Lookup(request_id) |
+ ->callbacks->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 |