Index: content/browser/bluetooth/web_bluetooth_service_impl.cc |
diff --git a/content/browser/bluetooth/web_bluetooth_service_impl.cc b/content/browser/bluetooth/web_bluetooth_service_impl.cc |
index 8f979a32b2cfaa9510db8f7fa88fe7d3d33cde0a..978aa88468219fdf3c73719494ea4787aad60b7b 100644 |
--- a/content/browser/bluetooth/web_bluetooth_service_impl.cc |
+++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc |
@@ -135,6 +135,42 @@ void WebBluetoothServiceImpl::SetClient( |
client_.Bind(std::move(client)); |
} |
+void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( |
+ const mojo::String& characteristic_instance_id, |
+ const RemoteCharacteristicReadValueCallback& callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ RecordWebBluetoothFunctionCall( |
+ UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); |
+ |
+ const CacheQueryResult query_result = |
+ GetBluetoothDispatcherHost()->QueryCacheForCharacteristic( |
+ GetOrigin(), characteristic_instance_id); |
+ |
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
+ return; |
+ } |
+ |
+ if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
+ RecordCharacteristicReadValueOutcome(query_result.outcome); |
+ callback.Run(query_result.GetWebError(), nullptr /* value */); |
+ return; |
+ } |
+ |
+ if (BluetoothBlacklist::Get().IsExcludedFromReads( |
+ query_result.characteristic->GetUUID())) { |
+ RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); |
+ callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_READ, |
+ nullptr /* value */); |
+ return; |
+ } |
+ |
+ query_result.characteristic->ReadRemoteCharacteristic( |
+ base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, |
+ weak_ptr_factory_.GetWeakPtr(), callback), |
+ base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
+} |
+ |
void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( |
const mojo::String& characteristic_instance_id, |
mojo::Array<uint8_t> value, |
@@ -258,6 +294,24 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( |
weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); |
} |
+void WebBluetoothServiceImpl::OnReadValueSuccess( |
+ const RemoteCharacteristicReadValueCallback& callback, |
+ const std::vector<uint8_t>& value) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
+ callback.Run(blink::mojom::WebBluetoothError::SUCCESS, |
+ mojo::Array<uint8_t>::From(value)); |
+} |
+ |
+void WebBluetoothServiceImpl::OnReadValueFailed( |
+ const RemoteCharacteristicReadValueCallback& callback, |
+ device::BluetoothGattService::GattErrorCode error_code) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ callback.Run(TranslateGATTErrorAndRecord( |
+ error_code, UMAGATTOperation::CHARACTERISTIC_READ), |
+ nullptr /* value */); |
+} |
+ |
void WebBluetoothServiceImpl::OnWriteValueSuccess( |
const RemoteCharacteristicWriteValueCallback& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |