| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 std::set<BluetoothUUID> union_of_services(optional_services.begin(), | 104 std::set<BluetoothUUID> union_of_services(optional_services.begin(), |
| 105 optional_services.end()); | 105 optional_services.end()); |
| 106 | 106 |
| 107 for (const content::BluetoothScanFilter& filter : filters) | 107 for (const content::BluetoothScanFilter& filter : filters) |
| 108 union_of_services.insert(filter.services.begin(), filter.services.end()); | 108 union_of_services.insert(filter.services.begin(), filter.services.end()); |
| 109 | 109 |
| 110 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", | 110 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", |
| 111 union_of_services.size()); | 111 union_of_services.size()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 enum class UMAGetPrimaryServiceOutcome { |
| 115 SUCCESS, |
| 116 NO_DEVICE, |
| 117 NOT_FOUND, |
| 118 // Note: Add new GetPrimaryService outcomes immediately above this line. Make |
| 119 // sure to update the enum list in tools/metrics/histograms/histograms.xml |
| 120 // accordingly. |
| 121 COUNT |
| 122 }; |
| 123 |
| 124 void RecordGetPrimaryServiceService(const BluetoothUUID& service) { |
| 125 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services", |
| 126 HashUUID(service)); |
| 127 } |
| 128 |
| 129 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) { |
| 130 UMA_HISTOGRAM_ENUMERATION( |
| 131 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome), |
| 132 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT)); |
| 133 } |
| 134 |
| 114 enum class UMAConnectGATTOutcome { | 135 enum class UMAConnectGATTOutcome { |
| 115 SUCCESS, | 136 SUCCESS, |
| 116 NO_DEVICE, | 137 NO_DEVICE, |
| 117 UNKNOWN, | 138 UNKNOWN, |
| 118 IN_PROGRESS, | 139 IN_PROGRESS, |
| 119 FAILED, | 140 FAILED, |
| 120 AUTH_FAILED, | 141 AUTH_FAILED, |
| 121 AUTH_CANCELED, | 142 AUTH_CANCELED, |
| 122 AUTH_REJECTED, | 143 AUTH_REJECTED, |
| 123 AUTH_TIMEOUT, | 144 AUTH_TIMEOUT, |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 device_instance_id, start_time)); | 489 device_instance_id, start_time)); |
| 469 } | 490 } |
| 470 | 491 |
| 471 void BluetoothDispatcherHost::OnGetPrimaryService( | 492 void BluetoothDispatcherHost::OnGetPrimaryService( |
| 472 int thread_id, | 493 int thread_id, |
| 473 int request_id, | 494 int request_id, |
| 474 const std::string& device_instance_id, | 495 const std::string& device_instance_id, |
| 475 const std::string& service_uuid) { | 496 const std::string& service_uuid) { |
| 476 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 497 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 477 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); | 498 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); |
| 499 RecordGetPrimaryServiceService(BluetoothUUID(service_uuid)); |
| 478 | 500 |
| 479 // TODO(ortuno): Check if device_instance_id is in "allowed devices" | 501 // TODO(ortuno): Check if device_instance_id is in "allowed devices" |
| 480 // https://crbug.com/493459 | 502 // https://crbug.com/493459 |
| 481 // TODO(ortuno): Check if service_uuid is in "allowed services" | 503 // TODO(ortuno): Check if service_uuid is in "allowed services" |
| 482 // https://crbug.com/493460 | 504 // https://crbug.com/493460 |
| 483 // For now just wait a fixed time and call OnServiceDiscovered. | 505 // For now just wait a fixed time and call OnServiceDiscovered. |
| 484 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 | 506 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 |
| 485 BrowserThread::PostDelayedTask( | 507 BrowserThread::PostDelayedTask( |
| 486 BrowserThread::UI, FROM_HERE, | 508 BrowserThread::UI, FROM_HERE, |
| 487 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, | 509 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 813 |
| 792 void BluetoothDispatcherHost::OnServicesDiscovered( | 814 void BluetoothDispatcherHost::OnServicesDiscovered( |
| 793 int thread_id, | 815 int thread_id, |
| 794 int request_id, | 816 int request_id, |
| 795 const std::string& device_instance_id, | 817 const std::string& device_instance_id, |
| 796 const std::string& service_uuid) { | 818 const std::string& service_uuid) { |
| 797 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 819 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 798 | 820 |
| 799 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); | 821 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); |
| 800 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | 822 if (device == nullptr) { // See "NETWORK_ERROR Note" above. |
| 823 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NO_DEVICE); |
| 824 VLOG(1) << "Bluetooth Device is no longer in range."; |
| 801 Send(new BluetoothMsg_GetPrimaryServiceError( | 825 Send(new BluetoothMsg_GetPrimaryServiceError( |
| 802 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | 826 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); |
| 803 return; | 827 return; |
| 804 } | 828 } |
| 805 for (BluetoothGattService* service : device->GetGattServices()) { | 829 for (BluetoothGattService* service : device->GetGattServices()) { |
| 806 if (service->GetUUID().canonical_value() == service_uuid) { | 830 if (service->GetUUID().canonical_value() == service_uuid) { |
| 807 // TODO(ortuno): Use generated instance ID instead. | 831 // TODO(ortuno): Use generated instance ID instead. |
| 808 // https://crbug.com/495379 | 832 // https://crbug.com/495379 |
| 809 const std::string& service_identifier = service->GetIdentifier(); | 833 const std::string& service_identifier = service->GetIdentifier(); |
| 810 auto insert_result = service_to_device_.insert( | 834 auto insert_result = service_to_device_.insert( |
| 811 make_pair(service_identifier, device_instance_id)); | 835 make_pair(service_identifier, device_instance_id)); |
| 812 | 836 |
| 813 // If a value is already in map, DCHECK it's valid. | 837 // If a value is already in map, DCHECK it's valid. |
| 814 if (!insert_result.second) | 838 if (!insert_result.second) |
| 815 DCHECK(insert_result.first->second == device_instance_id); | 839 DCHECK(insert_result.first->second == device_instance_id); |
| 816 | 840 |
| 841 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS); |
| 817 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, | 842 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, |
| 818 service_identifier)); | 843 service_identifier)); |
| 819 return; | 844 return; |
| 820 } | 845 } |
| 821 } | 846 } |
| 847 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); |
| 848 VLOG(1) << "No GATT services with UUID: " << service_uuid; |
| 822 Send(new BluetoothMsg_GetPrimaryServiceError( | 849 Send(new BluetoothMsg_GetPrimaryServiceError( |
| 823 thread_id, request_id, WebBluetoothError::ServiceNotFound)); | 850 thread_id, request_id, WebBluetoothError::ServiceNotFound)); |
| 824 } | 851 } |
| 825 | 852 |
| 826 void BluetoothDispatcherHost::OnCharacteristicValueRead( | 853 void BluetoothDispatcherHost::OnCharacteristicValueRead( |
| 827 int thread_id, | 854 int thread_id, |
| 828 int request_id, | 855 int request_id, |
| 829 const std::vector<uint8>& value) { | 856 const std::vector<uint8>& value) { |
| 830 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, | 857 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, |
| 831 value)); | 858 value)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 846 | 873 |
| 847 void BluetoothDispatcherHost::OnWriteValueFailed( | 874 void BluetoothDispatcherHost::OnWriteValueFailed( |
| 848 int thread_id, | 875 int thread_id, |
| 849 int request_id, | 876 int request_id, |
| 850 device::BluetoothGattService::GattErrorCode error_code) { | 877 device::BluetoothGattService::GattErrorCode error_code) { |
| 851 Send(new BluetoothMsg_WriteCharacteristicValueError( | 878 Send(new BluetoothMsg_WriteCharacteristicValueError( |
| 852 thread_id, request_id, TranslateGATTError(error_code))); | 879 thread_id, request_id, TranslateGATTError(error_code))); |
| 853 } | 880 } |
| 854 | 881 |
| 855 } // namespace content | 882 } // namespace content |
| OLD | NEW |