#include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
#include <stdint.h>
#include <unordered_set>
#include <utility>
#include "base/functional/bind.h"
#include "base/hash/hash.h"
#include "base/metrics/histogram_functions.h"
#include "base/types/optional_util.h"
#include "content/public/browser/browser_context.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_socket.h"
#include "extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h"
#include "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatcher.h"
#include "extensions/common/api/bluetooth/bluetooth_manifest_data.h"
#include "extensions/common/permissions/permissions_data.h"
#include "net/base/io_buffer.h"
BrowserThread;
BluetoothApiSocket;
ListenOptions;
SocketInfo;
SocketProperties;
namespace extensions {
namespace api {
namespace {
const char kDeviceNotFoundError[] = …;
const char kInvalidPsmError[] = …;
const char kInvalidUuidError[] = …;
const char kPermissionDeniedError[] = …;
const char kSocketNotFoundError[] = …;
SocketInfo CreateSocketInfo(int socket_id, BluetoothApiSocket* socket) { … }
void SetSocketProperties(BluetoothApiSocket* socket,
SocketProperties* properties) { … }
BluetoothSocketEventDispatcher* GetSocketEventDispatcher(
content::BrowserContext* browser_context) { … }
bool IsValidPsm(int psm) { … }
}
BluetoothSocketAsyncApiFunction::BluetoothSocketAsyncApiFunction() = default;
BluetoothSocketAsyncApiFunction::~BluetoothSocketAsyncApiFunction() = default;
bool BluetoothSocketAsyncApiFunction::PreRunValidation(std::string* error) { … }
int BluetoothSocketAsyncApiFunction::AddSocket(BluetoothApiSocket* socket) { … }
content::BrowserThread::ID
BluetoothSocketAsyncApiFunction::work_thread_id() const { … }
BluetoothApiSocket* BluetoothSocketAsyncApiFunction::GetSocket(
int api_resource_id) { … }
void BluetoothSocketAsyncApiFunction::RemoveSocket(int api_resource_id) { … }
std::unordered_set<int>* BluetoothSocketAsyncApiFunction::GetSocketIds() { … }
BluetoothSocketCreateFunction::BluetoothSocketCreateFunction() = default;
BluetoothSocketCreateFunction::~BluetoothSocketCreateFunction() = default;
ExtensionFunction::ResponseAction BluetoothSocketCreateFunction::Run() { … }
BluetoothSocketUpdateFunction::BluetoothSocketUpdateFunction() = default;
BluetoothSocketUpdateFunction::~BluetoothSocketUpdateFunction() = default;
ExtensionFunction::ResponseAction BluetoothSocketUpdateFunction::Run() { … }
BluetoothSocketSetPausedFunction::BluetoothSocketSetPausedFunction() = default;
BluetoothSocketSetPausedFunction::~BluetoothSocketSetPausedFunction() = default;
ExtensionFunction::ResponseAction BluetoothSocketSetPausedFunction::Run() { … }
BluetoothSocketListenFunction::BluetoothSocketListenFunction() = default;
BluetoothSocketListenFunction::~BluetoothSocketListenFunction() = default;
bool BluetoothSocketListenFunction::PreRunValidation(std::string* error) { … }
ExtensionFunction::ResponseAction BluetoothSocketListenFunction::Run() { … }
void BluetoothSocketListenFunction::OnGetAdapter(
scoped_refptr<device::BluetoothAdapter> adapter) { … }
void BluetoothSocketListenFunction::OnCreateService(
scoped_refptr<device::BluetoothSocket> socket) { … }
void BluetoothSocketListenFunction::OnCreateServiceError(
const std::string& message) { … }
BluetoothSocketListenUsingRfcommFunction::
BluetoothSocketListenUsingRfcommFunction() { … }
BluetoothSocketListenUsingRfcommFunction::
~BluetoothSocketListenUsingRfcommFunction() { … }
int BluetoothSocketListenUsingRfcommFunction::socket_id() const { … }
const std::string& BluetoothSocketListenUsingRfcommFunction::uuid() const { … }
bool BluetoothSocketListenUsingRfcommFunction::CreateParams() { … }
void BluetoothSocketListenUsingRfcommFunction::CreateService(
scoped_refptr<device::BluetoothAdapter> adapter,
const device::BluetoothUUID& uuid,
const std::optional<std::string>& name,
device::BluetoothAdapter::CreateServiceCallback callback,
device::BluetoothAdapter::CreateServiceErrorCallback error_callback) { … }
base::Value::List BluetoothSocketListenUsingRfcommFunction::CreateResults() { … }
BluetoothSocketListenUsingL2capFunction::
BluetoothSocketListenUsingL2capFunction() { … }
BluetoothSocketListenUsingL2capFunction::
~BluetoothSocketListenUsingL2capFunction() { … }
int BluetoothSocketListenUsingL2capFunction::socket_id() const { … }
const std::string& BluetoothSocketListenUsingL2capFunction::uuid() const { … }
bool BluetoothSocketListenUsingL2capFunction::CreateParams() { … }
void BluetoothSocketListenUsingL2capFunction::CreateService(
scoped_refptr<device::BluetoothAdapter> adapter,
const device::BluetoothUUID& uuid,
const std::optional<std::string>& name,
device::BluetoothAdapter::CreateServiceCallback callback,
device::BluetoothAdapter::CreateServiceErrorCallback error_callback) { … }
base::Value::List BluetoothSocketListenUsingL2capFunction::CreateResults() { … }
BluetoothSocketAbstractConnectFunction::
BluetoothSocketAbstractConnectFunction() { … }
BluetoothSocketAbstractConnectFunction::
~BluetoothSocketAbstractConnectFunction() { … }
bool BluetoothSocketAbstractConnectFunction::PreRunValidation(
std::string* error) { … }
ExtensionFunction::ResponseAction
BluetoothSocketAbstractConnectFunction::Run() { … }
void BluetoothSocketAbstractConnectFunction::OnGetAdapter(
scoped_refptr<device::BluetoothAdapter> adapter) { … }
void BluetoothSocketAbstractConnectFunction::OnConnect(
scoped_refptr<device::BluetoothSocket> socket) { … }
void BluetoothSocketAbstractConnectFunction::OnConnectError(
const std::string& message) { … }
BluetoothSocketConnectFunction::BluetoothSocketConnectFunction() = default;
BluetoothSocketConnectFunction::~BluetoothSocketConnectFunction() = default;
void BluetoothSocketConnectFunction::ConnectToService(
device::BluetoothDevice* device,
const device::BluetoothUUID& uuid) { … }
BluetoothSocketDisconnectFunction::BluetoothSocketDisconnectFunction() =
default;
BluetoothSocketDisconnectFunction::~BluetoothSocketDisconnectFunction() =
default;
ExtensionFunction::ResponseAction BluetoothSocketDisconnectFunction::Run() { … }
void BluetoothSocketDisconnectFunction::OnSuccess() { … }
BluetoothSocketCloseFunction::BluetoothSocketCloseFunction() = default;
BluetoothSocketCloseFunction::~BluetoothSocketCloseFunction() = default;
ExtensionFunction::ResponseAction BluetoothSocketCloseFunction::Run() { … }
BluetoothSocketSendFunction::BluetoothSocketSendFunction()
: … { … }
BluetoothSocketSendFunction::~BluetoothSocketSendFunction() = default;
ExtensionFunction::ResponseAction BluetoothSocketSendFunction::Run() { … }
void BluetoothSocketSendFunction::OnSuccess(int bytes_sent) { … }
void BluetoothSocketSendFunction::OnError(
BluetoothApiSocket::ErrorReason reason,
const std::string& message) { … }
BluetoothSocketGetInfoFunction::BluetoothSocketGetInfoFunction() = default;
BluetoothSocketGetInfoFunction::~BluetoothSocketGetInfoFunction() = default;
ExtensionFunction::ResponseAction BluetoothSocketGetInfoFunction::Run() { … }
BluetoothSocketGetSocketsFunction::BluetoothSocketGetSocketsFunction() =
default;
BluetoothSocketGetSocketsFunction::~BluetoothSocketGetSocketsFunction() =
default;
ExtensionFunction::ResponseAction BluetoothSocketGetSocketsFunction::Run() { … }
}
}