summaryrefslogtreecommitdiffstats
path: root/content/child/bluetooth/bluetooth_dispatcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'content/child/bluetooth/bluetooth_dispatcher.cc')
-rw-r--r--content/child/bluetooth/bluetooth_dispatcher.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/content/child/bluetooth/bluetooth_dispatcher.cc b/content/child/bluetooth/bluetooth_dispatcher.cc
index 40e5bef..7435825 100644
--- a/content/child/bluetooth/bluetooth_dispatcher.cc
+++ b/content/child/bluetooth/bluetooth_dispatcher.cc
@@ -12,12 +12,14 @@
#include "content/common/bluetooth/bluetooth_messages.h"
#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/WebBluetoothGATTCharacteristic.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::WebBluetoothGATTCharacteristic;
using blink::WebBluetoothGATTRemoteServer;
using blink::WebBluetoothGATTService;
using blink::WebBluetoothRequestDeviceCallbacks;
@@ -39,6 +41,21 @@ struct BluetoothPrimaryServiceRequest {
scoped_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks;
};
+struct BluetoothCharacteristicRequest {
+ BluetoothCharacteristicRequest(
+ blink::WebString service_instance_id,
+ blink::WebString characteristic_uuid,
+ blink::WebBluetoothGetCharacteristicCallbacks* callbacks)
+ : service_instance_id(service_instance_id),
+ characteristic_uuid(characteristic_uuid),
+ callbacks(callbacks) {}
+ ~BluetoothCharacteristicRequest() {}
+
+ blink::WebString service_instance_id;
+ blink::WebString characteristic_uuid;
+ scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks;
+};
+
namespace content {
namespace {
@@ -123,6 +140,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnGetPrimaryServiceSuccess);
IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError,
OnGetPrimaryServiceError);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess,
+ OnGetCharacteristicSuccess);
+ IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError,
+ OnGetCharacteristicError);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
DCHECK(handled) << "Unhandled message:" << msg.type();
@@ -154,6 +175,18 @@ void BluetoothDispatcher::getPrimaryService(
service_uuid.utf8()));
}
+void BluetoothDispatcher::getCharacteristic(
+ const blink::WebString& service_instance_id,
+ const blink::WebString& characteristic_uuid,
+ blink::WebBluetoothGetCharacteristicCallbacks* callbacks) {
+ int request_id =
+ pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest(
+ service_instance_id, characteristic_uuid, callbacks));
+ Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id,
+ service_instance_id.utf8(),
+ characteristic_uuid.utf8()));
+}
+
void BluetoothDispatcher::OnWorkerRunLoopStopped() {
delete this;
}
@@ -248,4 +281,40 @@ void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id,
pending_primary_service_requests_.Remove(request_id);
}
+void BluetoothDispatcher::OnGetCharacteristicSuccess(
+ int thread_id,
+ int request_id,
+ const std::string& characteristic_instance_id) {
+ DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
+
+ BluetoothCharacteristicRequest* request =
+ pending_characteristic_requests_.Lookup(request_id);
+ request->callbacks->onSuccess(new WebBluetoothGATTCharacteristic(
+ WebString::fromUTF8(characteristic_instance_id),
+ request->service_instance_id, request->characteristic_uuid));
+
+ pending_characteristic_requests_.Remove(request_id);
+}
+
+void BluetoothDispatcher::OnGetCharacteristicError(int thread_id,
+ int request_id,
+ BluetoothError error_type) {
+ DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
+
+ // Since we couldn't find the characteristic return null. See Step 3 of
+ // getCharacteristic algorithm:
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattservice-getcharacteristic
+ if (error_type == BluetoothError::NOT_FOUND) {
+ pending_characteristic_requests_.Lookup(request_id)
+ ->callbacks->onSuccess(nullptr);
+ } else {
+ pending_characteristic_requests_.Lookup(request_id)
+ ->callbacks->onError(new WebBluetoothError(
+ // TODO(ortuno): Return more descriptive error messages.
+ // http://crbug.com/490419
+ WebBluetoothErrorFromBluetoothError(error_type), ""));
+ }
+ pending_characteristic_requests_.Remove(request_id);
+}
+
} // namespace content