| 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 b4ee20fef4d531c53fa089eed3dac57c074edd7c..9779e009d5106311c7dc0764affce412bbe231eb 100644
|
| --- a/content/browser/bluetooth/web_bluetooth_service_impl.cc
|
| +++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc
|
| @@ -15,6 +15,7 @@
|
|
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| +#include "components/web_bluetooth/web_bluetooth_device_id.h"
|
| #include "content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h"
|
| #include "content/browser/bluetooth/bluetooth_blacklist.h"
|
| #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
|
| @@ -28,6 +29,7 @@
|
| #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
|
|
|
| using device::BluetoothUUID;
|
| +using web_bluetooth::WebBluetoothDeviceId;
|
|
|
| namespace content {
|
|
|
| @@ -236,13 +238,11 @@ void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter,
|
| device::BluetoothDevice* device) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| if (!device->IsGattConnected()) {
|
| - std::string device_id =
|
| + base::Optional<WebBluetoothDeviceId> device_id =
|
| connected_devices_->CloseConnectionToDeviceWithAddress(
|
| device->GetAddress());
|
| - if (!device_id.empty()) {
|
| - if (client_) {
|
| - client_->GattServerDisconnected(device_id);
|
| - }
|
| + if (device_id && client_) {
|
| + client_->GattServerDisconnected(device_id.value());
|
| }
|
| }
|
| }
|
| @@ -330,7 +330,7 @@ void WebBluetoothServiceImpl::RequestDevice(
|
| }
|
|
|
| void WebBluetoothServiceImpl::RemoteServerConnect(
|
| - const mojo::String& device_id,
|
| + const WebBluetoothDeviceId& device_id,
|
| const RemoteServerConnectCallback& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT);
|
| @@ -364,24 +364,23 @@ void WebBluetoothServiceImpl::RemoteServerConnect(
|
| weak_ptr_factory_.GetWeakPtr(), device_id, start_time,
|
| callback),
|
| base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed,
|
| - weak_ptr_factory_.GetWeakPtr(), device_id, start_time,
|
| - callback));
|
| + weak_ptr_factory_.GetWeakPtr(), start_time, callback));
|
| }
|
|
|
| void WebBluetoothServiceImpl::RemoteServerDisconnect(
|
| - const mojo::String& device_id) {
|
| + const WebBluetoothDeviceId& device_id) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| RecordWebBluetoothFunctionCall(
|
| UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT);
|
|
|
| if (connected_devices_->IsConnectedToDeviceWithId(device_id)) {
|
| - VLOG(1) << "Disconnecting device: " << device_id;
|
| + VLOG(1) << "Disconnecting device: " << device_id.str();
|
| connected_devices_->CloseConnectionToDeviceWithId(device_id);
|
| }
|
| }
|
|
|
| void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
|
| - const mojo::String& device_id,
|
| + const WebBluetoothDeviceId& device_id,
|
| blink::mojom::WebBluetoothGATTQueryQuantity quantity,
|
| const base::Optional<BluetoothUUID>& services_uuid,
|
| const RemoteServerGetPrimaryServicesCallback& callback) {
|
| @@ -691,7 +690,7 @@ void WebBluetoothServiceImpl::RequestDeviceImpl(
|
| }
|
|
|
| void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
|
| - const mojo::String& device_id,
|
| + const WebBluetoothDeviceId& device_id,
|
| blink::mojom::WebBluetoothGATTQueryQuantity quantity,
|
| const base::Optional<BluetoothUUID>& services_uuid,
|
| const RemoteServerGetPrimaryServicesCallback& callback,
|
| @@ -763,7 +762,7 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
|
| return;
|
| }
|
|
|
| - const std::string device_id_for_origin =
|
| + const WebBluetoothDeviceId device_id_for_origin =
|
| allowed_devices_map_.AddDevice(GetOrigin(), device_address, options);
|
|
|
| VLOG(1) << "Device: " << device->GetNameForDisplay();
|
| @@ -800,7 +799,7 @@ void WebBluetoothServiceImpl::OnGetDeviceFailed(
|
| }
|
|
|
| void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
|
| - const std::string& device_id,
|
| + const WebBluetoothDeviceId& device_id,
|
| base::TimeTicks start_time,
|
| const RemoteServerConnectCallback& callback,
|
| std::unique_ptr<device::BluetoothGattConnection> connection) {
|
| @@ -813,7 +812,6 @@ void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
|
| }
|
|
|
| void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed(
|
| - const std::string& device_id,
|
| base::TimeTicks start_time,
|
| const RemoteServerConnectCallback& callback,
|
| device::BluetoothDevice::ConnectErrorCode error_code) {
|
| @@ -885,7 +883,7 @@ void WebBluetoothServiceImpl::OnStopNotifySessionComplete(
|
| }
|
|
|
| CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
|
| - const std::string& device_id) {
|
| + const WebBluetoothDeviceId& device_id) {
|
| const std::string& device_address =
|
| allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id);
|
| if (device_address.empty()) {
|
| @@ -915,15 +913,15 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
|
| return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
|
| }
|
|
|
| - const std::string& device_id =
|
| + const WebBluetoothDeviceId* device_id =
|
| allowed_devices_map_.GetDeviceId(GetOrigin(), device_iter->second);
|
| // Kill the renderer if origin is not allowed to access the device.
|
| - if (device_id.empty()) {
|
| + if (device_id == nullptr) {
|
| CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
|
| return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
|
| }
|
|
|
| - CacheQueryResult result = QueryCacheForDevice(device_id);
|
| + CacheQueryResult result = QueryCacheForDevice(*device_id);
|
| if (result.outcome != CacheQueryOutcome::SUCCESS) {
|
| return result;
|
| }
|
| @@ -932,7 +930,7 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
|
| if (result.service == nullptr) {
|
| result.outcome = CacheQueryOutcome::NO_SERVICE;
|
| } else if (!allowed_devices_map_.IsOriginAllowedToAccessService(
|
| - GetOrigin(), device_id, result.service->GetUUID())) {
|
| + GetOrigin(), *device_id, result.service->GetUUID())) {
|
| CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN);
|
| return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
|
| }
|
|
|