#include "extensions/browser/api/serial/serial_api.h"
#include <algorithm>
#include <map>
#include <unordered_set>
#include <utility>
#include "base/functional/bind.h"
#include "base/values.h"
#include "build/build_config.h"
#include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/api/serial/serial_connection.h"
#include "extensions/browser/api/serial/serial_port_manager.h"
#include "extensions/common/api/serial.h"
#include "extensions/common/extension_id.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace extensions {
namespace api {
namespace {
const int kDefaultBufferSize = …;
const int kDefaultBitrate = …;
const serial::DataBits kDefaultDataBits = …;
const serial::ParityBit kDefaultParityBit = …;
const serial::StopBits kDefaultStopBits = …;
const int kDefaultReceiveTimeout = …;
const int kDefaultSendTimeout = …;
const char kErrorConnectFailed[] = …;
const char kErrorSerialConnectionNotFound[] = …;
const char kErrorGetControlSignalsFailed[] = …;
template <typename T>
void SetDefaultOptionalValue(std::optional<T>& field, const T& value) { … }
}
SerialExtensionFunction::SerialExtensionFunction() = default;
SerialExtensionFunction::~SerialExtensionFunction() = default;
SerialConnection* SerialExtensionFunction::GetSerialConnection(
int api_resource_id) { … }
void SerialExtensionFunction::RemoveSerialConnection(int api_resource_id) { … }
SerialGetDevicesFunction::SerialGetDevicesFunction() = default;
SerialGetDevicesFunction::~SerialGetDevicesFunction() = default;
ExtensionFunction::ResponseAction SerialGetDevicesFunction::Run() { … }
void SerialGetDevicesFunction::OnGotDevices(
std::vector<device::mojom::SerialPortInfoPtr> devices) { … }
SerialConnectFunction::SerialConnectFunction() = default;
SerialConnectFunction::~SerialConnectFunction() = default;
ExtensionFunction::ResponseAction SerialConnectFunction::Run() { … }
void SerialConnectFunction::OnConnected(bool success) { … }
void SerialConnectFunction::FinishConnect(
bool connected,
bool got_complete_info,
std::unique_ptr<serial::ConnectionInfo> info) { … }
SerialUpdateFunction::SerialUpdateFunction() = default;
SerialUpdateFunction::~SerialUpdateFunction() = default;
ExtensionFunction::ResponseAction SerialUpdateFunction::Run() { … }
void SerialUpdateFunction::OnUpdated(bool success) { … }
SerialDisconnectFunction::SerialDisconnectFunction() = default;
SerialDisconnectFunction::~SerialDisconnectFunction() = default;
ExtensionFunction::ResponseAction SerialDisconnectFunction::Run() { … }
void SerialDisconnectFunction::OnCloseComplete(int connection_id) { … }
SerialSendFunction::SerialSendFunction() = default;
SerialSendFunction::~SerialSendFunction() = default;
ExtensionFunction::ResponseAction SerialSendFunction::Run() { … }
void SerialSendFunction::OnSendComplete(uint32_t bytes_sent,
serial::SendError error) { … }
SerialFlushFunction::SerialFlushFunction() = default;
SerialFlushFunction::~SerialFlushFunction() = default;
ExtensionFunction::ResponseAction SerialFlushFunction::Run() { … }
void SerialFlushFunction::OnFlushed() { … }
SerialSetPausedFunction::SerialSetPausedFunction() = default;
SerialSetPausedFunction::~SerialSetPausedFunction() = default;
ExtensionFunction::ResponseAction SerialSetPausedFunction::Run() { … }
SerialGetInfoFunction::SerialGetInfoFunction() = default;
SerialGetInfoFunction::~SerialGetInfoFunction() = default;
ExtensionFunction::ResponseAction SerialGetInfoFunction::Run() { … }
void SerialGetInfoFunction::OnGotInfo(
int connection_id,
bool got_complete_info,
std::unique_ptr<serial::ConnectionInfo> info) { … }
SerialGetConnectionsFunction::SerialGetConnectionsFunction() = default;
SerialGetConnectionsFunction::~SerialGetConnectionsFunction() = default;
ExtensionFunction::ResponseAction SerialGetConnectionsFunction::Run() { … }
void SerialGetConnectionsFunction::OnGotOne(
int connection_id,
bool got_complete_info,
std::unique_ptr<serial::ConnectionInfo> info) { … }
SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() = default;
SerialGetControlSignalsFunction::~SerialGetControlSignalsFunction() = default;
ExtensionFunction::ResponseAction SerialGetControlSignalsFunction::Run() { … }
void SerialGetControlSignalsFunction::OnGotControlSignals(
std::unique_ptr<serial::DeviceControlSignals> signals) { … }
SerialSetControlSignalsFunction::SerialSetControlSignalsFunction() = default;
SerialSetControlSignalsFunction::~SerialSetControlSignalsFunction() = default;
ExtensionFunction::ResponseAction SerialSetControlSignalsFunction::Run() { … }
void SerialSetControlSignalsFunction::OnSetControlSignals(bool success) { … }
SerialSetBreakFunction::SerialSetBreakFunction() = default;
SerialSetBreakFunction::~SerialSetBreakFunction() = default;
ExtensionFunction::ResponseAction SerialSetBreakFunction::Run() { … }
void SerialSetBreakFunction::OnSetBreak(bool success) { … }
SerialClearBreakFunction::SerialClearBreakFunction() = default;
SerialClearBreakFunction::~SerialClearBreakFunction() = default;
ExtensionFunction::ResponseAction SerialClearBreakFunction::Run() { … }
void SerialClearBreakFunction::OnClearBreak(bool success) { … }
}
}