#include "services/device/serial/bluetooth_serial_device_enumerator.h"
#include <string_view>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "services/device/public/cpp/bluetooth/bluetooth_utils.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/public/mojom/serial.mojom.h"
#include "services/device/serial/bluetooth_serial_port_impl.h"
namespace device {
namespace {
mojom::SerialPortInfoPtr CreatePort(std::string_view device_address,
std::u16string_view device_name,
const BluetoothUUID& service_class_id,
bool connected) { … }
}
class BluetoothSerialDeviceEnumerator::AdapterHelper
: public BluetoothAdapter::Observer { … };
BluetoothSerialDeviceEnumerator::AdapterHelper::AdapterHelper(
base::WeakPtr<BluetoothSerialDeviceEnumerator> enumerator,
scoped_refptr<base::SequencedTaskRunner> enumerator_runner)
: … { … }
void BluetoothSerialDeviceEnumerator::AdapterHelper::OnGotClassicAdapter(
scoped_refptr<device::BluetoothAdapter> adapter) { … }
void BluetoothSerialDeviceEnumerator::AdapterHelper::DeviceAdded(
BluetoothAdapter* adapter,
BluetoothDevice* device) { … }
void BluetoothSerialDeviceEnumerator::AdapterHelper::DeviceRemoved(
BluetoothAdapter* adapter,
BluetoothDevice* device) { … }
void BluetoothSerialDeviceEnumerator::AdapterHelper::DeviceChanged(
BluetoothAdapter* adapter,
BluetoothDevice* device) { … }
void BluetoothSerialDeviceEnumerator::AdapterHelper::OpenPort(
const std::string& address,
const BluetoothUUID& service_class_id,
mojom::SerialConnectionOptionsPtr options,
mojo::PendingRemote<mojom::SerialPortClient> client,
mojo::PendingRemote<mojom::SerialPortConnectionWatcher> watcher,
BluetoothSerialPortImpl::OpenCallback callback) { … }
BluetoothSerialDeviceEnumerator::BluetoothSerialDeviceEnumerator(
scoped_refptr<base::SingleThreadTaskRunner> adapter_runner) { … }
BluetoothSerialDeviceEnumerator::~BluetoothSerialDeviceEnumerator() { … }
void BluetoothSerialDeviceEnumerator::GetDevicesAfterInitialEnumeration(
mojom::SerialPortManager::GetDevicesCallback callback) { … }
void BluetoothSerialDeviceEnumerator::DeviceAddedOrChanged(
std::string_view device_address,
std::u16string_view device_name,
BluetoothDevice::UUIDSet service_class_ids,
bool is_connected) { … }
void BluetoothSerialDeviceEnumerator::AddOrUpdateService(
std::string_view device_address,
std::u16string_view device_name,
const BluetoothUUID& service_class_id,
bool is_connected) { … }
void BluetoothSerialDeviceEnumerator::OnInitialEnumerationComplete() { … }
void BluetoothSerialDeviceEnumerator::DeviceRemoved(
const std::string& device_address) { … }
void BluetoothSerialDeviceEnumerator::OpenPort(
const std::string& address,
const BluetoothUUID& service_class_id,
mojom::SerialConnectionOptionsPtr options,
mojo::PendingRemote<mojom::SerialPortClient> client,
mojo::PendingRemote<mojom::SerialPortConnectionWatcher> watcher,
BluetoothSerialPortImpl::OpenCallback callback) { … }
std::optional<std::string> BluetoothSerialDeviceEnumerator::GetAddressFromToken(
const base::UnguessableToken& token) const { … }
BluetoothUUID BluetoothSerialDeviceEnumerator::GetServiceClassIdFromToken(
const base::UnguessableToken& token) const { … }
void BluetoothSerialDeviceEnumerator::DeviceAddedForTesting(
BluetoothAdapter* adapter,
BluetoothDevice* device) { … }
void BluetoothSerialDeviceEnumerator::DeviceChangedForTesting(
BluetoothAdapter* adapter,
BluetoothDevice* device) { … }
void BluetoothSerialDeviceEnumerator::SynchronouslyResetHelperForTesting() { … }
}