summaryrefslogtreecommitdiff
path: root/chromium/ipc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-20 10:33:36 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-22 11:45:12 +0000
commitbe59a35641616a4cf23c4a13fa0632624b021c1b (patch)
tree9da183258bdf9cc413f7562079d25ace6955467f /chromium/ipc
parentd702e4b6a64574e97fc7df8fe3238cde70242080 (diff)
downloadqtwebengine-chromium-be59a35641616a4cf23c4a13fa0632624b021c1b.tar.gz
BASELINE: Update Chromium to 62.0.3202.101
Change-Id: I2d5eca8117600df6d331f6166ab24d943d9814ac Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/ipc')
-rw-r--r--chromium/ipc/BUILD.gn15
-rw-r--r--chromium/ipc/README.md2
-rw-r--r--chromium/ipc/SECURITY_OWNERS1
-rw-r--r--chromium/ipc/handle_attachment_fuchsia.cc29
-rw-r--r--chromium/ipc/handle_attachment_fuchsia.h29
-rw-r--r--chromium/ipc/handle_attachment_win.cc16
-rw-r--r--chromium/ipc/handle_attachment_win.h24
-rw-r--r--chromium/ipc/handle_fuchsia.cc13
-rw-r--r--chromium/ipc/handle_fuchsia.h16
-rw-r--r--chromium/ipc/handle_win.cc12
-rw-r--r--chromium/ipc/handle_win.h15
-rw-r--r--chromium/ipc/ipc.mojom5
-rw-r--r--chromium/ipc/ipc_channel.cc3
-rw-r--r--chromium/ipc/ipc_channel.h2
-rw-r--r--chromium/ipc/ipc_channel_factory.cc2
-rw-r--r--chromium/ipc/ipc_channel_mojo.cc70
-rw-r--r--chromium/ipc/ipc_channel_mojo.h7
-rw-r--r--chromium/ipc/ipc_channel_mojo_unittest.cc292
-rw-r--r--chromium/ipc/ipc_channel_nacl.cc7
-rw-r--r--chromium/ipc/ipc_channel_proxy.cc4
-rw-r--r--chromium/ipc/ipc_channel_proxy_unittest.cc6
-rw-r--r--chromium/ipc/ipc_fuzzing_tests.cc5
-rw-r--r--chromium/ipc/ipc_message_attachment_set_posix_unittest.cc2
-rw-r--r--chromium/ipc/ipc_message_pipe_reader.cc11
-rw-r--r--chromium/ipc/ipc_message_pipe_reader.h4
-rw-r--r--chromium/ipc/ipc_message_start.h29
-rw-r--r--chromium/ipc/ipc_message_templates.h97
-rw-r--r--chromium/ipc/ipc_message_unittest.cc10
-rw-r--r--chromium/ipc/ipc_message_utils.cc21
-rw-r--r--chromium/ipc/ipc_message_utils_unittest.cc10
-rw-r--r--chromium/ipc/ipc_mojo_bootstrap.cc17
-rw-r--r--chromium/ipc/ipc_mojo_bootstrap_unittest.cc2
-rw-r--r--chromium/ipc/ipc_mojo_perftest.cc359
-rw-r--r--chromium/ipc/ipc_platform_file.cc4
-rw-r--r--chromium/ipc/ipc_send_fds_test.cc5
-rw-r--r--chromium/ipc/ipc_sync_channel.cc4
-rw-r--r--chromium/ipc/ipc_test.mojom7
-rw-r--r--chromium/ipc/ipc_test_base.cc2
-rw-r--r--chromium/ipc/ipc_test_channel_listener.cc6
-rw-r--r--chromium/ipc/message_router.h4
-rw-r--r--chromium/ipc/sync_socket_unittest.cc5
41 files changed, 749 insertions, 425 deletions
diff --git a/chromium/ipc/BUILD.gn b/chromium/ipc/BUILD.gn
index 5c2e20959df..42621399916 100644
--- a/chromium/ipc/BUILD.gn
+++ b/chromium/ipc/BUILD.gn
@@ -125,13 +125,9 @@ component("ipc") {
]
if (!is_nacl_nonsfi) {
- sources += [
- "ipc_message_protobuf_utils.h",
- ]
+ sources += [ "ipc_message_protobuf_utils.h" ]
- public_deps += [
- "//third_party/protobuf:protobuf_lite",
- ]
+ public_deps += [ "//third_party/protobuf:protobuf_lite" ]
}
deps = [
@@ -155,6 +151,9 @@ mojom_component("mojom") {
sources = [
"ipc.mojom",
]
+ public_deps = [
+ "//mojo/common:read_only_buffer",
+ ]
}
mojom("test_interfaces") {
@@ -245,9 +244,7 @@ if (!is_ios) {
}
if (!is_nacl_nonsfi) {
- sources += [
- "ipc_message_protobuf_utils_unittest.cc",
- ]
+ sources += [ "ipc_message_protobuf_utils_unittest.cc" ]
}
}
diff --git a/chromium/ipc/README.md b/chromium/ipc/README.md
index be5624dca39..250a15927f2 100644
--- a/chromium/ipc/README.md
+++ b/chromium/ipc/README.md
@@ -303,7 +303,7 @@ to binder function:
``` cpp
void BindFrobinator(mojom::FrobinatorRequest request) {
- mojo::MakeStrongBinding(base::MakeUnique<FrobinatorImpl>, std::move(request));
+ mojo::MakeStrongBinding(std::make_unique<FrobinatorImpl>, std::move(request));
}
// |registry| will hereby handle all incoming requests for "mojom::Frobinator"
diff --git a/chromium/ipc/SECURITY_OWNERS b/chromium/ipc/SECURITY_OWNERS
index 8a9c3810397..8bb1091dab6 100644
--- a/chromium/ipc/SECURITY_OWNERS
+++ b/chromium/ipc/SECURITY_OWNERS
@@ -3,6 +3,7 @@
dcheng@chromium.org
estark@chromium.org
kenrb@chromium.org
+kerrnel@chromium.org
meacer@chromium.org
mbarbella@chromium.org
mkwst@chromium.org
diff --git a/chromium/ipc/handle_attachment_fuchsia.cc b/chromium/ipc/handle_attachment_fuchsia.cc
index 2778002b1ae..88cf5184dd6 100644
--- a/chromium/ipc/handle_attachment_fuchsia.cc
+++ b/chromium/ipc/handle_attachment_fuchsia.cc
@@ -10,30 +10,17 @@
namespace IPC {
namespace internal {
-HandleAttachmentFuchsia::HandleAttachmentFuchsia(
- const mx_handle_t& handle,
- HandleFuchsia::Permissions permissions)
- : handle_(MX_HANDLE_INVALID),
- permissions_(HandleFuchsia::INVALID),
- owns_handle_(true) {
- mx_handle_t duplicated_handle;
- if (mx_handle_duplicate(handle, MX_RIGHT_SAME_RIGHTS, &duplicated_handle) ==
- MX_OK) {
- handle_ = duplicated_handle;
- permissions_ = permissions;
- }
+HandleAttachmentFuchsia::HandleAttachmentFuchsia(const mx_handle_t& handle) {
+ mx_status_t result =
+ mx_handle_duplicate(handle, MX_RIGHT_SAME_RIGHTS, handle_.receive());
+ DLOG_IF(ERROR, result != MX_OK)
+ << "mx_handle_duplicate: " << mx_status_get_string(result);
}
-HandleAttachmentFuchsia::HandleAttachmentFuchsia(const mx_handle_t& handle,
- FromWire from_wire)
- : handle_(handle),
- permissions_(HandleFuchsia::INVALID),
- owns_handle_(true) {}
+HandleAttachmentFuchsia::HandleAttachmentFuchsia(base::ScopedMxHandle handle)
+ : handle_(std::move(handle)) {}
-HandleAttachmentFuchsia::~HandleAttachmentFuchsia() {
- if (handle_ != MX_HANDLE_INVALID && owns_handle_)
- mx_handle_close(handle_);
-}
+HandleAttachmentFuchsia::~HandleAttachmentFuchsia() {}
MessageAttachment::Type HandleAttachmentFuchsia::GetType() const {
return Type::FUCHSIA_HANDLE;
diff --git a/chromium/ipc/handle_attachment_fuchsia.h b/chromium/ipc/handle_attachment_fuchsia.h
index a01c8028174..915e41663b8 100644
--- a/chromium/ipc/handle_attachment_fuchsia.h
+++ b/chromium/ipc/handle_attachment_fuchsia.h
@@ -7,7 +7,7 @@
#include <stdint.h>
-#include "base/process/process_handle.h"
+#include "base/fuchsia/scoped_mx_handle.h"
#include "ipc/handle_fuchsia.h"
#include "ipc/ipc_export.h"
#include "ipc/ipc_message_attachment.h"
@@ -20,37 +20,20 @@ class IPC_EXPORT HandleAttachmentFuchsia : public MessageAttachment {
public:
// This constructor makes a copy of |handle| and takes ownership of the
// result. Should only be called by the sender of a Chrome IPC message.
- HandleAttachmentFuchsia(const mx_handle_t& handle,
- HandleFuchsia::Permissions permissions);
+ explicit HandleAttachmentFuchsia(const mx_handle_t& handle);
- enum FromWire {
- FROM_WIRE,
- };
// This constructor takes ownership of |handle|. Should only be called by the
// receiver of a Chrome IPC message.
- HandleAttachmentFuchsia(const mx_handle_t& handle, FromWire from_wire);
+ explicit HandleAttachmentFuchsia(base::ScopedMxHandle handle);
Type GetType() const override;
- mx_handle_t get_handle() const { return handle_; }
-
- // The caller of this method has taken ownership of |handle_|.
- void reset_handle_ownership() {
- owns_handle_ = false;
- handle_ = MX_HANDLE_INVALID;
- }
+ mx_handle_t Take() { return handle_.release(); }
private:
~HandleAttachmentFuchsia() override;
- mx_handle_t handle_;
- HandleFuchsia::Permissions permissions_;
-
- // In the sender process, the attachment owns the mx_handle_t of a newly
- // created message. The attachment broker will eventually take ownership, and
- // set this member to |false|. In the destination process, the attachment owns
- // the handle until a call to ParamTraits<HandleFuchsia>::Read() takes
- // ownership.
- bool owns_handle_;
+
+ base::ScopedMxHandle handle_;
};
} // namespace internal
diff --git a/chromium/ipc/handle_attachment_win.cc b/chromium/ipc/handle_attachment_win.cc
index 9249a5a069c..6f6fc346477 100644
--- a/chromium/ipc/handle_attachment_win.cc
+++ b/chromium/ipc/handle_attachment_win.cc
@@ -9,29 +9,21 @@
namespace IPC {
namespace internal {
-HandleAttachmentWin::HandleAttachmentWin(const HANDLE& handle,
- HandleWin::Permissions permissions)
- : handle_(INVALID_HANDLE_VALUE),
- permissions_(HandleWin::INVALID),
- owns_handle_(true) {
+HandleAttachmentWin::HandleAttachmentWin(const HANDLE& handle) {
HANDLE duplicated_handle;
BOOL result =
::DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(),
&duplicated_handle, 0, FALSE, DUPLICATE_SAME_ACCESS);
if (result) {
- handle_ = duplicated_handle;
- permissions_ = permissions;
+ handle_.Set(duplicated_handle);
}
}
HandleAttachmentWin::HandleAttachmentWin(const HANDLE& handle,
FromWire from_wire)
- : handle_(handle), permissions_(HandleWin::INVALID), owns_handle_(true) {}
+ : handle_(handle) {}
-HandleAttachmentWin::~HandleAttachmentWin() {
- if (handle_ != INVALID_HANDLE_VALUE && owns_handle_)
- ::CloseHandle(handle_);
-}
+HandleAttachmentWin::~HandleAttachmentWin() {}
MessageAttachment::Type HandleAttachmentWin::GetType() const {
return Type::WIN_HANDLE;
diff --git a/chromium/ipc/handle_attachment_win.h b/chromium/ipc/handle_attachment_win.h
index ef3b89652ca..3ee9f43683a 100644
--- a/chromium/ipc/handle_attachment_win.h
+++ b/chromium/ipc/handle_attachment_win.h
@@ -7,7 +7,7 @@
#include <stdint.h>
-#include "base/process/process_handle.h"
+#include "base/win/scoped_handle.h"
#include "ipc/handle_win.h"
#include "ipc/ipc_export.h"
#include "ipc/ipc_message_attachment.h"
@@ -20,7 +20,7 @@ class IPC_EXPORT HandleAttachmentWin : public MessageAttachment {
public:
// This constructor makes a copy of |handle| and takes ownership of the
// result. Should only be called by the sender of a Chrome IPC message.
- HandleAttachmentWin(const HANDLE& handle, HandleWin::Permissions permissions);
+ explicit HandleAttachmentWin(const HANDLE& handle);
enum FromWire {
FROM_WIRE,
@@ -29,27 +29,15 @@ class IPC_EXPORT HandleAttachmentWin : public MessageAttachment {
// receiver of a Chrome IPC message.
HandleAttachmentWin(const HANDLE& handle, FromWire from_wire);
+ // MessageAttachment interface.
Type GetType() const override;
- HANDLE get_handle() const { return handle_; }
-
- // The caller of this method has taken ownership of |handle_|.
- void reset_handle_ownership() {
- owns_handle_ = false;
- handle_ = INVALID_HANDLE_VALUE;
- }
+ HANDLE Take() { return handle_.Take(); }
private:
~HandleAttachmentWin() override;
- HANDLE handle_;
- HandleWin::Permissions permissions_;
-
- // In the sender process, the attachment owns the HANDLE of a newly created
- // message. The attachment broker will eventually take ownership, and set
- // this member to |false|.
- // In the destination process, the attachment owns the Mach port until a call
- // to ParamTraits<HandleWin>::Read() takes ownership.
- bool owns_handle_;
+
+ base::win::ScopedHandle handle_;
};
} // namespace internal
diff --git a/chromium/ipc/handle_fuchsia.cc b/chromium/ipc/handle_fuchsia.cc
index 8b3cc5154d3..26dc9cf9a68 100644
--- a/chromium/ipc/handle_fuchsia.cc
+++ b/chromium/ipc/handle_fuchsia.cc
@@ -15,17 +15,14 @@
namespace IPC {
-HandleFuchsia::HandleFuchsia()
- : handle_(MX_HANDLE_INVALID), permissions_(INVALID) {}
+HandleFuchsia::HandleFuchsia() : handle_(MX_HANDLE_INVALID) {}
-HandleFuchsia::HandleFuchsia(const mx_handle_t& handle, Permissions permissions)
- : handle_(handle), permissions_(permissions) {}
+HandleFuchsia::HandleFuchsia(const mx_handle_t& handle) : handle_(handle) {}
// static
void ParamTraits<HandleFuchsia>::Write(base::Pickle* m, const param_type& p) {
scoped_refptr<IPC::internal::HandleAttachmentFuchsia> attachment(
- new IPC::internal::HandleAttachmentFuchsia(p.get_handle(),
- p.get_permissions()));
+ new IPC::internal::HandleAttachmentFuchsia(p.get_handle()));
if (!m->WriteAttachment(std::move(attachment)))
NOTREACHED();
}
@@ -43,15 +40,13 @@ bool ParamTraits<HandleFuchsia>::Read(const base::Pickle* m,
return false;
IPC::internal::HandleAttachmentFuchsia* handle_attachment =
static_cast<IPC::internal::HandleAttachmentFuchsia*>(attachment);
- r->set_handle(handle_attachment->get_handle());
- handle_attachment->reset_handle_ownership();
+ r->set_handle(handle_attachment->Take());
return true;
}
// static
void ParamTraits<HandleFuchsia>::Log(const param_type& p, std::string* l) {
l->append(base::StringPrintf("0x%x", p.get_handle()));
- l->append(base::IntToString(p.get_permissions()));
}
} // namespace IPC
diff --git a/chromium/ipc/handle_fuchsia.h b/chromium/ipc/handle_fuchsia.h
index 2ff6b53927d..babfe14f043 100644
--- a/chromium/ipc/handle_fuchsia.h
+++ b/chromium/ipc/handle_fuchsia.h
@@ -21,29 +21,15 @@ namespace IPC {
class IPC_EXPORT HandleFuchsia {
public:
- enum Permissions {
- // A placeholder value to be used by the receiving IPC channel, since the
- // permissions information is only used by the broker process.
- INVALID,
- // The new mx_handle_t will have the same permissions as the old
- // mx_handle_t.
- DUPLICATE,
- // The new mx_handle_t will have file read and write permissions.
- FILE_READ_WRITE,
- MAX_PERMISSIONS = FILE_READ_WRITE
- };
-
// Default constructor makes an invalid mx_handle_t.
HandleFuchsia();
- HandleFuchsia(const mx_handle_t& handle, Permissions permissions);
+ explicit HandleFuchsia(const mx_handle_t& handle);
mx_handle_t get_handle() const { return handle_; }
void set_handle(mx_handle_t handle) { handle_ = handle; }
- Permissions get_permissions() const { return permissions_; }
private:
mx_handle_t handle_;
- Permissions permissions_;
};
template <>
diff --git a/chromium/ipc/handle_win.cc b/chromium/ipc/handle_win.cc
index c8511e20173..ba981c1a57b 100644
--- a/chromium/ipc/handle_win.cc
+++ b/chromium/ipc/handle_win.cc
@@ -15,16 +15,14 @@
namespace IPC {
-HandleWin::HandleWin() : handle_(nullptr), permissions_(INVALID) {}
+HandleWin::HandleWin() : handle_(INVALID_HANDLE_VALUE) {}
-HandleWin::HandleWin(const HANDLE& handle, Permissions permissions)
- : handle_(handle), permissions_(permissions) {}
+HandleWin::HandleWin(const HANDLE& handle) : handle_(handle) {}
// static
void ParamTraits<HandleWin>::Write(base::Pickle* m, const param_type& p) {
scoped_refptr<IPC::internal::HandleAttachmentWin> attachment(
- new IPC::internal::HandleAttachmentWin(p.get_handle(),
- p.get_permissions()));
+ new IPC::internal::HandleAttachmentWin(p.get_handle()));
if (!m->WriteAttachment(std::move(attachment)))
NOTREACHED();
}
@@ -42,15 +40,13 @@ bool ParamTraits<HandleWin>::Read(const base::Pickle* m,
return false;
IPC::internal::HandleAttachmentWin* handle_attachment =
static_cast<IPC::internal::HandleAttachmentWin*>(attachment);
- r->set_handle(handle_attachment->get_handle());
- handle_attachment->reset_handle_ownership();
+ r->set_handle(handle_attachment->Take());
return true;
}
// static
void ParamTraits<HandleWin>::Log(const param_type& p, std::string* l) {
l->append(base::StringPrintf("0x%p", p.get_handle()));
- l->append(base::IntToString(p.get_permissions()));
}
} // namespace IPC
diff --git a/chromium/ipc/handle_win.h b/chromium/ipc/handle_win.h
index 96c1b0b423c..0120597c152 100644
--- a/chromium/ipc/handle_win.h
+++ b/chromium/ipc/handle_win.h
@@ -28,28 +28,15 @@ namespace IPC {
// discussion.
class IPC_EXPORT HandleWin {
public:
- enum Permissions {
- // A placeholder value to be used by the receiving IPC channel, since the
- // permissions information is only used by the broker process.
- INVALID,
- // The new HANDLE will have the same permissions as the old HANDLE.
- DUPLICATE,
- // The new HANDLE will have file read and write permissions.
- FILE_READ_WRITE,
- MAX_PERMISSIONS = FILE_READ_WRITE
- };
-
// Default constructor makes an invalid HANDLE.
HandleWin();
- HandleWin(const HANDLE& handle, Permissions permissions);
+ explicit HandleWin(const HANDLE& handle);
HANDLE get_handle() const { return handle_; }
void set_handle(HANDLE handle) { handle_ = handle; }
- Permissions get_permissions() const { return permissions_; }
private:
HANDLE handle_;
- Permissions permissions_;
};
template <>
diff --git a/chromium/ipc/ipc.mojom b/chromium/ipc/ipc.mojom
index f986c470d58..3ab4d4ef063 100644
--- a/chromium/ipc/ipc.mojom
+++ b/chromium/ipc/ipc.mojom
@@ -4,6 +4,8 @@
module IPC.mojom;
+import "mojo/common/read_only_buffer.mojom";
+
// NOTE: This MUST match the value of MSG_ROUTING_NONE in src/ipc/ipc_message.h.
const int32 kRoutingIdNone = -2;
@@ -31,7 +33,8 @@ interface Channel {
SetPeerPid(int32 pid);
// Transmits a classical Chrome IPC message.
- Receive(array<uint8> data, array<SerializedHandle>? handles);
+ Receive(mojo.common.mojom.ReadOnlyBuffer data,
+ array<SerializedHandle>? handles);
// Requests a Channel-associated interface.
GetAssociatedInterface(string name, associated GenericInterface& request);
diff --git a/chromium/ipc/ipc_channel.cc b/chromium/ipc/ipc_channel.cc
index 177b967601b..ca788e69b64 100644
--- a/chromium/ipc/ipc_channel.cc
+++ b/chromium/ipc/ipc_channel.cc
@@ -24,6 +24,9 @@ base::AtomicSequenceNumber g_last_id;
namespace IPC {
// static
+constexpr size_t Channel::kMaximumMessageSize;
+
+// static
std::string Channel::GenerateUniqueRandomChannelID() {
// Note: the string must start with the current process id, this is how
// some child processes determine the pid of the parent.
diff --git a/chromium/ipc/ipc_channel.h b/chromium/ipc/ipc_channel.h
index 25eac166c7e..82f8011c589 100644
--- a/chromium/ipc/ipc_channel.h
+++ b/chromium/ipc/ipc_channel.h
@@ -140,7 +140,7 @@ class IPC_EXPORT Channel : public Sender {
// The maximum message size in bytes. Attempting to receive a message of this
// size or bigger results in a channel error.
- static const size_t kMaximumMessageSize = 128 * 1024 * 1024;
+ static constexpr size_t kMaximumMessageSize = 128 * 1024 * 1024;
// Amount of data to read at once from the pipe.
static const size_t kReadBufferSize = 4 * 1024;
diff --git a/chromium/ipc/ipc_channel_factory.cc b/chromium/ipc/ipc_channel_factory.cc
index 775ac331ecc..08a52728d16 100644
--- a/chromium/ipc/ipc_channel_factory.cc
+++ b/chromium/ipc/ipc_channel_factory.cc
@@ -49,7 +49,7 @@ std::unique_ptr<ChannelFactory> ChannelFactory::Create(
const ChannelHandle& handle,
Channel::Mode mode,
const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
- return base::MakeUnique<PlatformChannelFactory>(handle, mode,
+ return std::make_unique<PlatformChannelFactory>(handle, mode,
ipc_task_runner);
}
diff --git a/chromium/ipc/ipc_channel_mojo.cc b/chromium/ipc/ipc_channel_mojo.cc
index ba6b8edfe9e..29451c6cf64 100644
--- a/chromium/ipc/ipc_channel_mojo.cc
+++ b/chromium/ipc/ipc_channel_mojo.cc
@@ -29,6 +29,7 @@
#include "mojo/public/cpp/system/platform_handle.h"
#if defined(OS_POSIX)
+#include "base/posix/eintr_wrapper.h"
#include "ipc/ipc_platform_file_attachment_posix.h"
#endif
@@ -40,6 +41,10 @@
#include "ipc/handle_attachment_win.h"
#endif
+#if defined(OS_FUCHSIA)
+#include "ipc/handle_attachment_fuchsia.h"
+#endif
+
namespace IPC {
namespace {
@@ -92,7 +97,6 @@ MojoResult WrapPlatformHandle(base::PlatformFile handle,
}
#if defined(OS_MACOSX)
-
MojoResult WrapMachPort(mach_port_t mach_port,
mojom::SerializedHandlePtr* serialized) {
MojoPlatformHandle platform_handle = {
@@ -110,17 +114,32 @@ MojoResult WrapMachPort(mach_port_t mach_port,
mojom::SerializedHandle::Type::MACH_PORT);
return MOJO_RESULT_OK;
}
+#elif defined(OS_FUCHSIA)
+MojoResult WrapMxHandle(mx_handle_t handle,
+ mojom::SerializedHandlePtr* serialized) {
+ MojoPlatformHandle platform_handle = {
+ sizeof(MojoPlatformHandle), MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE,
+ static_cast<uint64_t>(handle)};
-#endif
+ MojoHandle wrapped_handle;
+ MojoResult result = MojoWrapPlatformHandle(&platform_handle, &wrapped_handle);
+ if (result != MOJO_RESULT_OK)
+ return result;
-#if defined(OS_POSIX)
+ *serialized = CreateSerializedHandle(
+ mojo::MakeScopedHandle(mojo::Handle(wrapped_handle)),
+ mojom::SerializedHandle::Type::FUCHSIA_HANDLE);
+ return MOJO_RESULT_OK;
+}
+#endif // defined(OS_FUCHSIA)
+#if defined(OS_POSIX)
base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) {
- return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile())
- : base::ScopedFD(dup(attachment->file()));
+ return attachment->Owns()
+ ? base::ScopedFD(attachment->TakePlatformFile())
+ : base::ScopedFD(HANDLE_EINTR(dup(attachment->file())));
}
-
-#endif
+#endif // defined(OS_POSIX)
MojoResult WrapAttachmentImpl(MessageAttachment* attachment,
mojom::SerializedHandlePtr* serialized) {
@@ -146,7 +165,7 @@ MojoResult WrapAttachmentImpl(MessageAttachment* attachment,
mojom::SerializedHandle::Type::PLATFORM_FILE,
serialized);
}
-#endif
+#endif // defined(OS_POSIX)
#if defined(OS_MACOSX)
DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::MACH_PORT);
internal::MachPortAttachmentMac& mach_port_attachment =
@@ -155,14 +174,19 @@ MojoResult WrapAttachmentImpl(MessageAttachment* attachment,
serialized);
mach_port_attachment.reset_mach_port_ownership();
return result;
+#elif defined(OS_FUCHSIA)
+ DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::FUCHSIA_HANDLE);
+ internal::HandleAttachmentFuchsia& handle_attachment =
+ static_cast<internal::HandleAttachmentFuchsia&>(*attachment);
+ MojoResult result = WrapMxHandle(handle_attachment.Take(), serialized);
+ return result;
#elif defined(OS_WIN)
DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::WIN_HANDLE);
internal::HandleAttachmentWin& handle_attachment =
static_cast<internal::HandleAttachmentWin&>(*attachment);
- MojoResult result = WrapPlatformHandle(
- handle_attachment.get_handle(),
- mojom::SerializedHandle::Type::WIN_HANDLE, serialized);
- handle_attachment.reset_handle_ownership();
+ MojoResult result =
+ WrapPlatformHandle(handle_attachment.Take(),
+ mojom::SerializedHandle::Type::WIN_HANDLE, serialized);
return result;
#else
NOTREACHED();
@@ -212,8 +236,15 @@ MojoResult UnwrapAttachment(mojom::SerializedHandlePtr handle,
mach_port, internal::MachPortAttachmentMac::FROM_WIRE);
return MOJO_RESULT_OK;
}
-#endif // defined(OS_MACOSX)
-#if defined(OS_WIN)
+#elif defined(OS_FUCHSIA)
+ if (handle->type == mojom::SerializedHandle::Type::FUCHSIA_HANDLE) {
+ base::ScopedMxHandle handle;
+ if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE)
+ handle.reset(static_cast<mx_handle_t>(platform_handle.value));
+ *attachment = new internal::HandleAttachmentFuchsia(std::move(handle));
+ return MOJO_RESULT_OK;
+ }
+#elif defined(OS_WIN)
if (handle->type == mojom::SerializedHandle::Type::WIN_HANDLE) {
base::PlatformFile handle = base::kInvalidPlatformFile;
if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE)
@@ -257,7 +288,7 @@ std::unique_ptr<ChannelMojo> ChannelMojo::Create(
std::unique_ptr<ChannelFactory> ChannelMojo::CreateServerFactory(
mojo::ScopedMessagePipeHandle handle,
const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
- return base::MakeUnique<MojoChannelFactory>(
+ return std::make_unique<MojoChannelFactory>(
std::move(handle), Channel::MODE_SERVER, ipc_task_runner);
}
@@ -265,7 +296,7 @@ std::unique_ptr<ChannelFactory> ChannelMojo::CreateServerFactory(
std::unique_ptr<ChannelFactory> ChannelMojo::CreateClientFactory(
mojo::ScopedMessagePipeHandle handle,
const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
- return base::MakeUnique<MojoChannelFactory>(
+ return std::make_unique<MojoChannelFactory>(
std::move(handle), Channel::MODE_CLIENT, ipc_task_runner);
}
@@ -395,9 +426,10 @@ ChannelMojo::GetAssociatedInterfaceSupport() { return this; }
std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>>
ChannelMojo::CreateThreadSafeChannel() {
- return base::MakeUnique<mojo::ThreadSafeForwarder<mojom::Channel>>(
- task_runner_, base::Bind(&ChannelMojo::ForwardMessageFromThreadSafePtr,
- weak_factory_.GetWeakPtr()),
+ return std::make_unique<mojo::ThreadSafeForwarder<mojom::Channel>>(
+ task_runner_,
+ base::Bind(&ChannelMojo::ForwardMessageFromThreadSafePtr,
+ weak_factory_.GetWeakPtr()),
base::Bind(&ChannelMojo::ForwardMessageWithResponderFromThreadSafePtr,
weak_factory_.GetWeakPtr()),
*bootstrap_->GetAssociatedGroup());
diff --git a/chromium/ipc/ipc_channel_mojo.h b/chromium/ipc/ipc_channel_mojo.h
index 5aa06901953..e8b7b92afcd 100644
--- a/chromium/ipc/ipc_channel_mojo.h
+++ b/chromium/ipc/ipc_channel_mojo.h
@@ -40,10 +40,9 @@ namespace IPC {
// TODO(morrita): Add APIs to create extra MessagePipes to let
// Mojo-based objects talk over this Channel.
//
-class IPC_EXPORT ChannelMojo
- : public Channel,
- public Channel::AssociatedInterfaceSupport,
- public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) {
+class IPC_EXPORT ChannelMojo : public Channel,
+ public Channel::AssociatedInterfaceSupport,
+ public internal::MessagePipeReader::Delegate {
public:
// Creates a ChannelMojo.
static std::unique_ptr<ChannelMojo>
diff --git a/chromium/ipc/ipc_channel_mojo_unittest.cc b/chromium/ipc/ipc_channel_mojo_unittest.cc
index f0fc0c307ef..21a853f1dcf 100644
--- a/chromium/ipc/ipc_channel_mojo_unittest.cc
+++ b/chromium/ipc/ipc_channel_mojo_unittest.cc
@@ -17,6 +17,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/location.h"
#include "base/macros.h"
+#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/pickle.h"
@@ -30,6 +31,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "ipc/ipc_message.h"
+#include "ipc/ipc_message_utils.h"
#include "ipc/ipc_mojo_handle_attachment.h"
#include "ipc/ipc_mojo_message_helper.h"
#include "ipc/ipc_mojo_param_traits.h"
@@ -62,7 +64,8 @@ void SendValue(IPC::Sender* sender, int32_t value) {
class ListenerThatExpectsOK : public IPC::Listener {
public:
- ListenerThatExpectsOK() : received_ok_(false) {}
+ ListenerThatExpectsOK(base::Closure quit_closure)
+ : received_ok_(false), quit_closure_(quit_closure) {}
~ListenerThatExpectsOK() override {}
@@ -72,7 +75,7 @@ class ListenerThatExpectsOK : public IPC::Listener {
EXPECT_TRUE(iter.ReadString(&should_be_ok));
EXPECT_EQ(should_be_ok, "OK");
received_ok_ = true;
- base::MessageLoop::current()->QuitWhenIdle();
+ quit_closure_.Run();
return true;
}
@@ -87,6 +90,24 @@ class ListenerThatExpectsOK : public IPC::Listener {
private:
bool received_ok_;
+ base::Closure quit_closure_;
+};
+
+class TestListenerBase : public IPC::Listener {
+ public:
+ TestListenerBase(base::Closure quit_closure) : quit_closure_(quit_closure) {}
+
+ ~TestListenerBase() override {}
+
+ void OnChannelError() override { quit_closure_.Run(); }
+
+ void set_sender(IPC::Sender* sender) { sender_ = sender; }
+ IPC::Sender* sender() const { return sender_; }
+ base::Closure quit_closure() const { return quit_closure_; }
+
+ private:
+ IPC::Sender* sender_ = nullptr;
+ base::Closure quit_closure_;
};
using IPCChannelMojoTest = IPCChannelMojoTestBase;
@@ -144,15 +165,16 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient) {
Close();
}
-class ListenerExpectingErrors : public IPC::Listener {
+class ListenerExpectingErrors : public TestListenerBase {
public:
- ListenerExpectingErrors() : has_error_(false) {}
+ ListenerExpectingErrors(base::Closure quit_closure)
+ : TestListenerBase(quit_closure), has_error_(false) {}
bool OnMessageReceived(const IPC::Message& message) override { return true; }
void OnChannelError() override {
has_error_ = true;
- base::MessageLoop::current()->QuitWhenIdle();
+ TestListenerBase::OnChannelError();
}
bool has_error() const { return has_error_; }
@@ -163,21 +185,23 @@ class ListenerExpectingErrors : public IPC::Listener {
class ListenerThatQuits : public IPC::Listener {
public:
- ListenerThatQuits() {}
+ ListenerThatQuits(base::Closure quit_closure) : quit_closure_(quit_closure) {}
bool OnMessageReceived(const IPC::Message& message) override { return true; }
- void OnChannelConnected(int32_t peer_pid) override {
- base::MessageLoop::current()->QuitWhenIdle();
- }
+ void OnChannelConnected(int32_t peer_pid) override { quit_closure_.Run(); }
+
+ private:
+ base::Closure quit_closure_;
};
// A long running process that connects to us.
DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient) {
- ListenerThatQuits listener;
+ base::RunLoop run_loop;
+ ListenerThatQuits listener(run_loop.QuitClosure());
Connect(&listener);
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
@@ -186,7 +210,8 @@ TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) {
Init("IPCChannelMojoErraticTestClient");
// Set up IPC channel and start client.
- ListenerExpectingErrors listener;
+ base::RunLoop run_loop;
+ ListenerExpectingErrors listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
@@ -199,7 +224,7 @@ TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) {
overly_large_data.c_str());
}
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
@@ -286,7 +311,6 @@ class HandleSendingHelper {
static void ReadReceivedFile(const IPC::Message& message,
base::PickleIterator* iter) {
- base::ScopedFD fd;
scoped_refptr<base::Pickle::Attachment> attachment;
EXPECT_TRUE(message.ReadAttachment(iter, &attachment));
EXPECT_EQ(
@@ -302,40 +326,33 @@ class HandleSendingHelper {
#endif
};
-class ListenerThatExpectsMessagePipe : public IPC::Listener {
+class ListenerThatExpectsMessagePipe : public TestListenerBase {
public:
- ListenerThatExpectsMessagePipe() : sender_(NULL) {}
+ ListenerThatExpectsMessagePipe(base::Closure quit_closure)
+ : TestListenerBase(quit_closure) {}
~ListenerThatExpectsMessagePipe() override {}
bool OnMessageReceived(const IPC::Message& message) override {
base::PickleIterator iter(message);
HandleSendingHelper::ReadReceivedPipe(message, &iter);
- ListenerThatExpectsOK::SendOK(sender_);
+ ListenerThatExpectsOK::SendOK(sender());
return true;
}
-
- void OnChannelError() override {
- base::MessageLoop::current()->QuitWhenIdle();
- }
-
- void set_sender(IPC::Sender* sender) { sender_ = sender; }
-
- private:
- IPC::Sender* sender_;
};
TEST_F(IPCChannelMojoTest, SendMessagePipe) {
Init("IPCChannelMojoTestSendMessagePipeClient");
- ListenerThatExpectsOK listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
TestingMessagePipe pipe;
HandleSendingHelper::WritePipeThenSend(channel(), &pipe);
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
EXPECT_TRUE(WaitForClientShutdown());
@@ -343,11 +360,12 @@ TEST_F(IPCChannelMojoTest, SendMessagePipe) {
}
DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient) {
- ListenerThatExpectsMessagePipe listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsMessagePipe listener(run_loop.QuitClosure());
Connect(&listener);
listener.set_sender(channel());
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
@@ -367,10 +385,12 @@ void WriteOK(mojo::MessagePipeHandle pipe) {
nullptr, 0, 0));
}
-class ListenerThatExpectsMessagePipeUsingParamTrait : public IPC::Listener {
+class ListenerThatExpectsMessagePipeUsingParamTrait : public TestListenerBase {
public:
- explicit ListenerThatExpectsMessagePipeUsingParamTrait(bool receiving_valid)
- : sender_(NULL), receiving_valid_(receiving_valid) {}
+ explicit ListenerThatExpectsMessagePipeUsingParamTrait(
+ base::Closure quit_closure,
+ bool receiving_valid)
+ : TestListenerBase(quit_closure), receiving_valid_(receiving_valid) {}
~ListenerThatExpectsMessagePipeUsingParamTrait() override {}
@@ -385,30 +405,24 @@ class ListenerThatExpectsMessagePipeUsingParamTrait : public IPC::Listener {
MojoClose(handle.value());
}
- ListenerThatExpectsOK::SendOK(sender_);
+ ListenerThatExpectsOK::SendOK(sender());
return true;
}
- void OnChannelError() override {
- base::MessageLoop::current()->QuitWhenIdle();
- }
-
- void set_sender(IPC::Sender* sender) { sender_ = sender; }
-
private:
- IPC::Sender* sender_;
bool receiving_valid_;
};
class ParamTraitMessagePipeClient : public IpcChannelMojoTestClient {
public:
void RunTest(bool receiving_valid_handle) {
+ base::RunLoop run_loop;
ListenerThatExpectsMessagePipeUsingParamTrait listener(
- receiving_valid_handle);
+ run_loop.QuitClosure(), receiving_valid_handle);
Connect(&listener);
listener.set_sender(channel());
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
@@ -417,7 +431,8 @@ class ParamTraitMessagePipeClient : public IpcChannelMojoTestClient {
TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) {
Init("ParamTraitValidMessagePipeClient");
- ListenerThatExpectsOK listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
@@ -429,7 +444,7 @@ TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) {
WriteOK(pipe.self.get());
channel()->Send(message.release());
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
EXPECT_TRUE(WaitForClientShutdown());
@@ -445,7 +460,8 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) {
Init("ParamTraitInvalidMessagePipeClient");
- ListenerThatExpectsOK listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
@@ -455,7 +471,7 @@ TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) {
invalid_handle);
channel()->Send(message.release());
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
EXPECT_TRUE(WaitForClientShutdown());
@@ -471,11 +487,12 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
TEST_F(IPCChannelMojoTest, SendFailAfterClose) {
Init("IPCChannelMojoTestSendOkClient");
- ListenerThatExpectsOK listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
ASSERT_FALSE(channel()->Send(new IPC::Message()));
@@ -483,29 +500,26 @@ TEST_F(IPCChannelMojoTest, SendFailAfterClose) {
DestroyChannel();
}
-class ListenerSendingOneOk : public IPC::Listener {
+class ListenerSendingOneOk : public TestListenerBase {
public:
- ListenerSendingOneOk() {}
+ ListenerSendingOneOk(base::Closure quit_closure)
+ : TestListenerBase(quit_closure) {}
bool OnMessageReceived(const IPC::Message& message) override { return true; }
void OnChannelConnected(int32_t peer_pid) override {
- ListenerThatExpectsOK::SendOK(sender_);
- base::MessageLoop::current()->QuitWhenIdle();
+ ListenerThatExpectsOK::SendOK(sender());
+ quit_closure().Run();
}
-
- void set_sender(IPC::Sender* sender) { sender_ = sender; }
-
- private:
- IPC::Sender* sender_;
};
DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient) {
- ListenerSendingOneOk listener;
+ base::RunLoop run_loop;
+ ListenerSendingOneOk listener(run_loop.QuitClosure());
Connect(&listener);
listener.set_sender(channel());
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
@@ -555,7 +569,7 @@ class ListenerWithSimpleAssociatedInterface
EXPECT_EQ(kNumMessages, num_messages_received_);
received_quit_ = true;
std::move(callback).Run();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void BindRequest(IPC::mojom::SimpleTestDriverAssociatedRequest request) {
@@ -596,7 +610,7 @@ class ListenerSendingAssociatedMessages : public IPC::Listener {
void set_channel(IPC::Channel* channel) { channel_ = channel; }
private:
- static void OnQuitAck() { base::MessageLoop::current()->QuitWhenIdle(); }
+ static void OnQuitAck() { base::RunLoop::QuitCurrentWhenIdleDeprecated(); }
IPC::Channel* channel_ = nullptr;
IPC::mojom::SimpleTestDriverAssociatedPtr driver_;
@@ -743,7 +757,7 @@ class ListenerWithSimpleProxyAssociatedInterface
received_quit_ = true;
std::move(callback).Run();
binding_.Close();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void BindRequest(IPC::mojom::SimpleTestDriverAssociatedRequest request) {
@@ -1225,7 +1239,7 @@ class ExpectValueSequenceListener : public IPC::Listener {
EXPECT_EQ(expected_values_->front(), should_be_expected);
expected_values_->pop();
if (expected_values_->empty())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
return true;
}
@@ -1298,35 +1312,91 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(DropAssociatedRequest,
DestroyProxy();
}
-#if defined(OS_POSIX)
+#if !defined(OS_MACOSX)
+// TODO(wez): On Mac we need to set up a MachPortBroker before we can transfer
+// Mach ports (which underpin Sharedmemory on Mac) across IPC.
-class ListenerThatExpectsFile : public IPC::Listener {
+class ListenerThatExpectsSharedMemory : public TestListenerBase {
public:
- ListenerThatExpectsFile() : sender_(NULL) {}
-
- ~ListenerThatExpectsFile() override {}
+ ListenerThatExpectsSharedMemory(base::Closure quit_closure)
+ : TestListenerBase(quit_closure) {}
bool OnMessageReceived(const IPC::Message& message) override {
base::PickleIterator iter(message);
- HandleSendingHelper::ReadReceivedFile(message, &iter);
- ListenerThatExpectsOK::SendOK(sender_);
+
+ base::SharedMemoryHandle shared_memory;
+ EXPECT_TRUE(IPC::ReadParam(&message, &iter, &shared_memory));
+ EXPECT_TRUE(shared_memory.IsValid());
+ shared_memory.Close();
+
+ ListenerThatExpectsOK::SendOK(sender());
return true;
}
+};
- void OnChannelError() override {
- base::MessageLoop::current()->QuitWhenIdle();
- }
+TEST_F(IPCChannelMojoTest, SendSharedMemory) {
+ Init("IPCChannelMojoTestSendSharedMemoryClient");
- void set_sender(IPC::Sender* sender) { sender_ = sender; }
+ // Create some shared-memory to share.
+ base::SharedMemoryCreateOptions options;
+ options.size = 1004;
- private:
- IPC::Sender* sender_;
+ base::SharedMemory shmem;
+ ASSERT_TRUE(shmem.Create(options));
+
+ // Create a success listener, and launch the child process.
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
+ CreateChannel(&listener);
+ ASSERT_TRUE(ConnectChannel());
+
+ // Send the child process an IPC with |shmem| attached, to verify
+ // that is is correctly wrapped, transferred and unwrapped.
+ IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ IPC::WriteParam(message, shmem.handle());
+ ASSERT_TRUE(channel()->Send(message));
+
+ run_loop.Run();
+
+ channel()->Close();
+
+ EXPECT_TRUE(WaitForClientShutdown());
+ DestroyChannel();
+}
+
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendSharedMemoryClient) {
+ base::RunLoop run_loop;
+ ListenerThatExpectsSharedMemory listener(run_loop.QuitClosure());
+ Connect(&listener);
+ listener.set_sender(channel());
+
+ run_loop.Run();
+
+ Close();
+}
+
+#endif // !defined(OS_MACOSX)
+
+#if defined(OS_POSIX)
+
+class ListenerThatExpectsFile : public TestListenerBase {
+ public:
+ ListenerThatExpectsFile(base::Closure quit_closure)
+ : TestListenerBase(quit_closure) {}
+
+ bool OnMessageReceived(const IPC::Message& message) override {
+ base::PickleIterator iter(message);
+ HandleSendingHelper::ReadReceivedFile(message, &iter);
+ ListenerThatExpectsOK::SendOK(sender());
+ return true;
+ }
};
-TEST_F(IPCChannelMojoTest, SendPlatformHandle) {
- Init("IPCChannelMojoTestSendPlatformHandleClient");
+TEST_F(IPCChannelMojoTest, SendPlatformFile) {
+ Init("IPCChannelMojoTestSendPlatformFileClient");
- ListenerThatExpectsOK listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
@@ -1336,7 +1406,7 @@ TEST_F(IPCChannelMojoTest, SendPlatformHandle) {
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
base::File::FLAG_READ);
HandleSendingHelper::WriteFileThenSend(channel(), file);
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
@@ -1344,45 +1414,38 @@ TEST_F(IPCChannelMojoTest, SendPlatformHandle) {
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
- IPCChannelMojoTestSendPlatformHandleClient) {
- ListenerThatExpectsFile listener;
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendPlatformFileClient) {
+ base::RunLoop run_loop;
+ ListenerThatExpectsFile listener(run_loop.QuitClosure());
Connect(&listener);
listener.set_sender(channel());
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
-class ListenerThatExpectsFileAndPipe : public IPC::Listener {
+class ListenerThatExpectsFileAndMessagePipe : public TestListenerBase {
public:
- ListenerThatExpectsFileAndPipe() : sender_(NULL) {}
+ ListenerThatExpectsFileAndMessagePipe(base::Closure quit_closure)
+ : TestListenerBase(quit_closure) {}
- ~ListenerThatExpectsFileAndPipe() override {}
+ ~ListenerThatExpectsFileAndMessagePipe() override {}
bool OnMessageReceived(const IPC::Message& message) override {
base::PickleIterator iter(message);
HandleSendingHelper::ReadReceivedFile(message, &iter);
HandleSendingHelper::ReadReceivedPipe(message, &iter);
- ListenerThatExpectsOK::SendOK(sender_);
+ ListenerThatExpectsOK::SendOK(sender());
return true;
}
-
- void OnChannelError() override {
- base::MessageLoop::current()->QuitWhenIdle();
- }
-
- void set_sender(IPC::Sender* sender) { sender_ = sender; }
-
- private:
- IPC::Sender* sender_;
};
-TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) {
- Init("IPCChannelMojoTestSendPlatformHandleAndPipeClient");
+TEST_F(IPCChannelMojoTest, SendPlatformFileAndMessagePipe) {
+ Init("IPCChannelMojoTestSendPlatformFileAndMessagePipeClient");
- ListenerThatExpectsOK listener;
+ base::RunLoop run_loop;
+ ListenerThatExpectsOK listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
@@ -1394,7 +1457,7 @@ TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) {
TestingMessagePipe pipe;
HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe);
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
EXPECT_TRUE(WaitForClientShutdown());
@@ -1402,12 +1465,13 @@ TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) {
}
DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
- IPCChannelMojoTestSendPlatformHandleAndPipeClient) {
- ListenerThatExpectsFileAndPipe listener;
+ IPCChannelMojoTestSendPlatformFileAndMessagePipeClient) {
+ base::RunLoop run_loop;
+ ListenerThatExpectsFileAndMessagePipe listener(run_loop.QuitClosure());
Connect(&listener);
listener.set_sender(channel());
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
@@ -1418,11 +1482,14 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
const base::ProcessId kMagicChildId = 54321;
-class ListenerThatVerifiesPeerPid : public IPC::Listener {
+class ListenerThatVerifiesPeerPid : public TestListenerBase {
public:
+ ListenerThatVerifiesPeerPid(base::Closure quit_closure)
+ : TestListenerBase(quit_closure) {}
+
void OnChannelConnected(int32_t peer_pid) override {
EXPECT_EQ(peer_pid, kMagicChildId);
- base::MessageLoop::current()->QuitWhenIdle();
+ quit_closure().Run();
}
bool OnMessageReceived(const IPC::Message& message) override {
@@ -1434,11 +1501,12 @@ class ListenerThatVerifiesPeerPid : public IPC::Listener {
TEST_F(IPCChannelMojoTest, VerifyGlobalPid) {
Init("IPCChannelMojoTestVerifyGlobalPidClient");
- ListenerThatVerifiesPeerPid listener;
+ base::RunLoop run_loop;
+ ListenerThatVerifiesPeerPid listener(run_loop.QuitClosure());
CreateChannel(&listener);
ASSERT_TRUE(ConnectChannel());
- base::RunLoop().Run();
+ run_loop.Run();
channel()->Close();
EXPECT_TRUE(WaitForClientShutdown());
@@ -1447,10 +1515,12 @@ TEST_F(IPCChannelMojoTest, VerifyGlobalPid) {
DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestVerifyGlobalPidClient) {
IPC::Channel::SetGlobalPid(kMagicChildId);
- ListenerThatQuits listener;
+
+ base::RunLoop run_loop;
+ ListenerThatQuits listener(run_loop.QuitClosure());
Connect(&listener);
- base::RunLoop().Run();
+ run_loop.Run();
Close();
}
diff --git a/chromium/ipc/ipc_channel_nacl.cc b/chromium/ipc/ipc_channel_nacl.cc
index b95f8cb5453..3e16bb060d3 100644
--- a/chromium/ipc/ipc_channel_nacl.cc
+++ b/chromium/ipc/ipc_channel_nacl.cc
@@ -67,6 +67,9 @@ bool ReadDataOnReaderThread(int pipe, MessageContents* contents) {
} // namespace
+// static
+constexpr size_t Channel::kMaximumMessageSize;
+
class ChannelNacl::ReaderThreadRunner
: public base::DelegateSimpleThread::Delegate {
public:
@@ -220,7 +223,7 @@ void ChannelNacl::DidRecvMsg(std::unique_ptr<MessageContents> contents) {
if (pipe_ == -1)
return;
- auto data = base::MakeUnique<std::vector<char>>();
+ auto data = std::make_unique<std::vector<char>>();
data->swap(contents->data);
read_queue_.push_back(std::move(data));
@@ -386,7 +389,7 @@ std::unique_ptr<Channel> Channel::Create(
const IPC::ChannelHandle& channel_handle,
Mode mode,
Listener* listener) {
- return base::MakeUnique<ChannelNacl>(channel_handle, mode, listener);
+ return std::make_unique<ChannelNacl>(channel_handle, mode, listener);
}
} // namespace IPC
diff --git a/chromium/ipc/ipc_channel_proxy.cc b/chromium/ipc/ipc_channel_proxy.cc
index f48e44ce2c0..89b37565b6f 100644
--- a/chromium/ipc/ipc_channel_proxy.cc
+++ b/chromium/ipc/ipc_channel_proxy.cc
@@ -540,6 +540,10 @@ void ChannelProxy::SendInternal(Message* message) {
Logging::GetInstance()->OnSendMessage(message);
#endif
+ // See https://crbug.com/766032. This is to ensure that senders of oversized
+ // messages can be caught more easily in the wild.
+ CHECK_LE(message->size(), Channel::kMaximumMessageSize);
+
context_->Send(message);
}
diff --git a/chromium/ipc/ipc_channel_proxy_unittest.cc b/chromium/ipc/ipc_channel_proxy_unittest.cc
index 01b895582cb..ba3be18bbe6 100644
--- a/chromium/ipc/ipc_channel_proxy_unittest.cc
+++ b/chromium/ipc/ipc_channel_proxy_unittest.cc
@@ -65,9 +65,7 @@ class QuitListener : public IPC::Listener {
bad_message_received_ = true;
}
- void OnQuit() {
- base::MessageLoop::current()->QuitWhenIdle();
- }
+ void OnQuit() { base::RunLoop::QuitCurrentWhenIdleDeprecated(); }
void OnBadMessage(const BadType& bad_type) {
// Should never be called since IPC wouldn't be deserialized correctly.
@@ -113,7 +111,7 @@ class ChannelReflectorListener : public IPC::Listener {
void OnQuit() {
channel_->Send(new WorkerMsg_Quit());
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
private:
diff --git a/chromium/ipc/ipc_fuzzing_tests.cc b/chromium/ipc/ipc_fuzzing_tests.cc
index 5744135c56a..75c13b1571c 100644
--- a/chromium/ipc/ipc_fuzzing_tests.cc
+++ b/chromium/ipc/ipc_fuzzing_tests.cc
@@ -10,7 +10,6 @@
#include <sstream>
#include <string>
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
@@ -202,7 +201,7 @@ class FuzzerServerListener : public SimpleListener {
--message_count_;
--pending_messages_;
if (0 == message_count_)
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void ReplyMsgNotHandled(uint32_t type_id) {
@@ -229,7 +228,7 @@ class FuzzerClientListener : public SimpleListener {
bool OnMessageReceived(const IPC::Message& msg) override {
last_msg_ = new IPC::Message(msg);
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
return true;
}
diff --git a/chromium/ipc/ipc_message_attachment_set_posix_unittest.cc b/chromium/ipc/ipc_message_attachment_set_posix_unittest.cc
index 0bd143df4de..9fd318a8ba2 100644
--- a/chromium/ipc/ipc_message_attachment_set_posix_unittest.cc
+++ b/chromium/ipc/ipc_message_attachment_set_posix_unittest.cc
@@ -25,7 +25,7 @@ int GetSafeFd() {
// Returns true if fd was already closed. Closes fd if not closed.
bool VerifyClosed(int fd) {
- const int duped = dup(fd);
+ const int duped = HANDLE_EINTR(dup(fd));
if (duped != -1) {
EXPECT_NE(IGNORE_EINTR(close(duped)), -1);
EXPECT_NE(IGNORE_EINTR(close(fd)), -1);
diff --git a/chromium/ipc/ipc_message_pipe_reader.cc b/chromium/ipc/ipc_message_pipe_reader.cc
index cd174a25393..8b226817ee1 100644
--- a/chromium/ipc/ipc_message_pipe_reader.cc
+++ b/chromium/ipc/ipc_message_pipe_reader.cc
@@ -60,15 +60,12 @@ bool MessagePipeReader::Send(std::unique_ptr<Message> message) {
if (result != MOJO_RESULT_OK)
return false;
- std::vector<uint8_t> data(message->size());
- std::copy(reinterpret_cast<const uint8_t*>(message->data()),
- reinterpret_cast<const uint8_t*>(message->data()) + message->size(),
- data.data());
-
if (!sender_)
return false;
- sender_->Receive(data, std::move(handles));
+ sender_->Receive(base::make_span(static_cast<const uint8_t*>(message->data()),
+ message->size()),
+ std::move(handles));
DVLOG(4) << "Send " << message->type() << ": " << message->size();
return true;
@@ -88,7 +85,7 @@ void MessagePipeReader::SetPeerPid(int32_t peer_pid) {
}
void MessagePipeReader::Receive(
- const std::vector<uint8_t>& data,
+ base::span<const uint8_t> data,
base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) {
Message message(
data.empty() ? "" : reinterpret_cast<const char*>(data.data()),
diff --git a/chromium/ipc/ipc_message_pipe_reader.h b/chromium/ipc/ipc_message_pipe_reader.h
index ceb62feec76..b2f5044257f 100644
--- a/chromium/ipc/ipc_message_pipe_reader.h
+++ b/chromium/ipc/ipc_message_pipe_reader.h
@@ -42,7 +42,7 @@ namespace internal {
// be called on any thread. All |Delegate| functions will be called on the IO
// thread.
//
-class IPC_EXPORT MessagePipeReader : public NON_EXPORTED_BASE(mojom::Channel) {
+class IPC_EXPORT MessagePipeReader : public mojom::Channel {
public:
class Delegate {
public:
@@ -94,7 +94,7 @@ class IPC_EXPORT MessagePipeReader : public NON_EXPORTED_BASE(mojom::Channel) {
// mojom::Channel:
void SetPeerPid(int32_t peer_pid) override;
void Receive(
- const std::vector<uint8_t>& data,
+ base::span<const uint8_t> data,
base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) override;
void GetAssociatedInterface(
const std::string& name,
diff --git a/chromium/ipc/ipc_message_start.h b/chromium/ipc/ipc_message_start.h
index dba1acb4202..6359b3f6ec7 100644
--- a/chromium/ipc/ipc_message_start.h
+++ b/chromium/ipc/ipc_message_start.h
@@ -8,20 +8,21 @@
// Used by IPC_BEGIN_MESSAGES so that each message class starts from a unique
// base. Messages have unique IDs across channels in order for the IPC logging
// code to figure out the message class from its ID.
+//
+// You should no longer be adding any new message classes. Instead, use mojo
+// for all new work.
enum IPCMessageStart {
AutomationMsgStart = 0,
FrameMsgStart,
PageMsgStart,
ViewMsgStart,
InputMsgStart,
- ProfileImportMsgStart,
TestMsgStart,
DevToolsMsgStart,
WorkerMsgStart,
NaClMsgStart,
GpuChannelMsgStart,
MediaMsgStart,
- ServiceMsgStart,
PpapiMsgStart,
FirefoxImporterUnittestMsgStart,
FileUtilitiesMsgStart,
@@ -43,17 +44,11 @@ enum IPCMessageStart {
PrintMsgStart,
SpellCheckMsgStart,
ExtensionMsgStart,
- VideoCaptureMsgStart,
QuotaMsgStart,
TextInputClientMsgStart,
- ChromeUtilityMsgStart,
- MediaStreamMsgStart,
- ChromeBenchmarkingMsgStart,
JavaBridgeMsgStart,
- GamepadMsgStart,
ShellMsgStart,
AccessibilityMsgStart,
- PrefetchMsgStart,
PrerenderMsgStart,
ChromotingMsgStart,
BrowserPluginMsgStart,
@@ -63,37 +58,27 @@ enum IPCMessageStart {
MediaPlayerMsgStart,
TracingMsgStart,
PeerConnectionTrackerMsgStart,
- VisitedLinkMsgStart,
AppShimMsgStart,
WebRtcLoggingMsgStart,
TtsMsgStart,
- WebSocketMsgStart,
NaClHostMsgStart,
- WebRTCIdentityMsgStart,
- PowerMonitorMsgStart,
EncryptedMediaMsgStart,
CacheStorageMsgStart,
ServiceWorkerMsgStart,
- MessagePortMsgStart,
EmbeddedWorkerMsgStart,
EmbeddedWorkerContextMsgStart,
CastMsgStart,
- CdmMsgStart,
MediaStreamTrackMetricsHostMsgStart,
ChromeExtensionMsgStart,
- PushMessagingMsgStart,
GinJavaBridgeMsgStart,
ChromeUtilityPrintingMsgStart,
AecDumpMsgStart,
OzoneGpuMsgStart,
ChromeUtilityExtensionsMsgStart,
PlatformNotificationMsgStart,
- PDFMsgStart,
LayoutTestMsgStart,
NetworkHintsMsgStart,
- BluetoothMsgStart,
CastMediaMsgStart,
- AwMessagePortMsgStart,
SyncCompositorMsgStart,
ExtensionsGuestViewMsgStart,
GuestViewMsgStart,
@@ -101,16 +86,8 @@ enum IPCMessageStart {
// internal code. Contact gunsch@ before changing/removing.
CastCryptoMsgStart,
CastChannelMsgStart,
- DataReductionProxyStart,
- ChromeAppBannerMsgStart,
- AttachmentBrokerMsgStart,
RenderProcessMsgStart,
- PageLoadMetricsMsgStart,
IPCTestMsgStart,
- ArcInstanceMsgStart,
- ArcInstanceHostMsgStart,
- DistillerMsgStart,
- ArcCameraMsgStart,
DWriteFontProxyMsgStart,
MediaPlayerDelegateMsgStart,
SurfaceViewManagerMsgStart,
diff --git a/chromium/ipc/ipc_message_templates.h b/chromium/ipc/ipc_message_templates.h
index 57f5cf0b95e..c856ed98108 100644
--- a/chromium/ipc/ipc_message_templates.h
+++ b/chromium/ipc/ipc_message_templates.h
@@ -9,6 +9,7 @@
#include <tuple>
#include <type_traits>
+#include <utility>
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
@@ -19,11 +20,35 @@
namespace IPC {
+template <typename Tuple, size_t... Ns>
+auto TupleForwardImpl(Tuple&& tuple, std::index_sequence<Ns...>) -> decltype(
+ std::forward_as_tuple(std::get<Ns>(std::forward<Tuple>(tuple))...)) {
+ return std::forward_as_tuple(std::get<Ns>(std::forward<Tuple>(tuple))...);
+}
+
+// Transforms std::tuple contents to the forwarding form.
+// Example:
+// std::tuple<int, int&, const int&, int&&>&&
+// -> std::tuple<int&&, int&, const int&, int&&>.
+// const std::tuple<int, const int&, int&&>&
+// -> std::tuple<const int&, int&, const int&, int&>.
+//
+// TupleForward(std::make_tuple(a, b, c)) is equivalent to
+// std::forward_as_tuple(a, b, c).
+template <typename Tuple>
+auto TupleForward(Tuple&& tuple) -> decltype(TupleForwardImpl(
+ std::forward<Tuple>(tuple),
+ std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>())) {
+ return TupleForwardImpl(
+ std::forward<Tuple>(tuple),
+ std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>());
+}
+
// This function is for all the async IPCs that don't pass an extra parameter
// using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
template <typename ObjT, typename Method, typename P, typename Tuple>
-void DispatchToMethod(ObjT* obj, Method method, P*, const Tuple& tuple) {
- base::DispatchToMethod(obj, method, tuple);
+void DispatchToMethod(ObjT* obj, Method method, P*, Tuple&& tuple) {
+ base::DispatchToMethod(obj, method, std::forward<Tuple>(tuple));
}
template <typename ObjT,
@@ -34,22 +59,22 @@ template <typename ObjT,
void DispatchToMethodImpl(ObjT* obj,
Method method,
P* parameter,
- const Tuple& tuple,
- base::IndexSequence<Ns...>) {
- // TODO(mdempsky): Apply UnwrapTraits like base::DispatchToMethod?
- (obj->*method)(parameter, std::get<Ns>(tuple)...);
+ Tuple&& tuple,
+ std::index_sequence<Ns...>) {
+ (obj->*method)(parameter, std::get<Ns>(std::forward<Tuple>(tuple))...);
}
// The following function is for async IPCs which have a dispatcher with an
// extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
-template <typename ObjT, typename P, typename... Args, typename... Ts>
-typename std::enable_if<sizeof...(Args) == sizeof...(Ts)>::type
+template <typename ObjT, typename P, typename... Args, typename Tuple>
+std::enable_if_t<sizeof...(Args) == std::tuple_size<std::decay_t<Tuple>>::value>
DispatchToMethod(ObjT* obj,
void (ObjT::*method)(P*, Args...),
P* parameter,
- const std::tuple<Ts...>& tuple) {
- DispatchToMethodImpl(obj, method, parameter, tuple,
- base::MakeIndexSequence<sizeof...(Ts)>());
+ Tuple&& tuple) {
+ constexpr size_t size = std::tuple_size<std::decay_t<Tuple>>::value;
+ DispatchToMethodImpl(obj, method, parameter, std::forward<Tuple>(tuple),
+ std::make_index_sequence<size>());
}
enum class MessageKind {
@@ -118,7 +143,7 @@ class MessageT<Meta, std::tuple<Ins...>, void> : public Message {
TRACE_EVENT0("ipc", Meta::kName);
Param p;
if (Read(msg, &p)) {
- DispatchToMethod(obj, func, parameter, p);
+ DispatchToMethod(obj, func, parameter, std::move(p));
return true;
}
return false;
@@ -168,17 +193,19 @@ class MessageT<Meta, std::tuple<Ins...>, std::tuple<Outs...>>
SendParam send_params;
bool ok = ReadSendParam(msg, &send_params);
Message* reply = SyncMessage::GenerateReply(msg);
- if (ok) {
- ReplyParam reply_params;
- base::DispatchToMethod(obj, func, send_params, &reply_params);
- WriteParam(reply, reply_params);
- LogReplyParamsToMessage(reply_params, msg);
- } else {
+ if (!ok) {
NOTREACHED() << "Error deserializing message " << msg->type();
reply->set_reply_error();
+ sender->Send(reply);
+ return false;
}
+
+ ReplyParam reply_params;
+ base::DispatchToMethod(obj, func, std::move(send_params), &reply_params);
+ WriteParam(reply, reply_params);
+ LogReplyParamsToMessage(reply_params, msg);
sender->Send(reply);
- return ok;
+ return true;
}
template <class T, class P, class Method>
@@ -190,16 +217,17 @@ class MessageT<Meta, std::tuple<Ins...>, std::tuple<Outs...>>
SendParam send_params;
bool ok = ReadSendParam(msg, &send_params);
Message* reply = SyncMessage::GenerateReply(msg);
- if (ok) {
- std::tuple<Message&> t = std::tie(*reply);
- ConnectMessageAndReply(msg, reply);
- base::DispatchToMethod(obj, func, send_params, &t);
- } else {
+ if (!ok) {
NOTREACHED() << "Error deserializing message " << msg->type();
reply->set_reply_error();
obj->Send(reply);
+ return false;
}
- return ok;
+
+ std::tuple<Message&> t = std::tie(*reply);
+ ConnectMessageAndReply(msg, reply);
+ base::DispatchToMethod(obj, func, std::move(send_params), &t);
+ return true;
}
template <class T, class P, class Method>
@@ -211,18 +239,21 @@ class MessageT<Meta, std::tuple<Ins...>, std::tuple<Outs...>>
SendParam send_params;
bool ok = ReadSendParam(msg, &send_params);
Message* reply = SyncMessage::GenerateReply(msg);
- if (ok) {
- std::tuple<Message&> t = std::tie(*reply);
- ConnectMessageAndReply(msg, reply);
- std::tuple<P*> parameter_tuple(parameter);
- auto concat_params = std::tuple_cat(parameter_tuple, send_params);
- base::DispatchToMethod(obj, func, concat_params, &t);
- } else {
+ if (!ok) {
NOTREACHED() << "Error deserializing message " << msg->type();
reply->set_reply_error();
obj->Send(reply);
+ return false;
}
- return ok;
+
+ std::tuple<Message&> t = std::tie(*reply);
+ ConnectMessageAndReply(msg, reply);
+ std::tuple<P*> parameter_tuple(parameter);
+ base::DispatchToMethod(
+ obj, func,
+ std::tuple_cat(std::move(parameter_tuple), TupleForward(send_params)),
+ &t);
+ return true;
}
private:
diff --git a/chromium/ipc/ipc_message_unittest.cc b/chromium/ipc/ipc_message_unittest.cc
index 4e5bf07a23b..36b5d28da7a 100644
--- a/chromium/ipc/ipc_message_unittest.cc
+++ b/chromium/ipc/ipc_message_unittest.cc
@@ -69,7 +69,7 @@ TEST(IPCMessageTest, ListValue) {
base::ListValue input;
input.AppendDouble(42.42);
input.AppendString("forty");
- input.Append(base::MakeUnique<base::Value>());
+ input.Append(std::make_unique<base::Value>());
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
IPC::WriteParam(&msg, input);
@@ -89,16 +89,16 @@ TEST(IPCMessageTest, ListValue) {
TEST(IPCMessageTest, DictionaryValue) {
base::DictionaryValue input;
- input.Set("null", base::MakeUnique<base::Value>());
+ input.Set("null", std::make_unique<base::Value>());
input.SetBoolean("bool", true);
input.SetInteger("int", 42);
- input.SetIntegerWithoutPathExpansion("int.with.dot", 43);
+ input.SetKey("int.with.dot", base::Value(43));
- auto subdict = base::MakeUnique<base::DictionaryValue>();
+ auto subdict = std::make_unique<base::DictionaryValue>();
subdict->SetString("str", "forty two");
subdict->SetBoolean("bool", false);
- auto sublist = base::MakeUnique<base::ListValue>();
+ auto sublist = std::make_unique<base::ListValue>();
sublist->AppendDouble(42.42);
sublist->AppendString("forty");
sublist->AppendString("two");
diff --git a/chromium/ipc/ipc_message_utils.cc b/chromium/ipc/ipc_message_utils.cc
index c851d8a599e..dd065fd07f7 100644
--- a/chromium/ipc/ipc_message_utils.cc
+++ b/chromium/ipc/ipc_message_utils.cc
@@ -266,34 +266,34 @@ bool ReadValue(const base::Pickle* m,
switch (static_cast<base::Value::Type>(type)) {
case base::Value::Type::NONE:
- *value = base::MakeUnique<base::Value>();
+ *value = std::make_unique<base::Value>();
break;
case base::Value::Type::BOOLEAN: {
bool val;
if (!ReadParam(m, iter, &val))
return false;
- *value = base::MakeUnique<base::Value>(val);
+ *value = std::make_unique<base::Value>(val);
break;
}
case base::Value::Type::INTEGER: {
int val;
if (!ReadParam(m, iter, &val))
return false;
- *value = base::MakeUnique<base::Value>(val);
+ *value = std::make_unique<base::Value>(val);
break;
}
case base::Value::Type::DOUBLE: {
double val;
if (!ReadParam(m, iter, &val))
return false;
- *value = base::MakeUnique<base::Value>(val);
+ *value = std::make_unique<base::Value>(val);
break;
}
case base::Value::Type::STRING: {
std::string val;
if (!ReadParam(m, iter, &val))
return false;
- *value = base::MakeUnique<base::Value>(std::move(val));
+ *value = std::make_unique<base::Value>(std::move(val));
break;
}
case base::Value::Type::BINARY: {
@@ -308,14 +308,14 @@ bool ReadValue(const base::Pickle* m,
base::DictionaryValue val;
if (!ReadDictionaryValue(m, iter, &val, recursion))
return false;
- *value = base::MakeUnique<base::Value>(std::move(val));
+ *value = std::make_unique<base::Value>(std::move(val));
break;
}
case base::Value::Type::LIST: {
base::ListValue val;
if (!ReadListValue(m, iter, &val, recursion))
return false;
- *value = base::MakeUnique<base::Value>(std::move(val));
+ *value = std::make_unique<base::Value>(std::move(val));
break;
}
default:
@@ -712,8 +712,11 @@ void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m,
MachPortMac mach_port_mac(p.GetMemoryObject());
WriteParam(m, mach_port_mac);
#elif defined(OS_WIN)
- HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
+ HandleWin handle_win(p.GetHandle());
WriteParam(m, handle_win);
+#elif defined(OS_FUCHSIA)
+ HandleFuchsia handle_fuchsia(p.GetHandle());
+ WriteParam(m, handle_fuchsia);
#else
if (p.OwnershipPassesToIPC()) {
if (!m->WriteAttachment(new internal::PlatformFileAttachment(
@@ -830,7 +833,7 @@ void ParamTraits<PlatformFileForTransit>::Write(base::Pickle* m,
const param_type& p) {
m->WriteBool(p.IsValid());
if (p.IsValid()) {
- HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
+ HandleWin handle_win(p.GetHandle());
ParamTraits<HandleWin>::Write(m, handle_win);
::CloseHandle(p.GetHandle());
}
diff --git a/chromium/ipc/ipc_message_utils_unittest.cc b/chromium/ipc/ipc_message_utils_unittest.cc
index 867768089ba..f4ca6ba933d 100644
--- a/chromium/ipc/ipc_message_utils_unittest.cc
+++ b/chromium/ipc/ipc_message_utils_unittest.cc
@@ -99,13 +99,13 @@ TEST(IPCMessageUtilsTest, StackVector) {
// Tests that PickleSizer and Pickle agree on the size of a complex base::Value.
TEST(IPCMessageUtilsTest, ValueSize) {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
- value->SetIntegerWithoutPathExpansion("foo", 42);
- value->SetDoubleWithoutPathExpansion("bar", 3.14);
- value->SetStringWithoutPathExpansion("baz", "hello");
- value->SetWithoutPathExpansion("qux", base::MakeUnique<base::Value>());
+ value->SetKey("foo", base::Value(42));
+ value->SetKey("bar", base::Value(3.14));
+ value->SetKey("baz", base::Value("hello"));
+ value->SetWithoutPathExpansion("qux", std::make_unique<base::Value>());
std::unique_ptr<base::DictionaryValue> nested_dict(new base::DictionaryValue);
- nested_dict->SetIntegerWithoutPathExpansion("foobar", 5);
+ nested_dict->SetKey("foobar", base::Value(5));
value->SetWithoutPathExpansion("nested", std::move(nested_dict));
std::unique_ptr<base::ListValue> list_value(new base::ListValue);
diff --git a/chromium/ipc/ipc_mojo_bootstrap.cc b/chromium/ipc/ipc_mojo_bootstrap.cc
index afd0e3cc075..506c9f88cb4 100644
--- a/chromium/ipc/ipc_mojo_bootstrap.cc
+++ b/chromium/ipc/ipc_mojo_bootstrap.cc
@@ -172,6 +172,15 @@ class ChannelAssociatedGroupController
if (!mojo::IsValidInterfaceId(id))
return mojo::ScopedInterfaceEndpointHandle();
+ // Unless it is the master ID, |id| is from the remote side and therefore
+ // its namespace bit is supposed to be different than the value that this
+ // router would use.
+ if (!mojo::IsMasterInterfaceId(id) &&
+ set_interface_id_namespace_bit_ ==
+ mojo::HasInterfaceIdNamespaceBitSet(id)) {
+ return mojo::ScopedInterfaceEndpointHandle();
+ }
+
base::AutoLock locker(lock_);
bool inserted = false;
Endpoint* endpoint = FindOrInsertEndpoint(id, &inserted);
@@ -493,7 +502,7 @@ class ChannelAssociatedGroupController
{
base::AutoLock locker(controller_->lock_);
if (!sync_message_event_) {
- sync_message_event_ = base::MakeUnique<base::WaitableEvent>(
+ sync_message_event_ = std::make_unique<base::WaitableEvent>(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
if (peer_closed_ || !sync_messages_.empty())
@@ -501,7 +510,7 @@ class ChannelAssociatedGroupController
}
}
- sync_watcher_ = base::MakeUnique<mojo::SyncEventWatcher>(
+ sync_watcher_ = std::make_unique<mojo::SyncEventWatcher>(
sync_message_event_.get(),
base::Bind(&Endpoint::OnSyncMessageEventReady,
base::Unretained(this)));
@@ -821,8 +830,6 @@ class ChannelAssociatedGroupController
const base::Optional<mojo::DisconnectReason>& reason) override {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(!mojo::IsMasterInterfaceId(id) || reason);
-
scoped_refptr<ChannelAssociatedGroupController> keepalive(this);
base::AutoLock locker(lock_);
scoped_refptr<Endpoint> endpoint = FindOrInsertEndpoint(id, nullptr);
@@ -921,7 +928,7 @@ std::unique_ptr<MojoBootstrap> MojoBootstrap::Create(
mojo::ScopedMessagePipeHandle handle,
Channel::Mode mode,
const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
- return base::MakeUnique<MojoBootstrapImpl>(
+ return std::make_unique<MojoBootstrapImpl>(
std::move(handle), new ChannelAssociatedGroupController(
mode == Channel::MODE_SERVER, ipc_task_runner));
}
diff --git a/chromium/ipc/ipc_mojo_bootstrap_unittest.cc b/chromium/ipc/ipc_mojo_bootstrap_unittest.cc
index c6cde3ec636..52e261f1caa 100644
--- a/chromium/ipc/ipc_mojo_bootstrap_unittest.cc
+++ b/chromium/ipc/ipc_mojo_bootstrap_unittest.cc
@@ -42,7 +42,7 @@ class PeerPidReceiver : public IPC::mojom::Channel {
on_peer_pid_set_.Run();
}
- void Receive(const std::vector<uint8_t>& data,
+ void Receive(base::span<const uint8_t> data,
base::Optional<std::vector<IPC::mojom::SerializedHandlePtr>>
handles) override {}
diff --git a/chromium/ipc/ipc_mojo_perftest.cc b/chromium/ipc/ipc_mojo_perftest.cc
index 8513e08b286..45f5203e383 100644
--- a/chromium/ipc/ipc_mojo_perftest.cc
+++ b/chromium/ipc/ipc_mojo_perftest.cc
@@ -12,8 +12,7 @@
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/perf_time_logger.h"
-#include "base/test/test_io_thread.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/threading/thread.h"
#include "build/build_config.h"
#include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_sync_channel.h"
@@ -23,7 +22,9 @@
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/test/mojo_test_base.h"
#include "mojo/edk/test/multiprocess_test_helper.h"
+#include "mojo/public/cpp/bindings/associated_binding_set.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/system/message_pipe.h"
#define IPC_MESSAGE_IMPL
@@ -39,6 +40,12 @@ IPC_SYNC_MESSAGE_CONTROL1_1(TestMsg_SyncPing, std::string, std::string)
namespace IPC {
namespace {
+scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() {
+ scoped_refptr<base::TaskRunner> runner = mojo::edk::GetIOTaskRunner();
+ return scoped_refptr<base::SingleThreadTaskRunner>(
+ static_cast<base::SingleThreadTaskRunner*>(runner.get()));
+}
+
class PerformanceChannelListener : public Listener {
public:
explicit PerformanceChannelListener(const std::string& label)
@@ -88,13 +95,13 @@ class PerformanceChannelListener : public Listener {
static_cast<unsigned>(msg_size_));
perf_logger_.reset(new base::PerfTimeLogger(test_name.c_str()));
if (sync_) {
- for (int i = 0; i < count_down_; ++i) {
+ for (; count_down_ > 0; --count_down_) {
std::string response;
sender_->Send(new TestMsg_SyncPing(payload_, &response));
DCHECK_EQ(response, payload_);
}
perf_logger_.reset();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
} else {
SendPong();
}
@@ -108,7 +115,7 @@ class PerformanceChannelListener : public Listener {
count_down_--;
if (count_down_ == 0) {
perf_logger_.reset(); // Stop the perf timer now.
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
return;
}
@@ -168,7 +175,7 @@ class ChannelReflectorListener : public Listener {
*response = payload;
}
- void OnQuit() { base::MessageLoop::current()->QuitWhenIdle(); }
+ void OnQuit() { base::RunLoop::QuitCurrentWhenIdleDeprecated(); }
void Send(IPC::Message* message) { channel_->Send(message); }
@@ -238,15 +245,29 @@ class PingPongTestParams {
int message_count_;
};
-std::vector<PingPongTestParams> GetDefaultTestParams() {
-// Test several sizes. We use 12^N for message size, and limit the message
-// count to keep the test duration reasonable.
+class InterfacePassingTestParams {
+ public:
+ InterfacePassingTestParams(size_t rounds, size_t num_interfaces)
+ : rounds_(rounds), num_interfaces_(num_interfaces) {}
+
+ size_t rounds() const { return rounds_; }
+ size_t num_interfaces() const { return num_interfaces_; }
+
+ private:
+ size_t rounds_;
+ size_t num_interfaces_;
+};
+
#ifdef NDEBUG
- const int kMultiplier = 100;
+const int kMultiplier = 100;
#else
// Debug builds on Windows run these tests orders of magnitude more slowly.
- const int kMultiplier = 1;
+const int kMultiplier = 1;
#endif
+
+std::vector<PingPongTestParams> GetDefaultTestParams() {
+ // Test several sizes. We use 12^N for message size, and limit the message
+ // count to keep the test duration reasonable.
std::vector<PingPongTestParams> list;
list.push_back(PingPongTestParams(12, 500 * kMultiplier));
list.push_back(PingPongTestParams(144, 500 * kMultiplier));
@@ -256,6 +277,16 @@ std::vector<PingPongTestParams> GetDefaultTestParams() {
return list;
}
+std::vector<InterfacePassingTestParams> GetDefaultInterfacePassingTestParams() {
+ std::vector<InterfacePassingTestParams> list;
+ list.push_back({500 * kMultiplier, 0});
+ list.push_back({500 * kMultiplier, 1});
+ list.push_back({500 * kMultiplier, 2});
+ list.push_back({500 * kMultiplier, 4});
+ list.push_back({500 * kMultiplier, 8});
+ return list;
+}
+
// Avoid core 0 due to conflicts with Intel's Power Gadget.
// Setting thread affinity will fail harmlessly on single/dual core machines.
const int kSharedCore = 2;
@@ -266,15 +297,13 @@ class MojoChannelPerfTest : public IPCChannelMojoTestBase {
~MojoChannelPerfTest() override = default;
void RunTestChannelProxyPingPong() {
- io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
-
Init("MojoPerfTestClient");
// Set up IPC channel and start client.
PerformanceChannelListener listener("ChannelProxy");
auto channel_proxy = IPC::ChannelProxy::Create(
TakeHandle().release(), IPC::Channel::MODE_SERVER, &listener,
- io_thread_->task_runner());
+ GetIOThreadTaskRunner());
listener.Init(channel_proxy.get());
LockThreadAffinity thread_locker(kSharedCore);
@@ -295,13 +324,9 @@ class MojoChannelPerfTest : public IPCChannelMojoTestBase {
EXPECT_TRUE(WaitForClientShutdown());
channel_proxy.reset();
-
- io_thread_.reset();
}
void RunTestChannelProxySyncPing() {
- io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
-
Init("MojoPerfTestClient");
// Set up IPC channel and start client.
@@ -311,7 +336,7 @@ class MojoChannelPerfTest : public IPCChannelMojoTestBase {
base::WaitableEvent::InitialState::NOT_SIGNALED);
auto channel_proxy = IPC::SyncChannel::Create(
TakeHandle().release(), IPC::Channel::MODE_SERVER, &listener,
- io_thread_->task_runner(), false, &shutdown_event);
+ GetIOThreadTaskRunner(), false, &shutdown_event);
listener.Init(channel_proxy.get());
LockThreadAffinity thread_locker(kSharedCore);
@@ -332,18 +357,7 @@ class MojoChannelPerfTest : public IPCChannelMojoTestBase {
EXPECT_TRUE(WaitForClientShutdown());
channel_proxy.reset();
-
- io_thread_.reset();
}
-
- scoped_refptr<base::TaskRunner> io_task_runner() {
- if (io_thread_)
- return io_thread_->task_runner();
- return base::ThreadTaskRunnerHandle::Get();
- }
-
- private:
- std::unique_ptr<base::TestIOThread> io_thread_;
};
TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
@@ -371,11 +385,10 @@ class MojoPerfTestClient {
int Run(MojoHandle handle) {
handle_ = mojo::MakeScopedHandle(mojo::MessagePipeHandle(handle));
LockThreadAffinity thread_locker(kSharedCore);
- base::TestIOThread io_thread(base::TestIOThread::kAutoStart);
std::unique_ptr<ChannelProxy> channel =
IPC::ChannelProxy::Create(handle_.release(), Channel::MODE_CLIENT,
- listener_.get(), io_thread.task_runner());
+ listener_.get(), GetIOThreadTaskRunner());
listener_->Init(channel.get());
base::RunLoop().Run();
@@ -419,7 +432,7 @@ class ReflectorImpl : public IPC::mojom::Reflector {
std::move(callback).Run(value);
}
- void Quit() override { base::MessageLoop::current()->QuitWhenIdle(); }
+ void Quit() override { base::RunLoop::QuitCurrentWhenIdleDeprecated(); }
mojo::Binding<IPC::mojom::Reflector> binding_;
};
@@ -466,7 +479,7 @@ class MojoInterfacePerfTest : public mojo::edk::test::MojoTestBase {
count_down_--;
if (count_down_ == 0) {
perf_logger_.reset();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
return;
}
}
@@ -478,7 +491,7 @@ class MojoInterfacePerfTest : public mojo::edk::test::MojoTestBase {
DCHECK_EQ(response, payload_);
}
perf_logger_.reset();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
} else {
ping_receiver_->Ping(payload_, base::Bind(&MojoInterfacePerfTest::OnPong,
base::Unretained(this)));
@@ -514,16 +527,198 @@ class MojoInterfacePerfTest : public mojo::edk::test::MojoTestBase {
DISALLOW_COPY_AND_ASSIGN(MojoInterfacePerfTest);
};
+class InterfacePassingTestDriverImpl : public mojom::InterfacePassingTestDriver,
+ public mojom::PingReceiver {
+ public:
+ InterfacePassingTestDriverImpl(mojo::ScopedMessagePipeHandle handle,
+ const base::Closure& quit_closure)
+ : binding_(this,
+ mojom::InterfacePassingTestDriverRequest(std::move(handle))),
+ quit_closure_(quit_closure) {}
+ ~InterfacePassingTestDriverImpl() override {
+ ignore_result(binding_.Unbind().PassMessagePipe().release());
+ }
+
+ private:
+ // mojom::InterfacePassingTestDriver implementation:
+ void Init(InitCallback callback) override { std::move(callback).Run(); }
+
+ void GetPingReceiver(std::vector<mojom::PingReceiverRequest> requests,
+ GetPingReceiverCallback callback) override {
+ for (auto& request : requests)
+ ping_receiver_bindings_.AddBinding(this, std::move(request));
+ ping_receiver_bindings_.CloseAllBindings();
+ std::move(callback).Run();
+ }
+
+ void GetAssociatedPingReceiver(
+ std::vector<mojom::PingReceiverAssociatedRequest> requests,
+ GetAssociatedPingReceiverCallback callback) override {
+ for (auto& request : requests)
+ ping_receiver_associated_bindings_.AddBinding(this, std::move(request));
+ ping_receiver_associated_bindings_.CloseAllBindings();
+ std::move(callback).Run();
+ }
+
+ void Quit() override {
+ if (quit_closure_)
+ quit_closure_.Run();
+ }
+
+ // mojom::PingReceiver implementation:
+ void Ping(PingCallback callback) override { std::move(callback).Run(); }
+
+ mojo::BindingSet<mojom::PingReceiver> ping_receiver_bindings_;
+ mojo::AssociatedBindingSet<mojom::PingReceiver>
+ ping_receiver_associated_bindings_;
+ mojo::Binding<mojom::InterfacePassingTestDriver> binding_;
+
+ base::Closure quit_closure_;
+};
+
+class MojoInterfacePassingPerfTest : public mojo::edk::test::MojoTestBase {
+ public:
+ MojoInterfacePassingPerfTest() = default;
+
+ protected:
+ void RunInterfacePassingServer(MojoHandle mp,
+ const std::string& label,
+ bool associated) {
+ label_ = label;
+ associated_ = associated;
+
+ mojo::MessagePipeHandle mp_handle(mp);
+ mojo::ScopedMessagePipeHandle scoped_mp(mp_handle);
+ driver_ptr_.Bind(
+ mojom::InterfacePassingTestDriverPtrInfo(std::move(scoped_mp), 0u));
+
+ auto params = GetDefaultInterfacePassingTestParams();
+
+ LockThreadAffinity thread_locker(kSharedCore);
+ for (size_t i = 0; i < params.size(); ++i) {
+ driver_ptr_->Init(
+ base::Bind(&MojoInterfacePassingPerfTest::OnInitCallback,
+ base::Unretained(this)));
+ rounds_ = count_down_ = params[i].rounds();
+ num_interfaces_ = params[i].num_interfaces();
+
+ base::RunLoop run_loop;
+ quit_closure_ = run_loop.QuitWhenIdleClosure();
+ run_loop.Run();
+ }
+
+ driver_ptr_->Quit();
+
+ ignore_result(driver_ptr_.PassInterface().PassHandle().release());
+ }
+
+ void OnInitCallback() {
+ DCHECK(!perf_logger_.get());
+ std::string test_name = base::StringPrintf(
+ "IPC_%s_Perf_%zux_%zu", label_.c_str(), rounds_, num_interfaces_);
+ perf_logger_.reset(new base::PerfTimeLogger(test_name.c_str()));
+
+ DoNextRound();
+ }
+
+ void DoNextRound() {
+ if (associated_) {
+ std::vector<mojom::PingReceiverAssociatedPtr> associated_interfaces(
+ num_interfaces_);
+
+ std::vector<mojom::PingReceiverAssociatedRequest> requests(
+ num_interfaces_);
+ for (size_t i = 0; i < num_interfaces_; ++i) {
+ requests[i] = mojo::MakeRequest(&associated_interfaces[i]);
+ // Force the interface pointer to do full initialization.
+ associated_interfaces[i].get();
+ }
+
+ driver_ptr_->GetAssociatedPingReceiver(
+ std::move(requests),
+ base::Bind(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
+ base::Unretained(this)));
+ } else {
+ std::vector<mojom::PingReceiverPtr> interfaces(num_interfaces_);
+
+ std::vector<mojom::PingReceiverRequest> requests(num_interfaces_);
+ for (size_t i = 0; i < num_interfaces_; ++i) {
+ requests[i] = mojo::MakeRequest(&interfaces[i]);
+ // Force the interface pointer to do full initialization.
+ interfaces[i].get();
+ }
+
+ driver_ptr_->GetPingReceiver(
+ std::move(requests),
+ base::Bind(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
+ base::Unretained(this)));
+ }
+ }
+
+ void OnGetReceiverCallback() {
+ CHECK_GT(count_down_, 0u);
+ count_down_--;
+
+ if (count_down_ == 0) {
+ perf_logger_.reset();
+ quit_closure_.Run();
+ return;
+ }
+
+ DoNextRound();
+ }
+
+ static int RunInterfacePassingClient(MojoHandle mp) {
+ mojo::MessagePipeHandle mp_handle(mp);
+ mojo::ScopedMessagePipeHandle scoped_mp(mp_handle);
+
+ // In single process mode, this is running in a task and by default other
+ // tasks (in particular, the binding) won't run. To keep the single process
+ // and multi-process code paths the same, enable nestable tasks.
+ base::MessageLoop::ScopedNestableTaskAllower nest_loop(
+ base::MessageLoop::current());
+
+ LockThreadAffinity thread_locker(kSharedCore);
+ base::RunLoop run_loop;
+ InterfacePassingTestDriverImpl impl(std::move(scoped_mp),
+ run_loop.QuitWhenIdleClosure());
+ run_loop.Run();
+ return 0;
+ }
+
+ private:
+ size_t rounds_ = 0;
+ size_t count_down_ = 0;
+ size_t num_interfaces_ = 0;
+ std::string label_;
+ bool associated_ = false;
+ std::unique_ptr<base::PerfTimeLogger> perf_logger_;
+
+ mojom::InterfacePassingTestDriverPtr driver_ptr_;
+
+ base::Closure quit_closure_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoInterfacePassingPerfTest);
+};
+
+DEFINE_TEST_CLIENT_WITH_PIPE(InterfacePassingClient,
+ MojoInterfacePassingPerfTest,
+ h) {
+ base::MessageLoop main_message_loop;
+ return RunInterfacePassingClient(h);
+}
+
enum class InProcessMessageMode {
kSerialized,
kUnserialized,
};
-class MojoInProcessInterfacePerfTest
- : public MojoInterfacePerfTest,
+template <class TestBase>
+class InProcessPerfTest
+ : public TestBase,
public testing::WithParamInterface<InProcessMessageMode> {
public:
- MojoInProcessInterfacePerfTest() {
+ InProcessPerfTest() {
switch (GetParam()) {
case InProcessMessageMode::kSerialized:
mojo::Connector::OverrideDefaultSerializationBehaviorForTesting(
@@ -539,6 +734,10 @@ class MojoInProcessInterfacePerfTest
}
};
+using MojoInProcessInterfacePerfTest = InProcessPerfTest<MojoInterfacePerfTest>;
+using MojoInProcessInterfacePassingPerfTest =
+ InProcessPerfTest<MojoInterfacePassingPerfTest>;
+
DEFINE_TEST_CLIENT_WITH_PIPE(PingPongClient, MojoInterfacePerfTest, h) {
base::MessageLoop main_message_loop;
return RunPingPongClient(h);
@@ -561,6 +760,21 @@ TEST_F(MojoInterfacePerfTest, MultiprocessSyncPing) {
});
}
+TEST_F(MojoInterfacePassingPerfTest, MultiprocessInterfacePassing) {
+ RunTestClient("InterfacePassingClient", [&](MojoHandle h) {
+ base::MessageLoop main_message_loop;
+ RunInterfacePassingServer(h, "InterfacePassing", false /* associated */);
+ });
+}
+
+TEST_F(MojoInterfacePassingPerfTest, MultiprocessAssociatedInterfacePassing) {
+ RunTestClient("InterfacePassingClient", [&](MojoHandle h) {
+ base::MessageLoop main_message_loop;
+ RunInterfacePassingServer(h, "AssociatedInterfacePassing",
+ true /* associated*/);
+ });
+}
+
// A single process version of the above test.
TEST_P(MojoInProcessInterfacePerfTest, MultiThreadPingPong) {
MojoHandle server_handle, client_handle;
@@ -594,6 +808,71 @@ INSTANTIATE_TEST_CASE_P(,
testing::Values(InProcessMessageMode::kSerialized,
InProcessMessageMode::kUnserialized));
+TEST_P(MojoInProcessInterfacePassingPerfTest, MultiThreadInterfacePassing) {
+ MojoHandle server_handle, client_handle;
+ CreateMessagePipe(&server_handle, &client_handle);
+
+ base::Thread client_thread("InterfacePassingClient");
+ client_thread.Start();
+ client_thread.task_runner()->PostTask(
+ FROM_HERE, base::Bind(base::IgnoreResult(&RunInterfacePassingClient),
+ client_handle));
+
+ base::MessageLoop main_message_loop;
+ RunInterfacePassingServer(server_handle, "SingleProcess",
+ false /* associated */);
+}
+
+TEST_P(MojoInProcessInterfacePassingPerfTest,
+ MultiThreadAssociatedInterfacePassing) {
+ MojoHandle server_handle, client_handle;
+ CreateMessagePipe(&server_handle, &client_handle);
+
+ base::Thread client_thread("InterfacePassingClient");
+ client_thread.Start();
+ client_thread.task_runner()->PostTask(
+ FROM_HERE, base::Bind(base::IgnoreResult(&RunInterfacePassingClient),
+ client_handle));
+
+ base::MessageLoop main_message_loop;
+ RunInterfacePassingServer(server_handle, "SingleProcess",
+ true /* associated */);
+}
+
+TEST_P(MojoInProcessInterfacePassingPerfTest, SingleThreadInterfacePassing) {
+ MojoHandle server_handle, client_handle;
+ CreateMessagePipe(&server_handle, &client_handle);
+
+ base::MessageLoop main_message_loop;
+ mojo::MessagePipeHandle mp_handle(client_handle);
+ mojo::ScopedMessagePipeHandle scoped_mp(mp_handle);
+ LockThreadAffinity thread_locker(kSharedCore);
+ InterfacePassingTestDriverImpl impl(std::move(scoped_mp), base::Closure());
+
+ RunInterfacePassingServer(server_handle, "SingleProcess",
+ false /* associated */);
+}
+
+TEST_P(MojoInProcessInterfacePassingPerfTest,
+ SingleThreadAssociatedInterfacePassing) {
+ MojoHandle server_handle, client_handle;
+ CreateMessagePipe(&server_handle, &client_handle);
+
+ base::MessageLoop main_message_loop;
+ mojo::MessagePipeHandle mp_handle(client_handle);
+ mojo::ScopedMessagePipeHandle scoped_mp(mp_handle);
+ LockThreadAffinity thread_locker(kSharedCore);
+ InterfacePassingTestDriverImpl impl(std::move(scoped_mp), base::Closure());
+
+ RunInterfacePassingServer(server_handle, "SingleProcess",
+ true /* associated */);
+}
+
+INSTANTIATE_TEST_CASE_P(,
+ MojoInProcessInterfacePassingPerfTest,
+ testing::Values(InProcessMessageMode::kSerialized,
+ InProcessMessageMode::kUnserialized));
+
class CallbackPerfTest : public testing::Test {
public:
CallbackPerfTest()
@@ -637,7 +916,7 @@ class CallbackPerfTest : public testing::Test {
count_down_--;
if (count_down_ == 0) {
perf_logger_.reset();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
return;
}
}
@@ -712,7 +991,7 @@ class CallbackPerfTest : public testing::Test {
count_down_--;
if (count_down_ == 0) {
perf_logger_.reset();
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
return;
}
}
diff --git a/chromium/ipc/ipc_platform_file.cc b/chromium/ipc/ipc_platform_file.cc
index db5f8e52346..72ed737b6a8 100644
--- a/chromium/ipc/ipc_platform_file.cc
+++ b/chromium/ipc/ipc_platform_file.cc
@@ -7,6 +7,8 @@
#if defined(OS_POSIX)
#include <unistd.h>
+
+#include "base/posix/eintr_wrapper.h"
#endif
namespace IPC {
@@ -60,7 +62,7 @@ PlatformFileForTransit GetPlatformFileForTransit(base::PlatformFile handle,
// the other process from the I/O thread. Without the dup, calling code might
// close the source handle before the message is sent, creating a race
// condition.
- int fd = close_source_handle ? handle : ::dup(handle);
+ int fd = close_source_handle ? handle : HANDLE_EINTR(::dup(handle));
return base::FileDescriptor(fd, true);
#else
#error Not implemented.
diff --git a/chromium/ipc/ipc_send_fds_test.cc b/chromium/ipc/ipc_send_fds_test.cc
index 0b8a2798e61..9eb50fb2e28 100644
--- a/chromium/ipc/ipc_send_fds_test.cc
+++ b/chromium/ipc/ipc_send_fds_test.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/message_loop/message_loop.h"
#include "build/build_config.h"
#if defined(OS_POSIX)
@@ -83,7 +82,7 @@ class MyChannelDescriptorListener : public MyChannelDescriptorListenerBase {
}
void OnChannelError() override {
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
protected:
@@ -106,7 +105,7 @@ class MyChannelDescriptorListener : public MyChannelDescriptorListenerBase {
++num_fds_received_;
if (num_fds_received_ == kNumFDsToSend * kNumMessages)
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
private:
diff --git a/chromium/ipc/ipc_sync_channel.cc b/chromium/ipc/ipc_sync_channel.cc
index 05272a1ae91..dd636b552dd 100644
--- a/chromium/ipc/ipc_sync_channel.cc
+++ b/chromium/ipc/ipc_sync_channel.cc
@@ -280,7 +280,7 @@ class SyncChannel::ReceivedSyncMsgQueue :
dispatch_event_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED),
listener_task_runner_(base::ThreadTaskRunnerHandle::Get()),
- sync_dispatch_watcher_(base::MakeUnique<mojo::SyncEventWatcher>(
+ sync_dispatch_watcher_(std::make_unique<mojo::SyncEventWatcher>(
&dispatch_event_,
base::Bind(&ReceivedSyncMsgQueue::OnDispatchEventReady,
base::Unretained(this)))) {
@@ -635,7 +635,7 @@ void SyncChannel::WaitForReply(mojo::SyncHandleRegistry* registry,
base::WaitableEvent* pump_messages_event = nullptr;
if (pump_messages) {
if (!g_pump_messages_event.Get()) {
- g_pump_messages_event.Get() = base::MakeUnique<base::WaitableEvent>(
+ g_pump_messages_event.Get() = std::make_unique<base::WaitableEvent>(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::SIGNALED);
}
diff --git a/chromium/ipc/ipc_test.mojom b/chromium/ipc/ipc_test.mojom
index 33181b82659..2af9128f9af 100644
--- a/chromium/ipc/ipc_test.mojom
+++ b/chromium/ipc/ipc_test.mojom
@@ -39,3 +39,10 @@ interface Reflector {
interface AssociatedInterfaceVendor {
GetTestInterface(associated SimpleTestDriver& interface_reqest);
};
+
+interface InterfacePassingTestDriver {
+ Init() => ();
+ GetPingReceiver(array<PingReceiver&> request) => ();
+ GetAssociatedPingReceiver(array<associated PingReceiver&> request) => ();
+ Quit();
+};
diff --git a/chromium/ipc/ipc_test_base.cc b/chromium/ipc/ipc_test_base.cc
index d09b3b69ad9..49cb11619bb 100644
--- a/chromium/ipc/ipc_test_base.cc
+++ b/chromium/ipc/ipc_test_base.cc
@@ -18,7 +18,7 @@ IPCChannelMojoTestBase::~IPCChannelMojoTestBase() = default;
void IPCChannelMojoTestBase::Init(const std::string& test_client_name) {
InitWithCustomMessageLoop(test_client_name,
- base::MakeUnique<base::MessageLoop>());
+ std::make_unique<base::MessageLoop>());
}
void IPCChannelMojoTestBase::InitWithCustomMessageLoop(
diff --git a/chromium/ipc/ipc_test_channel_listener.cc b/chromium/ipc/ipc_test_channel_listener.cc
index a755b422d1a..611bfe835a7 100644
--- a/chromium/ipc/ipc_test_channel_listener.cc
+++ b/chromium/ipc/ipc_test_channel_listener.cc
@@ -4,7 +4,7 @@
#include "ipc/ipc_test_channel_listener.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sender.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -50,12 +50,12 @@ bool TestChannelListener::OnMessageReceived(const IPC::Message& message) {
void TestChannelListener::OnChannelError() {
// There is a race when closing the channel so the last message may be lost.
EXPECT_LE(messages_left_, 1);
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void TestChannelListener::SendNextMessage() {
if (--messages_left_ <= 0)
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
else
SendOneMessage(sender_, "Foo");
}
diff --git a/chromium/ipc/message_router.h b/chromium/ipc/message_router.h
index 82999ab0560..62c40592930 100644
--- a/chromium/ipc/message_router.h
+++ b/chromium/ipc/message_router.h
@@ -7,7 +7,7 @@
#include <stdint.h>
-#include "base/id_map.h"
+#include "base/containers/id_map.h"
#include "base/macros.h"
#include "ipc/ipc_export.h"
#include "ipc/ipc_listener.h"
@@ -64,7 +64,7 @@ class IPC_EXPORT MessageRouter : public Listener, public Sender {
private:
// A list of all listeners with assigned routing IDs.
- IDMap<Listener*> routes_;
+ base::IDMap<Listener*> routes_;
DISALLOW_COPY_AND_ASSIGN(MessageRouter);
};
diff --git a/chromium/ipc/sync_socket_unittest.cc b/chromium/ipc/sync_socket_unittest.cc
index e220281bc90..6fc55c4faba 100644
--- a/chromium/ipc/sync_socket_unittest.cc
+++ b/chromium/ipc/sync_socket_unittest.cc
@@ -13,7 +13,6 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
@@ -101,7 +100,7 @@ class SyncSocketServerListener : public IPC::Listener {
// When the client responds, it sends back a shutdown message,
// which causes the message loop to exit.
- void OnMsgClassShutdown() { base::MessageLoop::current()->QuitWhenIdle(); }
+ void OnMsgClassShutdown() { base::RunLoop::QuitCurrentWhenIdleDeprecated(); }
IPC::Channel* chan_;
@@ -154,7 +153,7 @@ class SyncSocketClientListener : public IPC::Listener {
EXPECT_EQ(0U, socket_->Peek());
IPC::Message* msg = new MsgClassShutdown();
EXPECT_TRUE(chan_->Send(msg));
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
base::SyncSocket* socket_;