Chromium Code Reviews| Index: content/child/bluetooth/bluetooth_dispatcher.cc |
| diff --git a/content/child/bluetooth/bluetooth_dispatcher.cc b/content/child/bluetooth/bluetooth_dispatcher.cc |
| index 74358255246f5460610f28a1260ba32ec48ab3c1..421993186acf2623106dc0978f360375db103d4d 100644 |
| --- a/content/child/bluetooth/bluetooth_dispatcher.cc |
| +++ b/content/child/bluetooth/bluetooth_dispatcher.cc |
| @@ -22,6 +22,7 @@ using blink::WebBluetoothError; |
| using blink::WebBluetoothGATTCharacteristic; |
| using blink::WebBluetoothGATTRemoteServer; |
| using blink::WebBluetoothGATTService; |
| +using blink::WebBluetoothReadValueCallbacks; |
| using blink::WebBluetoothRequestDeviceCallbacks; |
| using blink::WebString; |
| using blink::WebVector; |
| @@ -144,6 +145,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| OnGetCharacteristicSuccess); |
| IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, |
| OnGetCharacteristicError); |
| + IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, |
| + OnReadValueSuccess); |
| + IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, |
| + OnReadValueError); |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| DCHECK(handled) << "Unhandled message:" << msg.type(); |
| @@ -187,6 +192,14 @@ void BluetoothDispatcher::getCharacteristic( |
| characteristic_uuid.utf8())); |
| } |
| +void BluetoothDispatcher::readValue( |
| + const blink::WebString& characteristic_instance_id, |
| + blink::WebBluetoothReadValueCallbacks* callbacks) { |
| + int request_id = pending_read_value_requests_.Add(callbacks); |
| + Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, |
| + characteristic_instance_id.utf8())); |
| +} |
| + |
| void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
| delete this; |
| } |
| @@ -286,7 +299,6 @@ void BluetoothDispatcher::OnGetCharacteristicSuccess( |
| 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( |
| @@ -300,7 +312,6 @@ void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, |
| int request_id, |
| BluetoothError error_type) { |
| DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; |
| - |
|
Jeffrey Yasskin
2015/06/10 21:03:45
I kinda liked these blank lines.
ortuno
2015/06/10 22:03:01
Done.
|
| // Since we couldn't find the characteristic return null. See Step 3 of |
| // getCharacteristic algorithm: |
| // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattservice-getcharacteristic |
| @@ -317,4 +328,32 @@ void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, |
| pending_characteristic_requests_.Remove(request_id); |
| } |
| +void BluetoothDispatcher::OnReadValueSuccess( |
| + int thread_id, |
| + int request_id, |
| + const std::vector<uint8_t>& value) { |
| + DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; |
| + |
| + // WebArrayBuffer is not accessible from Source/modules so we pass a |
| + // WebVector instead. |
| + pending_read_value_requests_.Lookup(request_id) |
| + ->onSuccess(new WebVector<uint8_t>(value)); |
| + |
| + pending_read_value_requests_.Remove(request_id); |
| +} |
| + |
| +void BluetoothDispatcher::OnReadValueError(int thread_id, |
| + int request_id, |
| + BluetoothError error_type) { |
| + DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; |
| + |
| + pending_read_value_requests_.Lookup(request_id) |
| + ->onError(new WebBluetoothError( |
| + // TODO(ortuno): Return more descriptive error messages. |
| + // http://crbug.com/490419 |
| + WebBluetoothErrorFromBluetoothError(error_type), "")); |
| + |
| + pending_read_value_requests_.Remove(request_id); |
| +} |
| + |
| } // namespace content |