| 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 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ |
| 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_set> | 9 #include <unordered_set> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const ErrorCallback& error_callback); | 72 const ErrorCallback& error_callback); |
| 73 | 73 |
| 74 // Adds a device to the chooser. Should only be called after GetDevice and | 74 // Adds a device to the chooser. Should only be called after GetDevice and |
| 75 // before either of the callbacks are run. | 75 // before either of the callbacks are run. |
| 76 void AddFilteredDevice(const device::BluetoothDevice& device); | 76 void AddFilteredDevice(const device::BluetoothDevice& device); |
| 77 | 77 |
| 78 // Stops the current discovery session and notifies the chooser | 78 // Stops the current discovery session and notifies the chooser |
| 79 // that the adapter changed states. | 79 // that the adapter changed states. |
| 80 void AdapterPoweredChanged(bool powered); | 80 void AdapterPoweredChanged(bool powered); |
| 81 | 81 |
| 82 // Stops the discovery session and notifies the chooser |
| 83 // when discovery stops accidentally. |
| 84 void AdapterDiscoveringChanged(bool discovering); |
| 85 |
| 82 // Received Signal Strength Indicator (RSSI) is a measurement of the power | 86 // Received Signal Strength Indicator (RSSI) is a measurement of the power |
| 83 // present in a received radio signal. | 87 // present in a received radio signal. |
| 84 static int CalculateSignalStrengthLevel(int8_t rssi); | 88 static int CalculateSignalStrengthLevel(int8_t rssi); |
| 85 | 89 |
| 86 // After this method is called any new instance of | 90 // After this method is called any new instance of |
| 87 // BluetoothDeviceChooserController will have a scan duration of 0. | 91 // BluetoothDeviceChooserController will have a scan duration of 0. |
| 88 static void SetTestScanDurationForTesting(); | 92 static void SetTestScanDurationForTesting(); |
| 89 | 93 |
| 94 bool IsDiscoverySessionActive(); |
| 95 |
| 96 void StartDeviceDiscoveryForTesting(); |
| 97 |
| 90 private: | 98 private: |
| 91 // Populates the chooser with the GATT connected devices. | 99 // Populates the chooser with the GATT connected devices. |
| 92 void PopulateConnectedDevices(); | 100 void PopulateConnectedDevices(); |
| 93 | 101 |
| 94 // Notifies the chooser that discovery is starting and starts a discovery | 102 // Notifies the chooser that discovery is starting and starts a discovery |
| 95 // session. | 103 // session. |
| 96 void StartDeviceDiscovery(); | 104 void StartDeviceDiscovery(); |
| 97 | 105 |
| 98 // Stops the discovery session and notifies the chooser. | 106 // Stops the discovery session and notifies the chooser. |
| 99 void StopDeviceDiscovery(); | 107 void StopDeviceDiscovery(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ErrorCallback error_callback_; | 143 ErrorCallback error_callback_; |
| 136 | 144 |
| 137 // The currently opened BluetoothChooser. | 145 // The currently opened BluetoothChooser. |
| 138 std::unique_ptr<BluetoothChooser> chooser_; | 146 std::unique_ptr<BluetoothChooser> chooser_; |
| 139 | 147 |
| 140 // Automatically stops Bluetooth discovery a set amount of time after it was | 148 // Automatically stops Bluetooth discovery a set amount of time after it was |
| 141 // started. | 149 // started. |
| 142 base::Timer discovery_session_timer_; | 150 base::Timer discovery_session_timer_; |
| 143 | 151 |
| 144 // The last discovery session to be started. | 152 // The last discovery session to be started. |
| 145 // TODO(ortuno): This should be null unless there is an active discovery | |
| 146 // session. We need to null it when the platform stops discovery. | |
| 147 // http://crbug.com/611852 | |
| 148 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 153 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 149 | 154 |
| 150 // The time when scanning starts. | 155 // The time when scanning starts. |
| 151 base::Optional<base::TimeTicks> scanning_start_time_; | 156 base::Optional<base::TimeTicks> scanning_start_time_; |
| 152 | 157 |
| 153 // The device ids that are currently shown in the chooser. | 158 // The device ids that are currently shown in the chooser. |
| 154 std::unordered_set<std::string> device_ids_; | 159 std::unordered_set<std::string> device_ids_; |
| 155 | 160 |
| 156 // Weak pointer factory for generating 'this' pointers that might live longer | 161 // Weak pointer factory for generating 'this' pointers that might live longer |
| 157 // than we do. | 162 // than we do. |
| 158 // Note: This should remain the last member so it'll be destroyed and | 163 // Note: This should remain the last member so it'll be destroyed and |
| 159 // invalidate its weak pointers before any other members are destroyed. | 164 // invalidate its weak pointers before any other members are destroyed. |
| 160 base::WeakPtrFactory<BluetoothDeviceChooserController> weak_ptr_factory_; | 165 base::WeakPtrFactory<BluetoothDeviceChooserController> weak_ptr_factory_; |
| 161 }; | 166 }; |
| 162 | 167 |
| 163 } // namespace content | 168 } // namespace content |
| 164 | 169 |
| 165 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ | 170 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ |
| OLD | NEW |