| 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 "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 BluetoothCharacteristicsRequest( | 69 BluetoothCharacteristicsRequest( |
| 70 blink::WebString service_instance_id, | 70 blink::WebString service_instance_id, |
| 71 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) | 71 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) |
| 72 : service_instance_id(service_instance_id), callbacks(callbacks) {} | 72 : service_instance_id(service_instance_id), callbacks(callbacks) {} |
| 73 ~BluetoothCharacteristicsRequest() {} | 73 ~BluetoothCharacteristicsRequest() {} |
| 74 | 74 |
| 75 blink::WebString service_instance_id; | 75 blink::WebString service_instance_id; |
| 76 scoped_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks; | 76 scoped_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Struct that holds a pending WriteValue request. | |
| 80 struct BluetoothWriteValueRequest { | |
| 81 BluetoothWriteValueRequest(const blink::WebVector<uint8_t>& value, | |
| 82 blink::WebBluetoothWriteValueCallbacks* callbacks) | |
| 83 : value(value), callbacks(callbacks) {} | |
| 84 ~BluetoothWriteValueRequest() {} | |
| 85 | |
| 86 const blink::WebVector<uint8_t> value; | |
| 87 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks; | |
| 88 }; | |
| 89 | |
| 90 // Struct that holds a pending Start/StopNotifications request. | 79 // Struct that holds a pending Start/StopNotifications request. |
| 91 struct BluetoothNotificationsRequest { | 80 struct BluetoothNotificationsRequest { |
| 92 BluetoothNotificationsRequest( | 81 BluetoothNotificationsRequest( |
| 93 int frame_routing_id, | 82 int frame_routing_id, |
| 94 const std::string characteristic_instance_id, | 83 const std::string characteristic_instance_id, |
| 95 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, | 84 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, |
| 96 blink::WebBluetoothNotificationsCallbacks* callbacks, | 85 blink::WebBluetoothNotificationsCallbacks* callbacks, |
| 97 NotificationsRequestType type) | 86 NotificationsRequestType type) |
| 98 : frame_routing_id(frame_routing_id), | 87 : frame_routing_id(frame_routing_id), |
| 99 characteristic_instance_id(characteristic_instance_id), | 88 characteristic_instance_id(characteristic_instance_id), |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, | 180 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, |
| 192 OnGetCharacteristicError); | 181 OnGetCharacteristicError); |
| 193 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess, | 182 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess, |
| 194 OnGetCharacteristicsSuccess); | 183 OnGetCharacteristicsSuccess); |
| 195 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError, | 184 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError, |
| 196 OnGetCharacteristicsError); | 185 OnGetCharacteristicsError); |
| 197 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, | 186 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, |
| 198 OnReadValueSuccess); | 187 OnReadValueSuccess); |
| 199 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, | 188 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, |
| 200 OnReadValueError); | 189 OnReadValueError); |
| 201 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess, | |
| 202 OnWriteValueSuccess); | |
| 203 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError, | |
| 204 OnWriteValueError); | |
| 205 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess, | 190 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess, |
| 206 OnStartNotificationsSuccess) | 191 OnStartNotificationsSuccess) |
| 207 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsError, | 192 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsError, |
| 208 OnStartNotificationsError) | 193 OnStartNotificationsError) |
| 209 IPC_MESSAGE_HANDLER(BluetoothMsg_StopNotificationsSuccess, | 194 IPC_MESSAGE_HANDLER(BluetoothMsg_StopNotificationsSuccess, |
| 210 OnStopNotificationsSuccess) | 195 OnStopNotificationsSuccess) |
| 211 IPC_MESSAGE_HANDLER(BluetoothMsg_CharacteristicValueChanged, | 196 IPC_MESSAGE_HANDLER(BluetoothMsg_CharacteristicValueChanged, |
| 212 OnCharacteristicValueChanged) | 197 OnCharacteristicValueChanged) |
| 213 IPC_MESSAGE_UNHANDLED(handled = false) | 198 IPC_MESSAGE_UNHANDLED(handled = false) |
| 214 IPC_END_MESSAGE_MAP() | 199 IPC_END_MESSAGE_MAP() |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 void BluetoothDispatcher::readValue( | 284 void BluetoothDispatcher::readValue( |
| 300 int frame_routing_id, | 285 int frame_routing_id, |
| 301 const blink::WebString& characteristic_instance_id, | 286 const blink::WebString& characteristic_instance_id, |
| 302 blink::WebBluetoothReadValueCallbacks* callbacks) { | 287 blink::WebBluetoothReadValueCallbacks* callbacks) { |
| 303 int request_id = pending_read_value_requests_.Add(callbacks); | 288 int request_id = pending_read_value_requests_.Add(callbacks); |
| 304 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, | 289 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, |
| 305 frame_routing_id, | 290 frame_routing_id, |
| 306 characteristic_instance_id.utf8())); | 291 characteristic_instance_id.utf8())); |
| 307 } | 292 } |
| 308 | 293 |
| 309 void BluetoothDispatcher::writeValue( | |
| 310 int frame_routing_id, | |
| 311 const blink::WebString& characteristic_instance_id, | |
| 312 const blink::WebVector<uint8_t>& value, | |
| 313 blink::WebBluetoothWriteValueCallbacks* callbacks) { | |
| 314 int request_id = pending_write_value_requests_.Add( | |
| 315 new BluetoothWriteValueRequest(value, callbacks)); | |
| 316 Send(new BluetoothHostMsg_WriteValue( | |
| 317 CurrentWorkerId(), request_id, frame_routing_id, | |
| 318 characteristic_instance_id.utf8(), | |
| 319 std::vector<uint8_t>(value.begin(), value.end()))); | |
| 320 } | |
| 321 | |
| 322 void BluetoothDispatcher::startNotifications( | 294 void BluetoothDispatcher::startNotifications( |
| 323 int frame_routing_id, | 295 int frame_routing_id, |
| 324 const blink::WebString& characteristic_instance_id, | 296 const blink::WebString& characteristic_instance_id, |
| 325 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, | 297 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, |
| 326 blink::WebBluetoothNotificationsCallbacks* callbacks) { | 298 blink::WebBluetoothNotificationsCallbacks* callbacks) { |
| 327 int request_id = QueueNotificationRequest( | 299 int request_id = QueueNotificationRequest( |
| 328 frame_routing_id, characteristic_instance_id.utf8(), characteristic, | 300 frame_routing_id, characteristic_instance_id.utf8(), characteristic, |
| 329 callbacks, NotificationsRequestType::START); | 301 callbacks, NotificationsRequestType::START); |
| 330 // The Notification subscription's state can change after a request | 302 // The Notification subscription's state can change after a request |
| 331 // finishes. To avoid resolving with a soon-to-be-invalid state we queue | 303 // finishes. To avoid resolving with a soon-to-be-invalid state we queue |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 int request_id, | 732 int request_id, |
| 761 WebBluetoothError error) { | 733 WebBluetoothError error) { |
| 762 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; | 734 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; |
| 763 | 735 |
| 764 pending_read_value_requests_.Lookup(request_id) | 736 pending_read_value_requests_.Lookup(request_id) |
| 765 ->onError(WebBluetoothError(error)); | 737 ->onError(WebBluetoothError(error)); |
| 766 | 738 |
| 767 pending_read_value_requests_.Remove(request_id); | 739 pending_read_value_requests_.Remove(request_id); |
| 768 } | 740 } |
| 769 | 741 |
| 770 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { | |
| 771 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | |
| 772 | |
| 773 BluetoothWriteValueRequest* request = | |
| 774 pending_write_value_requests_.Lookup(request_id); | |
| 775 request->callbacks->onSuccess(request->value); | |
| 776 | |
| 777 pending_write_value_requests_.Remove(request_id); | |
| 778 } | |
| 779 | |
| 780 void BluetoothDispatcher::OnWriteValueError(int thread_id, | |
| 781 int request_id, | |
| 782 WebBluetoothError error) { | |
| 783 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | |
| 784 | |
| 785 BluetoothWriteValueRequest* request = | |
| 786 pending_write_value_requests_.Lookup(request_id); | |
| 787 request->callbacks->onError(WebBluetoothError(error)); | |
| 788 | |
| 789 pending_write_value_requests_.Remove(request_id); | |
| 790 } | |
| 791 | |
| 792 void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id, | 742 void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id, |
| 793 int request_id) { | 743 int request_id) { |
| 794 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id; | 744 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id; |
| 795 | 745 |
| 796 BluetoothNotificationsRequest* request = | 746 BluetoothNotificationsRequest* request = |
| 797 pending_notifications_requests_.Lookup(request_id); | 747 pending_notifications_requests_.Lookup(request_id); |
| 798 | 748 |
| 799 DCHECK(notification_requests_queues_[request->characteristic_instance_id] | 749 DCHECK(notification_requests_queues_[request->characteristic_instance_id] |
| 800 .front() == request_id); | 750 .front() == request_id); |
| 801 | 751 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 int thread_id, | 820 int thread_id, |
| 871 const std::string& characteristic_instance_id, | 821 const std::string& characteristic_instance_id, |
| 872 const std::vector<uint8_t> new_value) { | 822 const std::vector<uint8_t> new_value) { |
| 873 auto active_iter = active_characteristics_.find(characteristic_instance_id); | 823 auto active_iter = active_characteristics_.find(characteristic_instance_id); |
| 874 if (active_iter != active_characteristics_.end()) { | 824 if (active_iter != active_characteristics_.end()) { |
| 875 active_iter->second->dispatchCharacteristicValueChanged(new_value); | 825 active_iter->second->dispatchCharacteristicValueChanged(new_value); |
| 876 } | 826 } |
| 877 } | 827 } |
| 878 | 828 |
| 879 } // namespace content | 829 } // namespace content |
| OLD | NEW |