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 2643752506b8bfd013afd956a1216beeb76b7f81..5f8fd80f0535aedf376ec406e060c45d09b56fa1 100644 |
| --- a/content/child/bluetooth/bluetooth_dispatcher.cc |
| +++ b/content/child/bluetooth/bluetooth_dispatcher.cc |
| @@ -163,6 +163,10 @@ void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| OnReadValueSuccess); |
| IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, |
| OnReadValueError); |
| + IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess, |
| + OnWriteValueSuccess); |
| + IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError, |
| + OnWriteValueError); |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| DCHECK(handled) << "Unhandled message:" << msg.type(); |
| @@ -233,6 +237,20 @@ void BluetoothDispatcher::readValue( |
| characteristic_instance_id.utf8())); |
| } |
| +void BluetoothDispatcher::writeValue( |
| + const blink::WebString& characteristic_instance_id, |
| + const unsigned char* bytes, |
| + unsigned byteLength, |
| + blink::WebBluetoothWriteValueCallbacks* callbacks) { |
| + int request_id = pending_write_value_requests_.Add(callbacks); |
| + std::vector<uint8_t> value(byteLength); |
|
Jeffrey Yasskin
2015/07/07 00:31:42
You can initialize this with "std::vector<uint8_t>
|
| + for (unsigned i = 0; i < byteLength; i++) |
| + value[i] = bytes[i]; |
| + |
| + Send(new BluetoothHostMsg_WriteValue( |
| + CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), value)); |
| +} |
| + |
| void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
| delete this; |
| } |
| @@ -404,4 +422,26 @@ void BluetoothDispatcher::OnReadValueError(int thread_id, |
| pending_read_value_requests_.Remove(request_id); |
| } |
| +void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { |
| + DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
| + |
| + pending_write_value_requests_.Lookup(request_id)->onSuccess(); |
| + |
| + pending_write_value_requests_.Remove(request_id); |
| +} |
| + |
| +void BluetoothDispatcher::OnWriteValueError(int thread_id, |
| + int request_id, |
| + BluetoothError error_type, |
| + const std::string& error_message) { |
| + DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
| + |
| + pending_write_value_requests_.Lookup(request_id) |
| + ->onError( |
| + new WebBluetoothError(WebBluetoothErrorFromBluetoothError(error_type), |
| + WebString::fromUTF8(error_message))); |
| + |
| + pending_write_value_requests_.Remove(request_id); |
| +} |
| + |
| } // namespace content |