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

Unified Diff: content/renderer/bluetooth/web_bluetooth_impl.cc

Issue 2506813003: Use new wrapper types for web_bluetooth.mojom (Closed)
Patch Set: address comments Created 4 years, 1 month 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 ebfcce61da8aec0458e0e6be632de281274c1177..86334a6a03c146c992d97a8705b5524c96794168 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -170,15 +170,14 @@ void WebBluetoothImpl::registerCharacteristicObject(
}
void WebBluetoothImpl::RemoteCharacteristicValueChanged(
- const mojo::String& characteristic_instance_id,
- mojo::Array<uint8_t> value) {
+ const std::string& characteristic_instance_id,
+ const std::vector<uint8_t>& value) {
// 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()));
+ base::Unretained(this), characteristic_instance_id, value));
}
void WebBluetoothImpl::OnRequestDeviceComplete(
@@ -188,8 +187,8 @@ void WebBluetoothImpl::OnRequestDeviceComplete(
if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>(
blink::WebString::fromUTF8(device->id.str()),
- device->name.is_null() ? blink::WebString()
- : blink::WebString::fromUTF8(device->name)));
+ device->name ? blink::WebString::fromUTF8(device->name.value().c_str())
+ : blink::WebString()));
} else {
callbacks->onError(ToInt32(result));
}
@@ -223,17 +222,18 @@ void WebBluetoothImpl::OnGetPrimaryServicesComplete(
const blink::WebString& device_id,
std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks,
blink::mojom::WebBluetoothResult result,
- mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services) {
+ base::Optional<std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr>>
+ services) {
if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
+ DCHECK(services);
// TODO(dcheng): This WebVector should use smart pointers.
blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services(
- services.size());
-
- for (size_t i = 0; i < services.size(); i++) {
+ services->size());
+ for (size_t i = 0; i < services->size(); i++) {
promise_services[i] = new blink::WebBluetoothRemoteGATTService(
- blink::WebString::fromUTF8(services[i]->instance_id),
- blink::WebString::fromUTF8(services[i]->uuid), true /* isPrimary */,
- device_id);
+ blink::WebString::fromUTF8(services.value()[i]->instance_id),
+ blink::WebString::fromUTF8(services.value()[i]->uuid),
+ true /* isPrimary */, device_id);
}
callbacks->onSuccess(promise_services);
} else {
@@ -245,20 +245,21 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete(
const blink::WebString& service_instance_id,
std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
blink::mojom::WebBluetoothResult result,
- mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
+ base::Optional<
+ std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>>
characteristics) {
if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
+ DCHECK(characteristics);
// TODO(dcheng): This WebVector should use smart pointers.
blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*>
- promise_characteristics(characteristics.size());
-
- for (size_t i = 0; i < characteristics.size(); i++) {
+ promise_characteristics(characteristics->size());
+ for (size_t i = 0; i < characteristics->size(); i++) {
promise_characteristics[i] =
new blink::WebBluetoothRemoteGATTCharacteristicInit(
- service_instance_id,
- blink::WebString::fromUTF8(characteristics[i]->instance_id),
- blink::WebString::fromUTF8(characteristics[i]->uuid),
- characteristics[i]->properties);
+ service_instance_id, blink::WebString::fromUTF8(
+ characteristics.value()[i]->instance_id),
+ blink::WebString::fromUTF8(characteristics.value()[i]->uuid),
+ characteristics.value()[i]->properties);
}
callbacks->onSuccess(promise_characteristics);
} else {
@@ -269,9 +270,10 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete(
void WebBluetoothImpl::OnReadValueComplete(
std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
blink::mojom::WebBluetoothResult result,
- mojo::Array<uint8_t> value) {
+ const base::Optional<std::vector<uint8_t>>& value) {
if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
- callbacks->onSuccess(value.PassStorage());
+ DCHECK(value);
+ callbacks->onSuccess(std::move(value.value()));
} else {
callbacks->onError(ToInt32(result));
}
@@ -307,9 +309,8 @@ 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()) {
+ if (active_iter != active_characteristics_.end())
active_iter->second->dispatchCharacteristicValueChanged(value);
- }
}
blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() {

Powered by Google App Engine
This is Rietveld 408576698