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

Unified Diff: content/browser/bluetooth/web_bluetooth_service_impl.cc

Issue 1865613002: bluetooth: Move read value to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-notifications
Patch Set: Address jyasskin's comments Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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);
« no previous file with comments | « content/browser/bluetooth/web_bluetooth_service_impl.h ('k') | content/common/bluetooth/bluetooth_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698