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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 : service_instance_id(service_instance_id), | 60 : service_instance_id(service_instance_id), |
61 characteristic_uuid(characteristic_uuid), | 61 characteristic_uuid(characteristic_uuid), |
62 callbacks(callbacks) {} | 62 callbacks(callbacks) {} |
63 ~BluetoothCharacteristicRequest() {} | 63 ~BluetoothCharacteristicRequest() {} |
64 | 64 |
65 blink::WebString service_instance_id; | 65 blink::WebString service_instance_id; |
66 blink::WebString characteristic_uuid; | 66 blink::WebString characteristic_uuid; |
67 scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks; | 67 scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks; |
68 }; | 68 }; |
69 | 69 |
| 70 // Struct that holds a pending WriteValue request. |
| 71 struct BluetoothWriteValueRequest { |
| 72 BluetoothWriteValueRequest(const blink::WebVector<uint8_t>& value, |
| 73 blink::WebBluetoothWriteValueCallbacks* callbacks) |
| 74 : value(value), callbacks(callbacks) {} |
| 75 ~BluetoothWriteValueRequest() {} |
| 76 |
| 77 const blink::WebVector<uint8_t> value; |
| 78 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks; |
| 79 }; |
| 80 |
70 // Struct that holds a pending Start/StopNotifications request. | 81 // Struct that holds a pending Start/StopNotifications request. |
71 struct BluetoothNotificationsRequest { | 82 struct BluetoothNotificationsRequest { |
72 BluetoothNotificationsRequest( | 83 BluetoothNotificationsRequest( |
73 int frame_routing_id, | 84 int frame_routing_id, |
74 const std::string characteristic_instance_id, | 85 const std::string characteristic_instance_id, |
75 blink::WebBluetoothGATTCharacteristic* characteristic, | 86 blink::WebBluetoothGATTCharacteristic* characteristic, |
76 blink::WebBluetoothNotificationsCallbacks* callbacks, | 87 blink::WebBluetoothNotificationsCallbacks* callbacks, |
77 NotificationsRequestType type) | 88 NotificationsRequestType type) |
78 : frame_routing_id(frame_routing_id), | 89 : frame_routing_id(frame_routing_id), |
79 characteristic_instance_id(characteristic_instance_id), | 90 characteristic_instance_id(characteristic_instance_id), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, | 277 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, |
267 frame_routing_id, | 278 frame_routing_id, |
268 characteristic_instance_id.utf8())); | 279 characteristic_instance_id.utf8())); |
269 } | 280 } |
270 | 281 |
271 void BluetoothDispatcher::writeValue( | 282 void BluetoothDispatcher::writeValue( |
272 int frame_routing_id, | 283 int frame_routing_id, |
273 const blink::WebString& characteristic_instance_id, | 284 const blink::WebString& characteristic_instance_id, |
274 const blink::WebVector<uint8_t>& value, | 285 const blink::WebVector<uint8_t>& value, |
275 blink::WebBluetoothWriteValueCallbacks* callbacks) { | 286 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
276 int request_id = pending_write_value_requests_.Add(callbacks); | 287 int request_id = pending_write_value_requests_.Add( |
277 | 288 new BluetoothWriteValueRequest(value, callbacks)); |
278 Send(new BluetoothHostMsg_WriteValue( | 289 Send(new BluetoothHostMsg_WriteValue( |
279 CurrentWorkerId(), request_id, frame_routing_id, | 290 CurrentWorkerId(), request_id, frame_routing_id, |
280 characteristic_instance_id.utf8(), | 291 characteristic_instance_id.utf8(), |
281 std::vector<uint8_t>(value.begin(), value.end()))); | 292 std::vector<uint8_t>(value.begin(), value.end()))); |
282 } | 293 } |
283 | 294 |
284 void BluetoothDispatcher::startNotifications( | 295 void BluetoothDispatcher::startNotifications( |
285 int frame_routing_id, | 296 int frame_routing_id, |
286 const blink::WebString& characteristic_instance_id, | 297 const blink::WebString& characteristic_instance_id, |
287 blink::WebBluetoothGATTCharacteristic* characteristic, | 298 blink::WebBluetoothGATTCharacteristic* characteristic, |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 699 |
689 pending_read_value_requests_.Lookup(request_id) | 700 pending_read_value_requests_.Lookup(request_id) |
690 ->onError(WebBluetoothError(error)); | 701 ->onError(WebBluetoothError(error)); |
691 | 702 |
692 pending_read_value_requests_.Remove(request_id); | 703 pending_read_value_requests_.Remove(request_id); |
693 } | 704 } |
694 | 705 |
695 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { | 706 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { |
696 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | 707 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
697 | 708 |
698 pending_write_value_requests_.Lookup(request_id)->onSuccess(); | 709 BluetoothWriteValueRequest* request = |
| 710 pending_write_value_requests_.Lookup(request_id); |
| 711 request->callbacks->onSuccess(request->value); |
699 | 712 |
700 pending_write_value_requests_.Remove(request_id); | 713 pending_write_value_requests_.Remove(request_id); |
701 } | 714 } |
702 | 715 |
703 void BluetoothDispatcher::OnWriteValueError(int thread_id, | 716 void BluetoothDispatcher::OnWriteValueError(int thread_id, |
704 int request_id, | 717 int request_id, |
705 WebBluetoothError error) { | 718 WebBluetoothError error) { |
706 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | 719 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
707 | 720 |
708 pending_write_value_requests_.Lookup(request_id) | 721 BluetoothWriteValueRequest* request = |
709 ->onError(WebBluetoothError(error)); | 722 pending_write_value_requests_.Lookup(request_id); |
| 723 request->callbacks->onError(WebBluetoothError(error)); |
710 | 724 |
711 pending_write_value_requests_.Remove(request_id); | 725 pending_write_value_requests_.Remove(request_id); |
712 } | 726 } |
713 | 727 |
714 void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id, | 728 void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id, |
715 int request_id) { | 729 int request_id) { |
716 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id; | 730 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id; |
717 | 731 |
718 BluetoothNotificationsRequest* request = | 732 BluetoothNotificationsRequest* request = |
719 pending_notifications_requests_.Lookup(request_id); | 733 pending_notifications_requests_.Lookup(request_id); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 int thread_id, | 806 int thread_id, |
793 const std::string& characteristic_instance_id, | 807 const std::string& characteristic_instance_id, |
794 const std::vector<uint8_t> new_value) { | 808 const std::vector<uint8_t> new_value) { |
795 auto active_iter = active_characteristics_.find(characteristic_instance_id); | 809 auto active_iter = active_characteristics_.find(characteristic_instance_id); |
796 if (active_iter != active_characteristics_.end()) { | 810 if (active_iter != active_characteristics_.end()) { |
797 active_iter->second->dispatchCharacteristicValueChanged(new_value); | 811 active_iter->second->dispatchCharacteristicValueChanged(new_value); |
798 } | 812 } |
799 } | 813 } |
800 | 814 |
801 } // namespace content | 815 } // namespace content |
OLD | NEW |