Chromium Code Reviews| 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 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_set> | 9 #include <unordered_set> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 24 #include "device/bluetooth/bluetooth_adapter.h" | 24 #include "device/bluetooth/bluetooth_adapter.h" |
| 25 #include "device/bluetooth/bluetooth_common.h" | 25 #include "device/bluetooth/bluetooth_common.h" |
| 26 #include "device/bluetooth/bluetooth_discovery_session.h" | 26 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 27 | 27 |
| 28 using device::BluetoothUUID; | 28 using device::BluetoothUUID; |
| 29 using UUIDSet = device::BluetoothDevice::UUIDSet; | 29 using UUIDSet = device::BluetoothDevice::UUIDSet; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Anything worse than or equal to this will show 0 bars. | 33 // Signal Strength Display Notes: |
| 34 const int kMinRSSI = -100; | 34 // |
| 35 // Anything better than or equal to this will show the maximum bars. | 35 // RSSI values are displayed by the chooser to empower a user to differentiate |
| 36 const int kMaxRSSI = -55; | 36 // between multiple devices with the same name, comparing devices with different |
| 37 // Number of RSSI levels used in the signal strength image. | 37 // names is a secondary goal. It is important that a user be able to move closer |
|
juncai
2016/12/09 23:31:40
s/be/is
scheib
2016/12/10 00:04:04
Done.
| |
| 38 const int kNumSignalStrengthLevels = 5; | 38 // and farther away from a device and have it transition between two different |
| 39 | 39 // signal strength levels, thus we want to spread RSSI values out accross |
| 40 const content::UMARSSISignalStrengthLevel kRSSISignalStrengthEnumTable[] = { | 40 // displayed levels. |
| 41 content::UMARSSISignalStrengthLevel::LEVEL_0, | 41 // |
| 42 content::UMARSSISignalStrengthLevel::LEVEL_1, | 42 // RSSI values from UMA in RecordRSSISignalStrength are charted here: |
| 43 content::UMARSSISignalStrengthLevel::LEVEL_2, | 43 // https://goo.gl/photos/pCoAkF7mPyza9B1k7 (2016-12-08) |
| 44 content::UMARSSISignalStrengthLevel::LEVEL_3, | 44 // with a copy-paste of table data at every 5dBm: |
| 45 content::UMARSSISignalStrengthLevel::LEVEL_4}; | 45 // dBm CDF* Histogram Bucket Quantity (hand drawn estimate) |
| 46 // -100 00.0% - | |
| 47 // -95 00.4% -- | |
| 48 // -90 01.9% --- | |
| 49 // -85 05.1% --- | |
| 50 // -80 09.2% ---- | |
| 51 // -75 14.9% ----- | |
| 52 // -70 22.0% ------ | |
| 53 // -65 32.4% -------- | |
| 54 // -60 47.9% --------- | |
| 55 // -55 60.4% -------- | |
| 56 // -50 72.8% --------- | |
| 57 // -45 85.5% ------- | |
| 58 // -40 94.5% ----- | |
| 59 // -35 97.4% --- | |
| 60 // -30 99.0% -- | |
| 61 // -25 99.7% - | |
| 62 // | |
| 63 // CDF: Cumulative Distribution Function: | |
| 64 // https://en.wikipedia.org/wiki/Cumulative_distribution_function | |
| 65 // | |
| 66 // Conversion to signal strengths is done by selecting 4 threshold points | |
| 67 // equally spaced through the CDF. | |
| 68 const int k20thPercentileRSSI = -71; | |
| 69 const int k40thPercentileRSSI = -63; | |
| 70 const int k60thPercentileRSSI = -55; | |
| 71 const int k80thPercentileRSSI = -47; | |
| 46 | 72 |
| 47 } // namespace | 73 } // namespace |
| 48 | 74 |
| 49 namespace content { | 75 namespace content { |
| 50 | 76 |
| 51 bool BluetoothDeviceChooserController::use_test_scan_duration_ = false; | 77 bool BluetoothDeviceChooserController::use_test_scan_duration_ = false; |
| 52 | 78 |
| 53 namespace { | 79 namespace { |
| 54 constexpr size_t kMaxLengthForDeviceName = | 80 constexpr size_t kMaxLengthForDeviceName = |
| 55 29; // max length of device name in filter. | 81 29; // max length of device name in filter. |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 455 |
| 430 if (!powered) { | 456 if (!powered) { |
| 431 discovery_session_timer_.Stop(); | 457 discovery_session_timer_.Stop(); |
| 432 } | 458 } |
| 433 } | 459 } |
| 434 | 460 |
| 435 int BluetoothDeviceChooserController::CalculateSignalStrengthLevel( | 461 int BluetoothDeviceChooserController::CalculateSignalStrengthLevel( |
| 436 int8_t rssi) { | 462 int8_t rssi) { |
| 437 RecordRSSISignalStrength(rssi); | 463 RecordRSSISignalStrength(rssi); |
| 438 | 464 |
| 439 if (rssi <= kMinRSSI) { | 465 if (rssi < k20thPercentileRSSI) { |
| 440 RecordRSSISignalStrengthLevel( | 466 RecordRSSISignalStrengthLevel(content::UMARSSISignalStrengthLevel::LEVEL_0); |
| 441 UMARSSISignalStrengthLevel::LESS_THAN_OR_EQUAL_TO_MIN_RSSI); | |
|
juncai
2016/12/09 23:31:40
"LESS_THAN_OR_EQUAL_TO_MIN_RSSI" is not used, mayb
scheib
2016/12/10 00:04:04
We can't remove values for histograms. We could re
| |
| 442 return 0; | 467 return 0; |
| 468 } else if (rssi < k40thPercentileRSSI) { | |
| 469 RecordRSSISignalStrengthLevel(content::UMARSSISignalStrengthLevel::LEVEL_1); | |
| 470 return 1; | |
| 471 } else if (rssi < k60thPercentileRSSI) { | |
| 472 RecordRSSISignalStrengthLevel(content::UMARSSISignalStrengthLevel::LEVEL_2); | |
| 473 return 2; | |
| 474 } else if (rssi < k80thPercentileRSSI) { | |
| 475 RecordRSSISignalStrengthLevel(content::UMARSSISignalStrengthLevel::LEVEL_3); | |
| 476 return 3; | |
| 477 } else { | |
| 478 RecordRSSISignalStrengthLevel(content::UMARSSISignalStrengthLevel::LEVEL_4); | |
| 479 return 4; | |
| 443 } | 480 } |
| 444 | |
| 445 if (rssi >= kMaxRSSI) { | |
| 446 RecordRSSISignalStrengthLevel( | |
| 447 UMARSSISignalStrengthLevel::GREATER_THAN_OR_EQUAL_TO_MAX_RSSI); | |
|
juncai
2016/12/09 23:31:40
"GREATER_THAN_OR_EQUAL_TO_MAX_RSSI" is not used, m
scheib
2016/12/10 00:04:04
ditto
| |
| 448 return kNumSignalStrengthLevels - 1; | |
| 449 } | |
| 450 | |
| 451 double input_range = kMaxRSSI - kMinRSSI; | |
| 452 double output_range = kNumSignalStrengthLevels - 1; | |
| 453 int level = static_cast<int>((rssi - kMinRSSI) * output_range / input_range); | |
| 454 DCHECK(kNumSignalStrengthLevels == arraysize(kRSSISignalStrengthEnumTable)); | |
| 455 RecordRSSISignalStrengthLevel(kRSSISignalStrengthEnumTable[level]); | |
| 456 return level; | |
| 457 } | 481 } |
| 458 | 482 |
| 459 void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { | 483 void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { |
| 460 BluetoothDeviceChooserController::use_test_scan_duration_ = true; | 484 BluetoothDeviceChooserController::use_test_scan_duration_ = true; |
| 461 } | 485 } |
| 462 | 486 |
| 463 void BluetoothDeviceChooserController::PopulateConnectedDevices() { | 487 void BluetoothDeviceChooserController::PopulateConnectedDevices() { |
| 464 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { | 488 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { |
| 465 if (device->IsGattConnected()) { | 489 if (device->IsGattConnected()) { |
| 466 AddFilteredDevice(*device); | 490 AddFilteredDevice(*device); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 | 609 |
| 586 void BluetoothDeviceChooserController::PostErrorCallback( | 610 void BluetoothDeviceChooserController::PostErrorCallback( |
| 587 blink::mojom::WebBluetoothResult error) { | 611 blink::mojom::WebBluetoothResult error) { |
| 588 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 612 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 589 FROM_HERE, base::Bind(error_callback_, error))) { | 613 FROM_HERE, base::Bind(error_callback_, error))) { |
| 590 LOG(WARNING) << "No TaskRunner."; | 614 LOG(WARNING) << "No TaskRunner."; |
| 591 } | 615 } |
| 592 } | 616 } |
| 593 | 617 |
| 594 } // namespace content | 618 } // namespace content |
| OLD | NEW |