| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // WebBluetoothServiceImpl map [service_id_to_device_address_, | 7 // WebBluetoothServiceImpl map [service_id_to_device_address_, |
| 8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a | 8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a |
| 9 // hostile renderer because a renderer obtains the corresponding ID from this | 9 // hostile renderer because a renderer obtains the corresponding ID from this |
| 10 // class and it will be added to the map at that time. | 10 // class and it will be added to the map at that time. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" | 28 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 29 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 30 | 30 |
| 31 using device::BluetoothAdapterFactoryWrapper; | 31 using device::BluetoothAdapterFactoryWrapper; |
| 32 using device::BluetoothUUID; | 32 using device::BluetoothUUID; |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord( | 38 blink::mojom::WebBluetoothResult TranslateConnectErrorAndRecord( |
| 39 device::BluetoothDevice::ConnectErrorCode error_code) { | 39 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 40 switch (error_code) { | 40 switch (error_code) { |
| 41 case device::BluetoothDevice::ERROR_UNKNOWN: | 41 case device::BluetoothDevice::ERROR_UNKNOWN: |
| 42 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN); | 42 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN); |
| 43 return blink::mojom::WebBluetoothError::CONNECT_UNKNOWN_ERROR; | 43 return blink::mojom::WebBluetoothResult::CONNECT_UNKNOWN_ERROR; |
| 44 case device::BluetoothDevice::ERROR_INPROGRESS: | 44 case device::BluetoothDevice::ERROR_INPROGRESS: |
| 45 RecordConnectGATTOutcome(UMAConnectGATTOutcome::IN_PROGRESS); | 45 RecordConnectGATTOutcome(UMAConnectGATTOutcome::IN_PROGRESS); |
| 46 return blink::mojom::WebBluetoothError::CONNECT_ALREADY_IN_PROGRESS; | 46 return blink::mojom::WebBluetoothResult::CONNECT_ALREADY_IN_PROGRESS; |
| 47 case device::BluetoothDevice::ERROR_FAILED: | 47 case device::BluetoothDevice::ERROR_FAILED: |
| 48 RecordConnectGATTOutcome(UMAConnectGATTOutcome::FAILED); | 48 RecordConnectGATTOutcome(UMAConnectGATTOutcome::FAILED); |
| 49 return blink::mojom::WebBluetoothError::CONNECT_UNKNOWN_FAILURE; | 49 return blink::mojom::WebBluetoothResult::CONNECT_UNKNOWN_FAILURE; |
| 50 case device::BluetoothDevice::ERROR_AUTH_FAILED: | 50 case device::BluetoothDevice::ERROR_AUTH_FAILED: |
| 51 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_FAILED); | 51 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_FAILED); |
| 52 return blink::mojom::WebBluetoothError::CONNECT_AUTH_FAILED; | 52 return blink::mojom::WebBluetoothResult::CONNECT_AUTH_FAILED; |
| 53 case device::BluetoothDevice::ERROR_AUTH_CANCELED: | 53 case device::BluetoothDevice::ERROR_AUTH_CANCELED: |
| 54 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_CANCELED); | 54 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_CANCELED); |
| 55 return blink::mojom::WebBluetoothError::CONNECT_AUTH_CANCELED; | 55 return blink::mojom::WebBluetoothResult::CONNECT_AUTH_CANCELED; |
| 56 case device::BluetoothDevice::ERROR_AUTH_REJECTED: | 56 case device::BluetoothDevice::ERROR_AUTH_REJECTED: |
| 57 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_REJECTED); | 57 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_REJECTED); |
| 58 return blink::mojom::WebBluetoothError::CONNECT_AUTH_REJECTED; | 58 return blink::mojom::WebBluetoothResult::CONNECT_AUTH_REJECTED; |
| 59 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT: | 59 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT: |
| 60 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_TIMEOUT); | 60 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_TIMEOUT); |
| 61 return blink::mojom::WebBluetoothError::CONNECT_AUTH_TIMEOUT; | 61 return blink::mojom::WebBluetoothResult::CONNECT_AUTH_TIMEOUT; |
| 62 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: | 62 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: |
| 63 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE); | 63 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE); |
| 64 return blink::mojom::WebBluetoothError::CONNECT_UNSUPPORTED_DEVICE; | 64 return blink::mojom::WebBluetoothResult::CONNECT_UNSUPPORTED_DEVICE; |
| 65 case device::BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID: | 65 case device::BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID: |
| 66 RecordConnectGATTOutcome(UMAConnectGATTOutcome::ATTRIBUTE_LENGTH_INVALID); | 66 RecordConnectGATTOutcome(UMAConnectGATTOutcome::ATTRIBUTE_LENGTH_INVALID); |
| 67 return blink::mojom::WebBluetoothError::CONNECT_ATTRIBUTE_LENGTH_INVALID; | 67 return blink::mojom::WebBluetoothResult::CONNECT_ATTRIBUTE_LENGTH_INVALID; |
| 68 case device::BluetoothDevice::ERROR_CONNECTION_CONGESTED: | 68 case device::BluetoothDevice::ERROR_CONNECTION_CONGESTED: |
| 69 RecordConnectGATTOutcome(UMAConnectGATTOutcome::CONNECTION_CONGESTED); | 69 RecordConnectGATTOutcome(UMAConnectGATTOutcome::CONNECTION_CONGESTED); |
| 70 return blink::mojom::WebBluetoothError::CONNECT_CONNECTION_CONGESTED; | 70 return blink::mojom::WebBluetoothResult::CONNECT_CONNECTION_CONGESTED; |
| 71 case device::BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION: | 71 case device::BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION: |
| 72 RecordConnectGATTOutcome(UMAConnectGATTOutcome::INSUFFICIENT_ENCRYPTION); | 72 RecordConnectGATTOutcome(UMAConnectGATTOutcome::INSUFFICIENT_ENCRYPTION); |
| 73 return blink::mojom::WebBluetoothError::CONNECT_INSUFFICIENT_ENCRYPTION; | 73 return blink::mojom::WebBluetoothResult::CONNECT_INSUFFICIENT_ENCRYPTION; |
| 74 case device::BluetoothDevice::ERROR_OFFSET_INVALID: | 74 case device::BluetoothDevice::ERROR_OFFSET_INVALID: |
| 75 RecordConnectGATTOutcome(UMAConnectGATTOutcome::OFFSET_INVALID); | 75 RecordConnectGATTOutcome(UMAConnectGATTOutcome::OFFSET_INVALID); |
| 76 return blink::mojom::WebBluetoothError::CONNECT_OFFSET_INVALID; | 76 return blink::mojom::WebBluetoothResult::CONNECT_OFFSET_INVALID; |
| 77 case device::BluetoothDevice::ERROR_READ_NOT_PERMITTED: | 77 case device::BluetoothDevice::ERROR_READ_NOT_PERMITTED: |
| 78 RecordConnectGATTOutcome(UMAConnectGATTOutcome::READ_NOT_PERMITTED); | 78 RecordConnectGATTOutcome(UMAConnectGATTOutcome::READ_NOT_PERMITTED); |
| 79 return blink::mojom::WebBluetoothError::CONNECT_READ_NOT_PERMITTED; | 79 return blink::mojom::WebBluetoothResult::CONNECT_READ_NOT_PERMITTED; |
| 80 case device::BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED: | 80 case device::BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED: |
| 81 RecordConnectGATTOutcome(UMAConnectGATTOutcome::REQUEST_NOT_SUPPORTED); | 81 RecordConnectGATTOutcome(UMAConnectGATTOutcome::REQUEST_NOT_SUPPORTED); |
| 82 return blink::mojom::WebBluetoothError::CONNECT_REQUEST_NOT_SUPPORTED; | 82 return blink::mojom::WebBluetoothResult::CONNECT_REQUEST_NOT_SUPPORTED; |
| 83 case device::BluetoothDevice::ERROR_WRITE_NOT_PERMITTED: | 83 case device::BluetoothDevice::ERROR_WRITE_NOT_PERMITTED: |
| 84 RecordConnectGATTOutcome(UMAConnectGATTOutcome::WRITE_NOT_PERMITTED); | 84 RecordConnectGATTOutcome(UMAConnectGATTOutcome::WRITE_NOT_PERMITTED); |
| 85 return blink::mojom::WebBluetoothError::CONNECT_WRITE_NOT_PERMITTED; | 85 return blink::mojom::WebBluetoothResult::CONNECT_WRITE_NOT_PERMITTED; |
| 86 case device::BluetoothDevice::NUM_CONNECT_ERROR_CODES: | 86 case device::BluetoothDevice::NUM_CONNECT_ERROR_CODES: |
| 87 NOTREACHED(); | 87 NOTREACHED(); |
| 88 return blink::mojom::WebBluetoothError::UNTRANSLATED_CONNECT_ERROR_CODE; | 88 return blink::mojom::WebBluetoothResult::UNTRANSLATED_CONNECT_ERROR_CODE; |
| 89 } | 89 } |
| 90 NOTREACHED(); | 90 NOTREACHED(); |
| 91 return blink::mojom::WebBluetoothError::UNTRANSLATED_CONNECT_ERROR_CODE; | 91 return blink::mojom::WebBluetoothResult::UNTRANSLATED_CONNECT_ERROR_CODE; |
| 92 } | 92 } |
| 93 | 93 |
| 94 blink::mojom::WebBluetoothError TranslateGATTErrorAndRecord( | 94 blink::mojom::WebBluetoothResult TranslateGATTErrorAndRecord( |
| 95 device::BluetoothRemoteGattService::GattErrorCode error_code, | 95 device::BluetoothRemoteGattService::GattErrorCode error_code, |
| 96 UMAGATTOperation operation) { | 96 UMAGATTOperation operation) { |
| 97 switch (error_code) { | 97 switch (error_code) { |
| 98 case device::BluetoothRemoteGattService::GATT_ERROR_UNKNOWN: | 98 case device::BluetoothRemoteGattService::GATT_ERROR_UNKNOWN: |
| 99 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::UNKNOWN); | 99 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::UNKNOWN); |
| 100 return blink::mojom::WebBluetoothError::GATT_UNKNOWN_ERROR; | 100 return blink::mojom::WebBluetoothResult::GATT_UNKNOWN_ERROR; |
| 101 case device::BluetoothRemoteGattService::GATT_ERROR_FAILED: | 101 case device::BluetoothRemoteGattService::GATT_ERROR_FAILED: |
| 102 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::FAILED); | 102 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::FAILED); |
| 103 return blink::mojom::WebBluetoothError::GATT_UNKNOWN_FAILURE; | 103 return blink::mojom::WebBluetoothResult::GATT_UNKNOWN_FAILURE; |
| 104 case device::BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS: | 104 case device::BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS: |
| 105 RecordGATTOperationOutcome(operation, | 105 RecordGATTOperationOutcome(operation, |
| 106 UMAGATTOperationOutcome::IN_PROGRESS); | 106 UMAGATTOperationOutcome::IN_PROGRESS); |
| 107 return blink::mojom::WebBluetoothError::GATT_OPERATION_IN_PROGRESS; | 107 return blink::mojom::WebBluetoothResult::GATT_OPERATION_IN_PROGRESS; |
| 108 case device::BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH: | 108 case device::BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH: |
| 109 RecordGATTOperationOutcome(operation, | 109 RecordGATTOperationOutcome(operation, |
| 110 UMAGATTOperationOutcome::INVALID_LENGTH); | 110 UMAGATTOperationOutcome::INVALID_LENGTH); |
| 111 return blink::mojom::WebBluetoothError::GATT_INVALID_ATTRIBUTE_LENGTH; | 111 return blink::mojom::WebBluetoothResult::GATT_INVALID_ATTRIBUTE_LENGTH; |
| 112 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED: | 112 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED: |
| 113 RecordGATTOperationOutcome(operation, | 113 RecordGATTOperationOutcome(operation, |
| 114 UMAGATTOperationOutcome::NOT_PERMITTED); | 114 UMAGATTOperationOutcome::NOT_PERMITTED); |
| 115 return blink::mojom::WebBluetoothError::GATT_NOT_PERMITTED; | 115 return blink::mojom::WebBluetoothResult::GATT_NOT_PERMITTED; |
| 116 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_AUTHORIZED: | 116 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_AUTHORIZED: |
| 117 RecordGATTOperationOutcome(operation, | 117 RecordGATTOperationOutcome(operation, |
| 118 UMAGATTOperationOutcome::NOT_AUTHORIZED); | 118 UMAGATTOperationOutcome::NOT_AUTHORIZED); |
| 119 return blink::mojom::WebBluetoothError::GATT_NOT_AUTHORIZED; | 119 return blink::mojom::WebBluetoothResult::GATT_NOT_AUTHORIZED; |
| 120 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_PAIRED: | 120 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_PAIRED: |
| 121 RecordGATTOperationOutcome(operation, | 121 RecordGATTOperationOutcome(operation, |
| 122 UMAGATTOperationOutcome::NOT_PAIRED); | 122 UMAGATTOperationOutcome::NOT_PAIRED); |
| 123 return blink::mojom::WebBluetoothError::GATT_NOT_PAIRED; | 123 return blink::mojom::WebBluetoothResult::GATT_NOT_PAIRED; |
| 124 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED: | 124 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED: |
| 125 RecordGATTOperationOutcome(operation, | 125 RecordGATTOperationOutcome(operation, |
| 126 UMAGATTOperationOutcome::NOT_SUPPORTED); | 126 UMAGATTOperationOutcome::NOT_SUPPORTED); |
| 127 return blink::mojom::WebBluetoothError::GATT_NOT_SUPPORTED; | 127 return blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED; |
| 128 } | 128 } |
| 129 NOTREACHED(); | 129 NOTREACHED(); |
| 130 return blink::mojom::WebBluetoothError::GATT_UNTRANSLATED_ERROR_CODE; | 130 return blink::mojom::WebBluetoothResult::GATT_UNTRANSLATED_ERROR_CODE; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // TODO(ortuno): This should really be a BluetoothDevice method. | 133 // TODO(ortuno): This should really be a BluetoothDevice method. |
| 134 // Replace when implemented. http://crbug.com/552022 | 134 // Replace when implemented. http://crbug.com/552022 |
| 135 std::vector<device::BluetoothRemoteGattCharacteristic*> | 135 std::vector<device::BluetoothRemoteGattCharacteristic*> |
| 136 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service, | 136 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service, |
| 137 const BluetoothUUID& characteristic_uuid) { | 137 const BluetoothUUID& characteristic_uuid) { |
| 138 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; | 138 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; |
| 139 VLOG(1) << "Looking for characteristic: " | 139 VLOG(1) << "Looking for characteristic: " |
| 140 << characteristic_uuid.canonical_value(); | 140 << characteristic_uuid.canonical_value(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 if (!GetAdapter()) { | 330 if (!GetAdapter()) { |
| 331 if (BluetoothAdapterFactoryWrapper::Get().IsBluetoothAdapterAvailable()) { | 331 if (BluetoothAdapterFactoryWrapper::Get().IsBluetoothAdapterAvailable()) { |
| 332 BluetoothAdapterFactoryWrapper::Get().AcquireAdapter( | 332 BluetoothAdapterFactoryWrapper::Get().AcquireAdapter( |
| 333 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, | 333 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, |
| 334 weak_ptr_factory_.GetWeakPtr(), | 334 weak_ptr_factory_.GetWeakPtr(), |
| 335 base::Passed(std::move(options)), callback)); | 335 base::Passed(std::move(options)), callback)); |
| 336 return; | 336 return; |
| 337 } | 337 } |
| 338 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); | 338 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
| 339 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, | 339 callback.Run(blink::mojom::WebBluetoothResult::NO_BLUETOOTH_ADAPTER, |
| 340 nullptr /* device */); | 340 nullptr /* device */); |
| 341 return; | 341 return; |
| 342 } | 342 } |
| 343 RequestDeviceImpl(std::move(options), callback, GetAdapter()); | 343 RequestDeviceImpl(std::move(options), callback, GetAdapter()); |
| 344 } | 344 } |
| 345 | 345 |
| 346 void WebBluetoothServiceImpl::RemoteServerConnect( | 346 void WebBluetoothServiceImpl::RemoteServerConnect( |
| 347 const WebBluetoothDeviceId& device_id, | 347 const WebBluetoothDeviceId& device_id, |
| 348 const RemoteServerConnectCallback& callback) { | 348 const RemoteServerConnectCallback& callback) { |
| 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 350 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); | 350 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); |
| 351 | 351 |
| 352 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 352 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
| 353 | 353 |
| 354 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 354 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 355 RecordConnectGATTOutcome(query_result.outcome); | 355 RecordConnectGATTOutcome(query_result.outcome); |
| 356 callback.Run(query_result.GetWebError()); | 356 callback.Run(query_result.GetWebResult()); |
| 357 return; | 357 return; |
| 358 } | 358 } |
| 359 | 359 |
| 360 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 360 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
| 361 VLOG(1) << "Already connected."; | 361 VLOG(1) << "Already connected."; |
| 362 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 362 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 363 return; | 363 return; |
| 364 } | 364 } |
| 365 | 365 |
| 366 // It's possible for WebBluetoothServiceImpl to issue two successive | 366 // It's possible for WebBluetoothServiceImpl to issue two successive |
| 367 // connection requests for which it would get two successive responses | 367 // connection requests for which it would get two successive responses |
| 368 // and consequently try to insert two BluetoothGattConnections for the | 368 // and consequently try to insert two BluetoothGattConnections for the |
| 369 // same device. WebBluetoothServiceImpl should reject or queue connection | 369 // same device. WebBluetoothServiceImpl should reject or queue connection |
| 370 // requests if there is a pending connection already, but the platform | 370 // requests if there is a pending connection already, but the platform |
| 371 // abstraction doesn't currently support checking for pending connections. | 371 // abstraction doesn't currently support checking for pending connections. |
| 372 // TODO(ortuno): CHECK that this never happens once the platform | 372 // TODO(ortuno): CHECK that this never happens once the platform |
| (...skipping 28 matching lines...) Expand all Loading... |
| 401 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 401 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 402 RecordWebBluetoothFunctionCall( | 402 RecordWebBluetoothFunctionCall( |
| 403 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 403 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 404 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE | 404 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE |
| 405 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); | 405 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); |
| 406 RecordGetPrimaryServicesServices(quantity, services_uuid); | 406 RecordGetPrimaryServicesServices(quantity, services_uuid); |
| 407 | 407 |
| 408 if (services_uuid && | 408 if (services_uuid && |
| 409 !allowed_devices_map_.IsOriginAllowedToAccessService( | 409 !allowed_devices_map_.IsOriginAllowedToAccessService( |
| 410 GetOrigin(), device_id, services_uuid.value())) { | 410 GetOrigin(), device_id, services_uuid.value())) { |
| 411 callback.Run(blink::mojom::WebBluetoothError::NOT_ALLOWED_TO_ACCESS_SERVICE, | 411 callback.Run( |
| 412 nullptr /* service */); | 412 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE, |
| 413 nullptr /* service */); |
| 413 return; | 414 return; |
| 414 } | 415 } |
| 415 | 416 |
| 416 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 417 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
| 417 | 418 |
| 418 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 419 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 419 return; | 420 return; |
| 420 } | 421 } |
| 421 | 422 |
| 422 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 423 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 423 RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); | 424 RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); |
| 424 callback.Run(query_result.GetWebError(), nullptr /* service */); | 425 callback.Run(query_result.GetWebResult(), nullptr /* service */); |
| 425 return; | 426 return; |
| 426 } | 427 } |
| 427 | 428 |
| 428 const std::string& device_address = query_result.device->GetAddress(); | 429 const std::string& device_address = query_result.device->GetAddress(); |
| 429 | 430 |
| 430 // We can't know if a service is present or not until GATT service discovery | 431 // We can't know if a service is present or not until GATT service discovery |
| 431 // is complete for the device. | 432 // is complete for the device. |
| 432 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 433 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
| 433 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, | 434 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, |
| 434 callback, query_result.device); | 435 callback, query_result.device); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 452 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 453 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 453 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC | 454 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC |
| 454 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); | 455 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
| 455 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); | 456 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); |
| 456 | 457 |
| 457 if (characteristics_uuid && | 458 if (characteristics_uuid && |
| 458 BluetoothBlacklist::Get().IsExcluded(characteristics_uuid.value())) { | 459 BluetoothBlacklist::Get().IsExcluded(characteristics_uuid.value())) { |
| 459 RecordGetCharacteristicsOutcome(quantity, | 460 RecordGetCharacteristicsOutcome(quantity, |
| 460 UMAGetCharacteristicOutcome::BLACKLISTED); | 461 UMAGetCharacteristicOutcome::BLACKLISTED); |
| 461 callback.Run( | 462 callback.Run( |
| 462 blink::mojom::WebBluetoothError::BLACKLISTED_CHARACTERISTIC_UUID, | 463 blink::mojom::WebBluetoothResult::BLACKLISTED_CHARACTERISTIC_UUID, |
| 463 nullptr /* characteristics */); | 464 nullptr /* characteristics */); |
| 464 return; | 465 return; |
| 465 } | 466 } |
| 466 | 467 |
| 467 const CacheQueryResult query_result = | 468 const CacheQueryResult query_result = |
| 468 QueryCacheForService(service_instance_id); | 469 QueryCacheForService(service_instance_id); |
| 469 | 470 |
| 470 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 471 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 471 return; | 472 return; |
| 472 } | 473 } |
| 473 | 474 |
| 474 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 475 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 475 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 476 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
| 476 callback.Run(query_result.GetWebError(), nullptr /* characteristics */); | 477 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); |
| 477 return; | 478 return; |
| 478 } | 479 } |
| 479 | 480 |
| 480 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 481 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
| 481 characteristics_uuid | 482 characteristics_uuid |
| 482 ? GetCharacteristicsByUUID(query_result.service, | 483 ? GetCharacteristicsByUUID(query_result.service, |
| 483 characteristics_uuid.value()) | 484 characteristics_uuid.value()) |
| 484 : query_result.service->GetCharacteristics(); | 485 : query_result.service->GetCharacteristics(); |
| 485 | 486 |
| 486 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 487 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 506 response_characteristics.push_back(std::move(characteristic_ptr)); | 507 response_characteristics.push_back(std::move(characteristic_ptr)); |
| 507 | 508 |
| 508 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { | 509 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 509 break; | 510 break; |
| 510 } | 511 } |
| 511 } | 512 } |
| 512 | 513 |
| 513 if (!response_characteristics.empty()) { | 514 if (!response_characteristics.empty()) { |
| 514 RecordGetCharacteristicsOutcome(quantity, | 515 RecordGetCharacteristicsOutcome(quantity, |
| 515 UMAGetCharacteristicOutcome::SUCCESS); | 516 UMAGetCharacteristicOutcome::SUCCESS); |
| 516 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | 517 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 517 std::move(response_characteristics)); | 518 std::move(response_characteristics)); |
| 518 return; | 519 return; |
| 519 } | 520 } |
| 520 | 521 |
| 521 RecordGetCharacteristicsOutcome( | 522 RecordGetCharacteristicsOutcome( |
| 522 quantity, characteristics_uuid | 523 quantity, characteristics_uuid |
| 523 ? UMAGetCharacteristicOutcome::NOT_FOUND | 524 ? UMAGetCharacteristicOutcome::NOT_FOUND |
| 524 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); | 525 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); |
| 525 callback.Run(characteristics_uuid | 526 callback.Run(characteristics_uuid |
| 526 ? blink::mojom::WebBluetoothError::CHARACTERISTIC_NOT_FOUND | 527 ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND |
| 527 : blink::mojom::WebBluetoothError::NO_CHARACTERISTICS_FOUND, | 528 : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, |
| 528 nullptr /* characteristics */); | 529 nullptr /* characteristics */); |
| 529 } | 530 } |
| 530 | 531 |
| 531 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( | 532 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( |
| 532 const mojo::String& characteristic_instance_id, | 533 const mojo::String& characteristic_instance_id, |
| 533 const RemoteCharacteristicReadValueCallback& callback) { | 534 const RemoteCharacteristicReadValueCallback& callback) { |
| 534 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 535 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 535 RecordWebBluetoothFunctionCall( | 536 RecordWebBluetoothFunctionCall( |
| 536 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | 537 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); |
| 537 | 538 |
| 538 const CacheQueryResult query_result = | 539 const CacheQueryResult query_result = |
| 539 QueryCacheForCharacteristic(characteristic_instance_id); | 540 QueryCacheForCharacteristic(characteristic_instance_id); |
| 540 | 541 |
| 541 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 542 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 542 return; | 543 return; |
| 543 } | 544 } |
| 544 | 545 |
| 545 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 546 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 546 RecordCharacteristicReadValueOutcome(query_result.outcome); | 547 RecordCharacteristicReadValueOutcome(query_result.outcome); |
| 547 callback.Run(query_result.GetWebError(), nullptr /* value */); | 548 callback.Run(query_result.GetWebResult(), nullptr /* value */); |
| 548 return; | 549 return; |
| 549 } | 550 } |
| 550 | 551 |
| 551 if (BluetoothBlacklist::Get().IsExcludedFromReads( | 552 if (BluetoothBlacklist::Get().IsExcludedFromReads( |
| 552 query_result.characteristic->GetUUID())) { | 553 query_result.characteristic->GetUUID())) { |
| 553 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 554 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); |
| 554 callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_READ, | 555 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_READ, |
| 555 nullptr /* value */); | 556 nullptr /* value */); |
| 556 return; | 557 return; |
| 557 } | 558 } |
| 558 | 559 |
| 559 query_result.characteristic->ReadRemoteCharacteristic( | 560 query_result.characteristic->ReadRemoteCharacteristic( |
| 560 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | 561 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, |
| 561 weak_ptr_factory_.GetWeakPtr(), callback), | 562 weak_ptr_factory_.GetWeakPtr(), callback), |
| 562 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | 563 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, |
| 563 weak_ptr_factory_.GetWeakPtr(), callback)); | 564 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 564 } | 565 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 581 | 582 |
| 582 const CacheQueryResult query_result = | 583 const CacheQueryResult query_result = |
| 583 QueryCacheForCharacteristic(characteristic_instance_id); | 584 QueryCacheForCharacteristic(characteristic_instance_id); |
| 584 | 585 |
| 585 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 586 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 586 return; | 587 return; |
| 587 } | 588 } |
| 588 | 589 |
| 589 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 590 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 590 RecordCharacteristicWriteValueOutcome(query_result.outcome); | 591 RecordCharacteristicWriteValueOutcome(query_result.outcome); |
| 591 callback.Run(query_result.GetWebError()); | 592 callback.Run(query_result.GetWebResult()); |
| 592 return; | 593 return; |
| 593 } | 594 } |
| 594 | 595 |
| 595 if (BluetoothBlacklist::Get().IsExcludedFromWrites( | 596 if (BluetoothBlacklist::Get().IsExcludedFromWrites( |
| 596 query_result.characteristic->GetUUID())) { | 597 query_result.characteristic->GetUUID())) { |
| 597 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 598 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); |
| 598 callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_WRITE); | 599 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_WRITE); |
| 599 return; | 600 return; |
| 600 } | 601 } |
| 601 | 602 |
| 602 query_result.characteristic->WriteRemoteCharacteristic( | 603 query_result.characteristic->WriteRemoteCharacteristic( |
| 603 value.To<std::vector<uint8_t>>(), | 604 value.To<std::vector<uint8_t>>(), |
| 604 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, | 605 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, |
| 605 weak_ptr_factory_.GetWeakPtr(), callback), | 606 weak_ptr_factory_.GetWeakPtr(), callback), |
| 606 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, | 607 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, |
| 607 weak_ptr_factory_.GetWeakPtr(), callback)); | 608 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 608 } | 609 } |
| 609 | 610 |
| 610 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( | 611 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
| 611 const mojo::String& characteristic_instance_id, | 612 const mojo::String& characteristic_instance_id, |
| 612 const RemoteCharacteristicStartNotificationsCallback& callback) { | 613 const RemoteCharacteristicStartNotificationsCallback& callback) { |
| 613 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 614 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 614 RecordWebBluetoothFunctionCall( | 615 RecordWebBluetoothFunctionCall( |
| 615 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | 616 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); |
| 616 | 617 |
| 617 auto iter = | 618 auto iter = |
| 618 characteristic_id_to_notify_session_.find(characteristic_instance_id); | 619 characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| 619 if (iter != characteristic_id_to_notify_session_.end() && | 620 if (iter != characteristic_id_to_notify_session_.end() && |
| 620 iter->second->IsActive()) { | 621 iter->second->IsActive()) { |
| 621 // If the frame has already started notifications and the notifications | 622 // If the frame has already started notifications and the notifications |
| 622 // are active we return SUCCESS. | 623 // are active we return SUCCESS. |
| 623 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 624 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 624 return; | 625 return; |
| 625 } | 626 } |
| 626 | 627 |
| 627 const CacheQueryResult query_result = | 628 const CacheQueryResult query_result = |
| 628 QueryCacheForCharacteristic(characteristic_instance_id); | 629 QueryCacheForCharacteristic(characteristic_instance_id); |
| 629 | 630 |
| 630 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 631 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 631 return; | 632 return; |
| 632 } | 633 } |
| 633 | 634 |
| 634 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 635 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 635 RecordStartNotificationsOutcome(query_result.outcome); | 636 RecordStartNotificationsOutcome(query_result.outcome); |
| 636 callback.Run(query_result.GetWebError()); | 637 callback.Run(query_result.GetWebResult()); |
| 637 return; | 638 return; |
| 638 } | 639 } |
| 639 | 640 |
| 640 device::BluetoothRemoteGattCharacteristic::Properties notify_or_indicate = | 641 device::BluetoothRemoteGattCharacteristic::Properties notify_or_indicate = |
| 641 query_result.characteristic->GetProperties() & | 642 query_result.characteristic->GetProperties() & |
| 642 (device::BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | | 643 (device::BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | |
| 643 device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE); | 644 device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE); |
| 644 if (!notify_or_indicate) { | 645 if (!notify_or_indicate) { |
| 645 callback.Run(blink::mojom::WebBluetoothError::GATT_NOT_SUPPORTED); | 646 callback.Run(blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED); |
| 646 return; | 647 return; |
| 647 } | 648 } |
| 648 | 649 |
| 649 query_result.characteristic->StartNotifySession( | 650 query_result.characteristic->StartNotifySession( |
| 650 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, | 651 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, |
| 651 weak_ptr_factory_.GetWeakPtr(), callback), | 652 weak_ptr_factory_.GetWeakPtr(), callback), |
| 652 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, | 653 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, |
| 653 weak_ptr_factory_.GetWeakPtr(), callback)); | 654 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 654 } | 655 } |
| 655 | 656 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 738 |
| 738 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { | 739 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 739 break; | 740 break; |
| 740 } | 741 } |
| 741 } | 742 } |
| 742 | 743 |
| 743 if (!response_services.empty()) { | 744 if (!response_services.empty()) { |
| 744 VLOG(1) << "Services found in device."; | 745 VLOG(1) << "Services found in device."; |
| 745 RecordGetPrimaryServicesOutcome(quantity, | 746 RecordGetPrimaryServicesOutcome(quantity, |
| 746 UMAGetPrimaryServiceOutcome::SUCCESS); | 747 UMAGetPrimaryServiceOutcome::SUCCESS); |
| 747 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | 748 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 748 std::move(response_services)); | 749 std::move(response_services)); |
| 749 return; | 750 return; |
| 750 } | 751 } |
| 751 | 752 |
| 752 VLOG(1) << "Services not found in device."; | 753 VLOG(1) << "Services not found in device."; |
| 753 RecordGetPrimaryServicesOutcome( | 754 RecordGetPrimaryServicesOutcome( |
| 754 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND | 755 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND |
| 755 : UMAGetPrimaryServiceOutcome::NO_SERVICES); | 756 : UMAGetPrimaryServiceOutcome::NO_SERVICES); |
| 756 callback.Run(services_uuid | 757 callback.Run(services_uuid |
| 757 ? blink::mojom::WebBluetoothError::SERVICE_NOT_FOUND | 758 ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND |
| 758 : blink::mojom::WebBluetoothError::NO_SERVICES_FOUND, | 759 : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, |
| 759 nullptr /* services */); | 760 nullptr /* services */); |
| 760 } | 761 } |
| 761 | 762 |
| 762 void WebBluetoothServiceImpl::OnGetDeviceSuccess( | 763 void WebBluetoothServiceImpl::OnGetDeviceSuccess( |
| 763 const RequestDeviceCallback& callback, | 764 const RequestDeviceCallback& callback, |
| 764 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 765 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| 765 const std::string& device_address) { | 766 const std::string& device_address) { |
| 766 device_chooser_controller_.reset(); | 767 device_chooser_controller_.reset(); |
| 767 | 768 |
| 768 const device::BluetoothDevice* const device = | 769 const device::BluetoothDevice* const device = |
| 769 GetAdapter()->GetDevice(device_address); | 770 GetAdapter()->GetDevice(device_address); |
| 770 if (device == nullptr) { | 771 if (device == nullptr) { |
| 771 VLOG(1) << "Device " << device_address << " no longer in adapter"; | 772 VLOG(1) << "Device " << device_address << " no longer in adapter"; |
| 772 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); | 773 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); |
| 773 callback.Run(blink::mojom::WebBluetoothError::CHOSEN_DEVICE_VANISHED, | 774 callback.Run(blink::mojom::WebBluetoothResult::CHOSEN_DEVICE_VANISHED, |
| 774 nullptr /* device */); | 775 nullptr /* device */); |
| 775 return; | 776 return; |
| 776 } | 777 } |
| 777 | 778 |
| 778 const WebBluetoothDeviceId device_id_for_origin = | 779 const WebBluetoothDeviceId device_id_for_origin = |
| 779 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); | 780 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); |
| 780 | 781 |
| 781 VLOG(1) << "Device: " << device->GetNameForDisplay(); | 782 VLOG(1) << "Device: " << device->GetNameForDisplay(); |
| 782 VLOG(1) << "UUIDs: "; | 783 VLOG(1) << "UUIDs: "; |
| 783 | 784 |
| 784 mojo::Array<mojo::String> filtered_uuids; | 785 mojo::Array<mojo::String> filtered_uuids; |
| 785 for (const BluetoothUUID& uuid : device->GetUUIDs()) { | 786 for (const BluetoothUUID& uuid : device->GetUUIDs()) { |
| 786 if (allowed_devices_map_.IsOriginAllowedToAccessService( | 787 if (allowed_devices_map_.IsOriginAllowedToAccessService( |
| 787 GetOrigin(), device_id_for_origin, uuid)) { | 788 GetOrigin(), device_id_for_origin, uuid)) { |
| 788 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); | 789 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); |
| 789 filtered_uuids.push_back(uuid.canonical_value()); | 790 filtered_uuids.push_back(uuid.canonical_value()); |
| 790 } else { | 791 } else { |
| 791 VLOG(1) << "\t Not Allowed: " << uuid.canonical_value(); | 792 VLOG(1) << "\t Not Allowed: " << uuid.canonical_value(); |
| 792 } | 793 } |
| 793 } | 794 } |
| 794 | 795 |
| 795 blink::mojom::WebBluetoothDevicePtr device_ptr = | 796 blink::mojom::WebBluetoothDevicePtr device_ptr = |
| 796 blink::mojom::WebBluetoothDevice::New(); | 797 blink::mojom::WebBluetoothDevice::New(); |
| 797 device_ptr->id = device_id_for_origin; | 798 device_ptr->id = device_id_for_origin; |
| 798 device_ptr->name = device->GetName() ? mojo::String(device->GetName().value()) | 799 device_ptr->name = device->GetName() ? mojo::String(device->GetName().value()) |
| 799 : mojo::String(nullptr); | 800 : mojo::String(nullptr); |
| 800 device_ptr->uuids = std::move(filtered_uuids); | 801 device_ptr->uuids = std::move(filtered_uuids); |
| 801 | 802 |
| 802 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); | 803 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); |
| 803 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, std::move(device_ptr)); | 804 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 805 std::move(device_ptr)); |
| 804 } | 806 } |
| 805 | 807 |
| 806 void WebBluetoothServiceImpl::OnGetDeviceFailed( | 808 void WebBluetoothServiceImpl::OnGetDeviceFailed( |
| 807 const RequestDeviceCallback& callback, | 809 const RequestDeviceCallback& callback, |
| 808 blink::mojom::WebBluetoothError error) { | 810 blink::mojom::WebBluetoothResult result) { |
| 809 // Errors are recorded by the *device_chooser_controller_. | 811 // Errors are recorded by the *device_chooser_controller_. |
| 810 callback.Run(error, nullptr /* device */); | 812 callback.Run(result, nullptr /* device */); |
| 811 device_chooser_controller_.reset(); | 813 device_chooser_controller_.reset(); |
| 812 } | 814 } |
| 813 | 815 |
| 814 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( | 816 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( |
| 815 const WebBluetoothDeviceId& device_id, | 817 const WebBluetoothDeviceId& device_id, |
| 816 base::TimeTicks start_time, | 818 base::TimeTicks start_time, |
| 817 const RemoteServerConnectCallback& callback, | 819 const RemoteServerConnectCallback& callback, |
| 818 std::unique_ptr<device::BluetoothGattConnection> connection) { | 820 std::unique_ptr<device::BluetoothGattConnection> connection) { |
| 819 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 821 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 820 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); | 822 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); |
| 821 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); | 823 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); |
| 822 | 824 |
| 823 connected_devices_->Insert(device_id, std::move(connection)); | 825 connected_devices_->Insert(device_id, std::move(connection)); |
| 824 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 826 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 825 } | 827 } |
| 826 | 828 |
| 827 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( | 829 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( |
| 828 base::TimeTicks start_time, | 830 base::TimeTicks start_time, |
| 829 const RemoteServerConnectCallback& callback, | 831 const RemoteServerConnectCallback& callback, |
| 830 device::BluetoothDevice::ConnectErrorCode error_code) { | 832 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 831 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 833 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 832 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 834 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
| 833 callback.Run(TranslateConnectErrorAndRecord(error_code)); | 835 callback.Run(TranslateConnectErrorAndRecord(error_code)); |
| 834 } | 836 } |
| 835 | 837 |
| 836 void WebBluetoothServiceImpl::OnReadValueSuccess( | 838 void WebBluetoothServiceImpl::OnReadValueSuccess( |
| 837 const RemoteCharacteristicReadValueCallback& callback, | 839 const RemoteCharacteristicReadValueCallback& callback, |
| 838 const std::vector<uint8_t>& value) { | 840 const std::vector<uint8_t>& value) { |
| 839 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 841 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 840 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 842 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
| 841 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | 843 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 842 mojo::Array<uint8_t>::From(value)); | 844 mojo::Array<uint8_t>::From(value)); |
| 843 } | 845 } |
| 844 | 846 |
| 845 void WebBluetoothServiceImpl::OnReadValueFailed( | 847 void WebBluetoothServiceImpl::OnReadValueFailed( |
| 846 const RemoteCharacteristicReadValueCallback& callback, | 848 const RemoteCharacteristicReadValueCallback& callback, |
| 847 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 849 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 848 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 850 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 849 callback.Run(TranslateGATTErrorAndRecord( | 851 callback.Run(TranslateGATTErrorAndRecord( |
| 850 error_code, UMAGATTOperation::CHARACTERISTIC_READ), | 852 error_code, UMAGATTOperation::CHARACTERISTIC_READ), |
| 851 nullptr /* value */); | 853 nullptr /* value */); |
| 852 } | 854 } |
| 853 | 855 |
| 854 void WebBluetoothServiceImpl::OnWriteValueSuccess( | 856 void WebBluetoothServiceImpl::OnWriteValueSuccess( |
| 855 const RemoteCharacteristicWriteValueCallback& callback) { | 857 const RemoteCharacteristicWriteValueCallback& callback) { |
| 856 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 858 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 857 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 859 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
| 858 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 860 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 859 } | 861 } |
| 860 | 862 |
| 861 void WebBluetoothServiceImpl::OnWriteValueFailed( | 863 void WebBluetoothServiceImpl::OnWriteValueFailed( |
| 862 const RemoteCharacteristicWriteValueCallback& callback, | 864 const RemoteCharacteristicWriteValueCallback& callback, |
| 863 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 865 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 864 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 866 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 865 callback.Run(TranslateGATTErrorAndRecord( | 867 callback.Run(TranslateGATTErrorAndRecord( |
| 866 error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)); | 868 error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)); |
| 867 } | 869 } |
| 868 | 870 |
| 869 void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( | 871 void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( |
| 870 const RemoteCharacteristicStartNotificationsCallback& callback, | 872 const RemoteCharacteristicStartNotificationsCallback& callback, |
| 871 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { | 873 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { |
| 872 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 874 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 873 // Copy Characteristic Instance ID before passing a unique pointer because | 875 // Copy Characteristic Instance ID before passing a unique pointer because |
| 874 // compilers may evaluate arguments in any order. | 876 // compilers may evaluate arguments in any order. |
| 875 std::string characteristic_instance_id = | 877 std::string characteristic_instance_id = |
| 876 notify_session->GetCharacteristicIdentifier(); | 878 notify_session->GetCharacteristicIdentifier(); |
| 877 // Saving the BluetoothGattNotifySession keeps notifications active. | 879 // Saving the BluetoothGattNotifySession keeps notifications active. |
| 878 characteristic_id_to_notify_session_[characteristic_instance_id] = | 880 characteristic_id_to_notify_session_[characteristic_instance_id] = |
| 879 std::move(notify_session); | 881 std::move(notify_session); |
| 880 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 882 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 881 } | 883 } |
| 882 | 884 |
| 883 void WebBluetoothServiceImpl::OnStartNotifySessionFailed( | 885 void WebBluetoothServiceImpl::OnStartNotifySessionFailed( |
| 884 const RemoteCharacteristicStartNotificationsCallback& callback, | 886 const RemoteCharacteristicStartNotificationsCallback& callback, |
| 885 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 887 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 886 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 888 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 887 callback.Run(TranslateGATTErrorAndRecord( | 889 callback.Run(TranslateGATTErrorAndRecord( |
| 888 error_code, UMAGATTOperation::START_NOTIFICATIONS)); | 890 error_code, UMAGATTOperation::START_NOTIFICATIONS)); |
| 889 } | 891 } |
| 890 | 892 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 characteristic_id_to_service_id_.clear(); | 1003 characteristic_id_to_service_id_.clear(); |
| 1002 service_id_to_device_address_.clear(); | 1004 service_id_to_device_address_.clear(); |
| 1003 connected_devices_.reset( | 1005 connected_devices_.reset( |
| 1004 new FrameConnectedBluetoothDevices(render_frame_host_)); | 1006 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 1005 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 1007 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 1006 device_chooser_controller_.reset(); | 1008 device_chooser_controller_.reset(); |
| 1007 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 1009 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 1008 } | 1010 } |
| 1009 | 1011 |
| 1010 } // namespace content | 1012 } // namespace content |
| OLD | NEW |