Chromium Code Reviews| 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 340d153db3fb31fc0fe2264d3e5b9cd3585a84fe..f7448be06e35788676d6d3e997c1041f5e11499c 100644 |
| --- a/content/browser/bluetooth/web_bluetooth_service_impl.cc |
| +++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc |
| @@ -133,6 +133,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, |
| @@ -256,6 +292,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)); |
|
Jeffrey Yasskin
2016/04/15 20:59:35
Do the by-value and move thing again here. (The ca
ortuno
2016/04/15 21:34:07
I tried but OnReadValueSuccess needs to be a Value
Jeffrey Yasskin
2016/04/15 21:38:52
That's a good reason. We should eventually fix tha
|
| +} |
| + |
| +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); |