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

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

Issue 1286883002: bluetooth: Add histograms and logging for getCharacteristic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uma-refactoring
Patch Set: Merge with ToT Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // 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 19 matching lines...) Expand all
30 using device::BluetoothGattService; 30 using device::BluetoothGattService;
31 using device::BluetoothUUID; 31 using device::BluetoothUUID;
32 32
33 using UMAWebBluetoothFunction = 33 using UMAWebBluetoothFunction =
34 content::BluetoothMetrics::UMAWebBluetoothFunction; 34 content::BluetoothMetrics::UMAWebBluetoothFunction;
35 using UMARequestDeviceOutcome = 35 using UMARequestDeviceOutcome =
36 content::BluetoothMetrics::UMARequestDeviceOutcome; 36 content::BluetoothMetrics::UMARequestDeviceOutcome;
37 using UMAConnectGATTOutcome = content::BluetoothMetrics::UMAConnectGATTOutcome; 37 using UMAConnectGATTOutcome = content::BluetoothMetrics::UMAConnectGATTOutcome;
38 using UMAGetPrimaryServiceOutcome = 38 using UMAGetPrimaryServiceOutcome =
39 content::BluetoothMetrics::UMAGetPrimaryServiceOutcome; 39 content::BluetoothMetrics::UMAGetPrimaryServiceOutcome;
40 using UMAGetCharacteristicOutcome =
41 content::BluetoothMetrics::UMAGetCharacteristicOutcome;
40 using UMAGATTError = content::BluetoothMetrics::UMAGATTError; 42 using UMAGATTError = content::BluetoothMetrics::UMAGATTError;
41 43
42 namespace { 44 namespace {
43 45
44 // TODO(ortuno): Once we have a chooser for scanning and the right 46 // TODO(ortuno): Once we have a chooser for scanning and the right
45 // callback for discovered services we should delete these constants. 47 // callback for discovered services we should delete these constants.
46 // https://crbug.com/436280 and https://crbug.com/484504 48 // https://crbug.com/436280 and https://crbug.com/484504
47 const int kDelayTime = 5; // 5 seconds for scanning and discovering 49 const int kDelayTime = 5; // 5 seconds for scanning and discovering
48 const int kTestingDelayTime = 0; // No need to wait during tests 50 const int kTestingDelayTime = 0; // No need to wait during tests
49 51
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 383 }
382 384
383 void BluetoothDispatcherHost::OnGetCharacteristic( 385 void BluetoothDispatcherHost::OnGetCharacteristic(
384 int thread_id, 386 int thread_id,
385 int request_id, 387 int request_id,
386 const std::string& service_instance_id, 388 const std::string& service_instance_id,
387 const std::string& characteristic_uuid) { 389 const std::string& characteristic_uuid) {
388 DCHECK_CURRENTLY_ON(BrowserThread::UI); 390 DCHECK_CURRENTLY_ON(BrowserThread::UI);
389 BluetoothMetrics::RecordWebBluetoothFunctionCall( 391 BluetoothMetrics::RecordWebBluetoothFunctionCall(
390 UMAWebBluetoothFunction::GET_CHARACTERISTIC); 392 UMAWebBluetoothFunction::GET_CHARACTERISTIC);
393 BluetoothMetrics::RecordGetCharacteristicCharacteristic(characteristic_uuid);
391 394
392 auto device_iter = service_to_device_.find(service_instance_id); 395 auto device_iter = service_to_device_.find(service_instance_id);
393 // A service_instance_id not in the map implies a hostile renderer 396 // A service_instance_id not in the map implies a hostile renderer
394 // because a renderer obtains the service id from this class and 397 // because a renderer obtains the service id from this class and
395 // it will be added to the map at that time. 398 // it will be added to the map at that time.
396 if (device_iter == service_to_device_.end()) { 399 if (device_iter == service_to_device_.end()) {
397 // Kill the renderer 400 // Kill the renderer
398 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); 401 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID);
399 return; 402 return;
400 } 403 }
401 404
402 // TODO(ortuno): Check if domain has access to device. 405 // TODO(ortuno): Check if domain has access to device.
403 // https://crbug.com/493459 406 // https://crbug.com/493459
404 device::BluetoothDevice* device = 407 device::BluetoothDevice* device =
405 adapter_->GetDevice(device_iter->second /* device_instance_id */); 408 adapter_->GetDevice(device_iter->second /* device_instance_id */);
406 409
407 if (device == nullptr) { // See "NETWORK_ERROR Note" above. 410 if (device == nullptr) { // See "NETWORK_ERROR Note" above.
411 BluetoothMetrics::RecordGetCharacteristicOutcome(
412 UMAGetCharacteristicOutcome::NO_DEVICE);
413 VLOG(1) << "Bluetooth Device is no longer in range.";
Jeffrey Yasskin 2015/08/13 21:32:53 As discussed over IM, we should drop the VLOGs wit
ortuno 2015/08/14 16:23:35 Done.
408 Send(new BluetoothMsg_GetCharacteristicError( 414 Send(new BluetoothMsg_GetCharacteristicError(
409 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); 415 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange));
410 return; 416 return;
411 } 417 }
412 418
413 // TODO(ortuno): Check if domain has access to service 419 // TODO(ortuno): Check if domain has access to service
414 // http://crbug.com/493460 420 // http://crbug.com/493460
415 device::BluetoothGattService* service = 421 device::BluetoothGattService* service =
416 device->GetGattService(service_instance_id); 422 device->GetGattService(service_instance_id);
417 if (!service) { 423 if (!service) {
424 BluetoothMetrics::RecordGetCharacteristicOutcome(
425 UMAGetCharacteristicOutcome::NO_SERVICE);
426 VLOG(1) << "GATT Service no longer exists.";
418 Send(new BluetoothMsg_GetCharacteristicError( 427 Send(new BluetoothMsg_GetCharacteristicError(
419 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); 428 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists));
420 return; 429 return;
421 } 430 }
422 431
423 for (BluetoothGattCharacteristic* characteristic : 432 for (BluetoothGattCharacteristic* characteristic :
424 service->GetCharacteristics()) { 433 service->GetCharacteristics()) {
425 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { 434 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) {
426 const std::string& characteristic_instance_id = 435 const std::string& characteristic_instance_id =
427 characteristic->GetIdentifier(); 436 characteristic->GetIdentifier();
428 437
429 auto insert_result = characteristic_to_service_.insert( 438 auto insert_result = characteristic_to_service_.insert(
430 make_pair(characteristic_instance_id, service_instance_id)); 439 make_pair(characteristic_instance_id, service_instance_id));
431 440
432 // If value is already in map, DCHECK it's valid. 441 // If value is already in map, DCHECK it's valid.
433 if (!insert_result.second) 442 if (!insert_result.second)
434 DCHECK(insert_result.first->second == service_instance_id); 443 DCHECK(insert_result.first->second == service_instance_id);
435 444
445 BluetoothMetrics::RecordGetCharacteristicOutcome(
446 UMAGetCharacteristicOutcome::SUCCESS);
436 // TODO(ortuno): Use generated instance ID instead. 447 // TODO(ortuno): Use generated instance ID instead.
437 // https://crbug.com/495379 448 // https://crbug.com/495379
438 Send(new BluetoothMsg_GetCharacteristicSuccess( 449 Send(new BluetoothMsg_GetCharacteristicSuccess(
439 thread_id, request_id, characteristic_instance_id)); 450 thread_id, request_id, characteristic_instance_id));
440 return; 451 return;
441 } 452 }
442 } 453 }
454 BluetoothMetrics::RecordGetCharacteristicOutcome(
455 UMAGetCharacteristicOutcome::NOT_FOUND);
456 VLOG(1) << "No GATT Characteristic with UUID: " << characteristic_uuid;
Jeffrey Yasskin 2015/08/13 21:32:52 This one's probably also equivalent to its rejecti
ortuno 2015/08/14 16:23:35 Removed.
443 Send(new BluetoothMsg_GetCharacteristicError( 457 Send(new BluetoothMsg_GetCharacteristicError(
444 thread_id, request_id, WebBluetoothError::CharacteristicNotFound)); 458 thread_id, request_id, WebBluetoothError::CharacteristicNotFound));
445 } 459 }
446 460
447 void BluetoothDispatcherHost::OnReadValue( 461 void BluetoothDispatcherHost::OnReadValue(
448 int thread_id, 462 int thread_id,
449 int request_id, 463 int request_id,
450 const std::string& characteristic_instance_id) { 464 const std::string& characteristic_instance_id) {
451 DCHECK_CURRENTLY_ON(BrowserThread::UI); 465 DCHECK_CURRENTLY_ON(BrowserThread::UI);
452 BluetoothMetrics::RecordWebBluetoothFunctionCall( 466 BluetoothMetrics::RecordWebBluetoothFunctionCall(
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 765
752 void BluetoothDispatcherHost::OnWriteValueFailed( 766 void BluetoothDispatcherHost::OnWriteValueFailed(
753 int thread_id, 767 int thread_id,
754 int request_id, 768 int request_id,
755 device::BluetoothGattService::GattErrorCode error_code) { 769 device::BluetoothGattService::GattErrorCode error_code) {
756 Send(new BluetoothMsg_WriteCharacteristicValueError( 770 Send(new BluetoothMsg_WriteCharacteristicValueError(
757 thread_id, request_id, TranslateGATTError(error_code))); 771 thread_id, request_id, TranslateGATTError(error_code)));
758 } 772 }
759 773
760 } // namespace content 774 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_metrics.h » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698