#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatcher.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "content/public/browser/browser_thread.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/event_router.h"
#include "extensions/common/api/bluetooth_socket.h"
#include "extensions/common/extension_id.h"
#include "net/base/io_buffer.h"
namespace {
bluetooth_socket;
BluetoothApiSocket;
int kDefaultBufferSize = …;
bluetooth_socket::ReceiveError MapReceiveErrorReason(
BluetoothApiSocket::ErrorReason value) { … }
bluetooth_socket::AcceptError MapAcceptErrorReason(
BluetoothApiSocket::ErrorReason value) { … }
}
namespace extensions {
namespace api {
BrowserThread;
static base::LazyInstance<BrowserContextKeyedAPIFactory<
BluetoothSocketEventDispatcher>>::DestructorAtExit g_factory = …;
BrowserContextKeyedAPIFactory<BluetoothSocketEventDispatcher>*
BluetoothSocketEventDispatcher::GetFactoryInstance() { … }
BluetoothSocketEventDispatcher* BluetoothSocketEventDispatcher::Get(
content::BrowserContext* context) { … }
BluetoothSocketEventDispatcher::BluetoothSocketEventDispatcher(
content::BrowserContext* context)
: … { … }
BluetoothSocketEventDispatcher::~BluetoothSocketEventDispatcher() = default;
BluetoothSocketEventDispatcher::SocketParams::SocketParams() = default;
BluetoothSocketEventDispatcher::SocketParams::SocketParams(
const SocketParams& other) = default;
BluetoothSocketEventDispatcher::SocketParams::~SocketParams() = default;
void BluetoothSocketEventDispatcher::OnSocketConnect(
const ExtensionId& extension_id,
int socket_id) { … }
void BluetoothSocketEventDispatcher::OnSocketListen(
const ExtensionId& extension_id,
int socket_id) { … }
void BluetoothSocketEventDispatcher::OnSocketResume(
const ExtensionId& extension_id,
int socket_id) { … }
void BluetoothSocketEventDispatcher::StartReceive(const SocketParams& params) { … }
void BluetoothSocketEventDispatcher::ReceiveCallback(
const SocketParams& params,
int bytes_read,
scoped_refptr<net::IOBuffer> io_buffer) { … }
void BluetoothSocketEventDispatcher::ReceiveErrorCallback(
const SocketParams& params,
BluetoothApiSocket::ErrorReason error_reason,
const std::string& error) { … }
void BluetoothSocketEventDispatcher::StartAccept(const SocketParams& params) { … }
void BluetoothSocketEventDispatcher::AcceptCallback(
const SocketParams& params,
const device::BluetoothDevice* device,
scoped_refptr<device::BluetoothSocket> socket) { … }
void BluetoothSocketEventDispatcher::AcceptErrorCallback(
const SocketParams& params,
BluetoothApiSocket::ErrorReason error_reason,
const std::string& error) { … }
void BluetoothSocketEventDispatcher::PostEvent(const SocketParams& params,
std::unique_ptr<Event> event) { … }
void BluetoothSocketEventDispatcher::DispatchEvent(
void* browser_context_id,
const ExtensionId& extension_id,
std::unique_ptr<Event> event) { … }
}
}