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

Unified Diff: content/browser/bluetooth/web_bluetooth_service_impl.cc

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Address jyasskin's comments Created 4 years, 6 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/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 e2ecef259fb37b38cd60792077d1464d3acbf410..447a17c4af47c0b84dbc2b5800e9e90909042228 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()) {
- 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->GetNameForDisplay();
@@ -759,7 +757,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) {
@@ -772,7 +770,6 @@ void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
}
void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed(
- const std::string& device_id,
base::TimeTicks start_time,
const RemoteServerConnectCallback& callback,
device::BluetoothDevice::ConnectErrorCode error_code) {
@@ -844,7 +841,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()) {
@@ -874,15 +871,15 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
}
- const std::string& device_id =
+ const 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 == 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;
}
@@ -891,7 +888,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);
}

Powered by Google App Engine
This is Rietveld 408576698