Commit fa8f7938 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Remove all ARC dependencies on Mojo EDK

Replaces all EDK usage for ARC-related components with public Mojo
API calls. No functional changes.

Also cleans up relevant DEPS and GN deps.

Bug: 844763
Change-Id: I1cab5ed08bcb08049b4648e3fb4c28664fb04bf7
TBR: jcliang@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/1100041
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567334}
parent 4eab3f75
......@@ -23,7 +23,6 @@ include_rules = [
"+media/audio/sounds", # For system sounds
"+media/base/media_switches.h", # For media command line switches.
"+media/mojo/interfaces", # For platform verification mojom interface.
"+mojo/edk/embedder",
"+services/device/public",
"+services/metrics/public",
"+services/tracing/public",
......
......@@ -44,8 +44,8 @@
#include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
#include "device/bluetooth/bluez/bluetooth_device_bluez.h"
#include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/platform_handle.h"
using device::BluetoothAdapter;
using device::BluetoothAdapterFactory;
......@@ -1854,19 +1854,16 @@ void ArcBluetoothBridge::OpenBluetoothSocket(
std::move(callback).Run(mojo::ScopedHandle());
return;
}
mojo::edk::ScopedInternalPlatformHandle platform_handle{
mojo::edk::InternalPlatformHandle(sock.release())};
MojoHandle wrapped_handle;
MojoResult wrap_result = mojo::edk::CreateInternalPlatformHandleWrapper(
std::move(platform_handle), &wrapped_handle);
if (wrap_result != MOJO_RESULT_OK) {
LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result;
mojo::ScopedHandle handle =
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(sock)));
if (handle.is_valid() != MOJO_RESULT_OK) {
LOG(ERROR) << "Failed to wrap socket handle. Closing";
std::move(callback).Run(mojo::ScopedHandle());
return;
}
mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)};
std::move(callback).Run(std::move(scoped_handle));
std::move(callback).Run(std::move(handle));
}
bool ArcBluetoothBridge::IsGattServerAttributeHandleAvailable(int need) {
......
......@@ -12,7 +12,8 @@
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
......@@ -117,14 +118,14 @@ void ArcContentFileSystemFileStreamReader::OnOpenFile(
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
DCHECK(!file_);
mojo::edk::ScopedInternalPlatformHandle platform_handle;
if (mojo::edk::PassWrappedInternalPlatformHandle(
handle.release().value(), &platform_handle) != MOJO_RESULT_OK) {
mojo::PlatformHandle platform_handle =
mojo::UnwrapPlatformHandle(std::move(handle));
if (!platform_handle.is_valid()) {
LOG(ERROR) << "PassWrappedInternalPlatformHandle failed";
callback.Run(net::ERR_FAILED);
return;
}
file_.reset(new base::File(platform_handle.release().handle));
file_ = std::make_unique<base::File>(platform_handle.ReleaseFD());
if (!file_->IsValid()) {
LOG(ERROR) << "Invalid file.";
callback.Run(net::ERR_FAILED);
......
......@@ -21,8 +21,8 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/api/file_handlers/mime_util.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "net/base/escape.h"
#include "storage/browser/fileapi/file_system_context.h"
......@@ -253,17 +253,14 @@ void ArcFileSystemBridge::OnOpenFile(const GURL& url_decoded,
DCHECK_EQ(id_to_url_.count(id), 0u);
id_to_url_[id] = url_decoded;
mojo::edk::ScopedInternalPlatformHandle platform_handle{
mojo::edk::InternalPlatformHandle(fd.release())};
MojoHandle wrapped_handle = MOJO_HANDLE_INVALID;
MojoResult result = mojo::edk::CreateInternalPlatformHandleWrapper(
std::move(platform_handle), &wrapped_handle);
if (result != MOJO_RESULT_OK) {
LOG(ERROR) << "Failed to wrap handle: " << result;
mojo::ScopedHandle wrapped_handle =
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(fd)));
if (!wrapped_handle.is_valid()) {
LOG(ERROR) << "Failed to wrap handle";
std::move(callback).Run(mojo::ScopedHandle());
return;
}
std::move(callback).Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle)));
std::move(callback).Run(std::move(wrapped_handle));
}
bool ArcFileSystemBridge::HandleReadRequest(const std::string& id,
......
......@@ -31,8 +31,9 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/common/child_process_host.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
#include "printing/pdf_metafile_skia.h"
......@@ -600,16 +601,14 @@ void ArcPrintServiceImpl::Print(mojom::PrintJobInstancePtr instance,
settings->set_color(FromArcColorMode(attr->color_mode));
settings->set_copies(print_job->copies);
settings->set_duplex_mode(FromArcDuplexMode(attr->duplex_mode));
mojo::edk::ScopedInternalPlatformHandle scoped_handle;
PassWrappedInternalPlatformHandle(print_job->data.release().value(),
&scoped_handle);
base::ScopedFD fd =
mojo::UnwrapPlatformHandle(std::move(print_job->data)).TakeFD();
mojom::PrintJobHostPtr host_proxy;
auto job = std::make_unique<PrintJobHostImpl>(
mojo::MakeRequest(&host_proxy), std::move(instance), this,
chromeos::CupsPrintJobManagerFactory::GetForBrowserContext(profile_),
std::move(settings), base::File(scoped_handle.release().handle),
print_job->data_size);
std::move(settings), base::File(fd.release()), print_job->data_size);
PrintJobHostImpl* job_raw = job.get();
jobs_.emplace(job_raw, std::move(job));
std::move(callback).Run(std::move(host_proxy));
......
......@@ -92,7 +92,6 @@ static_library("arc") {
"//device/usb/mojo",
"//device/usb/public/mojom",
"//google_apis",
"//mojo/edk",
"//services/device/public/mojom",
"//skia",
"//third_party/re2:re2",
......@@ -260,7 +259,7 @@ static_library("arc_test_support") {
"//components/prefs:test_support",
"//components/user_prefs",
"//content/test:test_support",
"//mojo/edk",
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
]
}
......
......@@ -26,11 +26,11 @@
#include "components/arc/arc_bridge_host_impl.h"
#include "components/arc/arc_features.h"
#include "components/user_manager/user_manager.h"
#include "mojo/edk/embedder/platform_channel_utils_posix.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/platform/socket_utils_posix.h"
#include "mojo/public/cpp/system/invitation.h"
namespace arc {
......@@ -174,12 +174,10 @@ mojo::ScopedMessagePipeHandle ArcSessionDelegateImpl::ConnectMojoInternal(
return mojo::ScopedMessagePipeHandle();
}
mojo::edk::ScopedInternalPlatformHandle server_handle(
mojo::edk::InternalPlatformHandle(socket_fd.release()));
mojo::edk::ScopedInternalPlatformHandle scoped_fd;
if (!mojo::edk::ServerAcceptConnection(server_handle, &scoped_fd,
/* check_peer_user = */ false) ||
!scoped_fd.is_valid()) {
base::ScopedFD connection_fd;
if (!mojo::AcceptSocketConnection(socket_fd.get(), &connection_fd,
/* check_peer_user = */ false) ||
!connection_fd.is_valid()) {
return mojo::ScopedMessagePipeHandle();
}
......@@ -193,9 +191,8 @@ mojo::ScopedMessagePipeHandle ArcSessionDelegateImpl::ConnectMojoInternal(
base::kNullProcessHandle,
channel.TakeLocalEndpoint());
std::vector<mojo::edk::ScopedInternalPlatformHandle> handles;
handles.emplace_back(mojo::edk::InternalPlatformHandle(
channel.TakeRemoteEndpoint().TakePlatformHandle().TakeFD().release()));
std::vector<base::ScopedFD> fds;
fds.emplace_back(channel.TakeRemoteEndpoint().TakePlatformHandle().TakeFD());
// We need to send the length of the message as a single byte, so make sure it
// fits.
......@@ -203,8 +200,8 @@ mojo::ScopedMessagePipeHandle ArcSessionDelegateImpl::ConnectMojoInternal(
uint8_t message_length = static_cast<uint8_t>(token.size());
struct iovec iov[] = {{&message_length, sizeof(message_length)},
{const_cast<char*>(token.c_str()), token.size()}};
ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles(
scoped_fd, iov, sizeof(iov) / sizeof(iov[0]), handles);
ssize_t result = mojo::SendmsgWithHandles(connection_fd.get(), iov,
sizeof(iov) / sizeof(iov[0]), fds);
if (result == -1) {
PLOG(ERROR) << "sendmsg";
return mojo::ScopedMessagePipeHandle();
......
......@@ -9,6 +9,7 @@
#include <utility>
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/process/launch.h"
......@@ -16,7 +17,7 @@
#include "base/task_scheduler/task_traits.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace {
......@@ -27,11 +28,9 @@ void RunCrashReporter(const std::string& crash_type,
const std::string& device,
const std::string& board,
const std::string& cpu_abi,
mojo::edk::ScopedInternalPlatformHandle pipe) {
base::ScopedFD pipe) {
base::LaunchOptions options;
options.fds_to_remap.push_back(
std::make_pair(pipe.get().handle, STDIN_FILENO));
options.fds_to_remap.emplace_back(pipe.get(), STDIN_FILENO);
auto process =
base::LaunchProcess({kCrashReporterPath, "--arc_java_crash=" + crash_type,
"--arc_device=" + device, "--arc_board=" + board,
......@@ -91,14 +90,10 @@ ArcCrashCollectorBridge::~ArcCrashCollectorBridge() {
void ArcCrashCollectorBridge::DumpCrash(const std::string& type,
mojo::ScopedHandle pipe) {
mojo::edk::ScopedInternalPlatformHandle pipe_handle;
mojo::edk::PassWrappedInternalPlatformHandle(pipe.release().value(),
&pipe_handle);
base::PostTaskWithTraits(
FROM_HERE, {base::WithBaseSyncPrimitives()},
base::BindOnce(&RunCrashReporter, type, device_, board_, cpu_abi_,
std::move(pipe_handle)));
mojo::UnwrapPlatformHandle(std::move(pipe)).TakeFD()));
}
void ArcCrashCollectorBridge::SetBuildProperties(const std::string& device,
......
......@@ -19,7 +19,7 @@
#include "base/logging.h"
#include "base/optional.h"
#include "base/threading/thread_task_runner_handle.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace arc {
......@@ -207,16 +207,12 @@ void FakeFileSystemInstance::OpenFileToRead(const std::string& url,
file.seekable == File::Seekable::YES
? CreateRegularFileDescriptor(file.content, temp_dir_.GetPath())
: CreateStreamFileDescriptor(file.content);
mojo::edk::ScopedInternalPlatformHandle platform_handle(
mojo::edk::InternalPlatformHandle(fd.release()));
MojoHandle wrapped_handle;
MojoResult result = mojo::edk::CreateInternalPlatformHandleWrapper(
std::move(platform_handle), &wrapped_handle);
DCHECK_EQ(MOJO_RESULT_OK, result);
mojo::ScopedHandle wrapped_handle =
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(fd)));
DCHECK(wrapped_handle.is_valid());
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback),
mojo::ScopedHandle(mojo::Handle(wrapped_handle))));
base::BindOnce(std::move(callback), std::move(wrapped_handle)));
}
void FakeFileSystemInstance::GetDocument(const std::string& authority,
......
......@@ -19,8 +19,7 @@
#include "device/usb/mojo/type_converters.h"
#include "device/usb/usb_device_handle.h"
#include "device/usb/usb_device_linux.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace arc {
namespace {
......@@ -51,18 +50,14 @@ void OnDeviceOpened(mojom::UsbHostHost::OpenDeviceCallback callback,
std::move(callback).Run(mojo::ScopedHandle());
return;
}
mojo::edk::ScopedInternalPlatformHandle platform_handle{
mojo::edk::InternalPlatformHandle(fd.release())};
MojoHandle wrapped_handle;
MojoResult wrap_result = mojo::edk::CreateInternalPlatformHandleWrapper(
std::move(platform_handle), &wrapped_handle);
if (wrap_result != MOJO_RESULT_OK) {
LOG(ERROR) << "Failed to wrap device FD. Closing: " << wrap_result;
mojo::ScopedHandle wrapped_handle =
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(fd)));
if (!wrapped_handle.is_valid()) {
LOG(ERROR) << "Failed to wrap device FD. Closing.";
std::move(callback).Run(mojo::ScopedHandle());
return;
}
mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)};
std::move(callback).Run(std::move(scoped_handle));
std::move(callback).Run(std::move(wrapped_handle));
}
void OnDeviceOpenError(mojom::UsbHostHost::OpenDeviceCallback callback,
......
......@@ -5,7 +5,6 @@ include_rules = [
"+media/base/video_frame.h",
"+media/base/video_types.h",
"+media/gpu",
"+mojo/edk/embedder",
"+services/service_manager/public/cpp",
"+ui/gfx",
"+ui/ozone/public",
......
......@@ -254,7 +254,6 @@ component("capture_lib") {
deps += [
"//chromeos:chromeos",
"//media/capture/video/chromeos/mojo:cros_camera",
"//mojo/edk",
"//third_party/libdrm",
"//third_party/libsync",
]
......
include_rules = [
"+chromeos/dbus",
"+mojo/edk/embedder",
"+third_party/libsync",
]
......@@ -18,10 +18,9 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "mojo/edk/embedder/platform_channel_utils_posix.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/platform/socket_utils_posix.h"
#include "mojo/public/cpp/system/invitation.h"
namespace media {
......@@ -277,18 +276,18 @@ void CameraHalDispatcherImpl::StartServiceLoop(base::ScopedFD socket_fd,
return;
}
proxy_fd_.reset(mojo::edk::InternalPlatformHandle(socket_fd.release()));
proxy_fd_ = std::move(socket_fd);
started->Signal();
VLOG(1) << "CameraHalDispatcherImpl started; waiting for incoming connection";
while (true) {
if (!WaitForSocketReadable(proxy_fd_.get().handle, cancel_fd.get())) {
if (!WaitForSocketReadable(proxy_fd_.get(), cancel_fd.get())) {
VLOG(1) << "Quit CameraHalDispatcherImpl IO thread";
return;
}
mojo::edk::ScopedInternalPlatformHandle accepted_fd;
if (mojo::edk::ServerAcceptConnection(proxy_fd_, &accepted_fd, false) &&
base::ScopedFD accepted_fd;
if (mojo::AcceptSocketConnection(proxy_fd_.get(), &accepted_fd, false) &&
accepted_fd.is_valid()) {
VLOG(1) << "Accepted a connection";
// Hardcode pid 0 since it is unused in mojo.
......@@ -305,13 +304,12 @@ void CameraHalDispatcherImpl::StartServiceLoop(base::ScopedFD socket_fd,
channel.TakeLocalEndpoint());
auto remote_endpoint = channel.TakeRemoteEndpoint();
std::vector<mojo::edk::ScopedInternalPlatformHandle> handles;
handles.emplace_back(mojo::edk::InternalPlatformHandle(
remote_endpoint.TakePlatformHandle().TakeFD().release()));
std::vector<base::ScopedFD> fds;
fds.emplace_back(remote_endpoint.TakePlatformHandle().TakeFD());
struct iovec iov = {const_cast<char*>(token.c_str()), token.length()};
ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles(
accepted_fd, &iov, 1, handles);
ssize_t result =
mojo::SendmsgWithHandles(accepted_fd.get(), &iov, 1, fds);
if (result == -1) {
PLOG(ERROR) << "sendmsg()";
} else {
......
......@@ -8,12 +8,12 @@
#include <memory>
#include <set>
#include "base/files/scoped_file.h"
#include "base/memory/singleton.h"
#include "base/threading/thread.h"
#include "media/capture/capture_export.h"
#include "media/capture/video/chromeos/mojo/cros_camera_service.mojom.h"
#include "media/capture/video/video_capture_device_factory.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "mojo/public/cpp/platform/platform_channel_server_endpoint.h"
......@@ -95,7 +95,7 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final
void StopOnProxyThread();
mojo::edk::ScopedInternalPlatformHandle proxy_fd_;
base::ScopedFD proxy_fd_;
base::ScopedFD cancel_pipe_;
base::Thread proxy_thread_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment