Commit 84061ed2 authored by ortuno's avatar ortuno Committed by Commit bot

bluetooth: Remove non const references from BluetoothDispatcherHost

We had some non-const references that broke the style guide. This
patch removes them.

BUG=551696

Review URL: https://codereview.chromium.org/1434403006

Cr-Commit-Position: refs/heads/master@{#360603}
parent f2930fc0
...@@ -353,8 +353,13 @@ struct BluetoothDispatcherHost::CacheQueryResult { ...@@ -353,8 +353,13 @@ struct BluetoothDispatcherHost::CacheQueryResult {
service(nullptr), service(nullptr),
characteristic(nullptr), characteristic(nullptr),
outcome(CacheQueryOutcome::SUCCESS) {} outcome(CacheQueryOutcome::SUCCESS) {}
CacheQueryResult(CacheQueryOutcome outcome)
: device(nullptr),
service(nullptr),
characteristic(nullptr),
outcome(outcome) {}
~CacheQueryResult() {} ~CacheQueryResult() {}
WebBluetoothError GetWebError() { WebBluetoothError GetWebError() const {
switch (outcome) { switch (outcome) {
case CacheQueryOutcome::SUCCESS: case CacheQueryOutcome::SUCCESS:
case CacheQueryOutcome::BAD_RENDERER: case CacheQueryOutcome::BAD_RENDERER:
...@@ -690,8 +695,7 @@ void BluetoothDispatcherHost::OnConnectGATT(int thread_id, ...@@ -690,8 +695,7 @@ void BluetoothDispatcherHost::OnConnectGATT(int thread_id,
// permissions are implemented we should check that the domain has access to // permissions are implemented we should check that the domain has access to
// the device. https://crbug.com/484745 // the device. https://crbug.com/484745
CacheQueryResult query_result; const CacheQueryResult query_result = QueryCacheForDevice(device_id);
QueryCacheForDevice(device_id, query_result);
if (query_result.outcome != CacheQueryOutcome::SUCCESS) { if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordConnectGATTOutcome(query_result.outcome); RecordConnectGATTOutcome(query_result.outcome);
...@@ -723,8 +727,7 @@ void BluetoothDispatcherHost::OnGetPrimaryService( ...@@ -723,8 +727,7 @@ void BluetoothDispatcherHost::OnGetPrimaryService(
// TODO(ortuno): Check if service_uuid is in "allowed services" // TODO(ortuno): Check if service_uuid is in "allowed services"
// https://crbug.com/493460 // https://crbug.com/493460
CacheQueryResult query_result; const CacheQueryResult query_result = QueryCacheForDevice(device_id);
QueryCacheForDevice(device_id, query_result);
if (query_result.outcome != CacheQueryOutcome::SUCCESS) { if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordGetPrimaryServiceOutcome(query_result.outcome); RecordGetPrimaryServiceOutcome(query_result.outcome);
...@@ -780,8 +783,8 @@ void BluetoothDispatcherHost::OnGetCharacteristic( ...@@ -780,8 +783,8 @@ void BluetoothDispatcherHost::OnGetCharacteristic(
RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC); RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC);
RecordGetCharacteristicCharacteristic(characteristic_uuid); RecordGetCharacteristicCharacteristic(characteristic_uuid);
CacheQueryResult query_result; const CacheQueryResult query_result =
QueryCacheForService(service_instance_id, query_result); QueryCacheForService(service_instance_id);
if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
return; return;
...@@ -829,8 +832,8 @@ void BluetoothDispatcherHost::OnReadValue( ...@@ -829,8 +832,8 @@ void BluetoothDispatcherHost::OnReadValue(
RecordWebBluetoothFunctionCall( RecordWebBluetoothFunctionCall(
UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE);
CacheQueryResult query_result; const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id, query_result); QueryCacheForCharacteristic(characteristic_instance_id);
if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
return; return;
...@@ -870,8 +873,8 @@ void BluetoothDispatcherHost::OnWriteValue( ...@@ -870,8 +873,8 @@ void BluetoothDispatcherHost::OnWriteValue(
return; return;
} }
CacheQueryResult query_result; const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id, query_result); QueryCacheForCharacteristic(characteristic_instance_id);
if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
return; return;
...@@ -911,8 +914,8 @@ void BluetoothDispatcherHost::OnStartNotifications( ...@@ -911,8 +914,8 @@ void BluetoothDispatcherHost::OnStartNotifications(
// TODO(ortuno): Check if notify/indicate bit is set. // TODO(ortuno): Check if notify/indicate bit is set.
// http://crbug.com/538869 // http://crbug.com/538869
CacheQueryResult query_result; const CacheQueryResult query_result =
QueryCacheForCharacteristic(characteristic_instance_id, query_result); QueryCacheForCharacteristic(characteristic_instance_id);
if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
return; return;
...@@ -1243,8 +1246,9 @@ void BluetoothDispatcherHost::OnStopNotifySession( ...@@ -1243,8 +1246,9 @@ void BluetoothDispatcherHost::OnStopNotifySession(
Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id));
} }
void BluetoothDispatcherHost::QueryCacheForDevice(const std::string& device_id, BluetoothDispatcherHost::CacheQueryResult
CacheQueryResult& result) { BluetoothDispatcherHost::QueryCacheForDevice(const std::string& device_id) {
CacheQueryResult result;
result.device = adapter_->GetDevice(device_id); result.device = adapter_->GetDevice(device_id);
// When a device can't be found in the BluetoothAdapter, that generally // 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 // indicates that it's gone out of range. We reject with a NetworkError in
...@@ -1253,38 +1257,39 @@ void BluetoothDispatcherHost::QueryCacheForDevice(const std::string& device_id, ...@@ -1253,38 +1257,39 @@ void BluetoothDispatcherHost::QueryCacheForDevice(const std::string& device_id,
if (result.device == nullptr) { if (result.device == nullptr) {
result.outcome = CacheQueryOutcome::NO_DEVICE; result.outcome = CacheQueryOutcome::NO_DEVICE;
} }
return result;
} }
void BluetoothDispatcherHost::QueryCacheForService( BluetoothDispatcherHost::CacheQueryResult
const std::string& service_instance_id, BluetoothDispatcherHost::QueryCacheForService(
CacheQueryResult& result) { const std::string& service_instance_id) {
auto device_iter = service_to_device_.find(service_instance_id); auto device_iter = service_to_device_.find(service_instance_id);
// Kill the renderer, see "ID Not In Map Note" above. // Kill the renderer, see "ID Not In Map Note" above.
if (device_iter == service_to_device_.end()) { if (device_iter == service_to_device_.end()) {
bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID);
result.outcome = CacheQueryOutcome::BAD_RENDERER; return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
return;
} }
// TODO(ortuno): Check if domain has access to device. // TODO(ortuno): Check if domain has access to device.
// https://crbug.com/493459 // https://crbug.com/493459
QueryCacheForDevice(device_iter->second, result); CacheQueryResult result = QueryCacheForDevice(device_iter->second);
if (result.outcome != CacheQueryOutcome::SUCCESS) { if (result.outcome != CacheQueryOutcome::SUCCESS) {
return; return result;
} }
result.service = result.device->GetGattService(service_instance_id); result.service = result.device->GetGattService(service_instance_id);
if (result.service == nullptr) { if (result.service == nullptr) {
result.outcome = CacheQueryOutcome::NO_SERVICE; result.outcome = CacheQueryOutcome::NO_SERVICE;
} }
return result;
} }
void BluetoothDispatcherHost::QueryCacheForCharacteristic( BluetoothDispatcherHost::CacheQueryResult
const std::string& characteristic_instance_id, BluetoothDispatcherHost::QueryCacheForCharacteristic(
CacheQueryResult& result) { const std::string& characteristic_instance_id) {
auto characteristic_iter = auto characteristic_iter =
characteristic_to_service_.find(characteristic_instance_id); characteristic_to_service_.find(characteristic_instance_id);
...@@ -1292,13 +1297,12 @@ void BluetoothDispatcherHost::QueryCacheForCharacteristic( ...@@ -1292,13 +1297,12 @@ void BluetoothDispatcherHost::QueryCacheForCharacteristic(
if (characteristic_iter == characteristic_to_service_.end()) { if (characteristic_iter == characteristic_to_service_.end()) {
bad_message::ReceivedBadMessage(this, bad_message::ReceivedBadMessage(this,
bad_message::BDH_INVALID_CHARACTERISTIC_ID); bad_message::BDH_INVALID_CHARACTERISTIC_ID);
result.outcome = CacheQueryOutcome::BAD_RENDERER; return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
return;
} }
QueryCacheForService(characteristic_iter->second, result); CacheQueryResult result = QueryCacheForService(characteristic_iter->second);
if (result.outcome != CacheQueryOutcome::SUCCESS) { if (result.outcome != CacheQueryOutcome::SUCCESS) {
return; return result;
} }
result.characteristic = result.characteristic =
...@@ -1307,6 +1311,8 @@ void BluetoothDispatcherHost::QueryCacheForCharacteristic( ...@@ -1307,6 +1311,8 @@ void BluetoothDispatcherHost::QueryCacheForCharacteristic(
if (result.characteristic == nullptr) { if (result.characteristic == nullptr) {
result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC;
} }
return result;
} }
bool BluetoothDispatcherHost::IsServicesDiscoveryCompleteForDevice( bool BluetoothDispatcherHost::IsServicesDiscoveryCompleteForDevice(
......
...@@ -208,20 +208,17 @@ class CONTENT_EXPORT BluetoothDispatcherHost final ...@@ -208,20 +208,17 @@ class CONTENT_EXPORT BluetoothDispatcherHost final
// was already recorded and since there renderer crashed there is no need to // was already recorded and since there renderer crashed there is no need to
// send a response. // send a response.
// Queries the platform cache for a Device with |device_id|. If // Queries the platform cache for a Device with |device_id|. Fills in the
// successful the device will be in result.device // |outcome| field and the |device| field if successful.
void QueryCacheForDevice(const std::string& device_id, CacheQueryResult QueryCacheForDevice(const std::string& device_id);
CacheQueryResult& result); // Queries the platform cache for a Service with |service_instance_id|. Fills
// Queries the platform cache for a Service with |service_instance_id|. // in the |outcome| field, and |device| and |service| fields if successful.
// If successfull the service will be in result.service. CacheQueryResult QueryCacheForService(const std::string& service_instance_id);
void QueryCacheForService(const std::string& service_instance_id,
CacheQueryResult& result);
// Queries the platform cache for a characteristic with // Queries the platform cache for a characteristic with
// |characteristic_instance_id|. If successfull the characteristic will be in // |characteristic_instance_id|. Fills in the |outcome| field, and |device|,
// result.characteristic. // |service| and |characteristic| fields if successful.
void QueryCacheForCharacteristic( CacheQueryResult QueryCacheForCharacteristic(
const std::string& characteristic_instance_id, const std::string& characteristic_instance_id);
CacheQueryResult& result);
// Returns true if all services have been discovered for the device. // Returns true if all services have been discovered for the device.
// When the host gets a ServiceChanged indication, it automatically // When the host gets a ServiceChanged indication, it automatically
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment