Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| index b69fa4fa49f19a3632cda132998f947eec1a764d..30ddd160d514b5d46fa704a5eaa748d03d142a01 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -24,7 +24,6 @@ |
| #include "content/browser/bluetooth/bluetooth_metrics.h" |
| #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" |
| #include "content/browser/frame_host/render_frame_host_impl.h" |
| -#include "content/common/bluetooth/bluetooth_messages.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| @@ -310,7 +309,6 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristics, OnGetCharacteristics) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) |
| - IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_RegisterCharacteristic, |
| @@ -409,40 +407,32 @@ struct BluetoothDispatcherHost::RequestDeviceSession { |
| scoped_ptr<device::BluetoothDiscoverySession> discovery_session; |
| }; |
| -struct BluetoothDispatcherHost::CacheQueryResult { |
| - CacheQueryResult() |
| - : device(nullptr), |
| - service(nullptr), |
| - characteristic(nullptr), |
| - outcome(CacheQueryOutcome::SUCCESS) {} |
| - CacheQueryResult(CacheQueryOutcome outcome) |
| - : device(nullptr), |
| - service(nullptr), |
| - characteristic(nullptr), |
| - outcome(outcome) {} |
| - ~CacheQueryResult() {} |
| - WebBluetoothError GetWebError() const { |
| - switch (outcome) { |
| - case CacheQueryOutcome::SUCCESS: |
| - case CacheQueryOutcome::BAD_RENDERER: |
| - NOTREACHED(); |
| - return WebBluetoothError::DeviceNoLongerInRange; |
| - case CacheQueryOutcome::NO_DEVICE: |
| - return WebBluetoothError::DeviceNoLongerInRange; |
| - case CacheQueryOutcome::NO_SERVICE: |
| - return WebBluetoothError::ServiceNoLongerExists; |
| - case CacheQueryOutcome::NO_CHARACTERISTIC: |
| - return WebBluetoothError::CharacteristicNoLongerExists; |
| - } |
| - NOTREACHED(); |
| - return WebBluetoothError::DeviceNoLongerInRange; |
| - } |
| +BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult() |
| + : outcome(CacheQueryOutcome::SUCCESS) {} |
|
Jeffrey Yasskin
2016/03/25 00:48:23
I'd probably move this to a member initializer too
ortuno
2016/03/29 17:58:34
Done.
|
| - device::BluetoothDevice* device; |
| - device::BluetoothGattService* service; |
| - device::BluetoothGattCharacteristic* characteristic; |
| - CacheQueryOutcome outcome; |
| -}; |
| +BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult( |
| + CacheQueryOutcome outcome) |
| + : outcome(outcome) {} |
| + |
| +BluetoothDispatcherHost::CacheQueryResult::~CacheQueryResult() {} |
| + |
| +WebBluetoothError BluetoothDispatcherHost::CacheQueryResult::GetWebError() |
| + const { |
| + switch (outcome) { |
| + case CacheQueryOutcome::SUCCESS: |
| + case CacheQueryOutcome::BAD_RENDERER: |
| + NOTREACHED(); |
| + return WebBluetoothError::DeviceNoLongerInRange; |
| + case CacheQueryOutcome::NO_DEVICE: |
| + return WebBluetoothError::DeviceNoLongerInRange; |
| + case CacheQueryOutcome::NO_SERVICE: |
| + return WebBluetoothError::ServiceNoLongerExists; |
| + case CacheQueryOutcome::NO_CHARACTERISTIC: |
| + return WebBluetoothError::CharacteristicNoLongerExists; |
| + } |
| + NOTREACHED(); |
| + return WebBluetoothError::DeviceNoLongerInRange; |
| +} |
| struct BluetoothDispatcherHost::PrimaryServicesRequest { |
| enum CallingFunction { GET_PRIMARY_SERVICE, GET_PRIMARY_SERVICES }; |
| @@ -975,56 +965,6 @@ void BluetoothDispatcherHost::OnReadValue( |
| weak_ptr_on_ui_thread_, thread_id, request_id)); |
| } |
| -void BluetoothDispatcherHost::OnWriteValue( |
| - int thread_id, |
| - int request_id, |
| - int frame_routing_id, |
| - const std::string& characteristic_instance_id, |
| - const std::vector<uint8_t>& value) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - RecordWebBluetoothFunctionCall( |
| - UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); |
| - |
| - // Length check per step 3 of writeValue algorithm: |
| - // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattcharacteristic-writevalue |
| - // We perform the length check on the renderer side. So if we |
| - // get a value with length > 512, we can assume it's a hostile |
| - // renderer and kill it. |
| - if (value.size() > 512) { |
| - bad_message::ReceivedBadMessage( |
| - this, bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); |
| - return; |
| - } |
| - |
| - const CacheQueryResult query_result = QueryCacheForCharacteristic( |
| - GetOrigin(frame_routing_id), characteristic_instance_id); |
| - |
| - if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| - return; |
| - } |
| - |
| - if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| - RecordCharacteristicWriteValueOutcome(query_result.outcome); |
| - Send(new BluetoothMsg_WriteCharacteristicValueError( |
| - thread_id, request_id, query_result.GetWebError())); |
| - return; |
| - } |
| - |
| - if (BluetoothBlacklist::Get().IsExcludedFromWrites( |
| - query_result.characteristic->GetUUID())) { |
| - RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); |
| - Send(new BluetoothMsg_WriteCharacteristicValueError( |
| - thread_id, request_id, WebBluetoothError::BlacklistedWrite)); |
| - return; |
| - } |
| - |
| - query_result.characteristic->WriteRemoteCharacteristic( |
| - value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, |
| - weak_ptr_on_ui_thread_, thread_id, request_id), |
| - base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, |
| - weak_ptr_on_ui_thread_, thread_id, request_id)); |
| -} |
| - |
| void BluetoothDispatcherHost::OnStartNotifications( |
| int thread_id, |
| int request_id, |
| @@ -1505,24 +1445,6 @@ void BluetoothDispatcherHost::OnCharacteristicReadValueError( |
| TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ))); |
| } |
| -void BluetoothDispatcherHost::OnWriteValueSuccess(int thread_id, |
| - int request_id) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
| - Send(new BluetoothMsg_WriteCharacteristicValueSuccess(thread_id, request_id)); |
| -} |
| - |
| -void BluetoothDispatcherHost::OnWriteValueFailed( |
| - int thread_id, |
| - int request_id, |
| - device::BluetoothGattService::GattErrorCode error_code) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - // TranslateGATTError calls RecordGATTOperationOutcome. |
| - Send(new BluetoothMsg_WriteCharacteristicValueError( |
| - thread_id, request_id, |
| - TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); |
| -} |
| - |
| void BluetoothDispatcherHost::OnStartNotifySessionSuccess( |
| int thread_id, |
| int request_id, |