| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" | 5 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, | 148 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, |
| 149 OnGetPrimaryServiceError); | 149 OnGetPrimaryServiceError); |
| 150 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, | 150 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, |
| 151 OnGetCharacteristicSuccess); | 151 OnGetCharacteristicSuccess); |
| 152 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, | 152 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, |
| 153 OnGetCharacteristicError); | 153 OnGetCharacteristicError); |
| 154 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess, | 154 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess, |
| 155 OnGetCharacteristicsSuccess); | 155 OnGetCharacteristicsSuccess); |
| 156 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError, | 156 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError, |
| 157 OnGetCharacteristicsError); | 157 OnGetCharacteristicsError); |
| 158 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, | |
| 159 OnReadValueSuccess); | |
| 160 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, | |
| 161 OnReadValueError); | |
| 162 IPC_MESSAGE_UNHANDLED(handled = false) | 158 IPC_MESSAGE_UNHANDLED(handled = false) |
| 163 IPC_END_MESSAGE_MAP() | 159 IPC_END_MESSAGE_MAP() |
| 164 DCHECK(handled) << "Unhandled message:" << msg.type(); | 160 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 165 } | 161 } |
| 166 | 162 |
| 167 void BluetoothDispatcher::requestDevice( | 163 void BluetoothDispatcher::requestDevice( |
| 168 int frame_routing_id, | 164 int frame_routing_id, |
| 169 const WebRequestDeviceOptions& options, | 165 const WebRequestDeviceOptions& options, |
| 170 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 166 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 171 int request_id = pending_requests_.Add(callbacks); | 167 int request_id = pending_requests_.Add(callbacks); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 const blink::WebString& service_instance_id, | 234 const blink::WebString& service_instance_id, |
| 239 const blink::WebString& characteristics_uuid, | 235 const blink::WebString& characteristics_uuid, |
| 240 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { | 236 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { |
| 241 int request_id = pending_characteristics_requests_.Add( | 237 int request_id = pending_characteristics_requests_.Add( |
| 242 new BluetoothCharacteristicsRequest(service_instance_id, callbacks)); | 238 new BluetoothCharacteristicsRequest(service_instance_id, callbacks)); |
| 243 Send(new BluetoothHostMsg_GetCharacteristics( | 239 Send(new BluetoothHostMsg_GetCharacteristics( |
| 244 CurrentWorkerId(), request_id, frame_routing_id, | 240 CurrentWorkerId(), request_id, frame_routing_id, |
| 245 service_instance_id.utf8(), characteristics_uuid.utf8())); | 241 service_instance_id.utf8(), characteristics_uuid.utf8())); |
| 246 } | 242 } |
| 247 | 243 |
| 248 void BluetoothDispatcher::readValue( | |
| 249 int frame_routing_id, | |
| 250 const blink::WebString& characteristic_instance_id, | |
| 251 blink::WebBluetoothReadValueCallbacks* callbacks) { | |
| 252 int request_id = pending_read_value_requests_.Add(callbacks); | |
| 253 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, | |
| 254 frame_routing_id, | |
| 255 characteristic_instance_id.utf8())); | |
| 256 } | |
| 257 | |
| 258 void BluetoothDispatcher::WillStopCurrentWorkerThread() { | 244 void BluetoothDispatcher::WillStopCurrentWorkerThread() { |
| 259 delete this; | 245 delete this; |
| 260 } | 246 } |
| 261 | 247 |
| 262 void BluetoothDispatcher::OnRequestDeviceSuccess( | 248 void BluetoothDispatcher::OnRequestDeviceSuccess( |
| 263 int thread_id, | 249 int thread_id, |
| 264 int request_id, | 250 int request_id, |
| 265 const BluetoothDevice& device) { | 251 const BluetoothDevice& device) { |
| 266 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 252 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
| 267 | 253 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 int request_id, | 374 int request_id, |
| 389 WebBluetoothError error) { | 375 WebBluetoothError error) { |
| 390 DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id; | 376 DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id; |
| 391 | 377 |
| 392 pending_characteristics_requests_.Lookup(request_id) | 378 pending_characteristics_requests_.Lookup(request_id) |
| 393 ->callbacks->onError(WebBluetoothError(error)); | 379 ->callbacks->onError(WebBluetoothError(error)); |
| 394 | 380 |
| 395 pending_characteristics_requests_.Remove(request_id); | 381 pending_characteristics_requests_.Remove(request_id); |
| 396 } | 382 } |
| 397 | 383 |
| 398 void BluetoothDispatcher::OnReadValueSuccess( | |
| 399 int thread_id, | |
| 400 int request_id, | |
| 401 const std::vector<uint8_t>& value) { | |
| 402 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; | |
| 403 | |
| 404 // WebArrayBuffer is not accessible from Source/modules so we pass a | |
| 405 // WebVector instead. | |
| 406 pending_read_value_requests_.Lookup(request_id)->onSuccess(value); | |
| 407 | |
| 408 pending_read_value_requests_.Remove(request_id); | |
| 409 } | |
| 410 | |
| 411 void BluetoothDispatcher::OnReadValueError(int thread_id, | |
| 412 int request_id, | |
| 413 WebBluetoothError error) { | |
| 414 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; | |
| 415 | |
| 416 pending_read_value_requests_.Lookup(request_id) | |
| 417 ->onError(WebBluetoothError(error)); | |
| 418 | |
| 419 pending_read_value_requests_.Remove(request_id); | |
| 420 } | |
| 421 | |
| 422 } // namespace content | 384 } // namespace content |
| OLD | NEW |