OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // NETWORK_ERROR Note: | 5 // NETWORK_ERROR Note: |
6 // When a device can't be found in the BluetoothAdapter, that generally | 6 // When a device can't be found in the BluetoothAdapter, that generally |
7 // indicates that it's gone out of range. We reject with a NetworkError in that | 7 // indicates that it's gone out of range. We reject with a NetworkError in that |
8 // case. | 8 // case. |
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne
ctgatt | 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne
ctgatt |
10 | 10 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 base::TimeDelta::FromSeconds(current_delay_time_)); | 353 base::TimeDelta::FromSeconds(current_delay_time_)); |
354 } | 354 } |
355 | 355 |
356 void BluetoothDispatcherHost::OnGetCharacteristic( | 356 void BluetoothDispatcherHost::OnGetCharacteristic( |
357 int thread_id, | 357 int thread_id, |
358 int request_id, | 358 int request_id, |
359 const std::string& service_instance_id, | 359 const std::string& service_instance_id, |
360 const std::string& characteristic_uuid) { | 360 const std::string& characteristic_uuid) { |
361 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 361 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
362 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC); | 362 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC); |
| 363 RecordGetCharacteristicCharacteristic(characteristic_uuid); |
363 | 364 |
364 auto device_iter = service_to_device_.find(service_instance_id); | 365 auto device_iter = service_to_device_.find(service_instance_id); |
365 // A service_instance_id not in the map implies a hostile renderer | 366 // A service_instance_id not in the map implies a hostile renderer |
366 // because a renderer obtains the service id from this class and | 367 // because a renderer obtains the service id from this class and |
367 // it will be added to the map at that time. | 368 // it will be added to the map at that time. |
368 if (device_iter == service_to_device_.end()) { | 369 if (device_iter == service_to_device_.end()) { |
369 // Kill the renderer | 370 // Kill the renderer |
370 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); | 371 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); |
371 return; | 372 return; |
372 } | 373 } |
373 | 374 |
374 // TODO(ortuno): Check if domain has access to device. | 375 // TODO(ortuno): Check if domain has access to device. |
375 // https://crbug.com/493459 | 376 // https://crbug.com/493459 |
376 device::BluetoothDevice* device = | 377 device::BluetoothDevice* device = |
377 adapter_->GetDevice(device_iter->second /* device_instance_id */); | 378 adapter_->GetDevice(device_iter->second /* device_instance_id */); |
378 | 379 |
379 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | 380 if (device == nullptr) { // See "NETWORK_ERROR Note" above. |
| 381 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NO_DEVICE); |
380 Send(new BluetoothMsg_GetCharacteristicError( | 382 Send(new BluetoothMsg_GetCharacteristicError( |
381 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | 383 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); |
382 return; | 384 return; |
383 } | 385 } |
384 | 386 |
385 // TODO(ortuno): Check if domain has access to service | 387 // TODO(ortuno): Check if domain has access to service |
386 // http://crbug.com/493460 | 388 // http://crbug.com/493460 |
387 device::BluetoothGattService* service = | 389 device::BluetoothGattService* service = |
388 device->GetGattService(service_instance_id); | 390 device->GetGattService(service_instance_id); |
389 if (!service) { | 391 if (!service) { |
| 392 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NO_SERVICE); |
390 Send(new BluetoothMsg_GetCharacteristicError( | 393 Send(new BluetoothMsg_GetCharacteristicError( |
391 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); | 394 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); |
392 return; | 395 return; |
393 } | 396 } |
394 | 397 |
395 for (BluetoothGattCharacteristic* characteristic : | 398 for (BluetoothGattCharacteristic* characteristic : |
396 service->GetCharacteristics()) { | 399 service->GetCharacteristics()) { |
397 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { | 400 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { |
398 const std::string& characteristic_instance_id = | 401 const std::string& characteristic_instance_id = |
399 characteristic->GetIdentifier(); | 402 characteristic->GetIdentifier(); |
400 | 403 |
401 auto insert_result = characteristic_to_service_.insert( | 404 auto insert_result = characteristic_to_service_.insert( |
402 make_pair(characteristic_instance_id, service_instance_id)); | 405 make_pair(characteristic_instance_id, service_instance_id)); |
403 | 406 |
404 // If value is already in map, DCHECK it's valid. | 407 // If value is already in map, DCHECK it's valid. |
405 if (!insert_result.second) | 408 if (!insert_result.second) |
406 DCHECK(insert_result.first->second == service_instance_id); | 409 DCHECK(insert_result.first->second == service_instance_id); |
407 | 410 |
| 411 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::SUCCESS); |
408 // TODO(ortuno): Use generated instance ID instead. | 412 // TODO(ortuno): Use generated instance ID instead. |
409 // https://crbug.com/495379 | 413 // https://crbug.com/495379 |
410 Send(new BluetoothMsg_GetCharacteristicSuccess( | 414 Send(new BluetoothMsg_GetCharacteristicSuccess( |
411 thread_id, request_id, characteristic_instance_id)); | 415 thread_id, request_id, characteristic_instance_id)); |
412 return; | 416 return; |
413 } | 417 } |
414 } | 418 } |
| 419 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NOT_FOUND); |
415 Send(new BluetoothMsg_GetCharacteristicError( | 420 Send(new BluetoothMsg_GetCharacteristicError( |
416 thread_id, request_id, WebBluetoothError::CharacteristicNotFound)); | 421 thread_id, request_id, WebBluetoothError::CharacteristicNotFound)); |
417 } | 422 } |
418 | 423 |
419 void BluetoothDispatcherHost::OnReadValue( | 424 void BluetoothDispatcherHost::OnReadValue( |
420 int thread_id, | 425 int thread_id, |
421 int request_id, | 426 int request_id, |
422 const std::string& characteristic_instance_id) { | 427 const std::string& characteristic_instance_id) { |
423 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 428 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
424 RecordWebBluetoothFunctionCall( | 429 RecordWebBluetoothFunctionCall( |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 715 |
711 void BluetoothDispatcherHost::OnWriteValueFailed( | 716 void BluetoothDispatcherHost::OnWriteValueFailed( |
712 int thread_id, | 717 int thread_id, |
713 int request_id, | 718 int request_id, |
714 device::BluetoothGattService::GattErrorCode error_code) { | 719 device::BluetoothGattService::GattErrorCode error_code) { |
715 Send(new BluetoothMsg_WriteCharacteristicValueError( | 720 Send(new BluetoothMsg_WriteCharacteristicValueError( |
716 thread_id, request_id, TranslateGATTError(error_code))); | 721 thread_id, request_id, TranslateGATTError(error_code))); |
717 } | 722 } |
718 | 723 |
719 } // namespace content | 724 } // namespace content |
OLD | NEW |