chromium/services/device/serial/serial_io_handler.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/device/serial/serial_io_handler.h"

#include <memory>
#include <utility>

#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "components/device_event_log/device_event_log.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/dbus/permission_broker/permission_broker_client.h"  // nogncheck
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace device {

SerialIoHandler::SerialIoHandler(
    const base::FilePath& port,
    scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
    :{}

SerialIoHandler::~SerialIoHandler() {}

void SerialIoHandler::Open(const mojom::SerialConnectionOptions& options,
                           OpenCompleteCallback callback) {}

#if BUILDFLAG(IS_CHROMEOS)

void SerialIoHandler::OnPathOpened(
    scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
    base::ScopedFD fd) {
  base::File file(std::move(fd));
  io_thread_task_runner->PostTask(
      FROM_HERE,
      base::BindOnce(&SerialIoHandler::FinishOpen, this, std::move(file)));
}

void SerialIoHandler::OnPathOpenError(
    scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
    const std::string& error_name,
    const std::string& error_message) {
  io_thread_task_runner->PostTask(
      FROM_HERE, base::BindOnce(&SerialIoHandler::ReportPathOpenError, this,
                                error_name, error_message));
}

void SerialIoHandler::ReportPathOpenError(const std::string& error_name,
                                          const std::string& error_message) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  DCHECK(open_complete_);
  SERIAL_LOG(ERROR) << "Permission broker failed to open '" << port_
                    << "': " << error_name << ": " << error_message;
  std::move(open_complete_).Run(false);
}

#endif  // BUILDFLAG(IS_CHROMEOS)

void SerialIoHandler::MergeConnectionOptions(
    const mojom::SerialConnectionOptions& options) {}

void SerialIoHandler::StartOpen(
    scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {}

void SerialIoHandler::FinishOpen(base::File file) {}

bool SerialIoHandler::PostOpen() {}

void SerialIoHandler::PreClose() {}

void SerialIoHandler::Close(base::OnceClosure callback) {}

// static
void SerialIoHandler::DoClose(base::File port) {}

void SerialIoHandler::Read(base::span<uint8_t> buffer,
                           ReadCompleteCallback callback) {}

void SerialIoHandler::Write(base::span<const uint8_t> buffer,
                            WriteCompleteCallback callback) {}

void SerialIoHandler::ReadCompleted(int bytes_read,
                                    mojom::SerialReceiveError error) {}

void SerialIoHandler::WriteCompleted(int bytes_written,
                                     mojom::SerialSendError error) {}

bool SerialIoHandler::IsReadPending() const {}

bool SerialIoHandler::IsWritePending() const {}

void SerialIoHandler::CancelRead(mojom::SerialReceiveError reason) {}

void SerialIoHandler::CancelWrite(mojom::SerialSendError reason) {}

bool SerialIoHandler::ConfigurePort(
    const mojom::SerialConnectionOptions& options) {}

}  // namespace device