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

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: Rebase Created 4 years, 4 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
« no previous file with comments | « content/browser/bluetooth/web_bluetooth_service_impl.h ('k') | content/common/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6db050b1dc7ee06e028545942af3f29393c068ec..974eb1db941a03eadbc6b82a7ff941677824002d 100644
--- a/content/browser/bluetooth/web_bluetooth_service_impl.cc
+++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc
@@ -20,6 +20,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/web_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"
@@ -237,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());
}
}
}
@@ -331,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);
@@ -365,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 +689,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 +761,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 +798,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 +811,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 +882,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 +912,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 +929,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);
}
« no previous file with comments | « content/browser/bluetooth/web_bluetooth_service_impl.h ('k') | content/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698