| 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 cba6ef08cd133de36c74de271486c88399f073c3..6caa21773375997a11c57093db6545cd639a2ba5 100644
|
| --- a/content/browser/bluetooth/web_bluetooth_service_impl.cc
|
| +++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc
|
| @@ -21,6 +21,7 @@
|
| #include "content/browser/bluetooth/bluetooth_metrics.h"
|
| #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h"
|
| #include "content/browser/renderer_host/render_process_host_impl.h"
|
| +#include "content/common/bluetooth/bluetooth_device_id.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/navigation_handle.h"
|
| #include "content/public/browser/render_frame_host.h"
|
| @@ -220,13 +221,11 @@ void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter,
|
| device::BluetoothDevice* device) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| if (!device->IsGattConnected() || !device->IsConnected()) {
|
| - std::string device_id =
|
| + base::Optional<BluetoothDeviceId> 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());
|
| }
|
| }
|
| }
|
| @@ -314,7 +313,7 @@ void WebBluetoothServiceImpl::RequestDevice(
|
| }
|
|
|
| void WebBluetoothServiceImpl::RemoteServerConnect(
|
| - const mojo::String& device_id,
|
| + const BluetoothDeviceId& device_id,
|
| const RemoteServerConnectCallback& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT);
|
| @@ -348,24 +347,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 BluetoothDeviceId& 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::RemoteServerGetPrimaryService(
|
| - const mojo::String& device_id,
|
| + const BluetoothDeviceId& device_id,
|
| const base::Optional<BluetoothUUID>& service_uuid,
|
| const RemoteServerGetPrimaryServiceCallback& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| @@ -722,7 +720,7 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
|
| return;
|
| }
|
|
|
| - const std::string device_id_for_origin =
|
| + const BluetoothDeviceId device_id_for_origin =
|
| allowed_devices_map_.AddDevice(GetOrigin(), device_address, options);
|
|
|
| VLOG(1) << "Device: " << device->GetName();
|
| @@ -758,7 +756,7 @@ void WebBluetoothServiceImpl::OnGetDeviceFailed(
|
| }
|
|
|
| void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
|
| - const std::string& device_id,
|
| + const BluetoothDeviceId& device_id,
|
| base::TimeTicks start_time,
|
| const RemoteServerConnectCallback& callback,
|
| std::unique_ptr<device::BluetoothGattConnection> connection) {
|
| @@ -771,7 +769,6 @@ void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
|
| }
|
|
|
| void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed(
|
| - const std::string& device_id,
|
| base::TimeTicks start_time,
|
| const RemoteServerConnectCallback& callback,
|
| device::BluetoothDevice::ConnectErrorCode error_code) {
|
| @@ -843,7 +840,7 @@ void WebBluetoothServiceImpl::OnStopNotifySessionComplete(
|
| }
|
|
|
| CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
|
| - const std::string& device_id) {
|
| + const BluetoothDeviceId& device_id) {
|
| const std::string& device_address =
|
| allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id);
|
| if (device_address.empty()) {
|
| @@ -873,15 +870,15 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
|
| return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
|
| }
|
|
|
| - const std::string& device_id =
|
| + const base::Optional<BluetoothDeviceId>& 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) {
|
| CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
|
| return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
|
| }
|
|
|
| - CacheQueryResult result = QueryCacheForDevice(device_id);
|
| + CacheQueryResult result = QueryCacheForDevice(device_id.value());
|
| if (result.outcome != CacheQueryOutcome::SUCCESS) {
|
| return result;
|
| }
|
| @@ -890,7 +887,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.value(), result.service->GetUUID())) {
|
| CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN);
|
| return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
|
| }
|
|
|