| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 if (BluetoothAdapterFactoryWrapper::Get().IsLowEnergyAvailable()) { | 331 if (BluetoothAdapterFactoryWrapper::Get().IsLowEnergyAvailable()) { |
| 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( | 338 RecordRequestDeviceOutcome( |
| 339 UMARequestDeviceOutcome::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE); | 339 UMARequestDeviceOutcome::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE); |
| 340 callback.Run( | 340 callback.Run( |
| 341 blink::mojom::WebBluetoothError::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, | 341 blink::mojom::WebBluetoothResult::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, |
| 342 nullptr /* device */); | 342 nullptr /* device */); |
| 343 return; | 343 return; |
| 344 } | 344 } |
| 345 RequestDeviceImpl(std::move(options), callback, GetAdapter()); | 345 RequestDeviceImpl(std::move(options), callback, GetAdapter()); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void WebBluetoothServiceImpl::RemoteServerConnect( | 348 void WebBluetoothServiceImpl::RemoteServerConnect( |
| 349 const WebBluetoothDeviceId& device_id, | 349 const WebBluetoothDeviceId& device_id, |
| 350 const RemoteServerConnectCallback& callback) { | 350 const RemoteServerConnectCallback& callback) { |
| 351 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 351 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 352 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); | 352 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); |
| 353 | 353 |
| 354 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 354 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
| 355 | 355 |
| 356 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 356 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 357 RecordConnectGATTOutcome(query_result.outcome); | 357 RecordConnectGATTOutcome(query_result.outcome); |
| 358 callback.Run(query_result.GetWebError()); | 358 callback.Run(query_result.GetWebResult()); |
| 359 return; | 359 return; |
| 360 } | 360 } |
| 361 | 361 |
| 362 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 362 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
| 363 VLOG(1) << "Already connected."; | 363 VLOG(1) << "Already connected."; |
| 364 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 364 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 | 367 |
| 368 // It's possible for WebBluetoothServiceImpl to issue two successive | 368 // It's possible for WebBluetoothServiceImpl to issue two successive |
| 369 // connection requests for which it would get two successive responses | 369 // connection requests for which it would get two successive responses |
| 370 // and consequently try to insert two BluetoothGattConnections for the | 370 // and consequently try to insert two BluetoothGattConnections for the |
| 371 // same device. WebBluetoothServiceImpl should reject or queue connection | 371 // same device. WebBluetoothServiceImpl should reject or queue connection |
| 372 // requests if there is a pending connection already, but the platform | 372 // requests if there is a pending connection already, but the platform |
| 373 // abstraction doesn't currently support checking for pending connections. | 373 // abstraction doesn't currently support checking for pending connections. |
| 374 // TODO(ortuno): CHECK that this never happens once the platform | 374 // TODO(ortuno): CHECK that this never happens once the platform |
| (...skipping 28 matching lines...) Expand all Loading... |
| 403 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 403 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 404 RecordWebBluetoothFunctionCall( | 404 RecordWebBluetoothFunctionCall( |
| 405 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 405 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 406 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE | 406 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE |
| 407 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); | 407 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); |
| 408 RecordGetPrimaryServicesServices(quantity, services_uuid); | 408 RecordGetPrimaryServicesServices(quantity, services_uuid); |
| 409 | 409 |
| 410 if (services_uuid && | 410 if (services_uuid && |
| 411 !allowed_devices_map_.IsOriginAllowedToAccessService( | 411 !allowed_devices_map_.IsOriginAllowedToAccessService( |
| 412 GetOrigin(), device_id, services_uuid.value())) { | 412 GetOrigin(), device_id, services_uuid.value())) { |
| 413 callback.Run(blink::mojom::WebBluetoothError::NOT_ALLOWED_TO_ACCESS_SERVICE, | 413 callback.Run( |
| 414 nullptr /* service */); | 414 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE, |
| 415 nullptr /* service */); |
| 415 return; | 416 return; |
| 416 } | 417 } |
| 417 | 418 |
| 418 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 419 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
| 419 | 420 |
| 420 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 421 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 421 return; | 422 return; |
| 422 } | 423 } |
| 423 | 424 |
| 424 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 425 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 425 RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); | 426 RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); |
| 426 callback.Run(query_result.GetWebError(), nullptr /* service */); | 427 callback.Run(query_result.GetWebResult(), nullptr /* service */); |
| 427 return; | 428 return; |
| 428 } | 429 } |
| 429 | 430 |
| 430 const std::string& device_address = query_result.device->GetAddress(); | 431 const std::string& device_address = query_result.device->GetAddress(); |
| 431 | 432 |
| 432 // We can't know if a service is present or not until GATT service discovery | 433 // We can't know if a service is present or not until GATT service discovery |
| 433 // is complete for the device. | 434 // is complete for the device. |
| 434 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 435 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
| 435 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, | 436 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, |
| 436 callback, query_result.device); | 437 callback, query_result.device); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 454 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 455 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 455 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC | 456 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC |
| 456 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); | 457 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
| 457 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); | 458 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); |
| 458 | 459 |
| 459 if (characteristics_uuid && | 460 if (characteristics_uuid && |
| 460 BluetoothBlacklist::Get().IsExcluded(characteristics_uuid.value())) { | 461 BluetoothBlacklist::Get().IsExcluded(characteristics_uuid.value())) { |
| 461 RecordGetCharacteristicsOutcome(quantity, | 462 RecordGetCharacteristicsOutcome(quantity, |
| 462 UMAGetCharacteristicOutcome::BLACKLISTED); | 463 UMAGetCharacteristicOutcome::BLACKLISTED); |
| 463 callback.Run( | 464 callback.Run( |
| 464 blink::mojom::WebBluetoothError::BLACKLISTED_CHARACTERISTIC_UUID, | 465 blink::mojom::WebBluetoothResult::BLACKLISTED_CHARACTERISTIC_UUID, |
| 465 nullptr /* characteristics */); | 466 nullptr /* characteristics */); |
| 466 return; | 467 return; |
| 467 } | 468 } |
| 468 | 469 |
| 469 const CacheQueryResult query_result = | 470 const CacheQueryResult query_result = |
| 470 QueryCacheForService(service_instance_id); | 471 QueryCacheForService(service_instance_id); |
| 471 | 472 |
| 472 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 473 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 473 return; | 474 return; |
| 474 } | 475 } |
| 475 | 476 |
| 476 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 477 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 477 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 478 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
| 478 callback.Run(query_result.GetWebError(), nullptr /* characteristics */); | 479 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); |
| 479 return; | 480 return; |
| 480 } | 481 } |
| 481 | 482 |
| 482 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 483 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
| 483 characteristics_uuid | 484 characteristics_uuid |
| 484 ? GetCharacteristicsByUUID(query_result.service, | 485 ? GetCharacteristicsByUUID(query_result.service, |
| 485 characteristics_uuid.value()) | 486 characteristics_uuid.value()) |
| 486 : query_result.service->GetCharacteristics(); | 487 : query_result.service->GetCharacteristics(); |
| 487 | 488 |
| 488 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 489 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 508 response_characteristics.push_back(std::move(characteristic_ptr)); | 509 response_characteristics.push_back(std::move(characteristic_ptr)); |
| 509 | 510 |
| 510 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { | 511 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 511 break; | 512 break; |
| 512 } | 513 } |
| 513 } | 514 } |
| 514 | 515 |
| 515 if (!response_characteristics.empty()) { | 516 if (!response_characteristics.empty()) { |
| 516 RecordGetCharacteristicsOutcome(quantity, | 517 RecordGetCharacteristicsOutcome(quantity, |
| 517 UMAGetCharacteristicOutcome::SUCCESS); | 518 UMAGetCharacteristicOutcome::SUCCESS); |
| 518 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | 519 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 519 std::move(response_characteristics)); | 520 std::move(response_characteristics)); |
| 520 return; | 521 return; |
| 521 } | 522 } |
| 522 | 523 |
| 523 RecordGetCharacteristicsOutcome( | 524 RecordGetCharacteristicsOutcome( |
| 524 quantity, characteristics_uuid | 525 quantity, characteristics_uuid |
| 525 ? UMAGetCharacteristicOutcome::NOT_FOUND | 526 ? UMAGetCharacteristicOutcome::NOT_FOUND |
| 526 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); | 527 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); |
| 527 callback.Run(characteristics_uuid | 528 callback.Run(characteristics_uuid |
| 528 ? blink::mojom::WebBluetoothError::CHARACTERISTIC_NOT_FOUND | 529 ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND |
| 529 : blink::mojom::WebBluetoothError::NO_CHARACTERISTICS_FOUND, | 530 : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, |
| 530 nullptr /* characteristics */); | 531 nullptr /* characteristics */); |
| 531 } | 532 } |
| 532 | 533 |
| 533 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( | 534 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( |
| 534 const mojo::String& characteristic_instance_id, | 535 const mojo::String& characteristic_instance_id, |
| 535 const RemoteCharacteristicReadValueCallback& callback) { | 536 const RemoteCharacteristicReadValueCallback& callback) { |
| 536 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 537 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 537 RecordWebBluetoothFunctionCall( | 538 RecordWebBluetoothFunctionCall( |
| 538 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | 539 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); |
| 539 | 540 |
| 540 const CacheQueryResult query_result = | 541 const CacheQueryResult query_result = |
| 541 QueryCacheForCharacteristic(characteristic_instance_id); | 542 QueryCacheForCharacteristic(characteristic_instance_id); |
| 542 | 543 |
| 543 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 544 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 544 return; | 545 return; |
| 545 } | 546 } |
| 546 | 547 |
| 547 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 548 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 548 RecordCharacteristicReadValueOutcome(query_result.outcome); | 549 RecordCharacteristicReadValueOutcome(query_result.outcome); |
| 549 callback.Run(query_result.GetWebError(), nullptr /* value */); | 550 callback.Run(query_result.GetWebResult(), nullptr /* value */); |
| 550 return; | 551 return; |
| 551 } | 552 } |
| 552 | 553 |
| 553 if (BluetoothBlacklist::Get().IsExcludedFromReads( | 554 if (BluetoothBlacklist::Get().IsExcludedFromReads( |
| 554 query_result.characteristic->GetUUID())) { | 555 query_result.characteristic->GetUUID())) { |
| 555 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 556 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); |
| 556 callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_READ, | 557 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_READ, |
| 557 nullptr /* value */); | 558 nullptr /* value */); |
| 558 return; | 559 return; |
| 559 } | 560 } |
| 560 | 561 |
| 561 query_result.characteristic->ReadRemoteCharacteristic( | 562 query_result.characteristic->ReadRemoteCharacteristic( |
| 562 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | 563 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, |
| 563 weak_ptr_factory_.GetWeakPtr(), callback), | 564 weak_ptr_factory_.GetWeakPtr(), callback), |
| 564 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | 565 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, |
| 565 weak_ptr_factory_.GetWeakPtr(), callback)); | 566 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 566 } | 567 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 583 | 584 |
| 584 const CacheQueryResult query_result = | 585 const CacheQueryResult query_result = |
| 585 QueryCacheForCharacteristic(characteristic_instance_id); | 586 QueryCacheForCharacteristic(characteristic_instance_id); |
| 586 | 587 |
| 587 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 588 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 588 return; | 589 return; |
| 589 } | 590 } |
| 590 | 591 |
| 591 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 592 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 592 RecordCharacteristicWriteValueOutcome(query_result.outcome); | 593 RecordCharacteristicWriteValueOutcome(query_result.outcome); |
| 593 callback.Run(query_result.GetWebError()); | 594 callback.Run(query_result.GetWebResult()); |
| 594 return; | 595 return; |
| 595 } | 596 } |
| 596 | 597 |
| 597 if (BluetoothBlacklist::Get().IsExcludedFromWrites( | 598 if (BluetoothBlacklist::Get().IsExcludedFromWrites( |
| 598 query_result.characteristic->GetUUID())) { | 599 query_result.characteristic->GetUUID())) { |
| 599 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 600 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); |
| 600 callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_WRITE); | 601 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_WRITE); |
| 601 return; | 602 return; |
| 602 } | 603 } |
| 603 | 604 |
| 604 query_result.characteristic->WriteRemoteCharacteristic( | 605 query_result.characteristic->WriteRemoteCharacteristic( |
| 605 value.To<std::vector<uint8_t>>(), | 606 value.To<std::vector<uint8_t>>(), |
| 606 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, | 607 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, |
| 607 weak_ptr_factory_.GetWeakPtr(), callback), | 608 weak_ptr_factory_.GetWeakPtr(), callback), |
| 608 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, | 609 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, |
| 609 weak_ptr_factory_.GetWeakPtr(), callback)); | 610 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 610 } | 611 } |
| 611 | 612 |
| 612 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( | 613 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
| 613 const mojo::String& characteristic_instance_id, | 614 const mojo::String& characteristic_instance_id, |
| 614 const RemoteCharacteristicStartNotificationsCallback& callback) { | 615 const RemoteCharacteristicStartNotificationsCallback& callback) { |
| 615 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 616 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 616 RecordWebBluetoothFunctionCall( | 617 RecordWebBluetoothFunctionCall( |
| 617 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | 618 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); |
| 618 | 619 |
| 619 auto iter = | 620 auto iter = |
| 620 characteristic_id_to_notify_session_.find(characteristic_instance_id); | 621 characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| 621 if (iter != characteristic_id_to_notify_session_.end() && | 622 if (iter != characteristic_id_to_notify_session_.end() && |
| 622 iter->second->IsActive()) { | 623 iter->second->IsActive()) { |
| 623 // If the frame has already started notifications and the notifications | 624 // If the frame has already started notifications and the notifications |
| 624 // are active we return SUCCESS. | 625 // are active we return SUCCESS. |
| 625 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 626 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 626 return; | 627 return; |
| 627 } | 628 } |
| 628 | 629 |
| 629 const CacheQueryResult query_result = | 630 const CacheQueryResult query_result = |
| 630 QueryCacheForCharacteristic(characteristic_instance_id); | 631 QueryCacheForCharacteristic(characteristic_instance_id); |
| 631 | 632 |
| 632 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 633 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 633 return; | 634 return; |
| 634 } | 635 } |
| 635 | 636 |
| 636 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 637 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 637 RecordStartNotificationsOutcome(query_result.outcome); | 638 RecordStartNotificationsOutcome(query_result.outcome); |
| 638 callback.Run(query_result.GetWebError()); | 639 callback.Run(query_result.GetWebResult()); |
| 639 return; | 640 return; |
| 640 } | 641 } |
| 641 | 642 |
| 642 device::BluetoothRemoteGattCharacteristic::Properties notify_or_indicate = | 643 device::BluetoothRemoteGattCharacteristic::Properties notify_or_indicate = |
| 643 query_result.characteristic->GetProperties() & | 644 query_result.characteristic->GetProperties() & |
| 644 (device::BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | | 645 (device::BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | |
| 645 device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE); | 646 device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE); |
| 646 if (!notify_or_indicate) { | 647 if (!notify_or_indicate) { |
| 647 callback.Run(blink::mojom::WebBluetoothError::GATT_NOT_SUPPORTED); | 648 callback.Run(blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED); |
| 648 return; | 649 return; |
| 649 } | 650 } |
| 650 | 651 |
| 651 query_result.characteristic->StartNotifySession( | 652 query_result.characteristic->StartNotifySession( |
| 652 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, | 653 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, |
| 653 weak_ptr_factory_.GetWeakPtr(), callback), | 654 weak_ptr_factory_.GetWeakPtr(), callback), |
| 654 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, | 655 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, |
| 655 weak_ptr_factory_.GetWeakPtr(), callback)); | 656 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 656 } | 657 } |
| 657 | 658 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 | 740 |
| 740 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { | 741 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 741 break; | 742 break; |
| 742 } | 743 } |
| 743 } | 744 } |
| 744 | 745 |
| 745 if (!response_services.empty()) { | 746 if (!response_services.empty()) { |
| 746 VLOG(1) << "Services found in device."; | 747 VLOG(1) << "Services found in device."; |
| 747 RecordGetPrimaryServicesOutcome(quantity, | 748 RecordGetPrimaryServicesOutcome(quantity, |
| 748 UMAGetPrimaryServiceOutcome::SUCCESS); | 749 UMAGetPrimaryServiceOutcome::SUCCESS); |
| 749 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | 750 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 750 std::move(response_services)); | 751 std::move(response_services)); |
| 751 return; | 752 return; |
| 752 } | 753 } |
| 753 | 754 |
| 754 VLOG(1) << "Services not found in device."; | 755 VLOG(1) << "Services not found in device."; |
| 755 RecordGetPrimaryServicesOutcome( | 756 RecordGetPrimaryServicesOutcome( |
| 756 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND | 757 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND |
| 757 : UMAGetPrimaryServiceOutcome::NO_SERVICES); | 758 : UMAGetPrimaryServiceOutcome::NO_SERVICES); |
| 758 callback.Run(services_uuid | 759 callback.Run(services_uuid |
| 759 ? blink::mojom::WebBluetoothError::SERVICE_NOT_FOUND | 760 ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND |
| 760 : blink::mojom::WebBluetoothError::NO_SERVICES_FOUND, | 761 : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, |
| 761 nullptr /* services */); | 762 nullptr /* services */); |
| 762 } | 763 } |
| 763 | 764 |
| 764 void WebBluetoothServiceImpl::OnGetDeviceSuccess( | 765 void WebBluetoothServiceImpl::OnGetDeviceSuccess( |
| 765 const RequestDeviceCallback& callback, | 766 const RequestDeviceCallback& callback, |
| 766 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 767 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| 767 const std::string& device_address) { | 768 const std::string& device_address) { |
| 768 device_chooser_controller_.reset(); | 769 device_chooser_controller_.reset(); |
| 769 | 770 |
| 770 const device::BluetoothDevice* const device = | 771 const device::BluetoothDevice* const device = |
| 771 GetAdapter()->GetDevice(device_address); | 772 GetAdapter()->GetDevice(device_address); |
| 772 if (device == nullptr) { | 773 if (device == nullptr) { |
| 773 VLOG(1) << "Device " << device_address << " no longer in adapter"; | 774 VLOG(1) << "Device " << device_address << " no longer in adapter"; |
| 774 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); | 775 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); |
| 775 callback.Run(blink::mojom::WebBluetoothError::CHOSEN_DEVICE_VANISHED, | 776 callback.Run(blink::mojom::WebBluetoothResult::CHOSEN_DEVICE_VANISHED, |
| 776 nullptr /* device */); | 777 nullptr /* device */); |
| 777 return; | 778 return; |
| 778 } | 779 } |
| 779 | 780 |
| 780 const WebBluetoothDeviceId device_id_for_origin = | 781 const WebBluetoothDeviceId device_id_for_origin = |
| 781 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); | 782 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); |
| 782 | 783 |
| 783 VLOG(1) << "Device: " << device->GetNameForDisplay(); | 784 VLOG(1) << "Device: " << device->GetNameForDisplay(); |
| 784 VLOG(1) << "UUIDs: "; | 785 VLOG(1) << "UUIDs: "; |
| 785 | 786 |
| 786 mojo::Array<mojo::String> filtered_uuids; | 787 mojo::Array<mojo::String> filtered_uuids; |
| 787 for (const BluetoothUUID& uuid : device->GetUUIDs()) { | 788 for (const BluetoothUUID& uuid : device->GetUUIDs()) { |
| 788 if (allowed_devices_map_.IsOriginAllowedToAccessService( | 789 if (allowed_devices_map_.IsOriginAllowedToAccessService( |
| 789 GetOrigin(), device_id_for_origin, uuid)) { | 790 GetOrigin(), device_id_for_origin, uuid)) { |
| 790 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); | 791 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); |
| 791 filtered_uuids.push_back(uuid.canonical_value()); | 792 filtered_uuids.push_back(uuid.canonical_value()); |
| 792 } else { | 793 } else { |
| 793 VLOG(1) << "\t Not Allowed: " << uuid.canonical_value(); | 794 VLOG(1) << "\t Not Allowed: " << uuid.canonical_value(); |
| 794 } | 795 } |
| 795 } | 796 } |
| 796 | 797 |
| 797 blink::mojom::WebBluetoothDevicePtr device_ptr = | 798 blink::mojom::WebBluetoothDevicePtr device_ptr = |
| 798 blink::mojom::WebBluetoothDevice::New(); | 799 blink::mojom::WebBluetoothDevice::New(); |
| 799 device_ptr->id = device_id_for_origin; | 800 device_ptr->id = device_id_for_origin; |
| 800 device_ptr->name = device->GetName() ? mojo::String(device->GetName().value()) | 801 device_ptr->name = device->GetName() ? mojo::String(device->GetName().value()) |
| 801 : mojo::String(nullptr); | 802 : mojo::String(nullptr); |
| 802 device_ptr->uuids = std::move(filtered_uuids); | 803 device_ptr->uuids = std::move(filtered_uuids); |
| 803 | 804 |
| 804 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); | 805 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); |
| 805 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, std::move(device_ptr)); | 806 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 807 std::move(device_ptr)); |
| 806 } | 808 } |
| 807 | 809 |
| 808 void WebBluetoothServiceImpl::OnGetDeviceFailed( | 810 void WebBluetoothServiceImpl::OnGetDeviceFailed( |
| 809 const RequestDeviceCallback& callback, | 811 const RequestDeviceCallback& callback, |
| 810 blink::mojom::WebBluetoothError error) { | 812 blink::mojom::WebBluetoothResult result) { |
| 811 // Errors are recorded by the *device_chooser_controller_. | 813 // Errors are recorded by the *device_chooser_controller_. |
| 812 callback.Run(error, nullptr /* device */); | 814 callback.Run(result, nullptr /* device */); |
| 813 device_chooser_controller_.reset(); | 815 device_chooser_controller_.reset(); |
| 814 } | 816 } |
| 815 | 817 |
| 816 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( | 818 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( |
| 817 const WebBluetoothDeviceId& device_id, | 819 const WebBluetoothDeviceId& device_id, |
| 818 base::TimeTicks start_time, | 820 base::TimeTicks start_time, |
| 819 const RemoteServerConnectCallback& callback, | 821 const RemoteServerConnectCallback& callback, |
| 820 std::unique_ptr<device::BluetoothGattConnection> connection) { | 822 std::unique_ptr<device::BluetoothGattConnection> connection) { |
| 821 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 823 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 822 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); | 824 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); |
| 823 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); | 825 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); |
| 824 | 826 |
| 825 connected_devices_->Insert(device_id, std::move(connection)); | 827 connected_devices_->Insert(device_id, std::move(connection)); |
| 826 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 828 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 827 } | 829 } |
| 828 | 830 |
| 829 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( | 831 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( |
| 830 base::TimeTicks start_time, | 832 base::TimeTicks start_time, |
| 831 const RemoteServerConnectCallback& callback, | 833 const RemoteServerConnectCallback& callback, |
| 832 device::BluetoothDevice::ConnectErrorCode error_code) { | 834 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 833 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 835 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 834 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 836 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
| 835 callback.Run(TranslateConnectErrorAndRecord(error_code)); | 837 callback.Run(TranslateConnectErrorAndRecord(error_code)); |
| 836 } | 838 } |
| 837 | 839 |
| 838 void WebBluetoothServiceImpl::OnReadValueSuccess( | 840 void WebBluetoothServiceImpl::OnReadValueSuccess( |
| 839 const RemoteCharacteristicReadValueCallback& callback, | 841 const RemoteCharacteristicReadValueCallback& callback, |
| 840 const std::vector<uint8_t>& value) { | 842 const std::vector<uint8_t>& value) { |
| 841 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 843 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 842 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 844 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
| 843 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | 845 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 844 mojo::Array<uint8_t>::From(value)); | 846 mojo::Array<uint8_t>::From(value)); |
| 845 } | 847 } |
| 846 | 848 |
| 847 void WebBluetoothServiceImpl::OnReadValueFailed( | 849 void WebBluetoothServiceImpl::OnReadValueFailed( |
| 848 const RemoteCharacteristicReadValueCallback& callback, | 850 const RemoteCharacteristicReadValueCallback& callback, |
| 849 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 851 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 850 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 852 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 851 callback.Run(TranslateGATTErrorAndRecord( | 853 callback.Run(TranslateGATTErrorAndRecord( |
| 852 error_code, UMAGATTOperation::CHARACTERISTIC_READ), | 854 error_code, UMAGATTOperation::CHARACTERISTIC_READ), |
| 853 nullptr /* value */); | 855 nullptr /* value */); |
| 854 } | 856 } |
| 855 | 857 |
| 856 void WebBluetoothServiceImpl::OnWriteValueSuccess( | 858 void WebBluetoothServiceImpl::OnWriteValueSuccess( |
| 857 const RemoteCharacteristicWriteValueCallback& callback) { | 859 const RemoteCharacteristicWriteValueCallback& callback) { |
| 858 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 860 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 859 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 861 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
| 860 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 862 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 861 } | 863 } |
| 862 | 864 |
| 863 void WebBluetoothServiceImpl::OnWriteValueFailed( | 865 void WebBluetoothServiceImpl::OnWriteValueFailed( |
| 864 const RemoteCharacteristicWriteValueCallback& callback, | 866 const RemoteCharacteristicWriteValueCallback& callback, |
| 865 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 867 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 866 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 868 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 867 callback.Run(TranslateGATTErrorAndRecord( | 869 callback.Run(TranslateGATTErrorAndRecord( |
| 868 error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)); | 870 error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)); |
| 869 } | 871 } |
| 870 | 872 |
| 871 void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( | 873 void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( |
| 872 const RemoteCharacteristicStartNotificationsCallback& callback, | 874 const RemoteCharacteristicStartNotificationsCallback& callback, |
| 873 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { | 875 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { |
| 874 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 876 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 875 // Copy Characteristic Instance ID before passing a unique pointer because | 877 // Copy Characteristic Instance ID before passing a unique pointer because |
| 876 // compilers may evaluate arguments in any order. | 878 // compilers may evaluate arguments in any order. |
| 877 std::string characteristic_instance_id = | 879 std::string characteristic_instance_id = |
| 878 notify_session->GetCharacteristicIdentifier(); | 880 notify_session->GetCharacteristicIdentifier(); |
| 879 // Saving the BluetoothGattNotifySession keeps notifications active. | 881 // Saving the BluetoothGattNotifySession keeps notifications active. |
| 880 characteristic_id_to_notify_session_[characteristic_instance_id] = | 882 characteristic_id_to_notify_session_[characteristic_instance_id] = |
| 881 std::move(notify_session); | 883 std::move(notify_session); |
| 882 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 884 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 883 } | 885 } |
| 884 | 886 |
| 885 void WebBluetoothServiceImpl::OnStartNotifySessionFailed( | 887 void WebBluetoothServiceImpl::OnStartNotifySessionFailed( |
| 886 const RemoteCharacteristicStartNotificationsCallback& callback, | 888 const RemoteCharacteristicStartNotificationsCallback& callback, |
| 887 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 889 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 888 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 890 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 889 callback.Run(TranslateGATTErrorAndRecord( | 891 callback.Run(TranslateGATTErrorAndRecord( |
| 890 error_code, UMAGATTOperation::START_NOTIFICATIONS)); | 892 error_code, UMAGATTOperation::START_NOTIFICATIONS)); |
| 891 } | 893 } |
| 892 | 894 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 characteristic_id_to_service_id_.clear(); | 1005 characteristic_id_to_service_id_.clear(); |
| 1004 service_id_to_device_address_.clear(); | 1006 service_id_to_device_address_.clear(); |
| 1005 connected_devices_.reset( | 1007 connected_devices_.reset( |
| 1006 new FrameConnectedBluetoothDevices(render_frame_host_)); | 1008 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 1007 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 1009 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 1008 device_chooser_controller_.reset(); | 1010 device_chooser_controller_.reset(); |
| 1009 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 1011 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 1010 } | 1012 } |
| 1011 | 1013 |
| 1012 } // namespace content | 1014 } // namespace content |
| OLD | NEW |