Chromium Code Reviews| 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 // NETWORK_ERROR Note: | 5 // NETWORK_ERROR Note: |
| 6 // When a device can't be found in the BluetoothAdapter, that generally | 6 // When a device can't be found in the BluetoothAdapter, that generally |
| 7 // indicates that it's gone out of range. We reject with a NetworkError in that | 7 // indicates that it's gone out of range. We reject with a NetworkError in that |
| 8 // case. | 8 // case. |
| 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt | 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt |
| 10 | 10 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 192 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 194 bool handled = true; | 194 bool handled = true; |
| 195 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) | 195 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) |
| 196 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) | 196 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) |
| 197 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) | 197 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
| 198 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) | 198 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) |
| 199 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) | 199 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
| 200 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) | 200 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) |
| 201 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) | 201 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) |
| 202 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications) | |
| 203 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications) | |
| 202 IPC_MESSAGE_UNHANDLED(handled = false) | 204 IPC_MESSAGE_UNHANDLED(handled = false) |
| 203 IPC_END_MESSAGE_MAP() | 205 IPC_END_MESSAGE_MAP() |
| 204 return handled; | 206 return handled; |
| 205 } | 207 } |
| 206 | 208 |
| 207 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( | 209 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( |
| 208 scoped_refptr<device::BluetoothAdapter> mock_adapter) { | 210 scoped_refptr<device::BluetoothAdapter> mock_adapter) { |
| 209 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 211 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 210 current_delay_time_ = kTestingDelayTime; | 212 current_delay_time_ = kTestingDelayTime; |
| 211 // Reset the discovery session timer to use the new delay time. | 213 // Reset the discovery session timer to use the new delay time. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( | 342 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( |
| 341 &request_device_sessions_); | 343 &request_device_sessions_); |
| 342 !iter.IsAtEnd(); iter.Advance()) { | 344 !iter.IsAtEnd(); iter.Advance()) { |
| 343 RequestDeviceSession* session = iter.GetCurrentValue(); | 345 RequestDeviceSession* session = iter.GetCurrentValue(); |
| 344 if (session->chooser) { | 346 if (session->chooser) { |
| 345 session->chooser->RemoveDevice(device->GetAddress()); | 347 session->chooser->RemoveDevice(device->GetAddress()); |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 } | 350 } |
| 349 | 351 |
| 352 void BluetoothDispatcherHost::GattCharacteristicValueChanged( | |
| 353 device::BluetoothAdapter* adapter, | |
| 354 device::BluetoothGattCharacteristic* characteristic, | |
| 355 const std::vector<uint8>& value) { | |
| 356 // TODO(ortuno): Notify renderer the characteristic changed. | |
| 357 // http://crbug.com/529560 | |
| 358 VLOG(1) << "Characteristic updated."; | |
| 359 } | |
| 360 | |
| 350 void BluetoothDispatcherHost::OnRequestDevice( | 361 void BluetoothDispatcherHost::OnRequestDevice( |
| 351 int thread_id, | 362 int thread_id, |
| 352 int request_id, | 363 int request_id, |
| 353 int frame_routing_id, | 364 int frame_routing_id, |
| 354 const std::vector<BluetoothScanFilter>& filters, | 365 const std::vector<BluetoothScanFilter>& filters, |
| 355 const std::vector<BluetoothUUID>& optional_services) { | 366 const std::vector<BluetoothUUID>& optional_services) { |
| 356 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 367 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 357 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 368 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
| 358 RecordRequestDeviceArguments(filters, optional_services); | 369 RecordRequestDeviceArguments(filters, optional_services); |
| 359 | 370 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 WebBluetoothError::CharacteristicNoLongerExists)); | 698 WebBluetoothError::CharacteristicNoLongerExists)); |
| 688 return; | 699 return; |
| 689 } | 700 } |
| 690 characteristic->WriteRemoteCharacteristic( | 701 characteristic->WriteRemoteCharacteristic( |
| 691 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, | 702 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, |
| 692 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | 703 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
| 693 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, | 704 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, |
| 694 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | 705 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| 695 } | 706 } |
| 696 | 707 |
| 708 void BluetoothDispatcherHost::OnStartNotifications( | |
| 709 int thread_id, | |
| 710 int request_id, | |
| 711 const std::string& characteristic_instance_id) { | |
| 712 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 713 RecordWebBluetoothFunctionCall( | |
| 714 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | |
| 715 | |
| 716 // Check if already subscribed to notifications. | |
| 717 auto notify_session_iter = | |
| 718 characteristic_id_to_notify_session_.find(characteristic_instance_id); | |
| 719 if (notify_session_iter != characteristic_id_to_notify_session_.end()) { | |
| 720 Send(new BluetoothMsg_StartNotificationsSuccess(thread_id, request_id)); | |
|
Jeffrey Yasskin
2015/09/25 23:03:19
This is vulnerable to races if a second BluetoothH
ortuno
2015/09/29 22:47:36
This code was wrote before I implemented the queue
| |
| 721 return; | |
| 722 } | |
| 723 | |
| 724 // TODO(ortuno): Check if notify/indicate bit is set. | |
|
Jeffrey Yasskin
2015/09/25 23:03:19
Add a blank line below this, since it's not connec
ortuno
2015/09/29 22:47:36
Done.
| |
| 725 auto characteristic_iter = | |
| 726 characteristic_to_service_.find(characteristic_instance_id); | |
| 727 // A characteristic_instance_id not in the map implies a hostile renderer | |
| 728 // because a renderer obtains the characteristic id from this class and | |
| 729 // it will be added to the map at that time. | |
| 730 if (characteristic_iter == characteristic_to_service_.end()) { | |
| 731 // Kill the renderer | |
| 732 bad_message::ReceivedBadMessage(this, | |
| 733 bad_message::BDH_INVALID_CHARACTERISTIC_ID); | |
| 734 return; | |
| 735 } | |
| 736 | |
| 737 const std::string& service_instance_id = characteristic_iter->second; | |
| 738 auto device_iter = service_to_device_.find(service_instance_id); | |
| 739 CHECK(device_iter != service_to_device_.end()); | |
| 740 | |
| 741 device::BluetoothDevice* device = | |
| 742 adapter_->GetDevice(device_iter->second /* device_instance_id */); | |
| 743 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | |
| 744 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_DEVICE); | |
| 745 Send(new BluetoothMsg_StartNotificationsError( | |
| 746 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | |
| 747 return; | |
| 748 } | |
| 749 | |
| 750 BluetoothGattService* service = device->GetGattService(service_instance_id); | |
| 751 if (service == nullptr) { | |
| 752 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_SERVICE); | |
| 753 Send(new BluetoothMsg_StartNotificationsError( | |
| 754 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); | |
| 755 return; | |
| 756 } | |
| 757 | |
| 758 BluetoothGattCharacteristic* characteristic = | |
| 759 service->GetCharacteristic(characteristic_instance_id); | |
| 760 if (characteristic == nullptr) { | |
| 761 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_CHARACTERISTIC); | |
| 762 Send(new BluetoothMsg_StartNotificationsError( | |
| 763 thread_id, request_id, | |
| 764 WebBluetoothError::CharacteristicNoLongerExists)); | |
| 765 return; | |
| 766 } | |
| 767 | |
| 768 characteristic->StartNotifySession( | |
| 769 base::Bind(&BluetoothDispatcherHost::OnStartNotifySessionSuccess, | |
| 770 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | |
| 771 base::Bind(&BluetoothDispatcherHost::OnStartNotifySessionFailed, | |
| 772 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | |
| 773 } | |
| 774 void BluetoothDispatcherHost::OnStopNotifications( | |
| 775 int thread_id, | |
| 776 int request_id, | |
| 777 const std::string& characteristic_instance_id) { | |
| 778 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 779 RecordWebBluetoothFunctionCall( | |
| 780 UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS); | |
| 781 | |
| 782 auto notify_session_iter = | |
| 783 characteristic_id_to_notify_session_.find(characteristic_instance_id); | |
| 784 if (notify_session_iter == characteristic_id_to_notify_session_.end()) { | |
| 785 Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); | |
| 786 return; | |
| 787 } | |
| 788 notify_session_iter->second->Stop( | |
| 789 base::Bind(&BluetoothDispatcherHost::OnStopNotifySession, | |
| 790 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | |
| 791 characteristic_instance_id)); | |
| 792 } | |
| 793 | |
| 697 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 794 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| 698 int chooser_id, | 795 int chooser_id, |
| 699 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 796 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 700 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 797 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 701 VLOG(1) << "Started discovery session for " << chooser_id; | 798 VLOG(1) << "Started discovery session for " << chooser_id; |
| 702 if (RequestDeviceSession* session = | 799 if (RequestDeviceSession* session = |
| 703 request_device_sessions_.Lookup(chooser_id)) { | 800 request_device_sessions_.Lookup(chooser_id)) { |
| 704 session->discovery_session = discovery_session.Pass(); | 801 session->discovery_session = discovery_session.Pass(); |
| 705 | 802 |
| 706 // Arrange to stop discovery later. | 803 // Arrange to stop discovery later. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 void BluetoothDispatcherHost::OnWriteValueFailed( | 1013 void BluetoothDispatcherHost::OnWriteValueFailed( |
| 917 int thread_id, | 1014 int thread_id, |
| 918 int request_id, | 1015 int request_id, |
| 919 device::BluetoothGattService::GattErrorCode error_code) { | 1016 device::BluetoothGattService::GattErrorCode error_code) { |
| 920 // TranslateGATTError calls RecordGATTOperationOutcome. | 1017 // TranslateGATTError calls RecordGATTOperationOutcome. |
| 921 Send(new BluetoothMsg_WriteCharacteristicValueError( | 1018 Send(new BluetoothMsg_WriteCharacteristicValueError( |
| 922 thread_id, request_id, | 1019 thread_id, request_id, |
| 923 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); | 1020 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); |
| 924 } | 1021 } |
| 925 | 1022 |
| 1023 void BluetoothDispatcherHost::OnStartNotifySessionSuccess( | |
| 1024 int thread_id, | |
| 1025 int request_id, | |
| 1026 scoped_ptr<device::BluetoothGattNotifySession> notify_session) { | |
| 1027 characteristic_id_to_notify_session_.insert( | |
| 1028 notify_session->GetCharacteristicIdentifier(), notify_session.Pass()); | |
| 1029 Send(new BluetoothMsg_StartNotificationsSuccess(thread_id, request_id)); | |
|
Jeffrey Yasskin
2015/09/25 23:03:19
Call RecordStartNotificationsOutcome() here, right
ortuno
2015/09/29 22:47:36
Done.
| |
| 1030 } | |
| 1031 | |
| 1032 void BluetoothDispatcherHost::OnStartNotifySessionFailed( | |
| 1033 int thread_id, | |
| 1034 int request_id, | |
| 1035 device::BluetoothGattService::GattErrorCode error_code) { | |
| 1036 // TranslateGATTError calls RecordGATTOperationOutcome. | |
| 1037 Send(new BluetoothMsg_StartNotificationsError( | |
| 1038 thread_id, request_id, | |
| 1039 TranslateGATTError(error_code, UMAGATTOperation::START_NOTIFICATIONS))); | |
| 1040 } | |
| 1041 | |
| 1042 void BluetoothDispatcherHost::OnStopNotifySession( | |
| 1043 int thread_id, | |
| 1044 int request_id, | |
| 1045 const std::string& characteristic_instance_id) { | |
| 1046 characteristic_id_to_notify_session_.erase(characteristic_instance_id); | |
| 1047 Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); | |
| 1048 } | |
| 1049 | |
| 926 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { | 1050 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { |
| 927 NOTIMPLEMENTED(); | 1051 NOTIMPLEMENTED(); |
| 928 } | 1052 } |
| 929 | 1053 |
| 930 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { | 1054 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { |
| 931 NOTIMPLEMENTED(); | 1055 NOTIMPLEMENTED(); |
| 932 } | 1056 } |
| 933 | 1057 |
| 934 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { | 1058 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { |
| 935 NOTIMPLEMENTED(); | 1059 NOTIMPLEMENTED(); |
| 936 } | 1060 } |
| 937 | 1061 |
| 938 } // namespace content | 1062 } // namespace content |
| OLD | NEW |