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

Unified Diff: content/renderer/bluetooth/web_bluetooth_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/renderer/bluetooth/web_bluetooth_impl.cc
diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc
index 3f6286fe043628565d462de6abc804e0e6aad2fa..4dc301f448a5f18c42ba9885e61d22d010933e6f 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -71,8 +71,10 @@ void WebBluetoothImpl::getCharacteristics(
void WebBluetoothImpl::readValue(
const blink::WebString& characteristic_instance_id,
blink::WebBluetoothReadValueCallbacks* callbacks) {
- GetDispatcher()->readValue(frame_routing_id_, characteristic_instance_id,
- callbacks);
+ GetWebBluetoothService().RemoteCharacteristicReadValue(
+ mojo::String::From(characteristic_instance_id),
+ base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this),
+ base::Passed(base::WrapUnique(callbacks))));
}
void WebBluetoothImpl::writeValue(
@@ -126,10 +128,23 @@ void WebBluetoothImpl::registerCharacteristicObject(
void WebBluetoothImpl::RemoteCharacteristicValueChanged(
const mojo::String& characteristic_instance_id,
mojo::Array<uint8_t> value) {
- auto active_iter = active_characteristics_.find(characteristic_instance_id);
- if (active_iter != active_characteristics_.end()) {
- active_iter->second->dispatchCharacteristicValueChanged(
- value.PassStorage());
+ // We post a task so that the event is fired after any pending promises have
+ // resolved.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged,
+ base::Unretained(this), characteristic_instance_id,
+ value.PassStorage()));
+}
+
+void WebBluetoothImpl::OnReadValueComplete(
+ std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
+ blink::mojom::WebBluetoothError error,
+ mojo::Array<uint8_t> value) {
+ if (error == blink::mojom::WebBluetoothError::SUCCESS) {
+ callbacks->onSuccess(value.PassStorage());
+ } else {
+ callbacks->onError(error);
}
}
@@ -159,6 +174,15 @@ void WebBluetoothImpl::OnStopNotificationsComplete(
callbacks->onSuccess();
}
+void WebBluetoothImpl::DispatchCharacteristicValueChanged(
+ const std::string& characteristic_instance_id,
+ const std::vector<uint8_t>& value) {
+ auto active_iter = active_characteristics_.find(characteristic_instance_id);
+ if (active_iter != active_characteristics_.end()) {
+ active_iter->second->dispatchCharacteristicValueChanged(value);
+ }
+}
+
BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() {
return BluetoothDispatcher::GetOrCreateThreadSpecificInstance(
thread_safe_sender_.get());

Powered by Google App Engine
This is Rietveld 408576698