diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 15:06:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:48:58 +0000 |
commit | daa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch) | |
tree | 96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/ipc | |
parent | be59a35641616a4cf23c4a13fa0632624b021c1b (diff) | |
download | qtwebengine-chromium-daa093eea7c773db06799a13bd7e4e2e2a9f8f14.tar.gz |
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/ipc')
62 files changed, 1239 insertions, 1151 deletions
diff --git a/chromium/ipc/BUILD.gn b/chromium/ipc/BUILD.gn index 42621399916..a63907022b5 100644 --- a/chromium/ipc/BUILD.gn +++ b/chromium/ipc/BUILD.gn @@ -23,10 +23,6 @@ buildflag_header("ipc_features") { component("ipc") { sources = [ "export_template.h", - "handle_attachment_win.cc", - "handle_attachment_win.h", - "handle_win.cc", - "handle_win.h", "ipc_channel.cc", "ipc_channel.h", "ipc_channel_common.cc", @@ -45,12 +41,6 @@ component("ipc") { "ipc_listener.h", "ipc_logging.cc", "ipc_logging.h", - "ipc_message.cc", - "ipc_message.h", - "ipc_message_attachment.cc", - "ipc_message_attachment.h", - "ipc_message_attachment_set.cc", - "ipc_message_attachment_set.h", "ipc_message_macros.h", "ipc_message_pipe_reader.cc", "ipc_message_pipe_reader.h", @@ -61,27 +51,13 @@ component("ipc") { "ipc_message_utils.h", "ipc_mojo_bootstrap.cc", "ipc_mojo_bootstrap.h", - "ipc_mojo_handle_attachment.cc", - "ipc_mojo_handle_attachment.h", - "ipc_mojo_message_helper.cc", - "ipc_mojo_message_helper.h", "ipc_mojo_param_traits.cc", "ipc_mojo_param_traits.h", - "ipc_platform_file.cc", - "ipc_platform_file.h", - "ipc_platform_file_attachment_posix.cc", - "ipc_platform_file_attachment_posix.h", "ipc_sender.h", "ipc_sync_channel.cc", "ipc_sync_channel.h", - "ipc_sync_message.cc", - "ipc_sync_message.h", "ipc_sync_message_filter.cc", "ipc_sync_message_filter.h", - "mach_port_attachment_mac.cc", - "mach_port_attachment_mac.h", - "mach_port_mac.cc", - "mach_port_mac.h", "message_filter.cc", "message_filter.h", "message_filter_router.cc", @@ -105,20 +81,13 @@ component("ipc") { ] } - if (is_fuchsia) { - sources += [ - "handle_attachment_fuchsia.cc", - "handle_attachment_fuchsia.h", - "handle_fuchsia.cc", - "handle_fuchsia.h", - ] - } - defines = [ "IPC_IMPLEMENTATION" ] public_deps = [ ":ipc_features", + ":message_support", ":mojom", + ":native_handle_type_converters", ":param_traits", "//mojo/public/cpp/bindings", "//mojo/public/cpp/system", @@ -134,15 +103,76 @@ component("ipc") { "//base", ] + if (enable_ipc_fuzzer) { + public_configs = [ "//tools/ipc_fuzzer:ipc_fuzzer_config" ] + } +} + +component("message_support") { + sources = [ + "handle_attachment_win.cc", + "handle_attachment_win.h", + "handle_win.cc", + "handle_win.h", + "ipc_message.cc", + "ipc_message.h", + "ipc_message_attachment.cc", + "ipc_message_attachment.h", + "ipc_message_attachment_set.cc", + "ipc_message_attachment_set.h", + "ipc_message_support_export.h", + "ipc_mojo_handle_attachment.cc", + "ipc_mojo_handle_attachment.h", + "ipc_mojo_message_helper.cc", + "ipc_mojo_message_helper.h", + "ipc_platform_file.cc", + "ipc_platform_file.h", + "ipc_platform_file_attachment_posix.cc", + "ipc_platform_file_attachment_posix.h", + "ipc_sync_message.cc", + "ipc_sync_message.h", + "mach_port_attachment_mac.cc", + "mach_port_attachment_mac.h", + "mach_port_mac.cc", + "mach_port_mac.h", + ] + + if (is_fuchsia) { + sources += [ + "handle_attachment_fuchsia.cc", + "handle_attachment_fuchsia.h", + "handle_fuchsia.cc", + "handle_fuchsia.h", + ] + } + + defines = [ "IPC_MESSAGE_SUPPORT_IMPL" ] + + public_deps = [ + ":ipc_features", + ":param_traits", + "//base", + "//mojo/public/cpp/system", + ] + if (is_win || is_mac) { # On Windows HandleAttachmentWin needs to generate random IDs. # On Mac MachPortAttachmentMac needs to generate random IDs. - deps += [ "//crypto" ] + deps = [ + "//crypto", + ] } +} - if (enable_ipc_fuzzer) { - public_configs = [ "//tools/ipc_fuzzer:ipc_fuzzer_config" ] - } +source_set("native_handle_type_converters") { + sources = [ + "native_handle_type_converters.cc", + "native_handle_type_converters.h", + ] + public_deps = [ + ":message_support", + "//mojo/public/interfaces/bindings:bindings_shared__generator", + ] } mojom_component("mojom") { @@ -154,6 +184,16 @@ mojom_component("mojom") { public_deps = [ "//mojo/common:read_only_buffer", ] + + # Don't generate a variant sources since we depend on generated internal + # bindings types and we don't generate or build variants of those. + disable_variants = true +} + +mojom("mojom_constants") { + sources = [ + "constants.mojom", + ] } mojom("test_interfaces") { @@ -250,7 +290,12 @@ if (!is_ios) { test("ipc_perftests") { sources = [ + "ipc_cpu_perftest.cc", "ipc_mojo_perftest.cc", + "ipc_perftest_messages.cc", + "ipc_perftest_messages.h", + "ipc_perftest_util.cc", + "ipc_perftest_util.h", "run_all_perftests.cc", ] diff --git a/chromium/ipc/DEPS b/chromium/ipc/DEPS index f8d30bb7b47..662e3415c3d 100644 --- a/chromium/ipc/DEPS +++ b/chromium/ipc/DEPS @@ -14,7 +14,8 @@ specific_include_rules = { "+mojo/edk/embedder", "+mojo/edk/test", ], - "ipc_perftest_support\.cc": [ + "ipc_.*perftest.*\.cc": [ + "+mojo/edk/embedder", "+mojo/edk/test", ], "run_all_(unit|perf)tests\.cc": [ diff --git a/chromium/ipc/OWNERS b/chromium/ipc/OWNERS index 0617e7bf9d3..fa8fd311b6d 100644 --- a/chromium/ipc/OWNERS +++ b/chromium/ipc/OWNERS @@ -1,5 +1,3 @@ -cpu@chromium.org -darin@chromium.org jam@chromium.org rockot@chromium.org tsepez@chromium.org @@ -8,12 +6,16 @@ tsepez@chromium.org # new sandbox escapes. per-file ipc_message_start.h=set noparent per-file ipc_message_start.h=file://ipc/SECURITY_OWNERS +per-file *_messages.cc=set noparent +per-file *_messages.cc=file://ipc/SECURITY_OWNERS per-file *_messages*.h=set noparent per-file *_messages*.h=file://ipc/SECURITY_OWNERS per-file *.mojom=set noparent per-file *.mojom=file://ipc/SECURITY_OWNERS per-file *_param_traits*.*=set noparent per-file *_param_traits*.*=file://ipc/SECURITY_OWNERS +per-file *_type_converter*.*=set noparent +per-file *_type_converter*.*=file://ipc/SECURITY_OWNERS per-file SECURITY_OWNERS=file://ipc/SECURITY_OWNERS diff --git a/chromium/ipc/README.md b/chromium/ipc/README.md index 250a15927f2..c30689a29a7 100644 --- a/chromium/ipc/README.md +++ b/chromium/ipc/README.md @@ -548,20 +548,8 @@ the wire format used is defined entirely by `IPC::ParamTraits<T>` for whatever `foo::mojom::MyGiganticStructure` to `foo::MyGiganticStructure`, your typemap must point to some header which defines `IPC::ParamTraits<foo::MyGiganticStructure>`. - -Note that if your `ParamTraits` are defined manually (*i.e.* not by invocation -of `IPC_STRUCT_TRAITS*` macros) you must also ensure that they define the new -`GetSize` method: - -``` cpp -static void GetSize(base::PickleSizer* sizer, const param_type& p) { - // ... -} ``` -`base::PickleSizer` has an interface analogous to `base::Pickle`, except that it -merely accumulates a byte count rather than accumulating serialized data. - There are several examples of this traits implementation in common IPC traits defined [here](https://code.google.com/p/chromium/codesearch#chromium/src/ipc/ipc_message_utils.h). diff --git a/chromium/ipc/constants.mojom b/chromium/ipc/constants.mojom new file mode 100644 index 00000000000..502187f2e2a --- /dev/null +++ b/chromium/ipc/constants.mojom @@ -0,0 +1,8 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module IPC.mojom; + +// NOTE: This MUST match the value of MSG_ROUTING_NONE in src/ipc/ipc_message.h. +const int32 kRoutingIdNone = -2; diff --git a/chromium/ipc/handle_attachment_fuchsia.cc b/chromium/ipc/handle_attachment_fuchsia.cc index 88cf5184dd6..305e98c6e9a 100644 --- a/chromium/ipc/handle_attachment_fuchsia.cc +++ b/chromium/ipc/handle_attachment_fuchsia.cc @@ -4,20 +4,20 @@ #include "ipc/handle_attachment_fuchsia.h" -#include <magenta/syscalls.h> -#include <magenta/types.h> +#include <zircon/syscalls.h> +#include <zircon/types.h> namespace IPC { namespace internal { -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 zx_handle_t& handle) { + zx_status_t result = + zx_handle_duplicate(handle, ZX_RIGHT_SAME_RIGHTS, handle_.receive()); + DLOG_IF(ERROR, result != ZX_OK) + << "zx_handle_duplicate: " << zx_status_get_string(result); } -HandleAttachmentFuchsia::HandleAttachmentFuchsia(base::ScopedMxHandle handle) +HandleAttachmentFuchsia::HandleAttachmentFuchsia(base::ScopedZxHandle handle) : handle_(std::move(handle)) {} HandleAttachmentFuchsia::~HandleAttachmentFuchsia() {} diff --git a/chromium/ipc/handle_attachment_fuchsia.h b/chromium/ipc/handle_attachment_fuchsia.h index 915e41663b8..61db9065cc6 100644 --- a/chromium/ipc/handle_attachment_fuchsia.h +++ b/chromium/ipc/handle_attachment_fuchsia.h @@ -7,33 +7,34 @@ #include <stdint.h> -#include "base/fuchsia/scoped_mx_handle.h" +#include "base/fuchsia/scoped_zx_handle.h" #include "ipc/handle_fuchsia.h" -#include "ipc/ipc_export.h" #include "ipc/ipc_message_attachment.h" +#include "ipc/ipc_message_support_export.h" namespace IPC { namespace internal { -// This class represents a Fuchsia mx_handle_t attached to a Chrome IPC message. -class IPC_EXPORT HandleAttachmentFuchsia : public MessageAttachment { +// This class represents a Fuchsia zx_handle_t attached to a Chrome IPC message. +class IPC_MESSAGE_SUPPORT_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. - explicit HandleAttachmentFuchsia(const mx_handle_t& handle); + explicit HandleAttachmentFuchsia(const zx_handle_t& handle); // This constructor takes ownership of |handle|. Should only be called by the // receiver of a Chrome IPC message. - explicit HandleAttachmentFuchsia(base::ScopedMxHandle handle); + explicit HandleAttachmentFuchsia(base::ScopedZxHandle handle); Type GetType() const override; - mx_handle_t Take() { return handle_.release(); } + zx_handle_t Take() { return handle_.release(); } private: ~HandleAttachmentFuchsia() override; - base::ScopedMxHandle handle_; + base::ScopedZxHandle handle_; }; } // namespace internal diff --git a/chromium/ipc/handle_attachment_win.h b/chromium/ipc/handle_attachment_win.h index 3ee9f43683a..730afc82994 100644 --- a/chromium/ipc/handle_attachment_win.h +++ b/chromium/ipc/handle_attachment_win.h @@ -9,14 +9,15 @@ #include "base/win/scoped_handle.h" #include "ipc/handle_win.h" -#include "ipc/ipc_export.h" #include "ipc/ipc_message_attachment.h" +#include "ipc/ipc_message_support_export.h" namespace IPC { namespace internal { // This class represents a Windows HANDLE attached to a Chrome IPC message. -class IPC_EXPORT HandleAttachmentWin : public MessageAttachment { +class IPC_MESSAGE_SUPPORT_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. diff --git a/chromium/ipc/handle_fuchsia.cc b/chromium/ipc/handle_fuchsia.cc index 26dc9cf9a68..20ed1742248 100644 --- a/chromium/ipc/handle_fuchsia.cc +++ b/chromium/ipc/handle_fuchsia.cc @@ -15,9 +15,9 @@ namespace IPC { -HandleFuchsia::HandleFuchsia() : handle_(MX_HANDLE_INVALID) {} +HandleFuchsia::HandleFuchsia() : handle_(ZX_HANDLE_INVALID) {} -HandleFuchsia::HandleFuchsia(const mx_handle_t& handle) : handle_(handle) {} +HandleFuchsia::HandleFuchsia(const zx_handle_t& handle) : handle_(handle) {} // static void ParamTraits<HandleFuchsia>::Write(base::Pickle* m, const param_type& p) { diff --git a/chromium/ipc/handle_fuchsia.h b/chromium/ipc/handle_fuchsia.h index babfe14f043..52c87d84e91 100644 --- a/chromium/ipc/handle_fuchsia.h +++ b/chromium/ipc/handle_fuchsia.h @@ -5,11 +5,11 @@ #ifndef IPC_HANDLE_FUCHSIA_H_ #define IPC_HANDLE_FUCHSIA_H_ -#include <magenta/types.h> +#include <zircon/types.h> #include <string> -#include "ipc/ipc_export.h" +#include "ipc/ipc_message_support_export.h" #include "ipc/ipc_param_traits.h" namespace base { @@ -19,21 +19,21 @@ class PickleIterator; namespace IPC { -class IPC_EXPORT HandleFuchsia { +class IPC_MESSAGE_SUPPORT_EXPORT HandleFuchsia { public: - // Default constructor makes an invalid mx_handle_t. + // Default constructor makes an invalid zx_handle_t. HandleFuchsia(); - explicit HandleFuchsia(const mx_handle_t& handle); + explicit HandleFuchsia(const zx_handle_t& handle); - mx_handle_t get_handle() const { return handle_; } - void set_handle(mx_handle_t handle) { handle_ = handle; } + zx_handle_t get_handle() const { return handle_; } + void set_handle(zx_handle_t handle) { handle_ = handle; } private: - mx_handle_t handle_; + zx_handle_t handle_; }; template <> -struct IPC_EXPORT ParamTraits<HandleFuchsia> { +struct IPC_MESSAGE_SUPPORT_EXPORT ParamTraits<HandleFuchsia> { typedef HandleFuchsia param_type; static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, diff --git a/chromium/ipc/handle_win.h b/chromium/ipc/handle_win.h index 0120597c152..68afc67cbbd 100644 --- a/chromium/ipc/handle_win.h +++ b/chromium/ipc/handle_win.h @@ -9,7 +9,7 @@ #include <string> -#include "ipc/ipc_export.h" +#include "ipc/ipc_message_support_export.h" #include "ipc/ipc_param_traits.h" namespace base { @@ -26,7 +26,7 @@ namespace IPC { // The ownership semantics for the underlying |handle_| are complex. See // ipc/mach_port_mac.h (the OSX analog of this class) for an extensive // discussion. -class IPC_EXPORT HandleWin { +class IPC_MESSAGE_SUPPORT_EXPORT HandleWin { public: // Default constructor makes an invalid HANDLE. HandleWin(); @@ -40,7 +40,7 @@ class IPC_EXPORT HandleWin { }; template <> -struct IPC_EXPORT ParamTraits<HandleWin> { +struct IPC_MESSAGE_SUPPORT_EXPORT ParamTraits<HandleWin> { typedef HandleWin param_type; static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, diff --git a/chromium/ipc/ipc.mojom b/chromium/ipc/ipc.mojom index 3ab4d4ef063..2332111b2d9 100644 --- a/chromium/ipc/ipc.mojom +++ b/chromium/ipc/ipc.mojom @@ -5,23 +5,7 @@ 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; - -struct SerializedHandle { - handle the_handle; - - enum Type { - MOJO_HANDLE, - PLATFORM_FILE, - WIN_HANDLE, - MACH_PORT, - FUCHSIA_HANDLE, - }; - - Type type; -}; +import "mojo/public/interfaces/bindings/native_struct.mojom"; // A placeholder interface type since we don't yet support generic associated // message pipe handles. @@ -34,7 +18,7 @@ interface Channel { // Transmits a classical Chrome IPC message. Receive(mojo.common.mojom.ReadOnlyBuffer data, - array<SerializedHandle>? handles); + array<mojo.native.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 ca788e69b64..284d79bb3fa 100644 --- a/chromium/ipc/ipc_channel.cc +++ b/chromium/ipc/ipc_channel.cc @@ -48,14 +48,4 @@ std::string Channel::GenerateUniqueRandomChannelID() { base::RandInt(0, std::numeric_limits<int32_t>::max())); } -Channel::OutputElement::OutputElement(Message* message) - : message_(message), buffer_(nullptr), length_(0) {} - -Channel::OutputElement::OutputElement(void* buffer, size_t length) - : message_(nullptr), buffer_(buffer), length_(length) {} - -Channel::OutputElement::~OutputElement() { - free(buffer_); -} - } // namespace IPC diff --git a/chromium/ipc/ipc_channel.h b/chromium/ipc/ipc_channel.h index 82f8011c589..a0b7ca1fae1 100644 --- a/chromium/ipc/ipc_channel.h +++ b/chromium/ipc/ipc_channel.h @@ -254,26 +254,6 @@ class IPC_EXPORT Channel : public Sender { #endif protected: - // An OutputElement is a wrapper around a Message or raw buffer while it is - // waiting to be passed to the system's underlying IPC mechanism. - class OutputElement { - public: - // Takes ownership of message. - OutputElement(Message* message); - // Takes ownership of the buffer. |buffer| is freed via free(), so it - // must be malloced. - OutputElement(void* buffer, size_t length); - ~OutputElement(); - size_t size() const { return message_ ? message_->size() : length_; } - const void* data() const { return message_ ? message_->data() : buffer_; } - Message* get_message() const { return message_.get(); } - - private: - std::unique_ptr<Message> message_; - void* buffer_; - size_t length_; - }; - // Subclasses must call this method at the beginning of their implementation // of Connect(). void WillConnect(); diff --git a/chromium/ipc/ipc_channel_mojo.cc b/chromium/ipc/ipc_channel_mojo.cc index 29451c6cf64..6471d838ac7 100644 --- a/chromium/ipc/ipc_channel_mojo.cc +++ b/chromium/ipc/ipc_channel_mojo.cc @@ -25,26 +25,10 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_mojo_bootstrap.h" #include "ipc/ipc_mojo_handle_attachment.h" +#include "ipc/native_handle_type_converters.h" #include "mojo/public/cpp/bindings/binding.h" #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 - -#if defined(OS_MACOSX) -#include "ipc/mach_port_attachment_mac.h" -#endif - -#if defined(OS_WIN) -#include "ipc/handle_attachment_win.h" -#endif - -#if defined(OS_FUCHSIA) -#include "ipc/handle_attachment_fuchsia.h" -#endif - namespace IPC { namespace { @@ -76,188 +60,6 @@ class MojoChannelFactory : public ChannelFactory { DISALLOW_COPY_AND_ASSIGN(MojoChannelFactory); }; -mojom::SerializedHandlePtr CreateSerializedHandle( - mojo::ScopedHandle handle, - mojom::SerializedHandle::Type type) { - mojom::SerializedHandlePtr serialized_handle = mojom::SerializedHandle::New(); - serialized_handle->the_handle = std::move(handle); - serialized_handle->type = type; - return serialized_handle; -} - -MojoResult WrapPlatformHandle(base::PlatformFile handle, - mojom::SerializedHandle::Type type, - mojom::SerializedHandlePtr* serialized) { - mojo::ScopedHandle wrapped_handle = mojo::WrapPlatformFile(handle); - if (!wrapped_handle.is_valid()) - return MOJO_RESULT_UNKNOWN; - - *serialized = CreateSerializedHandle(std::move(wrapped_handle), type); - return MOJO_RESULT_OK; -} - -#if defined(OS_MACOSX) -MojoResult WrapMachPort(mach_port_t mach_port, - mojom::SerializedHandlePtr* serialized) { - MojoPlatformHandle platform_handle = { - sizeof(MojoPlatformHandle), MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, - static_cast<uint64_t>(mach_port) - }; - - MojoHandle wrapped_handle; - MojoResult result = MojoWrapPlatformHandle(&platform_handle, &wrapped_handle); - if (result != MOJO_RESULT_OK) - return result; - - *serialized = CreateSerializedHandle( - mojo::MakeScopedHandle(mojo::Handle(wrapped_handle)), - 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)}; - - MojoHandle wrapped_handle; - MojoResult result = MojoWrapPlatformHandle(&platform_handle, &wrapped_handle); - if (result != MOJO_RESULT_OK) - return result; - - *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(HANDLE_EINTR(dup(attachment->file()))); -} -#endif // defined(OS_POSIX) - -MojoResult WrapAttachmentImpl(MessageAttachment* attachment, - mojom::SerializedHandlePtr* serialized) { - if (attachment->GetType() == MessageAttachment::Type::MOJO_HANDLE) { - *serialized = CreateSerializedHandle( - static_cast<internal::MojoHandleAttachment&>(*attachment).TakeHandle(), - mojom::SerializedHandle::Type::MOJO_HANDLE); - return MOJO_RESULT_OK; - } -#if defined(OS_POSIX) - if (attachment->GetType() == MessageAttachment::Type::PLATFORM_FILE) { - // We dup() the handles in IPC::Message to transmit. - // IPC::MessageAttachmentSet has intricate lifecycle semantics - // of FDs, so just to dup()-and-own them is the safest option. - base::ScopedFD file = TakeOrDupFile( - static_cast<IPC::internal::PlatformFileAttachment*>(attachment)); - if (!file.is_valid()) { - DPLOG(WARNING) << "Failed to dup FD to transmit."; - return MOJO_RESULT_UNKNOWN; - } - - return WrapPlatformHandle(file.release(), - mojom::SerializedHandle::Type::PLATFORM_FILE, - serialized); - } -#endif // defined(OS_POSIX) -#if defined(OS_MACOSX) - DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::MACH_PORT); - internal::MachPortAttachmentMac& mach_port_attachment = - static_cast<internal::MachPortAttachmentMac&>(*attachment); - MojoResult result = WrapMachPort(mach_port_attachment.get_mach_port(), - 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.Take(), - mojom::SerializedHandle::Type::WIN_HANDLE, serialized); - return result; -#else - NOTREACHED(); - return MOJO_RESULT_UNKNOWN; -#endif // defined(OS_MACOSX) -} - -MojoResult WrapAttachment(MessageAttachment* attachment, - std::vector<mojom::SerializedHandlePtr>* handles) { - mojom::SerializedHandlePtr serialized_handle; - MojoResult wrap_result = WrapAttachmentImpl(attachment, &serialized_handle); - if (wrap_result != MOJO_RESULT_OK) { - LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; - return wrap_result; - } - handles->push_back(std::move(serialized_handle)); - return MOJO_RESULT_OK; -} - -MojoResult UnwrapAttachment(mojom::SerializedHandlePtr handle, - scoped_refptr<MessageAttachment>* attachment) { - if (handle->type == mojom::SerializedHandle::Type::MOJO_HANDLE) { - *attachment = - new IPC::internal::MojoHandleAttachment(std::move(handle->the_handle)); - return MOJO_RESULT_OK; - } - MojoPlatformHandle platform_handle = { sizeof(MojoPlatformHandle), 0, 0 }; - MojoResult unwrap_result = MojoUnwrapPlatformHandle( - handle->the_handle.release().value(), &platform_handle); - if (unwrap_result != MOJO_RESULT_OK) - return unwrap_result; -#if defined(OS_POSIX) - if (handle->type == mojom::SerializedHandle::Type::PLATFORM_FILE) { - base::PlatformFile file = base::kInvalidPlatformFile; - if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR) - file = static_cast<base::PlatformFile>(platform_handle.value); - *attachment = new internal::PlatformFileAttachment(file); - return MOJO_RESULT_OK; - } -#endif // defined(OS_POSIX) -#if defined(OS_MACOSX) - if (handle->type == mojom::SerializedHandle::Type::MACH_PORT) { - mach_port_t mach_port = MACH_PORT_NULL; - if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT) - mach_port = static_cast<mach_port_t>(platform_handle.value); - *attachment = new internal::MachPortAttachmentMac( - mach_port, internal::MachPortAttachmentMac::FROM_WIRE); - return MOJO_RESULT_OK; - } -#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) - handle = reinterpret_cast<base::PlatformFile>(platform_handle.value); - *attachment = new internal::HandleAttachmentWin( - handle, internal::HandleAttachmentWin::FROM_WIRE); - return MOJO_RESULT_OK; - } -#endif // defined(OS_WIN) - NOTREACHED(); - return MOJO_RESULT_UNKNOWN; -} - base::ProcessId GetSelfPID() { #if defined(OS_LINUX) if (int global_pid = Channel::GetGlobalPid()) @@ -451,18 +253,24 @@ void ChannelMojo::OnMessageReceived(const Message& message) { // static MojoResult ChannelMojo::ReadFromMessageAttachmentSet( Message* message, - base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles) { + base::Optional<std::vector<mojo::native::SerializedHandlePtr>>* handles) { DCHECK(!*handles); MojoResult result = MOJO_RESULT_OK; if (!message->HasAttachments()) return result; - std::vector<mojom::SerializedHandlePtr> output_handles; + std::vector<mojo::native::SerializedHandlePtr> output_handles; MessageAttachmentSet* set = message->attachment_set(); for (unsigned i = 0; result == MOJO_RESULT_OK && i < set->size(); ++i) { - result = WrapAttachment(set->GetAttachmentAt(i).get(), &output_handles); + auto attachment = set->GetAttachmentAt(i); + auto serialized_handle = mojo::native::SerializedHandle::New(); + serialized_handle->the_handle = attachment->TakeMojoHandle(); + serialized_handle->type = + mojo::ConvertTo<mojo::native::SerializedHandle::Type>( + attachment->GetType()); + output_handles.emplace_back(std::move(serialized_handle)); } set->CommitAllDescriptors(); @@ -474,20 +282,20 @@ MojoResult ChannelMojo::ReadFromMessageAttachmentSet( // static MojoResult ChannelMojo::WriteToMessageAttachmentSet( - base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer, + base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles, Message* message) { - if (!handle_buffer) + if (!handles) return MOJO_RESULT_OK; - for (size_t i = 0; i < handle_buffer->size(); ++i) { - scoped_refptr<MessageAttachment> unwrapped_attachment; - MojoResult unwrap_result = - UnwrapAttachment(std::move((*handle_buffer)[i]), &unwrapped_attachment); - if (unwrap_result != MOJO_RESULT_OK) { - LOG(WARNING) << "Pipe failed to unwrap handles. Closing: " - << unwrap_result; - return unwrap_result; + for (size_t i = 0; i < handles->size(); ++i) { + auto& handle = handles->at(i); + scoped_refptr<MessageAttachment> unwrapped_attachment = + MessageAttachment::CreateFromMojoHandle( + std::move(handle->the_handle), + mojo::ConvertTo<MessageAttachment::Type>(handle->type)); + if (!unwrapped_attachment) { + DLOG(WARNING) << "Pipe failed to unwrap handles."; + return MOJO_RESULT_UNKNOWN; } - DCHECK(unwrapped_attachment); bool ok = message->attachment_set()->AddAttachment( std::move(unwrapped_attachment)); diff --git a/chromium/ipc/ipc_channel_mojo.h b/chromium/ipc/ipc_channel_mojo.h index e8b7b92afcd..61bc0dba41e 100644 --- a/chromium/ipc/ipc_channel_mojo.h +++ b/chromium/ipc/ipc_channel_mojo.h @@ -28,6 +28,7 @@ #include "ipc/ipc_mojo_bootstrap.h" #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" #include "mojo/public/cpp/system/core.h" +#include "mojo/public/interfaces/bindings/native_struct.mojom.h" namespace IPC { @@ -77,11 +78,11 @@ class IPC_EXPORT ChannelMojo : public Channel, // These access protected API of IPC::Message, which has ChannelMojo // as a friend class. static MojoResult WriteToMessageAttachmentSet( - base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer, + base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles, Message* message); static MojoResult ReadFromMessageAttachmentSet( Message* message, - base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles); + base::Optional<std::vector<mojo::native::SerializedHandlePtr>>* handles); // MessagePipeReader::Delegate void OnPeerPidReceived(int32_t peer_pid) override; diff --git a/chromium/ipc/ipc_channel_mojo_unittest.cc b/chromium/ipc/ipc_channel_mojo_unittest.cc index 21a853f1dcf..fed532b556d 100644 --- a/chromium/ipc/ipc_channel_mojo_unittest.cc +++ b/chromium/ipc/ipc_channel_mojo_unittest.cc @@ -13,6 +13,7 @@ #include "base/base_paths.h" #include "base/bind.h" #include "base/callback_helpers.h" +#include "base/containers/queue.h" #include "base/files/file.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" @@ -1226,7 +1227,7 @@ TEST_F(IPCChannelProxyMojoTest, Pause) { class ExpectValueSequenceListener : public IPC::Listener { public: - explicit ExpectValueSequenceListener(std::queue<int32_t>* expected_values) + explicit ExpectValueSequenceListener(base::queue<int32_t>* expected_values) : expected_values_(expected_values) {} ~ExpectValueSequenceListener() override {} @@ -1244,14 +1245,14 @@ class ExpectValueSequenceListener : public IPC::Listener { } private: - std::queue<int32_t>* expected_values_; + base::queue<int32_t>* expected_values_; DISALLOW_COPY_AND_ASSIGN(ExpectValueSequenceListener); }; DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(CreatePausedClient, ChannelProxyClient) { - std::queue<int32_t> expected_values; + base::queue<int32_t> expected_values; ExpectValueSequenceListener listener(&expected_values); CreateProxy(&listener); expected_values.push(1); diff --git a/chromium/ipc/ipc_channel_nacl.h b/chromium/ipc/ipc_channel_nacl.h index e989f128559..06e7f6a2718 100644 --- a/chromium/ipc/ipc_channel_nacl.h +++ b/chromium/ipc/ipc_channel_nacl.h @@ -5,10 +5,10 @@ #ifndef IPC_IPC_CHANNEL_NACL_H_ #define IPC_IPC_CHANNEL_NACL_H_ -#include <deque> #include <memory> #include <string> +#include "base/containers/circular_deque.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/process/process.h" @@ -96,13 +96,13 @@ class ChannelNacl : public Channel, // the trouble given that we probably want to implement 1 and // 2 above in NaCl eventually. // When ReadData is called, it pulls the bytes out of this queue in order. - std::deque<std::unique_ptr<std::vector<char>>> read_queue_; + base::circular_deque<std::unique_ptr<std::vector<char>>> read_queue_; // Queue of file descriptor attachments extracted from imc_recvmsg messages. std::vector<scoped_refptr<MessageAttachment>> input_attachments_; // This queue is used when a message is sent prior to Connect having been // called. Normally after we're connected, the queue is empty. - std::deque<std::unique_ptr<Message>> output_queue_; + base::circular_deque<std::unique_ptr<Message>> output_queue_; base::WeakPtrFactory<ChannelNacl> weak_ptr_factory_; diff --git a/chromium/ipc/ipc_channel_proxy.cc b/chromium/ipc/ipc_channel_proxy.cc index 89b37565b6f..e6e8cb0abf7 100644 --- a/chromium/ipc/ipc_channel_proxy.cc +++ b/chromium/ipc/ipc_channel_proxy.cc @@ -14,7 +14,6 @@ #include "base/location.h" #include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" -#include "base/profiler/scoped_tracker.h" #include "base/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" @@ -188,10 +187,6 @@ void ChannelProxy::Context::OnChannelOpened() { // Called on the IPC::Channel thread void ChannelProxy::Context::OnChannelClosed() { - // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. - tracked_objects::ScopedTracker tracking_profile( - FROM_HERE_WITH_EXPLICIT_FUNCTION( - "477117 ChannelProxy::Context::OnChannelClosed")); // It's okay for IPC::ChannelProxy::Close to be called more than once, which // would result in this branch being taken. if (!channel_) @@ -226,10 +221,6 @@ void ChannelProxy::Context::Clear() { // Called on the IPC::Channel thread void ChannelProxy::Context::OnSendMessage(std::unique_ptr<Message> message) { - // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. - tracked_objects::ScopedTracker tracking_profile( - FROM_HERE_WITH_EXPLICIT_FUNCTION( - "477117 ChannelProxy::Context::OnSendMessage")); if (!channel_) { OnChannelClosed(); return; @@ -303,7 +294,7 @@ void ChannelProxy::Context::OnRemoveFilter(MessageFilter* filter) { // Called on the listener's thread void ChannelProxy::Context::AddFilter(MessageFilter* filter) { base::AutoLock auto_lock(pending_filters_lock_); - pending_filters_.push_back(make_scoped_refptr(filter)); + pending_filters_.push_back(base::WrapRefCounted(filter)); ipc_task_runner_->PostTask( FROM_HERE, base::Bind(&Context::OnAddFilter, this)); } diff --git a/chromium/ipc/ipc_channel_proxy_unittest.cc b/chromium/ipc/ipc_channel_proxy_unittest.cc index ba3be18bbe6..95182d31e12 100644 --- a/chromium/ipc/ipc_channel_proxy_unittest.cc +++ b/chromium/ipc/ipc_channel_proxy_unittest.cc @@ -280,9 +280,9 @@ TEST_F(IPCChannelProxyTest, MessageClassFilters) { // Construct a filter per message class. std::vector<scoped_refptr<MessageCountFilter>> class_filters; class_filters.push_back( - make_scoped_refptr(new MessageCountFilter(TestMsgStart))); + base::MakeRefCounted<MessageCountFilter>(TestMsgStart)); class_filters.push_back( - make_scoped_refptr(new MessageCountFilter(AutomationMsgStart))); + base::MakeRefCounted<MessageCountFilter>(AutomationMsgStart)); for (size_t i = 0; i < class_filters.size(); ++i) channel_proxy()->AddFilter(class_filters[i].get()); diff --git a/chromium/ipc/ipc_cpu_perftest.cc b/chromium/ipc/ipc_cpu_perftest.cc new file mode 100644 index 00000000000..976ca1f6de4 --- /dev/null +++ b/chromium/ipc/ipc_cpu_perftest.cc @@ -0,0 +1,416 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <memory> + +#include "base/message_loop/message_loop.h" +#include "base/process/process_metrics.h" +#include "base/run_loop.h" +#include "base/strings/stringprintf.h" +#include "base/synchronization/waitable_event.h" +#include "base/test/perf_log.h" +#include "base/timer/timer.h" +#include "ipc/ipc_channel_proxy.h" +#include "ipc/ipc_perftest_messages.h" +#include "ipc/ipc_perftest_util.h" +#include "ipc/ipc_sync_channel.h" +#include "ipc/ipc_test.mojom.h" +#include "ipc/ipc_test_base.h" +#include "mojo/edk/test/mojo_test_base.h" +#include "mojo/edk/test/multiprocess_test_helper.h" +#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/system/message_pipe.h" + +namespace IPC { +namespace { + +struct TestParams { + TestParams() {} + TestParams(size_t in_message_size, + size_t in_frames_per_second, + size_t in_messages_per_frame, + size_t in_duration_in_seconds) + : message_size(in_message_size), + frames_per_second(in_frames_per_second), + messages_per_frame(in_messages_per_frame), + duration_in_seconds(in_duration_in_seconds) {} + + size_t message_size; + size_t frames_per_second; + size_t messages_per_frame; + size_t duration_in_seconds; +}; + +std::vector<TestParams> GetDefaultTestParams() { + std::vector<TestParams> list; + list.push_back({144, 20, 10, 10}); + list.push_back({144, 60, 10, 10}); + return list; +} + +std::string GetLogTitle(const std::string& label, const TestParams& params) { + return base::StringPrintf( + "%s_MsgSize_%zu_FrmPerSec_%zu_MsgPerFrm_%zu", label.c_str(), + params.message_size, params.frames_per_second, params.messages_per_frame); +} + +base::TimeDelta GetFrameTime(size_t frames_per_second) { + return base::TimeDelta::FromSecondsD(1.0 / frames_per_second); +} + +class PerfCpuLogger { + public: + explicit PerfCpuLogger(base::StringPiece test_name) + : test_name_(test_name), + process_metrics_(base::ProcessMetrics::CreateCurrentProcessMetrics()) { + process_metrics_->GetPlatformIndependentCPUUsage(); + } + + ~PerfCpuLogger() { + double result = process_metrics_->GetPlatformIndependentCPUUsage(); + base::LogPerfResult(test_name_.c_str(), result, "%"); + } + + private: + std::string test_name_; + std::unique_ptr<base::ProcessMetrics> process_metrics_; + + DISALLOW_COPY_AND_ASSIGN(PerfCpuLogger); +}; + +MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) { + MojoPerfTestClient client; + int rv = mojo::edk::test::MultiprocessTestHelper::RunClientMain( + base::Bind(&MojoPerfTestClient::Run, base::Unretained(&client)), + true /* pass_pipe_ownership_to_main */); + + base::RunLoop run_loop; + run_loop.RunUntilIdle(); + + return rv; +} + +class ChannelSteadyPingPongListener : public Listener { + public: + ChannelSteadyPingPongListener() = default; + + ~ChannelSteadyPingPongListener() override = default; + + void Init(Sender* sender) { + DCHECK(!sender_); + sender_ = sender; + } + + void SetTestParams(const TestParams& params, + const std::string& label, + bool sync, + const base::Closure& quit_closure) { + params_ = params; + label_ = label; + sync_ = sync; + quit_closure_ = quit_closure; + payload_ = std::string(params.message_size, 'a'); + } + + bool OnMessageReceived(const Message& message) override { + CHECK(sender_); + + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(ChannelSteadyPingPongListener, message) + IPC_MESSAGE_HANDLER(TestMsg_Hello, OnHello) + IPC_MESSAGE_HANDLER(TestMsg_Ping, OnPing) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; + } + + void OnHello() { + cpu_logger_ = std::make_unique<PerfCpuLogger>(GetLogTitle(label_, params_)); + + frame_count_down_ = params_.frames_per_second * params_.duration_in_seconds; + + timer_.Start(FROM_HERE, GetFrameTime(params_.frames_per_second), this, + &ChannelSteadyPingPongListener::StartPingPong); + } + + void StartPingPong() { + if (sync_) { + base::TimeTicks before = base::TimeTicks::Now(); + for (count_down_ = params_.messages_per_frame; count_down_ > 0; + --count_down_) { + std::string response; + sender_->Send(new TestMsg_SyncPing(payload_, &response)); + DCHECK_EQ(response, payload_); + } + + if (base::TimeTicks::Now() - before > + GetFrameTime(params_.frames_per_second)) { + LOG(ERROR) << "Frame " << frame_count_down_ + << " wasn't able to complete on time!"; + } + + CHECK_GT(frame_count_down_, 0); + frame_count_down_--; + if (frame_count_down_ == 0) + StopPingPong(); + } else { + if (count_down_ != 0) { + LOG(ERROR) << "Frame " << frame_count_down_ + << " wasn't able to complete on time!"; + } else { + SendPong(); + } + count_down_ = params_.messages_per_frame; + } + } + + void StopPingPong() { + cpu_logger_.reset(); + timer_.AbandonAndStop(); + quit_closure_.Run(); + } + + void OnPing(const std::string& payload) { + // Include message deserialization in latency. + DCHECK_EQ(payload_.size(), payload.size()); + + CHECK_GT(count_down_, 0); + count_down_--; + if (count_down_ > 0) { + SendPong(); + } else { + CHECK_GT(frame_count_down_, 0); + frame_count_down_--; + if (frame_count_down_ == 0) + StopPingPong(); + } + } + + void SendPong() { sender_->Send(new TestMsg_Ping(payload_)); } + + private: + Sender* sender_ = nullptr; + TestParams params_; + std::string payload_; + std::string label_; + bool sync_ = false; + + int count_down_ = 0; + int frame_count_down_ = 0; + + base::RepeatingTimer timer_; + std::unique_ptr<PerfCpuLogger> cpu_logger_; + + base::Closure quit_closure_; +}; + +class ChannelSteadyPingPongTest : public IPCChannelMojoTestBase { + public: + ChannelSteadyPingPongTest() = default; + ~ChannelSteadyPingPongTest() override = default; + + void RunPingPongServer(const std::string& label, bool sync) { + Init("MojoPerfTestClient"); + + // Set up IPC channel and start client. + ChannelSteadyPingPongListener listener; + + std::unique_ptr<ChannelProxy> channel_proxy; + std::unique_ptr<base::WaitableEvent> shutdown_event; + + if (sync) { + shutdown_event = std::make_unique<base::WaitableEvent>( + base::WaitableEvent::ResetPolicy::MANUAL, + base::WaitableEvent::InitialState::NOT_SIGNALED); + channel_proxy = IPC::SyncChannel::Create( + TakeHandle().release(), IPC::Channel::MODE_SERVER, &listener, + GetIOThreadTaskRunner(), false, shutdown_event.get()); + } else { + channel_proxy = IPC::ChannelProxy::Create( + TakeHandle().release(), IPC::Channel::MODE_SERVER, &listener, + GetIOThreadTaskRunner()); + } + listener.Init(channel_proxy.get()); + + LockThreadAffinity thread_locker(kSharedCore); + std::vector<TestParams> params_list = GetDefaultTestParams(); + for (const auto& params : params_list) { + base::RunLoop run_loop; + + listener.SetTestParams(params, label, sync, + run_loop.QuitWhenIdleClosure()); + + // This initial message will kick-start the ping-pong of messages. + channel_proxy->Send(new TestMsg_Hello); + + run_loop.Run(); + } + + // Send quit message. + channel_proxy->Send(new TestMsg_Quit); + + EXPECT_TRUE(WaitForClientShutdown()); + channel_proxy.reset(); + } +}; + +TEST_F(ChannelSteadyPingPongTest, AsyncPingPong) { + RunPingPongServer("IPC_CPU_Async", false); +} + +TEST_F(ChannelSteadyPingPongTest, SyncPingPong) { + RunPingPongServer("IPC_CPU_Sync", true); +} + +class MojoSteadyPingPongTest : public mojo::edk::test::MojoTestBase { + public: + MojoSteadyPingPongTest() = default; + + protected: + void RunPingPongServer(MojoHandle mp, const std::string& label, bool sync) { + label_ = label; + sync_ = sync; + + mojo::MessagePipeHandle mp_handle(mp); + mojo::ScopedMessagePipeHandle scoped_mp(mp_handle); + ping_receiver_.Bind(IPC::mojom::ReflectorPtrInfo(std::move(scoped_mp), 0u)); + + LockThreadAffinity thread_locker(kSharedCore); + std::vector<TestParams> params_list = GetDefaultTestParams(); + for (const auto& params : params_list) { + params_ = params; + payload_ = std::string(params.message_size, 'a'); + + ping_receiver_->Ping("hello", base::Bind(&MojoSteadyPingPongTest::OnHello, + base::Unretained(this))); + base::RunLoop run_loop; + quit_closure_ = run_loop.QuitWhenIdleClosure(); + run_loop.Run(); + } + + ping_receiver_->Quit(); + + ignore_result(ping_receiver_.PassInterface().PassHandle().release()); + } + + void OnHello(const std::string& value) { + cpu_logger_ = std::make_unique<PerfCpuLogger>(GetLogTitle(label_, params_)); + + frame_count_down_ = params_.frames_per_second * params_.duration_in_seconds; + + timer_.Start(FROM_HERE, GetFrameTime(params_.frames_per_second), this, + &MojoSteadyPingPongTest::StartPingPong); + } + + void StartPingPong() { + if (sync_) { + base::TimeTicks before = base::TimeTicks::Now(); + for (count_down_ = params_.messages_per_frame; count_down_ > 0; + --count_down_) { + std::string response; + ping_receiver_->SyncPing(payload_, &response); + DCHECK_EQ(response, payload_); + } + + if (base::TimeTicks::Now() - before > + GetFrameTime(params_.frames_per_second)) { + LOG(ERROR) << "Frame " << frame_count_down_ + << " wasn't able to complete on time!"; + } + + CHECK_GT(frame_count_down_, 0); + frame_count_down_--; + if (frame_count_down_ == 0) + StopPingPong(); + } else { + if (count_down_ != 0) { + LOG(ERROR) << "Frame " << frame_count_down_ + << " wasn't able to complete on time!"; + } else { + SendPing(); + } + count_down_ = params_.messages_per_frame; + } + } + + void StopPingPong() { + cpu_logger_.reset(); + timer_.AbandonAndStop(); + quit_closure_.Run(); + } + + void OnPong(const std::string& value) { + // Include message deserialization in latency. + DCHECK_EQ(payload_.size(), value.size()); + + CHECK_GT(count_down_, 0); + count_down_--; + if (count_down_ > 0) { + SendPing(); + } else { + CHECK_GT(frame_count_down_, 0); + frame_count_down_--; + if (frame_count_down_ == 0) + StopPingPong(); + } + } + + void SendPing() { + ping_receiver_->Ping(payload_, base::Bind(&MojoSteadyPingPongTest::OnPong, + base::Unretained(this))); + } + + static int RunPingPongClient(MojoHandle mp) { + mojo::MessagePipeHandle mp_handle(mp); + mojo::ScopedMessagePipeHandle scoped_mp(mp_handle); + + LockThreadAffinity thread_locker(kSharedCore); + base::RunLoop run_loop; + ReflectorImpl impl(std::move(scoped_mp), run_loop.QuitWhenIdleClosure()); + run_loop.Run(); + return 0; + } + + private: + TestParams params_; + std::string payload_; + std::string label_; + bool sync_ = false; + + IPC::mojom::ReflectorPtr ping_receiver_; + + int count_down_ = 0; + int frame_count_down_ = 0; + + base::RepeatingTimer timer_; + std::unique_ptr<PerfCpuLogger> cpu_logger_; + + base::Closure quit_closure_; + + DISALLOW_COPY_AND_ASSIGN(MojoSteadyPingPongTest); +}; + +DEFINE_TEST_CLIENT_WITH_PIPE(PingPongClient, MojoSteadyPingPongTest, h) { + base::MessageLoop main_message_loop; + return RunPingPongClient(h); +} + +// Similar to ChannelSteadyPingPongTest above, but uses a Mojo interface +// instead of raw IPC::Messages. +TEST_F(MojoSteadyPingPongTest, AsyncPingPong) { + RunTestClient("PingPongClient", [&](MojoHandle h) { + base::MessageLoop main_message_loop; + RunPingPongServer(h, "Mojo_CPU_Async", false); + }); +} + +TEST_F(MojoSteadyPingPongTest, SyncPingPong) { + RunTestClient("PingPongClient", [&](MojoHandle h) { + base::MessageLoop main_message_loop; + RunPingPongServer(h, "Mojo_CPU_Sync", true); + }); +} + +} // namespace +} // namespace IPC diff --git a/chromium/ipc/ipc_fuzzing_tests.cc b/chromium/ipc/ipc_fuzzing_tests.cc index 75c13b1571c..ca8827b12b7 100644 --- a/chromium/ipc/ipc_fuzzing_tests.cc +++ b/chromium/ipc/ipc_fuzzing_tests.cc @@ -46,8 +46,8 @@ TEST(IPCMessageIntegrity, ReadBeyondBufferStr) { uint32_t v1 = std::numeric_limits<uint32_t>::max() - 1; int v2 = 666; IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(v1)); - EXPECT_TRUE(m.WriteInt(v2)); + m.WriteInt(v1); + m.WriteInt(v2); base::PickleIterator iter(m); std::string vs; @@ -59,8 +59,8 @@ TEST(IPCMessageIntegrity, ReadBeyondBufferStr16) { uint32_t v1 = std::numeric_limits<uint32_t>::max() - 1; int v2 = 777; IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(v1)); - EXPECT_TRUE(m.WriteInt(v2)); + m.WriteInt(v1); + m.WriteInt(v2); base::PickleIterator iter(m); base::string16 vs; @@ -70,8 +70,8 @@ TEST(IPCMessageIntegrity, ReadBeyondBufferStr16) { TEST(IPCMessageIntegrity, ReadBytesBadIterator) { // This was BUG 1035467. IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(1)); - EXPECT_TRUE(m.WriteInt(2)); + m.WriteInt(1); + m.WriteInt(2); base::PickleIterator iter(m); const char* data = NULL; @@ -83,10 +83,10 @@ TEST(IPCMessageIntegrity, ReadVectorNegativeSize) { // has a specialized template which is not vulnerable to this bug. So here // try to hit the non-specialized case vector<P>. IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(-1)); // This is the count of elements. - EXPECT_TRUE(m.WriteInt(1)); - EXPECT_TRUE(m.WriteInt(2)); - EXPECT_TRUE(m.WriteInt(3)); + m.WriteInt(-1); // This is the count of elements. + m.WriteInt(1); + m.WriteInt(2); + m.WriteInt(3); std::vector<double> vec; base::PickleIterator iter(m); @@ -102,9 +102,9 @@ TEST(IPCMessageIntegrity, MAYBE_ReadVectorTooLarge1) { // This was BUG 1006367. This is the large but positive length case. Again // we try to hit the non-specialized case vector<P>. IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(0x21000003)); // This is the count of elements. - EXPECT_TRUE(m.WriteInt64(1)); - EXPECT_TRUE(m.WriteInt64(2)); + m.WriteInt(0x21000003); // This is the count of elements. + m.WriteInt64(1); + m.WriteInt64(2); std::vector<int64_t> vec; base::PickleIterator iter(m); @@ -116,9 +116,9 @@ TEST(IPCMessageIntegrity, ReadVectorTooLarge2) { // integer overflow when computing the actual byte size. Again we try to hit // the non-specialized case vector<P>. IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(0x71000000)); // This is the count of elements. - EXPECT_TRUE(m.WriteInt64(1)); - EXPECT_TRUE(m.WriteInt64(2)); + m.WriteInt(0x71000000); // This is the count of elements. + m.WriteInt64(1); + m.WriteInt64(2); std::vector<int64_t> vec; base::PickleIterator iter(m); diff --git a/chromium/ipc/ipc_message.cc b/chromium/ipc/ipc_message.cc index 8f408eaf51f..c9234231e2f 100644 --- a/chromium/ipc/ipc_message.cc +++ b/chromium/ipc/ipc_message.cc @@ -168,13 +168,10 @@ bool Message::WriteAttachment( scoped_refptr<base::Pickle::Attachment> attachment) { size_t index; bool success = attachment_set()->AddAttachment( - make_scoped_refptr(static_cast<MessageAttachment*>(attachment.get())), + base::WrapRefCounted(static_cast<MessageAttachment*>(attachment.get())), &index); DCHECK(success); - // NOTE: If you add more data to the pickle, make sure to update - // PickleSizer::AddAttachment. - // Write the index of the descriptor so that we don't have to // keep the current descriptor as extra decoding state when deserialising. WriteInt(static_cast<int>(index)); diff --git a/chromium/ipc/ipc_message.h b/chromium/ipc/ipc_message.h index 3ca75482b18..8a924e21952 100644 --- a/chromium/ipc/ipc_message.h +++ b/chromium/ipc/ipc_message.h @@ -15,8 +15,14 @@ #include "base/pickle.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" -#include "ipc/ipc_export.h" #include "ipc/ipc_features.h" +#include "ipc/ipc_message_support_export.h" + +namespace mojo { +namespace internal { +struct UnmappedNativeStructSerializerImpl; +} +} // namespace mojo namespace IPC { @@ -29,7 +35,7 @@ class ChannelReader; struct LogData; class MessageAttachmentSet; -class IPC_EXPORT Message : public base::Pickle { +class IPC_MESSAGE_SUPPORT_EXPORT Message : public base::Pickle { public: enum PriorityValue { PRIORITY_LOW = 1, @@ -166,7 +172,7 @@ class IPC_EXPORT Message : public base::Pickle { // The static method FindNext() returns several pieces of information, which // are aggregated into an instance of this struct. - struct IPC_EXPORT NextMessageInfo { + struct IPC_MESSAGE_SUPPORT_EXPORT NextMessageInfo { NextMessageInfo(); ~NextMessageInfo(); @@ -234,6 +240,8 @@ class IPC_EXPORT Message : public base::Pickle { friend class MessageReplyDeserializer; friend class SyncMessage; + friend struct mojo::internal::UnmappedNativeStructSerializerImpl; + #pragma pack(push, 4) struct Header : base::Pickle::Header { int32_t routing; // ID of the view that this message is destined for diff --git a/chromium/ipc/ipc_message_attachment.cc b/chromium/ipc/ipc_message_attachment.cc index 83440ae8e00..c2fe5bf9ef9 100644 --- a/chromium/ipc/ipc_message_attachment.cc +++ b/chromium/ipc/ipc_message_attachment.cc @@ -4,12 +4,153 @@ #include "ipc/ipc_message_attachment.h" +#include "base/files/scoped_file.h" +#include "base/logging.h" +#include "ipc/ipc_mojo_handle_attachment.h" +#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 + +#if defined(OS_MACOSX) && !defined(OS_IOS) +#include "ipc/mach_port_attachment_mac.h" +#endif + +#if defined(OS_WIN) +#include "ipc/handle_attachment_win.h" +#endif + +#if defined(OS_FUCHSIA) +#include "ipc/handle_attachment_fuchsia.h" +#endif + namespace IPC { -MessageAttachment::MessageAttachment() { +namespace { + +#if defined(OS_POSIX) +base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { + return attachment->Owns() + ? base::ScopedFD(attachment->TakePlatformFile()) + : base::ScopedFD(HANDLE_EINTR(dup(attachment->file()))); +} +#endif // defined(OS_POSIX) + +} // namespace + +MessageAttachment::MessageAttachment() = default; + +MessageAttachment::~MessageAttachment() = default; + +mojo::ScopedHandle MessageAttachment::TakeMojoHandle() { + switch (GetType()) { + case Type::MOJO_HANDLE: + return static_cast<internal::MojoHandleAttachment*>(this)->TakeHandle(); + +#if defined(OS_POSIX) + case Type::PLATFORM_FILE: { + // We dup() the handles in IPC::Message to transmit. + // IPC::MessageAttachmentSet has intricate lifetime semantics for FDs, so + // just to dup()-and-own them is the safest option. + base::ScopedFD file = + TakeOrDupFile(static_cast<internal::PlatformFileAttachment*>(this)); + if (!file.is_valid()) { + DPLOG(WARNING) << "Failed to dup FD to transmit."; + return mojo::ScopedHandle(); + } + return mojo::WrapPlatformFile(file.release()); + } +#endif // defined(OS_POSIX) + +#if defined(OS_MACOSX) && !defined(OS_IOS) + case Type::MACH_PORT: { + auto* attachment = static_cast<internal::MachPortAttachmentMac*>(this); + MojoPlatformHandle platform_handle = { + sizeof(platform_handle), MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, + static_cast<uint64_t>(attachment->get_mach_port())}; + MojoHandle wrapped_handle; + if (MojoWrapPlatformHandle(&platform_handle, &wrapped_handle) != + MOJO_RESULT_OK) { + return mojo::ScopedHandle(); + } + attachment->reset_mach_port_ownership(); + return mojo::MakeScopedHandle(mojo::Handle(wrapped_handle)); + } +#elif defined(OS_FUCHSIA) + case Type::FUCHSIA_HANDLE: { + auto* attachment = static_cast<internal::HandleAttachmentFuchsia*>(this); + MojoPlatformHandle platform_handle = { + sizeof(platform_handle), MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE, + static_cast<uint64_t>(attachment->Take())}; + MojoHandle wrapped_handle; + if (MojoWrapPlatformHandle(&platform_handle, &wrapped_handle) != + MOJO_RESULT_OK) { + return mojo::ScopedHandle(); + } + return mojo::MakeScopedHandle(mojo::Handle(wrapped_handle)); + } +#elif defined(OS_WIN) + case Type::WIN_HANDLE: + return mojo::WrapPlatformFile( + static_cast<internal::HandleAttachmentWin*>(this)->Take()); +#endif + default: + break; + } + NOTREACHED(); + return mojo::ScopedHandle(); } -MessageAttachment::~MessageAttachment() { +// static +scoped_refptr<MessageAttachment> MessageAttachment::CreateFromMojoHandle( + mojo::ScopedHandle handle, + Type type) { + if (type == Type::MOJO_HANDLE) + return new internal::MojoHandleAttachment(std::move(handle)); + + MojoPlatformHandle platform_handle = {sizeof(platform_handle), 0, 0}; + MojoResult unwrap_result = + MojoUnwrapPlatformHandle(handle.release().value(), &platform_handle); + if (unwrap_result != MOJO_RESULT_OK) + return nullptr; + +#if defined(OS_POSIX) + if (type == Type::PLATFORM_FILE) { + base::PlatformFile file = base::kInvalidPlatformFile; + if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR) + file = static_cast<base::PlatformFile>(platform_handle.value); + return new internal::PlatformFileAttachment(file); + } +#endif // defined(OS_POSIX) + +#if defined(OS_MACOSX) && !defined(OS_IOS) + if (type == Type::MACH_PORT) { + mach_port_t mach_port = MACH_PORT_NULL; + if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT) + mach_port = static_cast<mach_port_t>(platform_handle.value); + return new internal::MachPortAttachmentMac( + mach_port, internal::MachPortAttachmentMac::FROM_WIRE); + } +#elif defined(OS_FUCHSIA) + if (type == Type::FUCHSIA_HANDLE) { + base::ScopedZxHandle handle; + if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE) + handle.reset(static_cast<zx_handle_t>(platform_handle.value)); + return new internal::HandleAttachmentFuchsia(std::move(handle)); + } +#elif defined(OS_WIN) + if (type == Type::WIN_HANDLE) { + base::PlatformFile handle = base::kInvalidPlatformFile; + if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE) + handle = reinterpret_cast<base::PlatformFile>(platform_handle.value); + return new internal::HandleAttachmentWin( + handle, internal::HandleAttachmentWin::FROM_WIRE); + } +#endif + NOTREACHED(); + return nullptr; } } // namespace IPC diff --git a/chromium/ipc/ipc_message_attachment.h b/chromium/ipc/ipc_message_attachment.h index 9ff1de8c32f..9c92f37b5ab 100644 --- a/chromium/ipc/ipc_message_attachment.h +++ b/chromium/ipc/ipc_message_attachment.h @@ -10,19 +10,32 @@ #include "base/memory/ref_counted.h" #include "base/pickle.h" #include "build/build_config.h" -#include "ipc/ipc.mojom.h" -#include "ipc/ipc_export.h" +#include "ipc/ipc_message_support_export.h" +#include "mojo/public/cpp/system/handle.h" namespace IPC { // Auxiliary data sent with |Message|. This can be a platform file descriptor // or a mojo |MessagePipe|. |GetType()| returns the type of the subclass. -class IPC_EXPORT MessageAttachment : public base::Pickle::Attachment { +class IPC_MESSAGE_SUPPORT_EXPORT MessageAttachment + : public base::Pickle::Attachment { public: - using Type = mojom::SerializedHandle::Type; + enum class Type { + MOJO_HANDLE, + PLATFORM_FILE, + WIN_HANDLE, + MACH_PORT, + FUCHSIA_HANDLE, + }; + + static scoped_refptr<MessageAttachment> CreateFromMojoHandle( + mojo::ScopedHandle handle, + Type type); virtual Type GetType() const = 0; + mojo::ScopedHandle TakeMojoHandle(); + protected: friend class base::RefCountedThreadSafe<MessageAttachment>; MessageAttachment(); diff --git a/chromium/ipc/ipc_message_attachment_set.h b/chromium/ipc/ipc_message_attachment_set.h index de372114358..78bdcb2308e 100644 --- a/chromium/ipc/ipc_message_attachment_set.h +++ b/chromium/ipc/ipc_message_attachment_set.h @@ -12,7 +12,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "build/build_config.h" -#include "ipc/ipc_export.h" +#include "ipc/ipc_message_support_export.h" namespace IPC { @@ -26,7 +26,7 @@ class MessageAttachment; // For ChannelNacl under SFI NaCl, only Type::PLATFORM_FILE is supported. In // that case, the FD is sent over socket. // ----------------------------------------------------------------------------- -class IPC_EXPORT MessageAttachmentSet +class IPC_MESSAGE_SUPPORT_EXPORT MessageAttachmentSet : public base::RefCountedThreadSafe<MessageAttachmentSet> { public: MessageAttachmentSet(); diff --git a/chromium/ipc/ipc_message_macros.h b/chromium/ipc/ipc_message_macros.h index 4fcaa161d34..ccb7ce4a17a 100644 --- a/chromium/ipc/ipc_message_macros.h +++ b/chromium/ipc/ipc_message_macros.h @@ -45,11 +45,6 @@ // // Generate destructors. // #include "ipc/struct_destructor_macros.h" // #include "path/to/YYY_message_generator.h" -// // Generate param traits size methods. -// #include "ipc/param_traits_size_macros.h" -// namespace IPC { -// #include "path/to/YYY_message_generator.h" -// } // namespace IPC // // Generate param traits write methods. // #include "ipc/param_traits_write_macros.h" // namespace IPC { @@ -206,7 +201,6 @@ #include <tuple> -#include "base/profiler/scoped_profile.h" #include "ipc/export_template.h" #include "ipc/ipc_message_templates.h" #include "ipc/ipc_message_utils.h" @@ -351,7 +345,6 @@ #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ case msg_class::ID: { \ - TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \ &member_func)) \ ipc_message__.set_dispatch_error(); \ @@ -363,7 +356,6 @@ #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ case msg_class::ID: { \ - TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \ &member_func)) \ ipc_message__.set_dispatch_error(); \ @@ -377,7 +369,6 @@ #define IPC_MESSAGE_FORWARD_WITH_PARAM_DELAY_REPLY(msg_class, obj, \ member_func) \ case msg_class::ID: { \ - TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ if (!msg_class::DispatchWithParamDelayReply(&ipc_message__, obj, param__, \ &member_func)) \ ipc_message__.set_dispatch_error(); \ @@ -390,14 +381,12 @@ #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ case msg_class::ID: { \ - TRACK_RUN_IN_THIS_SCOPED_REGION(code); \ code; \ } \ break; #define IPC_REPLY_HANDLER(func) \ case IPC_REPLY_ID: { \ - TRACK_RUN_IN_THIS_SCOPED_REGION(func); \ func(ipc_message__); \ } \ break; diff --git a/chromium/ipc/ipc_message_pipe_reader.cc b/chromium/ipc/ipc_message_pipe_reader.cc index 8b226817ee1..ebc18a3a943 100644 --- a/chromium/ipc/ipc_message_pipe_reader.cc +++ b/chromium/ipc/ipc_message_pipe_reader.cc @@ -54,7 +54,7 @@ bool MessagePipeReader::Send(std::unique_ptr<Message> message) { "MessagePipeReader::Send", message->flags(), TRACE_EVENT_FLAG_FLOW_OUT); - base::Optional<std::vector<mojom::SerializedHandlePtr>> handles; + base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles; MojoResult result = MOJO_RESULT_OK; result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles); if (result != MOJO_RESULT_OK) @@ -86,7 +86,7 @@ void MessagePipeReader::SetPeerPid(int32_t peer_pid) { void MessagePipeReader::Receive( base::span<const uint8_t> data, - base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) { + base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles) { Message message( data.empty() ? "" : reinterpret_cast<const char*>(data.data()), static_cast<uint32_t>(data.size())); diff --git a/chromium/ipc/ipc_message_pipe_reader.h b/chromium/ipc/ipc_message_pipe_reader.h index b2f5044257f..a155dcfb372 100644 --- a/chromium/ipc/ipc_message_pipe_reader.h +++ b/chromium/ipc/ipc_message_pipe_reader.h @@ -22,6 +22,7 @@ #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" #include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/message_pipe.h" +#include "mojo/public/interfaces/bindings/native_struct.mojom.h" namespace IPC { namespace internal { @@ -93,9 +94,9 @@ class IPC_EXPORT MessagePipeReader : public mojom::Channel { private: // mojom::Channel: void SetPeerPid(int32_t peer_pid) override; - void Receive( - base::span<const uint8_t> data, - base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) override; + void Receive(base::span<const uint8_t> data, + base::Optional<std::vector<mojo::native::SerializedHandlePtr>> + handles) override; void GetAssociatedInterface( const std::string& name, mojom::GenericInterfaceAssociatedRequest request) override; diff --git a/chromium/ipc/ipc_message_protobuf_utils.h b/chromium/ipc/ipc_message_protobuf_utils.h index 8cacfe8d933..0168b150fc4 100644 --- a/chromium/ipc/ipc_message_protobuf_utils.h +++ b/chromium/ipc/ipc_message_protobuf_utils.h @@ -23,11 +23,6 @@ namespace IPC { template <class RepeatedFieldLike, class StorageType> struct RepeatedFieldParamTraits { typedef RepeatedFieldLike param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, p.size()); - for (int i = 0; i < p.size(); i++) - GetParamSize(sizer, p.Get(i)); - } static void Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.size()); for (int i = 0; i < p.size(); i++) diff --git a/chromium/ipc/ipc_message_protobuf_utils_unittest.cc b/chromium/ipc/ipc_message_protobuf_utils_unittest.cc index 5c01a7f1e09..61421c6e42f 100644 --- a/chromium/ipc/ipc_message_protobuf_utils_unittest.cc +++ b/chromium/ipc/ipc_message_protobuf_utils_unittest.cc @@ -24,9 +24,6 @@ namespace IPC { template <> struct ParamTraits<ipc_message_utils_test::TestMessage1> { typedef ipc_message_utils_test::TestMessage1 param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, p.number()); - } static void Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.number()); } @@ -44,11 +41,6 @@ struct ParamTraits<ipc_message_utils_test::TestMessage1> { template <> struct ParamTraits<ipc_message_utils_test::TestMessage2> { typedef ipc_message_utils_test::TestMessage2 param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, p.numbers()); - GetParamSize(sizer, p.strings()); - GetParamSize(sizer, p.messages()); - } static void Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.numbers()); WriteParam(m, p.strings()); @@ -99,11 +91,6 @@ TEST(IPCMessageRepeatedFieldUtilsTest, RepeatedFieldShouldBeSerialized) { base::Pickle pickle; IPC::WriteParam(&pickle, message); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, message); - - ASSERT_EQ(sizer.payload_size(), pickle.payload_size()); - base::PickleIterator iter(pickle); ipc_message_utils_test::TestMessage2 output; ASSERT_TRUE(IPC::ReadParam(&pickle, &iter, &output)); @@ -124,11 +111,6 @@ TEST(IPCMessageRepeatedFieldUtilsTest, base::Pickle pickle; IPC::WriteParam(&pickle, message); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, message); - - ASSERT_EQ(sizer.payload_size(), pickle.payload_size()); - base::PickleIterator iter(pickle); ipc_message_utils_test::TestMessage2 output; ASSERT_TRUE(IPC::ReadParam(&pickle, &iter, &output)); @@ -144,11 +126,6 @@ TEST(IPCMessageRepeatedFieldUtilsTest, EmptyRepeatedFieldShouldBeSerialized) { base::Pickle pickle; IPC::WriteParam(&pickle, message); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, message); - - ASSERT_EQ(sizer.payload_size(), pickle.payload_size()); - base::PickleIterator iter(pickle); ipc_message_utils_test::TestMessage2 output; ASSERT_TRUE(IPC::ReadParam(&pickle, &iter, &output)); diff --git a/chromium/ipc/ipc_message_start.h b/chromium/ipc/ipc_message_start.h index 6359b3f6ec7..a57e618f003 100644 --- a/chromium/ipc/ipc_message_start.h +++ b/chromium/ipc/ipc_message_start.h @@ -74,7 +74,6 @@ enum IPCMessageStart { ChromeUtilityPrintingMsgStart, AecDumpMsgStart, OzoneGpuMsgStart, - ChromeUtilityExtensionsMsgStart, PlatformNotificationMsgStart, LayoutTestMsgStart, NetworkHintsMsgStart, diff --git a/chromium/ipc/ipc_message_support_export.h b/chromium/ipc/ipc_message_support_export.h new file mode 100644 index 00000000000..abfa67afcb5 --- /dev/null +++ b/chromium/ipc/ipc_message_support_export.h @@ -0,0 +1,31 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_IPC_MESSAGE_SUPPORT_EXPORT_H_ +#define IPC_IPC_MESSAGE_SUPPORT_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(IPC_MESSAGE_SUPPORT_IMPL) +#define IPC_MESSAGE_SUPPORT_EXPORT __declspec(dllexport) +#else +#define IPC_MESSAGE_SUPPORT_EXPORT __declspec(dllimport) +#endif // defined(IPC_MESSAGE_SUPPORT_IMPL) + +#else // defined(WIN32) + +#if defined(IPC_MESSAGE_SUPPORT_IMPL) +#define IPC_MESSAGE_SUPPORT_EXPORT __attribute__((visibility("default"))) +#else +#define IPC_MESSAGE_SUPPORT_EXPORT +#endif + +#endif + +#else // defined(COMPONENT_BUILD) +#define IPC_MESSAGE_SUPPORT_EXPORT +#endif + +#endif // IPC_IPC_MESSAGE_SUPPORT_EXPORT_H_ diff --git a/chromium/ipc/ipc_message_unittest.cc b/chromium/ipc/ipc_message_unittest.cc index 36b5d28da7a..5d9da31715a 100644 --- a/chromium/ipc/ipc_message_unittest.cc +++ b/chromium/ipc/ipc_message_unittest.cc @@ -40,9 +40,9 @@ TEST(IPCMessageTest, BasicMessageTest) { base::string16 v3(base::ASCIIToUTF16("hello world")); IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); - EXPECT_TRUE(m.WriteInt(v1)); - EXPECT_TRUE(m.WriteString(v2)); - EXPECT_TRUE(m.WriteString16(v3)); + m.WriteInt(v1); + m.WriteString(v2); + m.WriteString16(v3); base::PickleIterator iter(m); @@ -124,8 +124,8 @@ TEST(IPCMessageTest, DictionaryValue) { TEST(IPCMessageTest, FindNext) { IPC::Message message; - EXPECT_TRUE(message.WriteString("Goooooooogle")); - EXPECT_TRUE(message.WriteInt(111)); + message.WriteString("Goooooooogle"); + message.WriteInt(111); std::vector<char> message_data(message.size() + 7); memcpy(message_data.data(), message.data(), message.size()); @@ -173,8 +173,8 @@ TEST(IPCMessageTest, FindNext) { TEST(IPCMessageTest, FindNextOverflow) { IPC::Message message; - EXPECT_TRUE(message.WriteString("Data")); - EXPECT_TRUE(message.WriteInt(777)); + message.WriteString("Data"); + message.WriteInt(777); const char* data_start = reinterpret_cast<const char*>(message.data()); const char* data_end = data_start + message.size(); diff --git a/chromium/ipc/ipc_message_utils.cc b/chromium/ipc/ipc_message_utils.cc index dd065fd07f7..6ea3e902dcf 100644 --- a/chromium/ipc/ipc_message_utils.cc +++ b/chromium/ipc/ipc_message_utils.cc @@ -77,69 +77,6 @@ bool ReadValue(const base::Pickle* m, std::unique_ptr<base::Value>* value, int recursion); -void GetValueSize(base::PickleSizer* sizer, - const base::Value* value, - int recursion) { - if (recursion > kMaxRecursionDepth) { - LOG(ERROR) << "Max recursion depth hit in GetValueSize."; - return; - } - - sizer->AddInt(); - switch (value->GetType()) { - case base::Value::Type::NONE: - break; - case base::Value::Type::BOOLEAN: - sizer->AddBool(); - break; - case base::Value::Type::INTEGER: - sizer->AddInt(); - break; - case base::Value::Type::DOUBLE: - sizer->AddDouble(); - break; - case base::Value::Type::STRING: { - const base::Value* result; - value->GetAsString(&result); - if (value->GetAsString(&result)) { - DCHECK(result); - GetParamSize(sizer, result->GetString()); - } else { - std::string str; - bool as_string_result = value->GetAsString(&str); - DCHECK(as_string_result); - GetParamSize(sizer, str); - } - break; - } - case base::Value::Type::BINARY: { - sizer->AddData(static_cast<int>(value->GetBlob().size())); - break; - } - case base::Value::Type::DICTIONARY: { - sizer->AddInt(); - const base::DictionaryValue* dict = - static_cast<const base::DictionaryValue*>(value); - for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); - it.Advance()) { - GetParamSize(sizer, it.key()); - GetValueSize(sizer, &it.value(), recursion + 1); - } - break; - } - case base::Value::Type::LIST: { - sizer->AddInt(); - const base::ListValue* list = static_cast<const base::ListValue*>(value); - for (const auto& entry : *list) { - GetValueSize(sizer, &entry, recursion + 1); - } - break; - } - default: - NOTREACHED() << "Invalid base::Value type."; - } -} - void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { bool result; if (recursion > kMaxRecursionDepth) { @@ -147,9 +84,9 @@ void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { return; } - m->WriteInt(static_cast<int>(value->GetType())); + m->WriteInt(static_cast<int>(value->type())); - switch (value->GetType()) { + switch (value->type()) { case base::Value::Type::NONE: break; case base::Value::Type::BOOLEAN: { @@ -182,14 +119,14 @@ void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { } case base::Value::Type::BINARY: { m->WriteData(value->GetBlob().data(), - static_cast<int>(value->GetBlob().size())); + base::checked_cast<int>(value->GetBlob().size())); break; } case base::Value::Type::DICTIONARY: { const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(value); - WriteParam(m, static_cast<int>(dict->size())); + WriteParam(m, base::checked_cast<int>(dict->size())); for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { @@ -200,7 +137,7 @@ void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { } case base::Value::Type::LIST: { const base::ListValue* list = static_cast<const base::ListValue*>(value); - WriteParam(m, static_cast<int>(list->GetSize())); + WriteParam(m, base::checked_cast<int>(list->GetSize())); for (const auto& entry : *list) { WriteValue(m, &entry, recursion + 1); } @@ -346,11 +283,6 @@ void ParamTraits<bool>::Log(const param_type& p, std::string* l) { l->append(p ? "true" : "false"); } -void ParamTraits<signed char>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddBytes(sizeof(param_type)); -} - void ParamTraits<signed char>::Write(base::Pickle* m, const param_type& p) { m->WriteBytes(&p, sizeof(param_type)); } @@ -369,11 +301,6 @@ void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { l->append(base::IntToString(p)); } -void ParamTraits<unsigned char>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddBytes(sizeof(param_type)); -} - void ParamTraits<unsigned char>::Write(base::Pickle* m, const param_type& p) { m->WriteBytes(&p, sizeof(param_type)); } @@ -392,11 +319,6 @@ void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { l->append(base::UintToString(p)); } -void ParamTraits<unsigned short>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddBytes(sizeof(param_type)); -} - void ParamTraits<unsigned short>::Write(base::Pickle* m, const param_type& p) { m->WriteBytes(&p, sizeof(param_type)); } @@ -446,11 +368,6 @@ void ParamTraits<float>::Log(const param_type& p, std::string* l) { l->append(base::StringPrintf("%e", p)); } -void ParamTraits<double>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddBytes(sizeof(param_type)); -} - void ParamTraits<double>::Write(base::Pickle* m, const param_type& p) { m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); } @@ -480,17 +397,12 @@ void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { l->append(base::UTF16ToUTF8(p)); } -void ParamTraits<std::vector<char>>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddData(static_cast<int>(p.size())); -} - void ParamTraits<std::vector<char>>::Write(base::Pickle* m, const param_type& p) { if (p.empty()) { m->WriteData(NULL, 0); } else { - m->WriteData(&p.front(), static_cast<int>(p.size())); + m->WriteData(&p.front(), base::checked_cast<int>(p.size())); } } @@ -511,18 +423,13 @@ void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { LogBytes(p, l); } -void ParamTraits<std::vector<unsigned char>>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddData(static_cast<int>(p.size())); -} - void ParamTraits<std::vector<unsigned char>>::Write(base::Pickle* m, const param_type& p) { if (p.empty()) { m->WriteData(NULL, 0); } else { m->WriteData(reinterpret_cast<const char*>(&p.front()), - static_cast<int>(p.size())); + base::checked_cast<int>(p.size())); } } @@ -544,16 +451,9 @@ void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, LogBytes(p, l); } -void ParamTraits<std::vector<bool>>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, static_cast<int>(p.size())); - for (size_t i = 0; i < p.size(); ++i) - GetParamSize(sizer, static_cast<bool>(p[i])); -} - void ParamTraits<std::vector<bool>>::Write(base::Pickle* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.size())); + WriteParam(m, base::checked_cast<int>(p.size())); // Cast to bool below is required because libc++'s // vector<bool>::const_reference is different from bool, and we want to avoid // writing an extra specialization of ParamTraits for it. @@ -586,11 +486,6 @@ void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { } } -void ParamTraits<base::DictionaryValue>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetValueSize(sizer, &p, 0); -} - void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, const param_type& p) { WriteValue(m, &p, 0); @@ -615,13 +510,6 @@ void ParamTraits<base::DictionaryValue>::Log(const param_type& p, } #if defined(OS_POSIX) -void ParamTraits<base::FileDescriptor>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.fd >= 0); - if (p.fd >= 0) - sizer->AddAttachment(); -} - void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, const param_type& p) { // This serialization must be kept in sync with @@ -680,24 +568,6 @@ void ParamTraits<base::FileDescriptor>::Log(const param_type& p, } #endif // defined(OS_POSIX) -void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.IsValid()); - if (!p.IsValid()) - return; - -#if defined(OS_MACOSX) && !defined(OS_IOS) - GetParamSize(sizer, p.GetMemoryObject()); -#elif defined(OS_WIN) - GetParamSize(sizer, p.GetHandle()); -#else - sizer->AddAttachment(); -#endif - - GetParamSize(sizer, p.GetGUID()); - GetParamSize(sizer, static_cast<uint64_t>(p.GetSize())); -} - void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, const param_type& p) { // This serialization must be kept in sync with @@ -822,13 +692,6 @@ void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, } #if defined(OS_WIN) -void ParamTraits<PlatformFileForTransit>::GetSize(base::PickleSizer* s, - const param_type& p) { - GetParamSize(s, p.IsValid()); - if (p.IsValid()) - GetParamSize(s, p.GetHandle()); -} - void ParamTraits<PlatformFileForTransit>::Write(base::Pickle* m, const param_type& p) { m->WriteBool(p.IsValid()); @@ -863,11 +726,6 @@ void ParamTraits<PlatformFileForTransit>::Log(const param_type& p, } #endif // defined(OS_WIN) -void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - p.GetSizeForPickle(sizer); -} - void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { p.WriteToPickle(m); } @@ -882,11 +740,6 @@ void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { ParamTraits<base::FilePath::StringType>::Log(p.value(), l); } -void ParamTraits<base::ListValue>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetValueSize(sizer, &p, 0); -} - void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { WriteValue(m, &p, 0); } @@ -908,12 +761,6 @@ void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { l->append(json); } -void ParamTraits<base::NullableString16>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.string()); - GetParamSize(sizer, p.is_null()); -} - void ParamTraits<base::NullableString16>::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.string()); @@ -942,15 +789,6 @@ void ParamTraits<base::NullableString16>::Log(const param_type& p, l->append(")"); } -void ParamTraits<base::File::Info>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.size); - GetParamSize(sizer, p.is_directory); - GetParamSize(sizer, p.last_modified.ToDoubleT()); - GetParamSize(sizer, p.last_accessed.ToDoubleT()); - GetParamSize(sizer, p.creation_time.ToDoubleT()); -} - void ParamTraits<base::File::Info>::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.size); @@ -991,11 +829,6 @@ void ParamTraits<base::File::Info>::Log(const param_type& p, l->append(")"); } -void ParamTraits<base::Time>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddInt64(); -} - void ParamTraits<base::Time>::Write(base::Pickle* m, const param_type& p) { ParamTraits<int64_t>::Write(m, p.ToInternalValue()); } @@ -1014,11 +847,6 @@ void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { ParamTraits<int64_t>::Log(p.ToInternalValue(), l); } -void ParamTraits<base::TimeDelta>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddInt64(); -} - void ParamTraits<base::TimeDelta>::Write(base::Pickle* m, const param_type& p) { ParamTraits<int64_t>::Write(m, p.ToInternalValue()); } @@ -1038,11 +866,6 @@ void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { ParamTraits<int64_t>::Log(p.ToInternalValue(), l); } -void ParamTraits<base::TimeTicks>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddInt64(); -} - void ParamTraits<base::TimeTicks>::Write(base::Pickle* m, const param_type& p) { ParamTraits<int64_t>::Write(m, p.ToInternalValue()); } @@ -1067,11 +890,6 @@ void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t), "base::UnguessableToken should be of size 2 * sizeof(uint64_t)."); -void ParamTraits<base::UnguessableToken>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddBytes(2 * sizeof(uint64_t)); -} - void ParamTraits<base::UnguessableToken>::Write(base::Pickle* m, const param_type& p) { DCHECK(!p.is_empty()); @@ -1103,15 +921,6 @@ void ParamTraits<base::UnguessableToken>::Log(const param_type& p, l->append(p.ToString()); } -void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, - const param_type& p) { -#if defined(OS_NACL_SFI) - GetParamSize(sizer, p.socket); -#else - GetParamSize(sizer, p.mojo_handle); -#endif -} - void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, const param_type& p) { #if defined(OS_NACL_SFI) @@ -1142,19 +951,6 @@ void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, l->append(")"); } -void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.channel); - GetParamSize(sizer, p.routing_id); - GetParamSize(sizer, p.type); - GetParamSize(sizer, p.flags); - GetParamSize(sizer, p.sent); - GetParamSize(sizer, p.receive); - GetParamSize(sizer, p.dispatch); - GetParamSize(sizer, p.message_name); - GetParamSize(sizer, p.params); -} - void ParamTraits<LogData>::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.channel); WriteParam(m, p.routing_id); @@ -1224,7 +1020,8 @@ bool ParamTraits<Message>::Read(const base::Pickle* m, return false; r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); - return r->WriteBytes(payload, payload_size); + r->WriteBytes(payload, payload_size); + return true; } void ParamTraits<Message>::Log(const Message& p, std::string* l) { @@ -1232,11 +1029,6 @@ void ParamTraits<Message>::Log(const Message& p, std::string* l) { } #if defined(OS_WIN) -void ParamTraits<HANDLE>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddInt(); -} - // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 // bit systems. That's why we use the Windows macros to convert to 32 bits. void ParamTraits<HANDLE>::Write(base::Pickle* m, const param_type& p) { @@ -1257,11 +1049,6 @@ void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { l->append(base::StringPrintf("0x%p", p)); } -void ParamTraits<LOGFONT>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - sizer->AddData(sizeof(LOGFONT)); -} - void ParamTraits<LOGFONT>::Write(base::Pickle* m, const param_type& p) { m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); } @@ -1287,10 +1074,6 @@ void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { l->append(base::StringPrintf("<LOGFONT>")); } -void ParamTraits<MSG>::GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddData(sizeof(MSG)); -} - void ParamTraits<MSG>::Write(base::Pickle* m, const param_type& p) { m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); } diff --git a/chromium/ipc/ipc_message_utils.h b/chromium/ipc/ipc_message_utils.h index 348ff7eb61a..21063b45656 100644 --- a/chromium/ipc/ipc_message_utils.h +++ b/chromium/ipc/ipc_message_utils.h @@ -28,6 +28,7 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "build/build_config.h" +#include "ipc/ipc_export.h" #include "ipc/ipc_message_start.h" #include "ipc/ipc_param_traits.h" #include "ipc/ipc_sync_message.h" @@ -87,12 +88,6 @@ struct CheckedTuple { typedef std::tuple<Ts...> Tuple; }; -template <class P> -static inline void GetParamSize(base::PickleSizer* sizer, const P& p) { - typedef typename SimilarTypeTraits<P>::Type Type; - ParamTraits<Type>::GetSize(sizer, static_cast<const Type&>(p)); -} - // This function is checked by 'IPC checker' part of find-bad-constructs // Clang plugin to make it's not called on the following types: // 1. long / unsigned long (but not typedefs to) @@ -125,9 +120,6 @@ static inline void LogParam(const P& p, std::string* l) { template <> struct ParamTraits<bool> { typedef bool param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddBool(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteBool(p); } static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -140,7 +132,6 @@ struct ParamTraits<bool> { template <> struct IPC_EXPORT ParamTraits<signed char> { typedef signed char param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -151,7 +142,6 @@ struct IPC_EXPORT ParamTraits<signed char> { template <> struct IPC_EXPORT ParamTraits<unsigned char> { typedef unsigned char param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -162,7 +152,6 @@ struct IPC_EXPORT ParamTraits<unsigned char> { template <> struct IPC_EXPORT ParamTraits<unsigned short> { typedef unsigned short param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -173,9 +162,6 @@ struct IPC_EXPORT ParamTraits<unsigned short> { template <> struct ParamTraits<int> { typedef int param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddInt(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); } static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -188,9 +174,6 @@ struct ParamTraits<int> { template <> struct ParamTraits<unsigned int> { typedef unsigned int param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddInt(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); } static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -216,9 +199,6 @@ struct ParamTraits<unsigned int> { template <> struct ParamTraits<long> { typedef long param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddLong(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteLong(p); } @@ -233,9 +213,6 @@ struct ParamTraits<long> { template <> struct ParamTraits<unsigned long> { typedef unsigned long param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddLong(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteLong(p); } @@ -251,9 +228,6 @@ struct ParamTraits<unsigned long> { template <> struct ParamTraits<long long> { typedef long long param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddInt64(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteInt64(static_cast<int64_t>(p)); } @@ -268,9 +242,6 @@ struct ParamTraits<long long> { template <> struct ParamTraits<unsigned long long> { typedef unsigned long long param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddInt64(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteInt64(p); } static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -286,9 +257,6 @@ struct ParamTraits<unsigned long long> { template <> struct IPC_EXPORT ParamTraits<float> { typedef float param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddFloat(); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteFloat(p); } static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -301,7 +269,6 @@ struct IPC_EXPORT ParamTraits<float> { template <> struct IPC_EXPORT ParamTraits<double> { typedef double param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -312,10 +279,6 @@ struct IPC_EXPORT ParamTraits<double> { template <class P, size_t Size> struct ParamTraits<P[Size]> { using param_type = P[Size]; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - for (const P& element : p) - GetParamSize(sizer, element); - } static void Write(base::Pickle* m, const param_type& p) { for (const P& element : p) WriteParam(m, element); @@ -345,9 +308,6 @@ struct ParamTraits<P[Size]> { template <> struct ParamTraits<std::string> { typedef std::string param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddString(p); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -360,9 +320,6 @@ struct ParamTraits<std::string> { template <> struct ParamTraits<base::string16> { typedef base::string16 param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - sizer->AddString16(p); - } static void Write(base::Pickle* m, const param_type& p) { m->WriteString16(p); } @@ -377,7 +334,6 @@ struct ParamTraits<base::string16> { template <> struct IPC_EXPORT ParamTraits<std::vector<char> > { typedef std::vector<char> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle*, base::PickleIterator* iter, @@ -388,7 +344,6 @@ struct IPC_EXPORT ParamTraits<std::vector<char> > { template <> struct IPC_EXPORT ParamTraits<std::vector<unsigned char> > { typedef std::vector<unsigned char> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -399,7 +354,6 @@ struct IPC_EXPORT ParamTraits<std::vector<unsigned char> > { template <> struct IPC_EXPORT ParamTraits<std::vector<bool> > { typedef std::vector<bool> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -410,13 +364,8 @@ struct IPC_EXPORT ParamTraits<std::vector<bool> > { template <class P> struct ParamTraits<std::vector<P>> { typedef std::vector<P> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, static_cast<int>(p.size())); - for (size_t i = 0; i < p.size(); i++) - GetParamSize(sizer, p[i]); - } static void Write(base::Pickle* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.size())); + WriteParam(m, base::checked_cast<int>(p.size())); for (size_t i = 0; i < p.size(); i++) WriteParam(m, p[i]); } @@ -449,14 +398,8 @@ struct ParamTraits<std::vector<P>> { template <class P> struct ParamTraits<std::set<P> > { typedef std::set<P> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, static_cast<int>(p.size())); - typename param_type::const_iterator iter; - for (iter = p.begin(); iter != p.end(); ++iter) - GetParamSize(sizer, *iter); - } static void Write(base::Pickle* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.size())); + WriteParam(m, base::checked_cast<int>(p.size())); typename param_type::const_iterator iter; for (iter = p.begin(); iter != p.end(); ++iter) WriteParam(m, *iter); @@ -483,16 +426,8 @@ struct ParamTraits<std::set<P> > { template <class K, class V, class C, class A> struct ParamTraits<std::map<K, V, C, A> > { typedef std::map<K, V, C, A> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, static_cast<int>(p.size())); - typename param_type::const_iterator iter; - for (iter = p.begin(); iter != p.end(); ++iter) { - GetParamSize(sizer, iter->first); - GetParamSize(sizer, iter->second); - } - } static void Write(base::Pickle* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.size())); + WriteParam(m, base::checked_cast<int>(p.size())); typename param_type::const_iterator iter; for (iter = p.begin(); iter != p.end(); ++iter) { WriteParam(m, iter->first); @@ -523,10 +458,6 @@ struct ParamTraits<std::map<K, V, C, A> > { template <class A, class B> struct ParamTraits<std::pair<A, B> > { typedef std::pair<A, B> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, p.first); - GetParamSize(sizer, p.second); - } static void Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.first); WriteParam(m, p.second); @@ -550,7 +481,6 @@ struct ParamTraits<std::pair<A, B> > { template <> struct IPC_EXPORT ParamTraits<base::DictionaryValue> { typedef base::DictionaryValue param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -577,7 +507,6 @@ struct IPC_EXPORT ParamTraits<base::DictionaryValue> { template<> struct IPC_EXPORT ParamTraits<base::FileDescriptor> { typedef base::FileDescriptor param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -589,7 +518,6 @@ struct IPC_EXPORT ParamTraits<base::FileDescriptor> { template <> struct IPC_EXPORT ParamTraits<base::SharedMemoryHandle> { typedef base::SharedMemoryHandle param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -601,7 +529,6 @@ struct IPC_EXPORT ParamTraits<base::SharedMemoryHandle> { template <> struct IPC_EXPORT ParamTraits<PlatformFileForTransit> { typedef PlatformFileForTransit param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -613,7 +540,6 @@ struct IPC_EXPORT ParamTraits<PlatformFileForTransit> { template <> struct IPC_EXPORT ParamTraits<base::FilePath> { typedef base::FilePath param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -624,7 +550,6 @@ struct IPC_EXPORT ParamTraits<base::FilePath> { template <> struct IPC_EXPORT ParamTraits<base::ListValue> { typedef base::ListValue param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -635,7 +560,6 @@ struct IPC_EXPORT ParamTraits<base::ListValue> { template <> struct IPC_EXPORT ParamTraits<base::NullableString16> { typedef base::NullableString16 param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -646,7 +570,6 @@ struct IPC_EXPORT ParamTraits<base::NullableString16> { template <> struct IPC_EXPORT ParamTraits<base::File::Info> { typedef base::File::Info param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -669,7 +592,6 @@ struct SimilarTypeTraits<HWND> { template <> struct IPC_EXPORT ParamTraits<base::Time> { typedef base::Time param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -680,7 +602,6 @@ struct IPC_EXPORT ParamTraits<base::Time> { template <> struct IPC_EXPORT ParamTraits<base::TimeDelta> { typedef base::TimeDelta param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -691,7 +612,6 @@ struct IPC_EXPORT ParamTraits<base::TimeDelta> { template <> struct IPC_EXPORT ParamTraits<base::TimeTicks> { typedef base::TimeTicks param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -702,7 +622,6 @@ struct IPC_EXPORT ParamTraits<base::TimeTicks> { template <> struct IPC_EXPORT ParamTraits<base::UnguessableToken> { typedef base::UnguessableToken param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -713,7 +632,6 @@ struct IPC_EXPORT ParamTraits<base::UnguessableToken> { template <> struct ParamTraits<std::tuple<>> { typedef std::tuple<> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) {} static void Write(base::Pickle* m, const param_type& p) {} static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -728,11 +646,6 @@ template <typename T, int index, int count> struct TupleParamTraitsHelper { using Next = TupleParamTraitsHelper<T, index + 1, count>; - static void GetSize(base::PickleSizer* sizer, const T& p) { - GetParamSize(sizer, std::get<index>(p)); - Next::GetSize(sizer, p); - } - static void Write(base::Pickle* m, const T& p) { WriteParam(m, std::get<index>(p)); Next::Write(m, p); @@ -752,7 +665,6 @@ struct TupleParamTraitsHelper { template <typename T, int index> struct TupleParamTraitsHelper<T, index, index> { - static void GetSize(base::PickleSizer* sizer, const T& p) {} static void Write(base::Pickle* m, const T& p) {} static bool Read(const base::Pickle* m, base::PickleIterator* iter, T* r) { return true; @@ -766,10 +678,6 @@ struct ParamTraits<std::tuple<Args...>> { using Helper = TupleParamTraitsHelper<param_type, 0, std::tuple_size<param_type>::value>; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - Helper::GetSize(sizer, p); - } - static void Write(base::Pickle* m, const param_type& p) { Helper::Write(m, p); } @@ -786,13 +694,8 @@ struct ParamTraits<std::tuple<Args...>> { template <class P, size_t stack_capacity> struct ParamTraits<base::StackVector<P, stack_capacity> > { typedef base::StackVector<P, stack_capacity> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, static_cast<int>(p->size())); - for (size_t i = 0; i < p->size(); i++) - GetParamSize(sizer, p[i]); - } static void Write(base::Pickle* m, const param_type& p) { - WriteParam(m, static_cast<int>(p->size())); + WriteParam(m, base::checked_cast<int>(p->size())); for (size_t i = 0; i < p->size(); i++) WriteParam(m, p[i]); } @@ -831,16 +734,8 @@ struct ParamTraits<base::small_map<NormalMap, kArraySize, EqualKey, MapInit>> { using param_type = base::small_map<NormalMap, kArraySize, EqualKey, MapInit>; using K = typename param_type::key_type; using V = typename param_type::data_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - GetParamSize(sizer, static_cast<int>(p.size())); - typename param_type::const_iterator iter; - for (iter = p.begin(); iter != p.end(); ++iter) { - GetParamSize(sizer, iter->first); - GetParamSize(sizer, iter->second); - } - } static void Write(base::Pickle* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.size())); + WriteParam(m, base::checked_cast<int>(p.size())); typename param_type::const_iterator iter; for (iter = p.begin(); iter != p.end(); ++iter) { WriteParam(m, iter->first); @@ -871,17 +766,9 @@ struct ParamTraits<base::small_map<NormalMap, kArraySize, EqualKey, MapInit>> { template <class Key, class Mapped, class Compare> struct ParamTraits<base::flat_map<Key, Mapped, Compare>> { using param_type = base::flat_map<Key, Mapped, Compare>; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - DCHECK(base::IsValueInRangeForNumericType<int>(p.size())); - GetParamSize(sizer, static_cast<int>(p.size())); - for (const auto& iter : p) { - GetParamSize(sizer, iter.first); - GetParamSize(sizer, iter.second); - } - } static void Write(base::Pickle* m, const param_type& p) { DCHECK(base::IsValueInRangeForNumericType<int>(p.size())); - WriteParam(m, static_cast<int>(p.size())); + WriteParam(m, base::checked_cast<int>(p.size())); for (const auto& iter : p) { WriteParam(m, iter.first); WriteParam(m, iter.second); @@ -917,12 +804,6 @@ struct ParamTraits<base::flat_map<Key, Mapped, Compare>> { template <class P> struct ParamTraits<std::unique_ptr<P>> { typedef std::unique_ptr<P> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - bool valid = !!p; - GetParamSize(sizer, valid); - if (valid) - GetParamSize(sizer, *p); - } static void Write(base::Pickle* m, const param_type& p) { bool valid = !!p; WriteParam(m, valid); @@ -959,12 +840,6 @@ struct ParamTraits<std::unique_ptr<P>> { template <class P> struct ParamTraits<base::Optional<P>> { typedef base::Optional<P> param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p) { - const bool is_set = static_cast<bool>(p); - GetParamSize(sizer, is_set); - if (is_set) - GetParamSize(sizer, p.value()); - } static void Write(base::Pickle* m, const param_type& p) { const bool is_set = static_cast<bool>(p); WriteParam(m, is_set); @@ -1001,7 +876,6 @@ struct ParamTraits<base::Optional<P>> { template<> struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { typedef ChannelHandle param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -1012,7 +886,6 @@ struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { template <> struct IPC_EXPORT ParamTraits<LogData> { typedef LogData param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -1035,7 +908,6 @@ struct IPC_EXPORT ParamTraits<Message> { template <> struct IPC_EXPORT ParamTraits<HANDLE> { typedef HANDLE param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -1046,7 +918,6 @@ struct IPC_EXPORT ParamTraits<HANDLE> { template <> struct IPC_EXPORT ParamTraits<LOGFONT> { typedef LOGFONT param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, @@ -1057,7 +928,6 @@ struct IPC_EXPORT ParamTraits<LOGFONT> { template <> struct IPC_EXPORT ParamTraits<MSG> { typedef MSG param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, diff --git a/chromium/ipc/ipc_message_utils_unittest.cc b/chromium/ipc/ipc_message_utils_unittest.cc index f4ca6ba933d..084809c25a6 100644 --- a/chromium/ipc/ipc_message_utils_unittest.cc +++ b/chromium/ipc/ipc_message_utils_unittest.cc @@ -96,48 +96,6 @@ TEST(IPCMessageUtilsTest, StackVector) { EXPECT_EQ(stack_vector[i], output[i]); } -// 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->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->SetKey("foobar", base::Value(5)); - value->SetWithoutPathExpansion("nested", std::move(nested_dict)); - - std::unique_ptr<base::ListValue> list_value(new base::ListValue); - list_value->AppendString("im a string"); - list_value->AppendString("im another string"); - value->SetWithoutPathExpansion("awesome-list", std::move(list_value)); - - base::Pickle pickle; - IPC::WriteParam(&pickle, *value); - - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, *value); - - EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); -} - -TEST(IPCMessageUtilsTest, JsonValueSize) { - const char kJson[] = "[ { \"foo\": \"bar\", \"baz\": 1234.0 } ]"; - std::unique_ptr<base::Value> json_value = base::JSONReader::Read(kJson); - EXPECT_NE(nullptr, json_value); - base::ListValue value; - value.Append(std::move(json_value)); - - base::Pickle pickle; - IPC::WriteParam(&pickle, value); - - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, value); - - EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); -} - TEST(IPCMessageUtilsTest, MojoChannelHandle) { mojo::MessagePipe message_pipe; IPC::ChannelHandle channel_handle(message_pipe.handle0.release()); @@ -145,10 +103,6 @@ TEST(IPCMessageUtilsTest, MojoChannelHandle) { IPC::Message message; IPC::WriteParam(&message, channel_handle); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, channel_handle); - EXPECT_EQ(sizer.payload_size(), message.payload_size()); - base::PickleIterator iter(message); IPC::ChannelHandle result_handle; EXPECT_TRUE(IPC::ReadParam(&message, &iter, &result_handle)); @@ -160,11 +114,6 @@ TEST(IPCMessageUtilsTest, OptionalUnset) { base::Pickle pickle; IPC::WriteParam(&pickle, opt); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, opt); - - EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); - std::string log; IPC::LogParam(opt, &log); EXPECT_EQ("(unset)", log); @@ -180,11 +129,6 @@ TEST(IPCMessageUtilsTest, OptionalSet) { base::Pickle pickle; IPC::WriteParam(&pickle, opt); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, opt); - - EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); - std::string log; IPC::LogParam(opt, &log); EXPECT_EQ("10", log); @@ -220,11 +164,6 @@ TEST(IPCMessageUtilsTest, UnguessableTokenTest) { base::Pickle pickle; IPC::WriteParam(&pickle, token); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, token); - - EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); - std::string log; IPC::LogParam(token, &log); EXPECT_EQ(token.ToString(), log); @@ -243,11 +182,6 @@ TEST(IPCMessageUtilsTest, FlatMap) { base::Pickle pickle; IPC::WriteParam(&pickle, input); - base::PickleSizer sizer; - IPC::GetParamSize(&sizer, input); - - EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); - base::PickleIterator iter(pickle); base::flat_map<std::string, int> output; EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &output)); diff --git a/chromium/ipc/ipc_mojo_bootstrap.cc b/chromium/ipc/ipc_mojo_bootstrap.cc index 506c9f88cb4..7f471bd37c1 100644 --- a/chromium/ipc/ipc_mojo_bootstrap.cc +++ b/chromium/ipc/ipc_mojo_bootstrap.cc @@ -8,11 +8,11 @@ #include <map> #include <memory> -#include <queue> #include <utility> #include <vector> #include "base/callback.h" +#include "base/containers/queue.h" #include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" @@ -534,7 +534,7 @@ class ChannelAssociatedGroupController scoped_refptr<base::SequencedTaskRunner> task_runner_; std::unique_ptr<mojo::SyncEventWatcher> sync_watcher_; std::unique_ptr<base::WaitableEvent> sync_message_event_; - std::queue<std::pair<uint32_t, MessageWrapper>> sync_messages_; + base::queue<std::pair<uint32_t, MessageWrapper>> sync_messages_; uint32_t next_sync_message_id_ = 0; DISALLOW_COPY_AND_ASSIGN(Endpoint); diff --git a/chromium/ipc/ipc_mojo_bootstrap_unittest.cc b/chromium/ipc/ipc_mojo_bootstrap_unittest.cc index 52e261f1caa..d74903c2e45 100644 --- a/chromium/ipc/ipc_mojo_bootstrap_unittest.cc +++ b/chromium/ipc/ipc_mojo_bootstrap_unittest.cc @@ -43,7 +43,7 @@ class PeerPidReceiver : public IPC::mojom::Channel { } void Receive(base::span<const uint8_t> data, - base::Optional<std::vector<IPC::mojom::SerializedHandlePtr>> + base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles) override {} void GetAssociatedInterface( diff --git a/chromium/ipc/ipc_mojo_handle_attachment.h b/chromium/ipc/ipc_mojo_handle_attachment.h index d6152769efd..94e40599aec 100644 --- a/chromium/ipc/ipc_mojo_handle_attachment.h +++ b/chromium/ipc/ipc_mojo_handle_attachment.h @@ -8,8 +8,8 @@ #include "base/files/file.h" #include "base/macros.h" #include "build/build_config.h" -#include "ipc/ipc_export.h" #include "ipc/ipc_message_attachment.h" +#include "ipc/ipc_message_support_export.h" #include "mojo/public/cpp/system/handle.h" namespace IPC { @@ -20,7 +20,8 @@ namespace internal { // This can hold any type of transferrable Mojo handle (i.e. message pipe, data // pipe, etc), but the receiver is expected to know what type of handle to // expect. -class IPC_EXPORT MojoHandleAttachment : public MessageAttachment { +class IPC_MESSAGE_SUPPORT_EXPORT MojoHandleAttachment + : public MessageAttachment { public: explicit MojoHandleAttachment(mojo::ScopedHandle handle); diff --git a/chromium/ipc/ipc_mojo_message_helper.cc b/chromium/ipc/ipc_mojo_message_helper.cc index a87a2d694d5..41ac70f4084 100644 --- a/chromium/ipc/ipc_mojo_message_helper.cc +++ b/chromium/ipc/ipc_mojo_message_helper.cc @@ -33,7 +33,7 @@ bool MojoMessageHelper::ReadMessagePipeFrom( MessageAttachment::Type type = static_cast<MessageAttachment*>(attachment.get())->GetType(); if (type != MessageAttachment::Type::MOJO_HANDLE) { - LOG(ERROR) << "Unxpected attachment type:" << type; + LOG(ERROR) << "Unxpected attachment type:" << static_cast<int>(type); return false; } diff --git a/chromium/ipc/ipc_mojo_message_helper.h b/chromium/ipc/ipc_mojo_message_helper.h index 4a71b5c96cd..156c6678298 100644 --- a/chromium/ipc/ipc_mojo_message_helper.h +++ b/chromium/ipc/ipc_mojo_message_helper.h @@ -5,14 +5,14 @@ #ifndef IPC_IPC_MOJO_MESSAGE_HELPER_H_ #define IPC_IPC_MOJO_MESSAGE_HELPER_H_ -#include "ipc/ipc_export.h" #include "ipc/ipc_message.h" +#include "ipc/ipc_message_support_export.h" #include "mojo/public/cpp/system/message_pipe.h" namespace IPC { // Reads and writes |mojo::MessagePipe| from/to |Message|. -class IPC_EXPORT MojoMessageHelper { +class IPC_MESSAGE_SUPPORT_EXPORT MojoMessageHelper { public: static bool WriteMessagePipeTo(base::Pickle* message, mojo::ScopedMessagePipeHandle handle); diff --git a/chromium/ipc/ipc_mojo_param_traits.cc b/chromium/ipc/ipc_mojo_param_traits.cc index 12aaacee106..5eeb9f0fbb7 100644 --- a/chromium/ipc/ipc_mojo_param_traits.cc +++ b/chromium/ipc/ipc_mojo_param_traits.cc @@ -10,13 +10,6 @@ namespace IPC { -void ParamTraits<mojo::MessagePipeHandle>::GetSize(base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.is_valid()); - if (p.is_valid()) - sizer->AddAttachment(); -} - void ParamTraits<mojo::MessagePipeHandle>::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.is_valid()); @@ -48,14 +41,6 @@ void ParamTraits<mojo::MessagePipeHandle>::Log(const param_type& p, l->append(")"); } -void ParamTraits<mojo::DataPipeConsumerHandle>::GetSize( - base::PickleSizer* sizer, - const param_type& p) { - GetParamSize(sizer, p.is_valid()); - if (p.is_valid()) - sizer->AddAttachment(); -} - void ParamTraits<mojo::DataPipeConsumerHandle>::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.is_valid()); @@ -84,7 +69,7 @@ bool ParamTraits<mojo::DataPipeConsumerHandle>::Read(const base::Pickle* m, MessageAttachment::Type type = static_cast<MessageAttachment*>(attachment.get())->GetType(); if (type != MessageAttachment::Type::MOJO_HANDLE) { - DLOG(ERROR) << "Unexpected attachment type:" << type; + DLOG(ERROR) << "Unexpected attachment type:" << static_cast<int>(type); return false; } diff --git a/chromium/ipc/ipc_mojo_param_traits.h b/chromium/ipc/ipc_mojo_param_traits.h index a4d0228c0a6..9562587dda4 100644 --- a/chromium/ipc/ipc_mojo_param_traits.h +++ b/chromium/ipc/ipc_mojo_param_traits.h @@ -15,7 +15,6 @@ namespace base { class Pickle; class PickleIterator; -class PickleSizer; } namespace IPC { @@ -23,7 +22,6 @@ namespace IPC { template <> struct IPC_EXPORT ParamTraits<mojo::MessagePipeHandle> { typedef mojo::MessagePipeHandle param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, param_type* r); @@ -33,7 +31,6 @@ struct IPC_EXPORT ParamTraits<mojo::MessagePipeHandle> { template <> struct IPC_EXPORT ParamTraits<mojo::DataPipeConsumerHandle> { typedef mojo::DataPipeConsumerHandle param_type; - static void GetSize(base::PickleSizer* sizer, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, diff --git a/chromium/ipc/ipc_mojo_perftest.cc b/chromium/ipc/ipc_mojo_perftest.cc index 45f5203e383..b7cea2a93a3 100644 --- a/chromium/ipc/ipc_mojo_perftest.cc +++ b/chromium/ipc/ipc_mojo_perftest.cc @@ -15,6 +15,8 @@ #include "base/threading/thread.h" #include "build/build_config.h" #include "ipc/ipc_channel_mojo.h" +#include "ipc/ipc_perftest_messages.h" +#include "ipc/ipc_perftest_util.h" #include "ipc/ipc_sync_channel.h" #include "ipc/ipc_test.mojom.h" #include "ipc/ipc_test_base.h" @@ -27,25 +29,9 @@ #include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/system/message_pipe.h" -#define IPC_MESSAGE_IMPL -#include "ipc/ipc_message_macros.h" - -#define IPC_MESSAGE_START TestMsgStart - -IPC_MESSAGE_CONTROL0(TestMsg_Hello) -IPC_MESSAGE_CONTROL0(TestMsg_Quit) -IPC_MESSAGE_CONTROL1(TestMsg_Ping, std::string) -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) @@ -136,102 +122,6 @@ class PerformanceChannelListener : public Listener { std::unique_ptr<base::PerfTimeLogger> perf_logger_; }; -// This channel listener just replies to all messages with the exact same -// message. It assumes each message has one string parameter. When the string -// "quit" is sent, it will exit. -class ChannelReflectorListener : public Listener { - public: - ChannelReflectorListener() : channel_(NULL) { - VLOG(1) << "Client listener up"; - } - - ~ChannelReflectorListener() override { VLOG(1) << "Client listener down"; } - - void Init(Sender* channel) { - DCHECK(!channel_); - channel_ = channel; - } - - bool OnMessageReceived(const Message& message) override { - CHECK(channel_); - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(ChannelReflectorListener, message) - IPC_MESSAGE_HANDLER(TestMsg_Hello, OnHello) - IPC_MESSAGE_HANDLER(TestMsg_Ping, OnPing) - IPC_MESSAGE_HANDLER(TestMsg_SyncPing, OnSyncPing) - IPC_MESSAGE_HANDLER(TestMsg_Quit, OnQuit) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; - } - - void OnHello() { channel_->Send(new TestMsg_Hello); } - - void OnPing(const std::string& payload) { - channel_->Send(new TestMsg_Ping(payload)); - } - - void OnSyncPing(const std::string& payload, std::string* response) { - *response = payload; - } - - void OnQuit() { base::RunLoop::QuitCurrentWhenIdleDeprecated(); } - - void Send(IPC::Message* message) { channel_->Send(message); } - - private: - Sender* channel_; -}; - -// This class locks the current thread to a particular CPU core. This is -// important because otherwise the different threads and processes of these -// tests end up on different CPU cores which means that all of the cores are -// lightly loaded so the OS (Windows and Linux) fails to ramp up the CPU -// frequency, leading to unpredictable and often poor performance. -class LockThreadAffinity { - public: - explicit LockThreadAffinity(int cpu_number) : affinity_set_ok_(false) { -#if defined(OS_WIN) - const DWORD_PTR thread_mask = static_cast<DWORD_PTR>(1) << cpu_number; - old_affinity_ = SetThreadAffinityMask(GetCurrentThread(), thread_mask); - affinity_set_ok_ = old_affinity_ != 0; -#elif defined(OS_LINUX) - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - CPU_SET(cpu_number, &cpuset); - auto get_result = sched_getaffinity(0, sizeof(old_cpuset_), &old_cpuset_); - DCHECK_EQ(0, get_result); - auto set_result = sched_setaffinity(0, sizeof(cpuset), &cpuset); - // Check for get_result failure, even though it should always succeed. - affinity_set_ok_ = (set_result == 0) && (get_result == 0); -#endif - if (!affinity_set_ok_) - LOG(WARNING) << "Failed to set thread affinity to CPU " << cpu_number; - } - - ~LockThreadAffinity() { - if (!affinity_set_ok_) - return; -#if defined(OS_WIN) - auto set_result = SetThreadAffinityMask(GetCurrentThread(), old_affinity_); - DCHECK_NE(0u, set_result); -#elif defined(OS_LINUX) - auto set_result = sched_setaffinity(0, sizeof(old_cpuset_), &old_cpuset_); - DCHECK_EQ(0, set_result); -#endif - } - - private: - bool affinity_set_ok_; -#if defined(OS_WIN) - DWORD_PTR old_affinity_; -#elif defined(OS_LINUX) - cpu_set_t old_cpuset_; -#endif - - DISALLOW_COPY_AND_ASSIGN(LockThreadAffinity); -}; - class PingPongTestParams { public: PingPongTestParams(size_t size, int count) @@ -287,10 +177,6 @@ std::vector<InterfacePassingTestParams> GetDefaultInterfacePassingTestParams() { 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; - class MojoChannelPerfTest : public IPCChannelMojoTestBase { public: MojoChannelPerfTest() = default; @@ -374,34 +260,6 @@ TEST_F(MojoChannelPerfTest, ChannelProxySyncPing) { run_loop.RunUntilIdle(); } -class MojoPerfTestClient { - public: - MojoPerfTestClient() : listener_(new ChannelReflectorListener()) { - mojo::edk::test::MultiprocessTestHelper::ChildSetup(); - } - - ~MojoPerfTestClient() = default; - - int Run(MojoHandle handle) { - handle_ = mojo::MakeScopedHandle(mojo::MessagePipeHandle(handle)); - LockThreadAffinity thread_locker(kSharedCore); - - std::unique_ptr<ChannelProxy> channel = - IPC::ChannelProxy::Create(handle_.release(), Channel::MODE_CLIENT, - listener_.get(), GetIOThreadTaskRunner()); - listener_->Init(channel.get()); - - base::RunLoop().Run(); - return 0; - } - - private: - base::MessageLoop main_message_loop_; - std::unique_ptr<ChannelReflectorListener> listener_; - std::unique_ptr<Channel> channel_; - mojo::ScopedMessagePipeHandle handle_; -}; - MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) { MojoPerfTestClient client; int rv = mojo::edk::test::MultiprocessTestHelper::RunClientMain( @@ -414,29 +272,6 @@ MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) { return rv; } -class ReflectorImpl : public IPC::mojom::Reflector { - public: - explicit ReflectorImpl(mojo::ScopedMessagePipeHandle handle) - : binding_(this, IPC::mojom::ReflectorRequest(std::move(handle))) {} - ~ReflectorImpl() override { - ignore_result(binding_.Unbind().PassMessagePipe().release()); - } - - private: - // IPC::mojom::Reflector: - void Ping(const std::string& value, PingCallback callback) override { - std::move(callback).Run(value); - } - - void SyncPing(const std::string& value, PingCallback callback) override { - std::move(callback).Run(value); - } - - void Quit() override { base::RunLoop::QuitCurrentWhenIdleDeprecated(); } - - mojo::Binding<IPC::mojom::Reflector> binding_; -}; - class MojoInterfacePerfTest : public mojo::edk::test::MojoTestBase { public: MojoInterfacePerfTest() : message_count_(0), count_down_(0) {} @@ -509,8 +344,9 @@ class MojoInterfacePerfTest : public mojo::edk::test::MojoTestBase { base::MessageLoop::current()); LockThreadAffinity thread_locker(kSharedCore); - ReflectorImpl impl(std::move(scoped_mp)); - base::RunLoop().Run(); + base::RunLoop run_loop; + ReflectorImpl impl(std::move(scoped_mp), run_loop.QuitWhenIdleClosure()); + run_loop.Run(); return 0; } @@ -798,7 +634,7 @@ TEST_P(MojoInProcessInterfacePerfTest, SingleThreadPingPong) { mojo::MessagePipeHandle mp_handle(client_handle); mojo::ScopedMessagePipeHandle scoped_mp(mp_handle); LockThreadAffinity thread_locker(kSharedCore); - ReflectorImpl impl(std::move(scoped_mp)); + ReflectorImpl impl(std::move(scoped_mp), base::Closure()); RunPingPongServer(server_handle, "SingleProcess"); } diff --git a/chromium/ipc/ipc_perftest_messages.cc b/chromium/ipc/ipc_perftest_messages.cc new file mode 100644 index 00000000000..4a84dae2267 --- /dev/null +++ b/chromium/ipc/ipc_perftest_messages.cc @@ -0,0 +1,7 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "ipc/ipc_perftest_messages.h" diff --git a/chromium/ipc/ipc_perftest_messages.h b/chromium/ipc/ipc_perftest_messages.h new file mode 100644 index 00000000000..1dc0890574f --- /dev/null +++ b/chromium/ipc/ipc_perftest_messages.h @@ -0,0 +1,16 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Multiply-included message header, no traditional include guard. + +#include <string> + +#include "ipc/ipc_message_macros.h" + +#define IPC_MESSAGE_START TestMsgStart + +IPC_MESSAGE_CONTROL0(TestMsg_Hello) +IPC_MESSAGE_CONTROL0(TestMsg_Quit) +IPC_MESSAGE_CONTROL1(TestMsg_Ping, std::string) +IPC_SYNC_MESSAGE_CONTROL1_1(TestMsg_SyncPing, std::string, std::string) diff --git a/chromium/ipc/ipc_perftest_util.cc b/chromium/ipc/ipc_perftest_util.cc new file mode 100644 index 00000000000..57f054d08c6 --- /dev/null +++ b/chromium/ipc/ipc_perftest_util.cc @@ -0,0 +1,145 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ipc/ipc_perftest_util.h" + +#include "base/logging.h" +#include "base/run_loop.h" +#include "ipc/ipc_channel_proxy.h" +#include "ipc/ipc_perftest_messages.h" +#include "mojo/edk/embedder/embedder.h" +#include "mojo/edk/test/multiprocess_test_helper.h" + +namespace IPC { + +scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() { + scoped_refptr<base::TaskRunner> runner = mojo::edk::GetIOTaskRunner(); + return scoped_refptr<base::SingleThreadTaskRunner>( + static_cast<base::SingleThreadTaskRunner*>(runner.get())); +} + +ChannelReflectorListener::ChannelReflectorListener() : channel_(NULL) { + VLOG(1) << "Client listener up"; +} + +ChannelReflectorListener::~ChannelReflectorListener() { + VLOG(1) << "Client listener down"; +} + +void ChannelReflectorListener::Init(Sender* channel, + const base::Closure& quit_closure) { + DCHECK(!channel_); + channel_ = channel; + quit_closure_ = quit_closure; +} + +bool ChannelReflectorListener::OnMessageReceived(const Message& message) { + CHECK(channel_); + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(ChannelReflectorListener, message) + IPC_MESSAGE_HANDLER(TestMsg_Hello, OnHello) + IPC_MESSAGE_HANDLER(TestMsg_Ping, OnPing) + IPC_MESSAGE_HANDLER(TestMsg_SyncPing, OnSyncPing) + IPC_MESSAGE_HANDLER(TestMsg_Quit, OnQuit) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void ChannelReflectorListener::OnHello() { + channel_->Send(new TestMsg_Hello); +} + +void ChannelReflectorListener::OnPing(const std::string& payload) { + channel_->Send(new TestMsg_Ping(payload)); +} + +void ChannelReflectorListener::OnSyncPing(const std::string& payload, + std::string* response) { + *response = payload; +} + +void ChannelReflectorListener::OnQuit() { + quit_closure_.Run(); +} + +void ChannelReflectorListener::Send(IPC::Message* message) { + channel_->Send(message); +} + +LockThreadAffinity::LockThreadAffinity(int cpu_number) + : affinity_set_ok_(false) { +#if defined(OS_WIN) + const DWORD_PTR thread_mask = static_cast<DWORD_PTR>(1) << cpu_number; + old_affinity_ = SetThreadAffinityMask(GetCurrentThread(), thread_mask); + affinity_set_ok_ = old_affinity_ != 0; +#elif defined(OS_LINUX) + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(cpu_number, &cpuset); + auto get_result = sched_getaffinity(0, sizeof(old_cpuset_), &old_cpuset_); + DCHECK_EQ(0, get_result); + auto set_result = sched_setaffinity(0, sizeof(cpuset), &cpuset); + // Check for get_result failure, even though it should always succeed. + affinity_set_ok_ = (set_result == 0) && (get_result == 0); +#endif + if (!affinity_set_ok_) + LOG(WARNING) << "Failed to set thread affinity to CPU " << cpu_number; +} + +LockThreadAffinity::~LockThreadAffinity() { + if (!affinity_set_ok_) + return; +#if defined(OS_WIN) + auto set_result = SetThreadAffinityMask(GetCurrentThread(), old_affinity_); + DCHECK_NE(0u, set_result); +#elif defined(OS_LINUX) + auto set_result = sched_setaffinity(0, sizeof(old_cpuset_), &old_cpuset_); + DCHECK_EQ(0, set_result); +#endif +} + +MojoPerfTestClient::MojoPerfTestClient() + : listener_(new ChannelReflectorListener()) { + mojo::edk::test::MultiprocessTestHelper::ChildSetup(); +} + +MojoPerfTestClient::~MojoPerfTestClient() = default; + +int MojoPerfTestClient::Run(MojoHandle handle) { + handle_ = mojo::MakeScopedHandle(mojo::MessagePipeHandle(handle)); + LockThreadAffinity thread_locker(kSharedCore); + + base::RunLoop run_loop; + std::unique_ptr<ChannelProxy> channel = + IPC::ChannelProxy::Create(handle_.release(), Channel::MODE_CLIENT, + listener_.get(), GetIOThreadTaskRunner()); + listener_->Init(channel.get(), run_loop.QuitWhenIdleClosure()); + run_loop.Run(); + return 0; +} + +ReflectorImpl::ReflectorImpl(mojo::ScopedMessagePipeHandle handle, + const base::Closure& quit_closure) + : quit_closure_(quit_closure), + binding_(this, IPC::mojom::ReflectorRequest(std::move(handle))) {} + +ReflectorImpl::~ReflectorImpl() { + ignore_result(binding_.Unbind().PassMessagePipe().release()); +} + +void ReflectorImpl::Ping(const std::string& value, PingCallback callback) { + std::move(callback).Run(value); +} + +void ReflectorImpl::SyncPing(const std::string& value, PingCallback callback) { + std::move(callback).Run(value); +} + +void ReflectorImpl::Quit() { + if (quit_closure_) + quit_closure_.Run(); +} + +} // namespace IPC diff --git a/chromium/ipc/ipc_perftest_util.h b/chromium/ipc/ipc_perftest_util.h new file mode 100644 index 00000000000..3c9ceeb2bf4 --- /dev/null +++ b/chromium/ipc/ipc_perftest_util.h @@ -0,0 +1,119 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_IPC_PERFTEST_UTIL_H_ +#define IPC_IPC_PERFTEST_UTIL_H_ + +#include <string> + +#include "base/callback.h" +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/message_loop/message_loop.h" +#include "base/process/process_metrics.h" +#include "base/single_thread_task_runner.h" +#include "build/build_config.h" +#include "ipc/ipc_channel.h" +#include "ipc/ipc_listener.h" +#include "ipc/ipc_message.h" +#include "ipc/ipc_sender.h" +#include "ipc/ipc_test.mojom.h" +#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/system/core.h" + +namespace IPC { + +scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner(); + +// This channel listener just replies to all messages with the exact same +// message. It assumes each message has one string parameter. When the string +// "quit" is sent, it will exit. +class ChannelReflectorListener : public Listener { + public: + ChannelReflectorListener(); + + ~ChannelReflectorListener() override; + + void Init(Sender* channel, const base::Closure& quit_closure); + + bool OnMessageReceived(const Message& message) override; + + void OnHello(); + + void OnPing(const std::string& payload); + + void OnSyncPing(const std::string& payload, std::string* response); + + void OnQuit(); + + void Send(IPC::Message* message); + + private: + Sender* channel_; + base::Closure quit_closure_; +}; + +// This class locks the current thread to a particular CPU core. This is +// important because otherwise the different threads and processes of these +// tests end up on different CPU cores which means that all of the cores are +// lightly loaded so the OS (Windows and Linux) fails to ramp up the CPU +// frequency, leading to unpredictable and often poor performance. +class LockThreadAffinity { + public: + explicit LockThreadAffinity(int cpu_number); + + ~LockThreadAffinity(); + + private: + bool affinity_set_ok_; +#if defined(OS_WIN) + DWORD_PTR old_affinity_; +#elif defined(OS_LINUX) + cpu_set_t old_cpuset_; +#endif + + DISALLOW_COPY_AND_ASSIGN(LockThreadAffinity); +}; + +// 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; + +class MojoPerfTestClient { + public: + MojoPerfTestClient(); + + ~MojoPerfTestClient(); + + int Run(MojoHandle handle); + + private: + base::MessageLoop main_message_loop_; + std::unique_ptr<ChannelReflectorListener> listener_; + std::unique_ptr<Channel> channel_; + mojo::ScopedMessagePipeHandle handle_; +}; + +class ReflectorImpl : public IPC::mojom::Reflector { + public: + explicit ReflectorImpl(mojo::ScopedMessagePipeHandle handle, + const base::Closure& quit_closure); + + ~ReflectorImpl() override; + + private: + // IPC::mojom::Reflector: + void Ping(const std::string& value, PingCallback callback) override; + + void SyncPing(const std::string& value, PingCallback callback) override; + + void Quit() override; + + base::Closure quit_closure_; + mojo::Binding<IPC::mojom::Reflector> binding_; +}; + +} // namespace IPC + +#endif // IPC_IPC_PERFTEST_UTIL_H_ diff --git a/chromium/ipc/ipc_platform_file.h b/chromium/ipc/ipc_platform_file.h index ea295af8c54..1704b943c3c 100644 --- a/chromium/ipc/ipc_platform_file.h +++ b/chromium/ipc/ipc_platform_file.h @@ -8,7 +8,7 @@ #include "base/files/file.h" #include "base/process/process.h" #include "build/build_config.h" -#include "ipc/ipc_export.h" +#include "ipc/ipc_message_support_export.h" #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" @@ -17,7 +17,7 @@ namespace IPC { #if defined(OS_WIN) -class IPC_EXPORT PlatformFileForTransit { +class IPC_MESSAGE_SUPPORT_EXPORT PlatformFileForTransit { public: // Creates an invalid platform file. PlatformFileForTransit(); @@ -72,14 +72,14 @@ inline base::File PlatformFileForTransitToFile( // Creates a new handle that can be passed through IPC. The result must be // passed to the IPC layer as part of a message, or else it will leak. -IPC_EXPORT PlatformFileForTransit GetPlatformFileForTransit( - base::PlatformFile file, - bool close_source_handle); +IPC_MESSAGE_SUPPORT_EXPORT PlatformFileForTransit +GetPlatformFileForTransit(base::PlatformFile file, bool close_source_handle); // Creates a new handle that can be passed through IPC. The result must be // passed to the IPC layer as part of a message, or else it will leak. // Note that this function takes ownership of |file|. -IPC_EXPORT PlatformFileForTransit TakePlatformFileForTransit(base::File file); +IPC_MESSAGE_SUPPORT_EXPORT PlatformFileForTransit +TakePlatformFileForTransit(base::File file); } // namespace IPC diff --git a/chromium/ipc/ipc_platform_file_attachment_posix.h b/chromium/ipc/ipc_platform_file_attachment_posix.h index 9b0790093b0..945c3455749 100644 --- a/chromium/ipc/ipc_platform_file_attachment_posix.h +++ b/chromium/ipc/ipc_platform_file_attachment_posix.h @@ -5,8 +5,8 @@ #ifndef IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ #define IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ -#include "ipc/ipc_export.h" #include "ipc/ipc_message_attachment.h" +#include "ipc/ipc_message_support_export.h" namespace IPC { namespace internal { @@ -15,7 +15,8 @@ namespace internal { // PlatformFileAttachment optionally owns the file and |owning_| is set in that // case. Also, |file_| is not cleared even after the ownership is taken. // Some old clients require this strange behavior. -class IPC_EXPORT PlatformFileAttachment : public MessageAttachment { +class IPC_MESSAGE_SUPPORT_EXPORT PlatformFileAttachment + : public MessageAttachment { public: // Non-owning constructor explicit PlatformFileAttachment(base::PlatformFile file); diff --git a/chromium/ipc/ipc_sync_channel.h b/chromium/ipc/ipc_sync_channel.h index 74a61471174..cdc3cc85c2b 100644 --- a/chromium/ipc/ipc_sync_channel.h +++ b/chromium/ipc/ipc_sync_channel.h @@ -5,11 +5,11 @@ #ifndef IPC_IPC_SYNC_CHANNEL_H_ #define IPC_IPC_SYNC_CHANNEL_H_ -#include <deque> #include <memory> #include <string> #include <vector> +#include "base/containers/circular_deque.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" @@ -199,7 +199,7 @@ class IPC_EXPORT SyncChannel : public ChannelProxy { void OnShutdownEventSignaled(base::WaitableEvent* event); - typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; + using PendingSyncMessageQueue = base::circular_deque<PendingSyncMsg>; PendingSyncMessageQueue deserializers_; bool reject_new_deserializers_ = false; base::Lock deserializers_lock_; diff --git a/chromium/ipc/ipc_sync_message.cc b/chromium/ipc/ipc_sync_message.cc index 34cb875db2f..a6b39793e3a 100644 --- a/chromium/ipc/ipc_sync_message.cc +++ b/chromium/ipc/ipc_sync_message.cc @@ -6,8 +6,6 @@ #include <stdint.h> -#include <stack> - #include "base/atomic_sequence_num.h" #include "base/logging.h" #include "build/build_config.h" @@ -103,11 +101,7 @@ bool SyncMessage::ReadSyncHeader(const Message& msg, SyncHeader* header) { bool SyncMessage::WriteSyncHeader(Message* msg, const SyncHeader& header) { DCHECK(msg->is_sync() || msg->is_reply()); DCHECK(msg->payload_size() == 0); - bool result = msg->WriteInt(header.message_id); - if (!result) { - NOTREACHED(); - return false; - } + msg->WriteInt(header.message_id); // Note: if you add anything here, you need to update kSyncMessageHeaderSize. DCHECK(kSyncMessageHeaderSize == msg->payload_size()); diff --git a/chromium/ipc/ipc_sync_message.h b/chromium/ipc/ipc_sync_message.h index 7f0555134a2..c9a1287a66d 100644 --- a/chromium/ipc/ipc_sync_message.h +++ b/chromium/ipc/ipc_sync_message.h @@ -16,6 +16,7 @@ #include "build/build_config.h" #include "ipc/ipc_message.h" +#include "ipc/ipc_message_support_export.h" namespace base { class WaitableEvent; @@ -25,7 +26,7 @@ namespace IPC { class MessageReplyDeserializer; -class IPC_EXPORT SyncMessage : public Message { +class IPC_MESSAGE_SUPPORT_EXPORT SyncMessage : public Message { public: SyncMessage(int32_t routing_id, uint32_t type, @@ -79,7 +80,7 @@ class IPC_EXPORT SyncMessage : public Message { }; // Used to deserialize parameters from a reply to a synchronous message -class IPC_EXPORT MessageReplyDeserializer { +class IPC_MESSAGE_SUPPORT_EXPORT MessageReplyDeserializer { public: virtual ~MessageReplyDeserializer() {} bool SerializeOutputParameters(const Message& msg); diff --git a/chromium/ipc/mach_port_attachment_mac.h b/chromium/ipc/mach_port_attachment_mac.h index 861c4e30656..ae41cd03d34 100644 --- a/chromium/ipc/mach_port_attachment_mac.h +++ b/chromium/ipc/mach_port_attachment_mac.h @@ -10,15 +10,16 @@ #include "base/macros.h" #include "base/process/process_handle.h" -#include "ipc/ipc_export.h" #include "ipc/ipc_message_attachment.h" +#include "ipc/ipc_message_support_export.h" #include "ipc/mach_port_mac.h" namespace IPC { namespace internal { // This class represents an OSX mach_port_t attached to a Chrome IPC message. -class IPC_EXPORT MachPortAttachmentMac : public MessageAttachment { +class IPC_MESSAGE_SUPPORT_EXPORT MachPortAttachmentMac + : public MessageAttachment { public: // This constructor increments the ref count of |mach_port_| and takes // ownership of the result. Should only be called by the sender of a Chrome diff --git a/chromium/ipc/mach_port_mac.cc b/chromium/ipc/mach_port_mac.cc index 6d3045a5606..91663641714 100644 --- a/chromium/ipc/mach_port_mac.cc +++ b/chromium/ipc/mach_port_mac.cc @@ -7,17 +7,12 @@ #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/stringprintf.h" #include "ipc/mach_port_attachment_mac.h" namespace IPC { // static -void ParamTraits<MachPortMac>::GetSize(base::PickleSizer* s, - const param_type& p) { - s->AddAttachment(); -} - -// static void ParamTraits<MachPortMac>::Write(base::Pickle* m, const param_type& p) { if (!m->WriteAttachment( new IPC::internal::MachPortAttachmentMac(p.get_mach_port()))) { diff --git a/chromium/ipc/mach_port_mac.h b/chromium/ipc/mach_port_mac.h index f8511344f6b..49ca1c3f206 100644 --- a/chromium/ipc/mach_port_mac.h +++ b/chromium/ipc/mach_port_mac.h @@ -8,8 +8,9 @@ #include <mach/mach.h> #include "base/macros.h" -#include "ipc/ipc_export.h" -#include "ipc/ipc_message_macros.h" +#include "base/pickle.h" +#include "ipc/ipc_message_support_export.h" +#include "ipc/ipc_param_traits.h" namespace IPC { @@ -18,7 +19,7 @@ namespace IPC { // to the Mach port will be duplicated into the destination process by the // attachment broker. If needed, attachment brokering can be trivially extended // to support duplication of other types of rights. -class IPC_EXPORT MachPortMac { +class IPC_MESSAGE_SUPPORT_EXPORT MachPortMac { public: MachPortMac() : mach_port_(MACH_PORT_NULL) {} @@ -69,9 +70,8 @@ class IPC_EXPORT MachPortMac { }; template <> -struct IPC_EXPORT ParamTraits<MachPortMac> { +struct IPC_MESSAGE_SUPPORT_EXPORT ParamTraits<MachPortMac> { typedef MachPortMac param_type; - static void GetSize(base::PickleSizer* s, const param_type& p); static void Write(base::Pickle* m, const param_type& p); static bool Read(const base::Pickle* m, base::PickleIterator* iter, diff --git a/chromium/ipc/native_handle_type_converters.cc b/chromium/ipc/native_handle_type_converters.cc new file mode 100644 index 00000000000..a0391b69112 --- /dev/null +++ b/chromium/ipc/native_handle_type_converters.cc @@ -0,0 +1,49 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ipc/native_handle_type_converters.h" + +namespace mojo { + +// static +IPC::MessageAttachment::Type +TypeConverter<IPC::MessageAttachment::Type, native::SerializedHandle_Type>:: + Convert(native::SerializedHandle_Type type) { + switch (type) { + case native::SerializedHandle_Type::MOJO_HANDLE: + return IPC::MessageAttachment::Type::MOJO_HANDLE; + case native::SerializedHandle_Type::PLATFORM_FILE: + return IPC::MessageAttachment::Type::PLATFORM_FILE; + case native::SerializedHandle_Type::WIN_HANDLE: + return IPC::MessageAttachment::Type::WIN_HANDLE; + case native::SerializedHandle_Type::MACH_PORT: + return IPC::MessageAttachment::Type::MACH_PORT; + case native::SerializedHandle_Type::FUCHSIA_HANDLE: + return IPC::MessageAttachment::Type::FUCHSIA_HANDLE; + } + NOTREACHED(); + return IPC::MessageAttachment::Type::MOJO_HANDLE; +} + +// static +native::SerializedHandle_Type TypeConverter< + native::SerializedHandle_Type, + IPC::MessageAttachment::Type>::Convert(IPC::MessageAttachment::Type type) { + switch (type) { + case IPC::MessageAttachment::Type::MOJO_HANDLE: + return native::SerializedHandle_Type::MOJO_HANDLE; + case IPC::MessageAttachment::Type::PLATFORM_FILE: + return native::SerializedHandle_Type::PLATFORM_FILE; + case IPC::MessageAttachment::Type::WIN_HANDLE: + return native::SerializedHandle_Type::WIN_HANDLE; + case IPC::MessageAttachment::Type::MACH_PORT: + return native::SerializedHandle_Type::MACH_PORT; + case IPC::MessageAttachment::Type::FUCHSIA_HANDLE: + return native::SerializedHandle_Type::FUCHSIA_HANDLE; + } + NOTREACHED(); + return native::SerializedHandle_Type::MOJO_HANDLE; +} + +} // namespace mojo diff --git a/chromium/ipc/native_handle_type_converters.h b/chromium/ipc/native_handle_type_converters.h new file mode 100644 index 00000000000..81d26c5a992 --- /dev/null +++ b/chromium/ipc/native_handle_type_converters.h @@ -0,0 +1,30 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_NATIVE_HANDLE_CONVERTER_H_ +#define IPC_NATIVE_HANDLE_CONVERTER_H_ + +#include "ipc/ipc_message_attachment.h" +#include "mojo/public/cpp/bindings/type_converter.h" // nogncheck +#include "mojo/public/interfaces/bindings/native_struct.mojom-shared.h" + +namespace mojo { + +template <> +struct TypeConverter<IPC::MessageAttachment::Type, + native::SerializedHandle_Type> { + static IPC::MessageAttachment::Type Convert( + native::SerializedHandle_Type type); +}; + +template <> +struct TypeConverter<native::SerializedHandle_Type, + IPC::MessageAttachment::Type> { + static native::SerializedHandle_Type Convert( + IPC::MessageAttachment::Type type); +}; + +} // namespace mojo + +#endif // IPC_NATIVE_HANDLE_CONVERTER_H_ diff --git a/chromium/ipc/param_traits_macros.h b/chromium/ipc/param_traits_macros.h index 10034402382..7c4cc69275b 100644 --- a/chromium/ipc/param_traits_macros.h +++ b/chromium/ipc/param_traits_macros.h @@ -13,8 +13,6 @@ template <> \ struct IPC_MESSAGE_EXPORT ParamTraits<struct_name> { \ typedef struct_name param_type; \ - static void GetSize(base::PickleSizer* sizer, \ - const param_type& p); \ static void Write(base::Pickle* m, const param_type& p); \ static bool Read(const base::Pickle* m, \ base::PickleIterator* iter, \ @@ -55,8 +53,6 @@ template <> \ struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \ typedef enum_name param_type; \ - static void GetSize(base::PickleSizer* sizer, \ - const param_type& p); \ static void Write(base::Pickle* m, const param_type& p); \ static bool Read(const base::Pickle* m, \ base::PickleIterator* iter, \ diff --git a/chromium/ipc/param_traits_size_macros.h b/chromium/ipc/param_traits_size_macros.h deleted file mode 100644 index 142b55a32d6..00000000000 --- a/chromium/ipc/param_traits_size_macros.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef IPC_PARAM_TRAITS_SIZE_MACROS_H_ -#define IPC_PARAM_TRAITS_SIZE_MACROS_H_ - -// Null out all the macros that need nulling. -#include "ipc/ipc_message_null_macros.h" - -// STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur. -#undef IPC_STRUCT_BEGIN_WITH_PARENT -#undef IPC_STRUCT_MEMBER -#undef IPC_STRUCT_END -#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \ - IPC_STRUCT_TRAITS_BEGIN(struct_name) -#define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name) -#define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END() - -// Set up so next include will generate size methods. -#undef IPC_STRUCT_TRAITS_BEGIN -#undef IPC_STRUCT_TRAITS_MEMBER -#undef IPC_STRUCT_TRAITS_PARENT -#undef IPC_STRUCT_TRAITS_END -#define IPC_STRUCT_TRAITS_BEGIN(struct_name) \ - void ParamTraits<struct_name>::GetSize(base::PickleSizer* sizer, \ - const param_type& p) { -#define IPC_STRUCT_TRAITS_MEMBER(name) GetParamSize(sizer, p.name); -#define IPC_STRUCT_TRAITS_PARENT(type) ParamTraits<type>::GetSize(sizer, p); -#define IPC_STRUCT_TRAITS_END() } - -#undef IPC_ENUM_TRAITS_VALIDATE -#define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \ - void ParamTraits<enum_name>::GetSize(base::PickleSizer* sizer, \ - const param_type& value) { \ - sizer->AddInt(); \ - } - -#endif // IPC_PARAM_TRAITS_SIZE_MACROS_H_ - |