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

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

Issue 2506813003: Use new wrapper types for web_bluetooth.mojom (Closed)
Patch Set: address comments Created 4 years, 1 month 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 e75ec1799441fb72c41595d4b56e61c40dc8bfcc..ebd130ff8c0d4ea66611c8a5f073808d94bb51d5 100644
--- a/content/browser/bluetooth/web_bluetooth_service_impl.cc
+++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc
@@ -142,9 +142,8 @@ GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service,
service->GetCharacteristics()) {
VLOG(1) << "Characteristic in cache: "
<< characteristic->GetUUID().canonical_value();
- if (characteristic->GetUUID() == characteristic_uuid) {
ortuno 2016/11/22 02:32:21 nit: Please leave these. Owners (me) prefer to hav
juncai 2016/11/23 20:54:22 Done.
+ if (characteristic->GetUUID() == characteristic_uuid)
characteristics.push_back(characteristic);
- }
}
return characteristics;
}
@@ -159,9 +158,8 @@ std::vector<device::BluetoothRemoteGattService*> GetPrimaryServicesByUUID(
for (device::BluetoothRemoteGattService* service :
device->GetGattServices()) {
VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value();
- if (service->GetUUID() == service_uuid && service->IsPrimary()) {
+ if (service->GetUUID() == service_uuid && service->IsPrimary())
services.push_back(service);
- }
}
return services;
}
@@ -175,9 +173,8 @@ std::vector<device::BluetoothRemoteGattService*> GetPrimaryServices(
for (device::BluetoothRemoteGattService* service :
device->GetGattServices()) {
VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value();
- if (service->IsPrimary()) {
+ if (service->IsPrimary())
services.push_back(service);
- }
}
return services;
}
@@ -225,59 +222,52 @@ void WebBluetoothServiceImpl::AdapterPoweredChanged(
device::BluetoothAdapter* adapter,
bool powered) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (device_chooser_controller_.get()) {
+ if (device_chooser_controller_.get())
device_chooser_controller_->AdapterPoweredChanged(powered);
- }
}
void WebBluetoothServiceImpl::DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (device_chooser_controller_.get()) {
+ if (device_chooser_controller_.get())
device_chooser_controller_->AddFilteredDevice(*device);
- }
}
void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (device_chooser_controller_.get()) {
+ if (device_chooser_controller_.get())
device_chooser_controller_->AddFilteredDevice(*device);
- }
if (!device->IsGattConnected()) {
base::Optional<WebBluetoothDeviceId> device_id =
connected_devices_->CloseConnectionToDeviceWithAddress(
device->GetAddress());
- if (device_id && client_) {
+ if (device_id && client_)
client_->GattServerDisconnected(device_id.value());
- }
}
}
void WebBluetoothServiceImpl::GattServicesDiscovered(
device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
- if (device_chooser_controller_.get()) {
+ if (device_chooser_controller_.get())
device_chooser_controller_->AddFilteredDevice(*device);
- }
DCHECK_CURRENTLY_ON(BrowserThread::UI);
const std::string& device_address = device->GetAddress();
VLOG(1) << "Services discovered for device: " << device_address;
auto iter = pending_primary_services_requests_.find(device_address);
- if (iter == pending_primary_services_requests_.end()) {
+ if (iter == pending_primary_services_requests_.end())
return;
- }
std::vector<PrimaryServicesRequestCallback> requests =
std::move(iter->second);
pending_primary_services_requests_.erase(iter);
- for (const PrimaryServicesRequestCallback& request : requests) {
+ for (const PrimaryServicesRequestCallback& request : requests)
request.Run(device);
- }
// Sending get-service responses unexpectedly queued another request.
DCHECK(
@@ -310,8 +300,8 @@ void WebBluetoothServiceImpl::NotifyCharacteristicValueChanged(
const std::string& characteristic_instance_id,
std::vector<uint8_t> value) {
if (client_) {
- client_->RemoteCharacteristicValueChanged(
- characteristic_instance_id, mojo::Array<uint8_t>(std::move(value)));
+ client_->RemoteCharacteristicValueChanged(characteristic_instance_id,
+ std::move(value));
}
}
@@ -411,7 +401,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
GetOrigin(), device_id)) {
callback.Run(
blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE,
- nullptr /* service */);
+ base::nullopt /* service */);
return;
}
@@ -420,19 +410,18 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
GetOrigin(), device_id, services_uuid.value())) {
callback.Run(
blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE,
- nullptr /* service */);
+ base::nullopt /* service */);
return;
}
const CacheQueryResult query_result = QueryCacheForDevice(device_id);
- if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER)
return;
- }
if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordGetPrimaryServicesOutcome(quantity, query_result.outcome);
- callback.Run(query_result.GetWebResult(), nullptr /* service */);
+ callback.Run(query_result.GetWebResult(), base::nullopt /* service */);
return;
}
@@ -453,7 +442,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
}
void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
- const mojo::String& service_instance_id,
+ const std::string& service_instance_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<BluetoothUUID>& characteristics_uuid,
const RemoteServiceGetCharacteristicsCallback& callback) {
@@ -471,20 +460,20 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
UMAGetCharacteristicOutcome::BLACKLISTED);
callback.Run(
blink::mojom::WebBluetoothResult::BLACKLISTED_CHARACTERISTIC_UUID,
- nullptr /* characteristics */);
+ base::nullopt /* characteristics */);
return;
}
const CacheQueryResult query_result =
QueryCacheForService(service_instance_id);
- if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER)
return;
- }
if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordGetCharacteristicsOutcome(quantity, query_result.outcome);
- callback.Run(query_result.GetWebResult(), nullptr /* characteristics */);
+ callback.Run(query_result.GetWebResult(),
+ base::nullopt /* characteristics */);
return;
}
@@ -494,13 +483,12 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
characteristics_uuid.value())
: query_result.service->GetCharacteristics();
- mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
+ std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
response_characteristics;
for (device::BluetoothRemoteGattCharacteristic* characteristic :
characteristics) {
- if (BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID())) {
+ if (BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()))
continue;
- }
std::string characteristic_instance_id = characteristic->GetIdentifier();
auto insert_result = characteristic_id_to_service_id_.insert(
std::make_pair(characteristic_instance_id, service_instance_id));
@@ -516,9 +504,8 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
static_cast<uint32_t>(characteristic->GetProperties());
response_characteristics.push_back(std::move(characteristic_ptr));
- if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) {
+ if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE)
break;
- }
}
if (!response_characteristics.empty()) {
@@ -536,11 +523,11 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
callback.Run(characteristics_uuid
? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND
: blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND,
- nullptr /* characteristics */);
+ base::nullopt /* characteristics */);
}
void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
- const mojo::String& characteristic_instance_id,
+ const std::string& characteristic_instance_id,
const RemoteCharacteristicReadValueCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall(
@@ -549,13 +536,12 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id);
- if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER)
return;
- }
if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordCharacteristicReadValueOutcome(query_result.outcome);
- callback.Run(query_result.GetWebResult(), nullptr /* value */);
+ callback.Run(query_result.GetWebResult(), base::nullopt /* value */);
return;
}
@@ -563,7 +549,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
query_result.characteristic->GetUUID())) {
RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED);
callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_READ,
- nullptr /* value */);
+ base::nullopt /* value */);
return;
}
@@ -575,8 +561,8 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
}
void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
- const mojo::String& characteristic_instance_id,
- mojo::Array<uint8_t> value,
+ const std::string& characteristic_instance_id,
+ const std::vector<uint8_t>& value,
const RemoteCharacteristicWriteValueCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall(
@@ -593,9 +579,8 @@ void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id);
- if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER)
return;
- }
if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordCharacteristicWriteValueOutcome(query_result.outcome);
@@ -611,15 +596,14 @@ void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
}
query_result.characteristic->WriteRemoteCharacteristic(
- value.To<std::vector<uint8_t>>(),
- base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess,
- weak_ptr_factory_.GetWeakPtr(), callback),
+ value, base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess,
+ weak_ptr_factory_.GetWeakPtr(), callback),
base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications(
- const mojo::String& characteristic_instance_id,
+ const std::string& characteristic_instance_id,
const RemoteCharacteristicStartNotificationsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall(
@@ -638,9 +622,8 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications(
const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id);
- if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER)
return;
- }
if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordStartNotificationsOutcome(query_result.outcome);
@@ -665,7 +648,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications(
}
void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications(
- const mojo::String& characteristic_instance_id,
+ const std::string& characteristic_instance_id,
const RemoteCharacteristicStopNotificationsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall(
@@ -674,9 +657,8 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications(
const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id);
- if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
+ if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER)
return;
- }
auto notify_session_iter =
characteristic_id_to_notify_session_.find(characteristic_instance_id);
@@ -726,7 +708,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value())
: GetPrimaryServices(device);
- mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services;
+ std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services;
for (device::BluetoothRemoteGattService* service : services) {
if (!allowed_devices_map_.IsOriginAllowedToAccessService(
GetOrigin(), device_id, service->GetUUID())) {
@@ -746,9 +728,8 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
service_ptr->uuid = service->GetUUID().canonical_value();
response_services.push_back(std::move(service_ptr));
- if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) {
+ if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE)
break;
- }
}
if (!response_services.empty()) {
@@ -767,7 +748,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
callback.Run(services_uuid
? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND
: blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND,
- nullptr /* services */);
+ base::nullopt /* services */);
}
void WebBluetoothServiceImpl::OnGetDeviceSuccess(
@@ -794,8 +775,7 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
blink::mojom::WebBluetoothDevicePtr device_ptr =
blink::mojom::WebBluetoothDevice::New();
device_ptr->id = device_id_for_origin;
- device_ptr->name = device->GetName() ? mojo::String(device->GetName().value())
- : mojo::String(nullptr);
+ device_ptr->name = device->GetName();
RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS);
callback.Run(blink::mojom::WebBluetoothResult::SUCCESS,
@@ -837,8 +817,7 @@ void WebBluetoothServiceImpl::OnReadValueSuccess(
const std::vector<uint8_t>& value) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS);
- callback.Run(blink::mojom::WebBluetoothResult::SUCCESS,
- mojo::Array<uint8_t>::From(value));
+ callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, value);
}
void WebBluetoothServiceImpl::OnReadValueFailed(
@@ -847,7 +826,7 @@ void WebBluetoothServiceImpl::OnReadValueFailed(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
callback.Run(TranslateGATTErrorAndRecord(
error_code, UMAGATTOperation::CHARACTERISTIC_READ),
- nullptr /* value */);
+ base::nullopt /* value */);
}
void WebBluetoothServiceImpl::OnWriteValueSuccess(
@@ -909,9 +888,8 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
// When a device can't be found in the BluetoothAdapter, that generally
// indicates that it's gone out of range. We reject with a NetworkError in
// that case.
- if (result.device == nullptr) {
+ if (result.device == nullptr)
result.outcome = CacheQueryOutcome::NO_DEVICE;
- }
return result;
}
@@ -934,9 +912,8 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
}
CacheQueryResult result = QueryCacheForDevice(*device_id);
- if (result.outcome != CacheQueryOutcome::SUCCESS) {
+ if (result.outcome != CacheQueryOutcome::SUCCESS)
return result;
- }
result.service = result.device->GetGattService(service_instance_id);
if (result.service == nullptr) {
@@ -962,16 +939,14 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic(
CacheQueryResult result = QueryCacheForService(characteristic_iter->second);
- if (result.outcome != CacheQueryOutcome::SUCCESS) {
+ if (result.outcome != CacheQueryOutcome::SUCCESS)
return result;
- }
result.characteristic =
result.service->GetCharacteristic(characteristic_instance_id);
- if (result.characteristic == nullptr) {
+ if (result.characteristic == nullptr)
result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC;
- }
return result;
}

Powered by Google App Engine
This is Rietveld 408576698