0
Files
src/ipc/ipc_mojo_message_helper.cc
Avi Drissman ea1be23a8b Update copyright headers in ipc/, ios/, infra/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c95.

No-Try: true
Bug: 1098010
Change-Id: I958bc4caa48822ca0d15594e906783852cd0c499
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3893343
Reviewed-by: Mark Mentovai <mark@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1047189}
2022-09-14 23:29:06 +00:00

52 lines
1.4 KiB
C++

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ipc/ipc_mojo_message_helper.h"
#include <utility>
#include "base/logging.h"
#include "ipc/ipc_mojo_handle_attachment.h"
namespace IPC {
// static
bool MojoMessageHelper::WriteMessagePipeTo(
base::Pickle* message,
mojo::ScopedMessagePipeHandle handle) {
message->WriteAttachment(new internal::MojoHandleAttachment(
mojo::ScopedHandle::From(std::move(handle))));
return true;
}
// static
bool MojoMessageHelper::ReadMessagePipeFrom(
const base::Pickle* message,
base::PickleIterator* iter,
mojo::ScopedMessagePipeHandle* handle) {
scoped_refptr<base::Pickle::Attachment> attachment;
if (!message->ReadAttachment(iter, &attachment)) {
LOG(ERROR) << "Failed to read attachment for message pipe.";
return false;
}
MessageAttachment::Type type =
static_cast<MessageAttachment*>(attachment.get())->GetType();
if (type != MessageAttachment::Type::MOJO_HANDLE) {
LOG(ERROR) << "Unxpected attachment type:" << static_cast<int>(type);
return false;
}
handle->reset(mojo::MessagePipeHandle(
static_cast<internal::MojoHandleAttachment*>(attachment.get())
->TakeHandle()
.release()
.value()));
return true;
}
MojoMessageHelper::MojoMessageHelper() = default;
} // namespace IPC