Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: content/renderer/bluetooth/bluetooth_dispatcher.cc

Issue 1775953004: bluetooth: Move writeValue to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Moar cleanup Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "content/child/mojo/type_converters.h"
13 #include "content/child/thread_safe_sender.h" 14 #include "content/child/thread_safe_sender.h"
14 #include "content/common/bluetooth/bluetooth_messages.h" 15 #include "content/common/bluetooth/bluetooth_messages.h"
16 #include "content/public/common/service_registry.h"
17 #include "content/renderer/bluetooth/bluetooth_type_converters.h"
15 #include "device/bluetooth/bluetooth_uuid.h" 18 #include "device/bluetooth/bluetooth_uuid.h"
19 #include "mojo/public/cpp/bindings/array.h"
16 #include "third_party/WebKit/public/platform/WebPassOwnPtr.h" 20 #include "third_party/WebKit/public/platform/WebPassOwnPtr.h"
17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" 23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h"
20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h" 24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h"
21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h" 25 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h"
22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h" 26 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
23 27
24 using blink::WebBluetoothDevice; 28 using blink::WebBluetoothDevice;
25 using blink::WebBluetoothError;
26 using blink::WebBluetoothRemoteGATTCharacteristicInit; 29 using blink::WebBluetoothRemoteGATTCharacteristicInit;
27 using blink::WebBluetoothRemoteGATTServerConnectCallbacks; 30 using blink::WebBluetoothRemoteGATTServerConnectCallbacks;
28 using blink::WebBluetoothRemoteGATTService; 31 using blink::WebBluetoothRemoteGATTService;
29 using blink::WebBluetoothReadValueCallbacks; 32 using blink::WebBluetoothReadValueCallbacks;
30 using blink::WebBluetoothRequestDeviceCallbacks; 33 using blink::WebBluetoothRequestDeviceCallbacks;
31 using blink::WebBluetoothScanFilter; 34 using blink::WebBluetoothScanFilter;
32 using blink::WebRequestDeviceOptions; 35 using blink::WebRequestDeviceOptions;
33 using blink::WebString; 36 using blink::WebString;
34 using blink::WebVector; 37 using blink::WebVector;
35 using NotificationsRequestType = 38 using NotificationsRequestType =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 BluetoothCharacteristicsRequest( 72 BluetoothCharacteristicsRequest(
70 blink::WebString service_instance_id, 73 blink::WebString service_instance_id,
71 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) 74 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks)
72 : service_instance_id(service_instance_id), callbacks(callbacks) {} 75 : service_instance_id(service_instance_id), callbacks(callbacks) {}
73 ~BluetoothCharacteristicsRequest() {} 76 ~BluetoothCharacteristicsRequest() {}
74 77
75 blink::WebString service_instance_id; 78 blink::WebString service_instance_id;
76 scoped_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks; 79 scoped_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks;
77 }; 80 };
78 81
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. 82 // Struct that holds a pending Start/StopNotifications request.
91 struct BluetoothNotificationsRequest { 83 struct BluetoothNotificationsRequest {
92 BluetoothNotificationsRequest( 84 BluetoothNotificationsRequest(
93 int frame_routing_id, 85 int frame_routing_id,
94 const std::string characteristic_instance_id, 86 const std::string characteristic_instance_id,
95 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, 87 blink::WebBluetoothRemoteGATTCharacteristic* characteristic,
96 blink::WebBluetoothNotificationsCallbacks* callbacks, 88 blink::WebBluetoothNotificationsCallbacks* callbacks,
97 NotificationsRequestType type) 89 NotificationsRequestType type)
98 : frame_routing_id(frame_routing_id), 90 : frame_routing_id(frame_routing_id),
99 characteristic_instance_id(characteristic_instance_id), 91 characteristic_instance_id(characteristic_instance_id),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return WebBluetoothDevice::VendorIDSource::Bluetooth; 129 return WebBluetoothDevice::VendorIDSource::Bluetooth;
138 case device::BluetoothDevice::VENDOR_ID_USB: 130 case device::BluetoothDevice::VENDOR_ID_USB:
139 return WebBluetoothDevice::VendorIDSource::USB; 131 return WebBluetoothDevice::VendorIDSource::USB;
140 } 132 }
141 NOTREACHED(); 133 NOTREACHED();
142 return WebBluetoothDevice::VendorIDSource::Unknown; 134 return WebBluetoothDevice::VendorIDSource::Unknown;
143 } 135 }
144 136
145 } // namespace 137 } // namespace
146 138
147 BluetoothDispatcher::BluetoothDispatcher(ThreadSafeSender* sender) 139 BluetoothDispatcher::BluetoothDispatcher(ThreadSafeSender* sender,
148 : thread_safe_sender_(sender) { 140 ServiceRegistry* service_registry)
141 : thread_safe_sender_(sender), service_registry_(service_registry) {
149 g_dispatcher_tls.Pointer()->Set(static_cast<void*>(this)); 142 g_dispatcher_tls.Pointer()->Set(static_cast<void*>(this));
150 } 143 }
151 144
152 BluetoothDispatcher::~BluetoothDispatcher() { 145 BluetoothDispatcher::~BluetoothDispatcher() {
ortuno 2016/03/09 01:21:22 FWIW I tried setting a error handler but it never
153 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 146 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
154 } 147 }
155 148
156 BluetoothDispatcher* BluetoothDispatcher::GetOrCreateThreadSpecificInstance( 149 BluetoothDispatcher* BluetoothDispatcher::GetOrCreateThreadSpecificInstance(
157 ThreadSafeSender* thread_safe_sender) { 150 ThreadSafeSender* thread_safe_sender,
151 ServiceRegistry* service_registry) {
158 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { 152 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) {
159 NOTREACHED() << "Re-instantiating TLS BluetoothDispatcher."; 153 NOTREACHED() << "Re-instantiating TLS BluetoothDispatcher.";
160 g_dispatcher_tls.Pointer()->Set(NULL); 154 g_dispatcher_tls.Pointer()->Set(NULL);
161 } 155 }
162 if (g_dispatcher_tls.Pointer()->Get()) 156 if (g_dispatcher_tls.Pointer()->Get())
163 return static_cast<BluetoothDispatcher*>(g_dispatcher_tls.Pointer()->Get()); 157 return static_cast<BluetoothDispatcher*>(g_dispatcher_tls.Pointer()->Get());
164 158
165 BluetoothDispatcher* dispatcher = new BluetoothDispatcher(thread_safe_sender); 159 BluetoothDispatcher* dispatcher =
160 new BluetoothDispatcher(thread_safe_sender, service_registry);
166 if (CurrentWorkerId()) 161 if (CurrentWorkerId())
167 WorkerThread::AddObserver(dispatcher); 162 WorkerThread::AddObserver(dispatcher);
168 return dispatcher; 163 return dispatcher;
169 } 164 }
170 165
171 bool BluetoothDispatcher::Send(IPC::Message* msg) { 166 bool BluetoothDispatcher::Send(IPC::Message* msg) {
172 return thread_safe_sender_->Send(msg); 167 return thread_safe_sender_->Send(msg);
173 } 168 }
174 169
175 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { 170 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
(...skipping 15 matching lines...) Expand all
191 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, 186 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError,
192 OnGetCharacteristicError); 187 OnGetCharacteristicError);
193 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess, 188 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess,
194 OnGetCharacteristicsSuccess); 189 OnGetCharacteristicsSuccess);
195 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError, 190 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError,
196 OnGetCharacteristicsError); 191 OnGetCharacteristicsError);
197 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, 192 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess,
198 OnReadValueSuccess); 193 OnReadValueSuccess);
199 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, 194 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
200 OnReadValueError); 195 OnReadValueError);
201 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess,
202 OnWriteValueSuccess);
203 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError,
204 OnWriteValueError);
205 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess, 196 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess,
206 OnStartNotificationsSuccess) 197 OnStartNotificationsSuccess)
207 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsError, 198 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsError,
208 OnStartNotificationsError) 199 OnStartNotificationsError)
209 IPC_MESSAGE_HANDLER(BluetoothMsg_StopNotificationsSuccess, 200 IPC_MESSAGE_HANDLER(BluetoothMsg_StopNotificationsSuccess,
210 OnStopNotificationsSuccess) 201 OnStopNotificationsSuccess)
211 IPC_MESSAGE_HANDLER(BluetoothMsg_CharacteristicValueChanged, 202 IPC_MESSAGE_HANDLER(BluetoothMsg_CharacteristicValueChanged,
212 OnCharacteristicValueChanged) 203 OnCharacteristicValueChanged)
213 IPC_MESSAGE_UNHANDLED(handled = false) 204 IPC_MESSAGE_UNHANDLED(handled = false)
214 IPC_END_MESSAGE_MAP() 205 IPC_END_MESSAGE_MAP()
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, 295 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id,
305 frame_routing_id, 296 frame_routing_id,
306 characteristic_instance_id.utf8())); 297 characteristic_instance_id.utf8()));
307 } 298 }
308 299
309 void BluetoothDispatcher::writeValue( 300 void BluetoothDispatcher::writeValue(
310 int frame_routing_id, 301 int frame_routing_id,
311 const blink::WebString& characteristic_instance_id, 302 const blink::WebString& characteristic_instance_id,
312 const blink::WebVector<uint8_t>& value, 303 const blink::WebVector<uint8_t>& value,
313 blink::WebBluetoothWriteValueCallbacks* callbacks) { 304 blink::WebBluetoothWriteValueCallbacks* callbacks) {
314 int request_id = pending_write_value_requests_.Add( 305 GetBluetoothService()->RemoteCharacteristicWriteValue(
315 new BluetoothWriteValueRequest(value, callbacks)); 306 frame_routing_id, mojo::String::From(characteristic_instance_id),
316 Send(new BluetoothHostMsg_WriteValue( 307 mojo::Array<uint8_t>::From(value),
317 CurrentWorkerId(), request_id, frame_routing_id, 308 base::Bind(&BluetoothDispatcher::OnWriteValue, base::Unretained(this),
ortuno 2016/03/09 01:21:23 This is safe because if the class gets destroyed t
Ken Rockot(use gerrit already) 2016/03/09 19:31:26 Correct, the callback will never be invoked if the
318 characteristic_instance_id.utf8(), 309 value, base::Passed(make_scoped_ptr(callbacks))));
319 std::vector<uint8_t>(value.begin(), value.end()))); 310 }
311
312 void BluetoothDispatcher::OnWriteValue(
313 const blink::WebVector<uint8_t>& value,
314 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks,
315 blink::mojom::WebBluetoothError error) {
316 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
ortuno 2016/03/09 01:21:23 It would be nice if there was a way we could do th
Ken Rockot(use gerrit already) 2016/03/09 19:31:26 Can you elaborate on what a more ideal situation w
ortuno 2016/03/16 16:29:45 Jeffrey started a thread about it a while ago: htt
317 callbacks->onSuccess(value);
318 } else {
319 callbacks->onError(error);
320 }
320 } 321 }
321 322
322 void BluetoothDispatcher::startNotifications( 323 void BluetoothDispatcher::startNotifications(
323 int frame_routing_id, 324 int frame_routing_id,
324 const blink::WebString& characteristic_instance_id, 325 const blink::WebString& characteristic_instance_id,
325 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, 326 blink::WebBluetoothRemoteGATTCharacteristic* characteristic,
326 blink::WebBluetoothNotificationsCallbacks* callbacks) { 327 blink::WebBluetoothNotificationsCallbacks* callbacks) {
327 int request_id = QueueNotificationRequest( 328 int request_id = QueueNotificationRequest(
328 frame_routing_id, characteristic_instance_id.utf8(), characteristic, 329 frame_routing_id, characteristic_instance_id.utf8(), characteristic,
329 callbacks, NotificationsRequestType::START); 330 callbacks, NotificationsRequestType::START);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 ->onSuccess(blink::adoptWebPtr(new WebBluetoothDevice( 623 ->onSuccess(blink::adoptWebPtr(new WebBluetoothDevice(
623 WebString::fromUTF8(device.id), WebString(device.name), 624 WebString::fromUTF8(device.id), WebString(device.name),
624 device.tx_power, device.rssi, device.device_class, 625 device.tx_power, device.rssi, device.device_class,
625 GetWebVendorIdSource(device.vendor_id_source), device.vendor_id, 626 GetWebVendorIdSource(device.vendor_id_source), device.vendor_id,
626 device.product_id, device.product_version, uuids))); 627 device.product_id, device.product_version, uuids)));
627 pending_requests_.Remove(request_id); 628 pending_requests_.Remove(request_id);
628 } 629 }
629 630
630 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, 631 void BluetoothDispatcher::OnRequestDeviceError(int thread_id,
631 int request_id, 632 int request_id,
632 WebBluetoothError error) { 633 blink::WebBluetoothError error) {
633 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 634 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
634 pending_requests_.Lookup(request_id)->onError(WebBluetoothError(error)); 635 pending_requests_.Lookup(request_id)
636 ->onError(blink::WebBluetoothError(error));
635 pending_requests_.Remove(request_id); 637 pending_requests_.Remove(request_id);
636 } 638 }
637 639
638 void BluetoothDispatcher::OnGATTServerConnectSuccess(int thread_id, 640 void BluetoothDispatcher::OnGATTServerConnectSuccess(int thread_id,
639 int request_id) { 641 int request_id) {
640 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; 642 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
641 pending_connect_requests_.Lookup(request_id)->onSuccess(); 643 pending_connect_requests_.Lookup(request_id)->onSuccess();
642 pending_connect_requests_.Remove(request_id); 644 pending_connect_requests_.Remove(request_id);
643 } 645 }
644 646
645 void BluetoothDispatcher::OnGATTServerConnectError(int thread_id, 647 void BluetoothDispatcher::OnGATTServerConnectError(
646 int request_id, 648 int thread_id,
647 WebBluetoothError error) { 649 int request_id,
650 blink::WebBluetoothError error) {
648 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; 651 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
649 pending_connect_requests_.Lookup(request_id) 652 pending_connect_requests_.Lookup(request_id)
650 ->onError(WebBluetoothError(error)); 653 ->onError(blink::WebBluetoothError(error));
651 pending_connect_requests_.Remove(request_id); 654 pending_connect_requests_.Remove(request_id);
652 } 655 }
653 656
654 void BluetoothDispatcher::OnGetPrimaryServiceSuccess( 657 void BluetoothDispatcher::OnGetPrimaryServiceSuccess(
655 int thread_id, 658 int thread_id,
656 int request_id, 659 int request_id,
657 const std::string& service_instance_id) { 660 const std::string& service_instance_id) {
658 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; 661 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
659 BluetoothPrimaryServiceRequest* request = 662 BluetoothPrimaryServiceRequest* request =
660 pending_primary_service_requests_.Lookup(request_id); 663 pending_primary_service_requests_.Lookup(request_id);
661 request->callbacks->onSuccess( 664 request->callbacks->onSuccess(
662 blink::adoptWebPtr(new WebBluetoothRemoteGATTService( 665 blink::adoptWebPtr(new WebBluetoothRemoteGATTService(
663 WebString::fromUTF8(service_instance_id), request->service_uuid, 666 WebString::fromUTF8(service_instance_id), request->service_uuid,
664 true /* isPrimary */, request->device_id))); 667 true /* isPrimary */, request->device_id)));
665 pending_primary_service_requests_.Remove(request_id); 668 pending_primary_service_requests_.Remove(request_id);
666 } 669 }
667 670
668 void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id, 671 void BluetoothDispatcher::OnGetPrimaryServiceError(
669 int request_id, 672 int thread_id,
670 WebBluetoothError error) { 673 int request_id,
674 blink::WebBluetoothError error) {
671 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; 675 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
672 676
673 pending_primary_service_requests_.Lookup(request_id) 677 pending_primary_service_requests_.Lookup(request_id)
674 ->callbacks->onError(WebBluetoothError(error)); 678 ->callbacks->onError(blink::WebBluetoothError(error));
675 pending_primary_service_requests_.Remove(request_id); 679 pending_primary_service_requests_.Remove(request_id);
676 } 680 }
677 681
678 void BluetoothDispatcher::OnGetCharacteristicSuccess( 682 void BluetoothDispatcher::OnGetCharacteristicSuccess(
679 int thread_id, 683 int thread_id,
680 int request_id, 684 int request_id,
681 const std::string& characteristic_instance_id, 685 const std::string& characteristic_instance_id,
682 uint32_t characteristic_properties) { 686 uint32_t characteristic_properties) {
683 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; 687 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
684 688
685 BluetoothCharacteristicRequest* request = 689 BluetoothCharacteristicRequest* request =
686 pending_characteristic_requests_.Lookup(request_id); 690 pending_characteristic_requests_.Lookup(request_id);
687 request->callbacks->onSuccess( 691 request->callbacks->onSuccess(
688 blink::adoptWebPtr(new WebBluetoothRemoteGATTCharacteristicInit( 692 blink::adoptWebPtr(new WebBluetoothRemoteGATTCharacteristicInit(
689 request->service_instance_id, 693 request->service_instance_id,
690 WebString::fromUTF8(characteristic_instance_id), 694 WebString::fromUTF8(characteristic_instance_id),
691 request->characteristic_uuid, characteristic_properties))); 695 request->characteristic_uuid, characteristic_properties)));
692 696
693 pending_characteristic_requests_.Remove(request_id); 697 pending_characteristic_requests_.Remove(request_id);
694 } 698 }
695 699
696 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, 700 void BluetoothDispatcher::OnGetCharacteristicError(
697 int request_id, 701 int thread_id,
698 WebBluetoothError error) { 702 int request_id,
703 blink::WebBluetoothError error) {
699 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; 704 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
700 705
701 pending_characteristic_requests_.Lookup(request_id) 706 pending_characteristic_requests_.Lookup(request_id)
702 ->callbacks->onError(WebBluetoothError(error)); 707 ->callbacks->onError(blink::WebBluetoothError(error));
703 708
704 pending_characteristic_requests_.Remove(request_id); 709 pending_characteristic_requests_.Remove(request_id);
705 } 710 }
706 711
707 void BluetoothDispatcher::OnGetCharacteristicsSuccess( 712 void BluetoothDispatcher::OnGetCharacteristicsSuccess(
708 int thread_id, 713 int thread_id,
709 int request_id, 714 int request_id,
710 const std::vector<std::string>& characteristics_instance_ids, 715 const std::vector<std::string>& characteristics_instance_ids,
711 const std::vector<std::string>& characteristics_uuids, 716 const std::vector<std::string>& characteristics_uuids,
712 const std::vector<uint32_t>& characteristics_properties) { 717 const std::vector<uint32_t>& characteristics_properties) {
(...skipping 12 matching lines...) Expand all
725 WebString::fromUTF8(characteristics_instance_ids[i]), 730 WebString::fromUTF8(characteristics_instance_ids[i]),
726 WebString::fromUTF8(characteristics_uuids[i]), 731 WebString::fromUTF8(characteristics_uuids[i]),
727 characteristics_properties[i]); 732 characteristics_properties[i]);
728 } 733 }
729 734
730 request->callbacks->onSuccess(blink::adoptWebPtr(characteristics)); 735 request->callbacks->onSuccess(blink::adoptWebPtr(characteristics));
731 736
732 pending_characteristics_requests_.Remove(request_id); 737 pending_characteristics_requests_.Remove(request_id);
733 } 738 }
734 739
735 void BluetoothDispatcher::OnGetCharacteristicsError(int thread_id, 740 void BluetoothDispatcher::OnGetCharacteristicsError(
736 int request_id, 741 int thread_id,
737 WebBluetoothError error) { 742 int request_id,
743 blink::WebBluetoothError error) {
738 DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id; 744 DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id;
739 745
740 pending_characteristics_requests_.Lookup(request_id) 746 pending_characteristics_requests_.Lookup(request_id)
741 ->callbacks->onError(WebBluetoothError(error)); 747 ->callbacks->onError(blink::WebBluetoothError(error));
742 748
743 pending_characteristics_requests_.Remove(request_id); 749 pending_characteristics_requests_.Remove(request_id);
744 } 750 }
745 751
746 void BluetoothDispatcher::OnReadValueSuccess( 752 void BluetoothDispatcher::OnReadValueSuccess(
747 int thread_id, 753 int thread_id,
748 int request_id, 754 int request_id,
749 const std::vector<uint8_t>& value) { 755 const std::vector<uint8_t>& value) {
750 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; 756 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
751 757
752 // WebArrayBuffer is not accessible from Source/modules so we pass a 758 // WebArrayBuffer is not accessible from Source/modules so we pass a
753 // WebVector instead. 759 // WebVector instead.
754 pending_read_value_requests_.Lookup(request_id)->onSuccess(value); 760 pending_read_value_requests_.Lookup(request_id)->onSuccess(value);
755 761
756 pending_read_value_requests_.Remove(request_id); 762 pending_read_value_requests_.Remove(request_id);
757 } 763 }
758 764
759 void BluetoothDispatcher::OnReadValueError(int thread_id, 765 void BluetoothDispatcher::OnReadValueError(int thread_id,
760 int request_id, 766 int request_id,
761 WebBluetoothError error) { 767 blink::WebBluetoothError error) {
762 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; 768 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
763 769
764 pending_read_value_requests_.Lookup(request_id) 770 pending_read_value_requests_.Lookup(request_id)
765 ->onError(WebBluetoothError(error)); 771 ->onError(blink::WebBluetoothError(error));
766 772
767 pending_read_value_requests_.Remove(request_id); 773 pending_read_value_requests_.Remove(request_id);
768 } 774 }
769 775
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, 776 void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id,
793 int request_id) { 777 int request_id) {
794 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id; 778 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id;
795 779
796 BluetoothNotificationsRequest* request = 780 BluetoothNotificationsRequest* request =
797 pending_notifications_requests_.Lookup(request_id); 781 pending_notifications_requests_.Lookup(request_id);
798 782
799 DCHECK(notification_requests_queues_[request->characteristic_instance_id] 783 DCHECK(notification_requests_queues_[request->characteristic_instance_id]
800 .front() == request_id); 784 .front() == request_id);
801 785
(...skipping 16 matching lines...) Expand all
818 request->frame_routing_id, request->characteristic_instance_id, 802 request->frame_routing_id, request->characteristic_instance_id,
819 nullptr /* characteristic */, nullptr /* callbacks */, 803 nullptr /* characteristic */, nullptr /* callbacks */,
820 NotificationsRequestType::STOP); 804 NotificationsRequestType::STOP);
821 } 805 }
822 806
823 request->callbacks->onSuccess(); 807 request->callbacks->onSuccess();
824 808
825 PopNotificationRequestQueueAndProcessNext(request_id); 809 PopNotificationRequestQueueAndProcessNext(request_id);
826 } 810 }
827 811
828 void BluetoothDispatcher::OnStartNotificationsError(int thread_id, 812 void BluetoothDispatcher::OnStartNotificationsError(
829 int request_id, 813 int thread_id,
830 WebBluetoothError error) { 814 int request_id,
815 blink::WebBluetoothError error) {
831 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id; 816 DCHECK(pending_notifications_requests_.Lookup(request_id)) << request_id;
832 817
833 BluetoothNotificationsRequest* request = 818 BluetoothNotificationsRequest* request =
834 pending_notifications_requests_.Lookup(request_id); 819 pending_notifications_requests_.Lookup(request_id);
835 820
836 DCHECK(notification_requests_queues_[request->characteristic_instance_id] 821 DCHECK(notification_requests_queues_[request->characteristic_instance_id]
837 .front() == request_id); 822 .front() == request_id);
838 823
839 // We only send an IPC for inactive notifications. 824 // We only send an IPC for inactive notifications.
840 DCHECK( 825 DCHECK(
(...skipping 28 matching lines...) Expand all
869 void BluetoothDispatcher::OnCharacteristicValueChanged( 854 void BluetoothDispatcher::OnCharacteristicValueChanged(
870 int thread_id, 855 int thread_id,
871 const std::string& characteristic_instance_id, 856 const std::string& characteristic_instance_id,
872 const std::vector<uint8_t> new_value) { 857 const std::vector<uint8_t> new_value) {
873 auto active_iter = active_characteristics_.find(characteristic_instance_id); 858 auto active_iter = active_characteristics_.find(characteristic_instance_id);
874 if (active_iter != active_characteristics_.end()) { 859 if (active_iter != active_characteristics_.end()) {
875 active_iter->second->dispatchCharacteristicValueChanged(new_value); 860 active_iter->second->dispatchCharacteristicValueChanged(new_value);
876 } 861 }
877 } 862 }
878 863
864 mojom::BluetoothServicePtr& BluetoothDispatcher::GetBluetoothService() {
865 if (!bluetooth_service_) {
866 service_registry_->ConnectToRemoteService(
867 mojo::GetProxy(&bluetooth_service_));
868 }
869 return bluetooth_service_;
870 }
871
879 } // namespace content 872 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698