| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Anything worse than or equal to this will show 0 bars. | 31 // Anything worse than or equal to this will show 0 bars. |
| 32 const int kMinRSSI = -100; | 32 const int kMinRSSI = -100; |
| 33 // Anything better than or equal to this will show the maximum bars. | 33 // Anything better than or equal to this will show the maximum bars. |
| 34 const int kMaxRSSI = -55; | 34 const int kMaxRSSI = -55; |
| 35 // Number of RSSI levels used in the signal strength image. | 35 // Number of RSSI levels used in the signal strength image. |
| 36 const int kNumSignalStrengthLevels = 5; | 36 const int kNumSignalStrengthLevels = 5; |
| 37 | 37 |
| 38 const content::UMARSSISignalStrengthLevel kRSSISignalStrengthEnumTable[] = { |
| 39 content::UMARSSISignalStrengthLevel::LEVEL_0, |
| 40 content::UMARSSISignalStrengthLevel::LEVEL_1, |
| 41 content::UMARSSISignalStrengthLevel::LEVEL_2, |
| 42 content::UMARSSISignalStrengthLevel::LEVEL_3, |
| 43 content::UMARSSISignalStrengthLevel::LEVEL_4}; |
| 44 |
| 38 } // namespace | 45 } // namespace |
| 39 | 46 |
| 40 namespace content { | 47 namespace content { |
| 41 | 48 |
| 42 bool BluetoothDeviceChooserController::use_test_scan_duration_ = false; | 49 bool BluetoothDeviceChooserController::use_test_scan_duration_ = false; |
| 43 | 50 |
| 44 namespace { | 51 namespace { |
| 45 constexpr size_t kMaxLengthForDeviceName = | 52 constexpr size_t kMaxLengthForDeviceName = |
| 46 29; // max length of device name in filter. | 53 29; // max length of device name in filter. |
| 47 | 54 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 384 } |
| 378 } | 385 } |
| 379 | 386 |
| 380 if (!powered) { | 387 if (!powered) { |
| 381 discovery_session_timer_.Stop(); | 388 discovery_session_timer_.Stop(); |
| 382 } | 389 } |
| 383 } | 390 } |
| 384 | 391 |
| 385 int BluetoothDeviceChooserController::CalculateSignalStrengthLevel( | 392 int BluetoothDeviceChooserController::CalculateSignalStrengthLevel( |
| 386 int8_t rssi) { | 393 int8_t rssi) { |
| 387 if (rssi <= kMinRSSI) | 394 RecordRSSISignalStrength(rssi); |
| 395 |
| 396 if (rssi <= kMinRSSI) { |
| 397 RecordRSSISignalStrengthLevel( |
| 398 UMARSSISignalStrengthLevel::LESS_THAN_OR_EQUAL_TO_MIN_RSSI); |
| 388 return 0; | 399 return 0; |
| 400 } |
| 389 | 401 |
| 390 if (rssi >= kMaxRSSI) | 402 if (rssi >= kMaxRSSI) { |
| 403 RecordRSSISignalStrengthLevel( |
| 404 UMARSSISignalStrengthLevel::GREATER_THAN_OR_EQUAL_TO_MAX_RSSI); |
| 391 return kNumSignalStrengthLevels - 1; | 405 return kNumSignalStrengthLevels - 1; |
| 406 } |
| 392 | 407 |
| 393 double input_range = kMaxRSSI - kMinRSSI; | 408 double input_range = kMaxRSSI - kMinRSSI; |
| 394 double output_range = kNumSignalStrengthLevels - 1; | 409 double output_range = kNumSignalStrengthLevels - 1; |
| 395 return static_cast<int>((rssi - kMinRSSI) * output_range / input_range); | 410 int level = static_cast<int>((rssi - kMinRSSI) * output_range / input_range); |
| 411 DCHECK(kNumSignalStrengthLevels == arraysize(kRSSISignalStrengthEnumTable)); |
| 412 RecordRSSISignalStrengthLevel(kRSSISignalStrengthEnumTable[level]); |
| 413 return level; |
| 396 } | 414 } |
| 397 | 415 |
| 398 void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { | 416 void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { |
| 399 BluetoothDeviceChooserController::use_test_scan_duration_ = true; | 417 BluetoothDeviceChooserController::use_test_scan_duration_ = true; |
| 400 } | 418 } |
| 401 | 419 |
| 402 void BluetoothDeviceChooserController::PopulateConnectedDevices() { | 420 void BluetoothDeviceChooserController::PopulateConnectedDevices() { |
| 403 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { | 421 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { |
| 404 if (device->IsGattConnected()) { | 422 if (device->IsGattConnected()) { |
| 405 AddFilteredDevice(*device); | 423 AddFilteredDevice(*device); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 530 |
| 513 void BluetoothDeviceChooserController::PostErrorCallback( | 531 void BluetoothDeviceChooserController::PostErrorCallback( |
| 514 blink::mojom::WebBluetoothResult error) { | 532 blink::mojom::WebBluetoothResult error) { |
| 515 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 533 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 516 FROM_HERE, base::Bind(error_callback_, error))) { | 534 FROM_HERE, base::Bind(error_callback_, error))) { |
| 517 LOG(WARNING) << "No TaskRunner."; | 535 LOG(WARNING) << "No TaskRunner."; |
| 518 } | 536 } |
| 519 } | 537 } |
| 520 | 538 |
| 521 } // namespace content | 539 } // namespace content |
| OLD | NEW |