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

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1865613002: bluetooth: Move read value to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-notifications
Patch Set: Address jyasskin's comments Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // ID Not In Map Note: 5 // ID Not In Map Note:
6 // A service, characteristic, or descriptor ID not in the corresponding 6 // A service, characteristic, or descriptor ID not in the corresponding
7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_,
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer
9 // obtains the corresponding ID from this class and it will be added to the map 9 // obtains the corresponding ID from this class and it will be added to the map
10 // at that time. 10 // at that time.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 RecordConnectGATTOutcome(UMAConnectGATTOutcome::WRITE_NOT_PERMITTED); 161 RecordConnectGATTOutcome(UMAConnectGATTOutcome::WRITE_NOT_PERMITTED);
162 return WebBluetoothError::CONNECT_WRITE_NOT_PERMITTED; 162 return WebBluetoothError::CONNECT_WRITE_NOT_PERMITTED;
163 case device::BluetoothDevice::NUM_CONNECT_ERROR_CODES: 163 case device::BluetoothDevice::NUM_CONNECT_ERROR_CODES:
164 NOTREACHED(); 164 NOTREACHED();
165 return WebBluetoothError::UNTRANSLATED_CONNECT_ERROR_CODE; 165 return WebBluetoothError::UNTRANSLATED_CONNECT_ERROR_CODE;
166 } 166 }
167 NOTREACHED(); 167 NOTREACHED();
168 return WebBluetoothError::UNTRANSLATED_CONNECT_ERROR_CODE; 168 return WebBluetoothError::UNTRANSLATED_CONNECT_ERROR_CODE;
169 } 169 }
170 170
171 WebBluetoothError TranslateGATTError(
172 BluetoothGattService::GattErrorCode error_code,
173 UMAGATTOperation operation) {
174 switch (error_code) {
175 case BluetoothGattService::GATT_ERROR_UNKNOWN:
176 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::UNKNOWN);
177 return blink::WebBluetoothError::GATT_UNKNOWN_ERROR;
178 case BluetoothGattService::GATT_ERROR_FAILED:
179 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::FAILED);
180 return blink::WebBluetoothError::GATT_UNKNOWN_FAILURE;
181 case BluetoothGattService::GATT_ERROR_IN_PROGRESS:
182 RecordGATTOperationOutcome(operation,
183 UMAGATTOperationOutcome::IN_PROGRESS);
184 return blink::WebBluetoothError::GATT_OPERATION_IN_PROGRESS;
185 case BluetoothGattService::GATT_ERROR_INVALID_LENGTH:
186 RecordGATTOperationOutcome(operation,
187 UMAGATTOperationOutcome::INVALID_LENGTH);
188 return blink::WebBluetoothError::GATT_INVALID_ATTRIBUTE_LENGTH;
189 case BluetoothGattService::GATT_ERROR_NOT_PERMITTED:
190 RecordGATTOperationOutcome(operation,
191 UMAGATTOperationOutcome::NOT_PERMITTED);
192 return blink::WebBluetoothError::GATT_NOT_PERMITTED;
193 case BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED:
194 RecordGATTOperationOutcome(operation,
195 UMAGATTOperationOutcome::NOT_AUTHORIZED);
196 return blink::WebBluetoothError::GATT_NOT_AUTHORIZED;
197 case BluetoothGattService::GATT_ERROR_NOT_PAIRED:
198 RecordGATTOperationOutcome(operation,
199 UMAGATTOperationOutcome::NOT_PAIRED);
200 return blink::WebBluetoothError::GATT_NOT_PAIRED;
201 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED:
202 RecordGATTOperationOutcome(operation,
203 UMAGATTOperationOutcome::NOT_SUPPORTED);
204 return blink::WebBluetoothError::GATT_NOT_SUPPORTED;
205 }
206 NOTREACHED();
207 return blink::WebBluetoothError::GATT_UNTRANSLATED_ERROR_CODE;
208 }
209
210 void StopDiscoverySession( 171 void StopDiscoverySession(
211 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { 172 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) {
212 // Nothing goes wrong if the discovery session fails to stop, and we don't 173 // Nothing goes wrong if the discovery session fails to stop, and we don't
213 // need to wait for it before letting the user's script proceed, so we ignore 174 // need to wait for it before letting the user's script proceed, so we ignore
214 // the results here. 175 // the results here.
215 discovery_session->Stop(base::Bind(&base::DoNothing), 176 discovery_session->Stop(base::Bind(&base::DoNothing),
216 base::Bind(&base::DoNothing)); 177 base::Bind(&base::DoNothing));
217 } 178 }
218 179
219 // TODO(ortuno): This should really be a BluetoothDevice method. 180 // TODO(ortuno): This should really be a BluetoothDevice method.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 DCHECK_CURRENTLY_ON(BrowserThread::UI); 264 DCHECK_CURRENTLY_ON(BrowserThread::UI);
304 bool handled = true; 265 bool handled = true;
305 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) 266 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message)
306 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) 267 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice)
307 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerConnect, OnGATTServerConnect) 268 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerConnect, OnGATTServerConnect)
308 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerDisconnect, 269 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerDisconnect,
309 OnGATTServerDisconnect) 270 OnGATTServerDisconnect)
310 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) 271 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService)
311 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) 272 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic)
312 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristics, OnGetCharacteristics) 273 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristics, OnGetCharacteristics)
313 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue)
314 IPC_MESSAGE_UNHANDLED(handled = false) 274 IPC_MESSAGE_UNHANDLED(handled = false)
315 IPC_END_MESSAGE_MAP() 275 IPC_END_MESSAGE_MAP()
316 return handled; 276 return handled;
317 } 277 }
318 278
319 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( 279 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting(
320 scoped_refptr<device::BluetoothAdapter> mock_adapter) { 280 scoped_refptr<device::BluetoothAdapter> mock_adapter) {
321 DCHECK_CURRENTLY_ON(BrowserThread::UI); 281 DCHECK_CURRENTLY_ON(BrowserThread::UI);
322 282
323 if (mock_adapter.get()) { 283 if (mock_adapter.get()) {
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 characteristics_uuid.empty() 911 characteristics_uuid.empty()
952 ? UMAGetCharacteristicOutcome::NO_CHARACTERISTICS 912 ? UMAGetCharacteristicOutcome::NO_CHARACTERISTICS
953 : UMAGetCharacteristicOutcome::NOT_FOUND); 913 : UMAGetCharacteristicOutcome::NOT_FOUND);
954 Send(new BluetoothMsg_GetCharacteristicsError( 914 Send(new BluetoothMsg_GetCharacteristicsError(
955 thread_id, request_id, 915 thread_id, request_id,
956 characteristics_uuid.empty() 916 characteristics_uuid.empty()
957 ? WebBluetoothError::NO_CHARACTERISTICS_FOUND 917 ? WebBluetoothError::NO_CHARACTERISTICS_FOUND
958 : WebBluetoothError::CHARACTERISTIC_NOT_FOUND)); 918 : WebBluetoothError::CHARACTERISTIC_NOT_FOUND));
959 } 919 }
960 920
961 void BluetoothDispatcherHost::OnReadValue(
962 int thread_id,
963 int request_id,
964 int frame_routing_id,
965 const std::string& characteristic_instance_id) {
966 DCHECK_CURRENTLY_ON(BrowserThread::UI);
967 RecordWebBluetoothFunctionCall(
968 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE);
969
970 const CacheQueryResult query_result = QueryCacheForCharacteristic(
971 GetOrigin(frame_routing_id), characteristic_instance_id);
972
973 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
974 return;
975 }
976
977 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
978 RecordCharacteristicReadValueOutcome(query_result.outcome);
979 Send(new BluetoothMsg_ReadCharacteristicValueError(
980 thread_id, request_id, query_result.GetWebError()));
981 return;
982 }
983
984 if (BluetoothBlacklist::Get().IsExcludedFromReads(
985 query_result.characteristic->GetUUID())) {
986 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED);
987 Send(new BluetoothMsg_ReadCharacteristicValueError(
988 thread_id, request_id, WebBluetoothError::BLACKLISTED_READ));
989 return;
990 }
991
992 query_result.characteristic->ReadRemoteCharacteristic(
993 base::Bind(&BluetoothDispatcherHost::OnCharacteristicValueRead,
994 weak_ptr_on_ui_thread_, thread_id, request_id),
995 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError,
996 weak_ptr_on_ui_thread_, thread_id, request_id));
997 }
998
999 void BluetoothDispatcherHost::OnGetAdapter( 921 void BluetoothDispatcherHost::OnGetAdapter(
1000 base::Closure continuation, 922 base::Closure continuation,
1001 scoped_refptr<device::BluetoothAdapter> adapter) { 923 scoped_refptr<device::BluetoothAdapter> adapter) {
1002 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 924 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1003 set_adapter(adapter); 925 set_adapter(adapter);
1004 continuation.Run(); 926 continuation.Run();
1005 } 927 }
1006 928
1007 void BluetoothDispatcherHost::OnRequestDeviceImpl( 929 void BluetoothDispatcherHost::OnRequestDeviceImpl(
1008 int thread_id, 930 int thread_id,
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 1293
1372 // If a value is already in map, DCHECK it's valid. 1294 // If a value is already in map, DCHECK it's valid.
1373 if (!insert_result.second) 1295 if (!insert_result.second)
1374 DCHECK_EQ(insert_result.first->second, device_address); 1296 DCHECK_EQ(insert_result.first->second, device_address);
1375 1297
1376 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS); 1298 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS);
1377 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, 1299 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id,
1378 service_identifier)); 1300 service_identifier));
1379 } 1301 }
1380 1302
1381 void BluetoothDispatcherHost::OnCharacteristicValueRead(
1382 int thread_id,
1383 int request_id,
1384 const std::vector<uint8_t>& value) {
1385 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1386 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS);
1387 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id,
1388 value));
1389 }
1390
1391 void BluetoothDispatcherHost::OnCharacteristicReadValueError(
1392 int thread_id,
1393 int request_id,
1394 device::BluetoothGattService::GattErrorCode error_code) {
1395 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1396 // TranslateGATTError calls RecordGATTOperationOutcome.
1397 Send(new BluetoothMsg_ReadCharacteristicValueError(
1398 thread_id, request_id,
1399 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ)));
1400 }
1401
1402 BluetoothDispatcherHost::CacheQueryResult 1303 BluetoothDispatcherHost::CacheQueryResult
1403 BluetoothDispatcherHost::QueryCacheForDevice(const url::Origin& origin, 1304 BluetoothDispatcherHost::QueryCacheForDevice(const url::Origin& origin,
1404 const std::string& device_id) { 1305 const std::string& device_id) {
1405 const std::string& device_address = 1306 const std::string& device_address =
1406 allowed_devices_map_.GetDeviceAddress(origin, device_id); 1307 allowed_devices_map_.GetDeviceAddress(origin, device_id);
1407 if (device_address.empty()) { 1308 if (device_address.empty()) {
1408 bad_message::ReceivedBadMessage( 1309 bad_message::ReceivedBadMessage(
1409 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 1310 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
1410 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 1311 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
1411 } 1312 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 const PrimaryServicesRequest& request) { 1415 const PrimaryServicesRequest& request) {
1515 pending_primary_services_requests_[device_address].push_back(request); 1416 pending_primary_services_requests_[device_address].push_back(request);
1516 } 1417 }
1517 1418
1518 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) { 1419 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) {
1519 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id) 1420 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id)
1520 ->GetLastCommittedOrigin(); 1421 ->GetLastCommittedOrigin();
1521 } 1422 }
1522 1423
1523 } // namespace content 1424 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/browser/bluetooth/web_bluetooth_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698