Chromium Code Reviews| 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..6e4765e54087e7735c62ff67b0031a294854fe58 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,21 @@ 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) { |
| // 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++) { |
| - promise_services[i] = new blink::WebBluetoothRemoteGATTService( |
| - blink::WebString::fromUTF8(services[i]->instance_id), |
| - blink::WebString::fromUTF8(services[i]->uuid), true /* isPrimary */, |
| - device_id); |
| + blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services; |
| + if (services) { |
|
ortuno
2016/11/21 04:42:31
Just DCHECK. If result == SUCCESS then we are guar
juncai
2016/11/21 21:27:05
Done.
|
| + blink::WebVector<blink::WebBluetoothRemoteGATTService*> tmp( |
| + services->size()); |
| + promise_services.swap(tmp); |
| + for (size_t i = 0; i < services->size(); i++) { |
| + promise_services[i] = new blink::WebBluetoothRemoteGATTService( |
| + 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 +248,26 @@ 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) { |
| // 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[i] = |
| - new blink::WebBluetoothRemoteGATTCharacteristicInit( |
| - service_instance_id, |
| - blink::WebString::fromUTF8(characteristics[i]->instance_id), |
| - blink::WebString::fromUTF8(characteristics[i]->uuid), |
| - characteristics[i]->properties); |
| + promise_characteristics; |
| + if (characteristics) { |
|
ortuno
2016/11/21 04:42:31
Same here. Just DCHECK.
juncai
2016/11/21 21:27:05
Done.
|
| + blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*> tmp( |
| + characteristics->size()); |
| + promise_characteristics.swap(tmp); |
| + for (size_t i = 0; i < characteristics->size(); i++) { |
| + promise_characteristics[i] = |
| + new blink::WebBluetoothRemoteGATTCharacteristicInit( |
| + 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 +278,9 @@ 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()); |
| + callbacks->onSuccess(value ? value.value() : std::vector<uint8_t>()); |
|
ortuno
2016/11/21 04:42:31
And here as well. Just DCHECK. Also does it make s
juncai
2016/11/21 21:27:05
Done.
|
| } else { |
| callbacks->onError(ToInt32(result)); |
| } |