forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use BigBuffer for legacy IPC messages
This replaces use of ReadOnlyBuffer with a new mojom Message type specific to //ipc. This type maps to another new C++ MessageView type which in turn wraps a BigBufferView. This allows us to transparently fall back onto shared memory for large IPC messages without increasing the number of copies during send or receive in any (small- or large-message) cases. In order to avoid introducing more mojo-base targets, this also removes the remaining [Native] structs from mojo_base mojom (LOGFONT and FileInfo) and replaces them with real mojom structures + StructTraits, thus allowing //ipc to depend on mojo/public/*/base in its entirety. Also fixes random missing public_deps entries for a chrome/services/file_util typemap, because it decided to start breaking all of my local builds. :3 Bug: 784069 Change-Id: I359b964ffc1fe44ffd6aa704405ea63156f4fbc9 Reviewed-on: https://chromium-review.googlesource.com/1131685 Commit-Queue: Ken Rockot <rockot@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/master@{#573956}
- Loading branch information
Showing
27 changed files
with
391 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2018 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. | ||
|
||
mojom = "//ipc/ipc.mojom" | ||
public_headers = [ "//ipc/message_view.h" ] | ||
traits_headers = [ "//ipc/message_mojom_traits.h" ] | ||
sources = [ | ||
"//ipc/message_mojom_traits.cc", | ||
"//ipc/message_mojom_traits.h", | ||
"//ipc/message_view.cc", | ||
"//ipc/message_view.h", | ||
] | ||
public_deps = [ | ||
"//ipc:message_support", | ||
"//mojo/public/cpp/base:shared_typemap_traits", | ||
] | ||
type_mappings = [ "IPC.mojom.Message=IPC::MessageView[move_only]" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 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/message_mojom_traits.h" | ||
|
||
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h" | ||
|
||
namespace mojo { | ||
|
||
// static | ||
mojo_base::BigBufferView | ||
StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::buffer( | ||
IPC::MessageView& view) { | ||
return view.TakeBufferView(); | ||
} | ||
|
||
// static | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> | ||
StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::handles( | ||
IPC::MessageView& view) { | ||
return view.TakeHandles(); | ||
} | ||
|
||
// static | ||
bool StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::Read( | ||
IPC::mojom::MessageDataView data, | ||
IPC::MessageView* out) { | ||
mojo_base::BigBufferView buffer_view; | ||
if (!data.ReadBuffer(&buffer_view)) | ||
return false; | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles; | ||
if (!data.ReadHandles(&handles)) | ||
return false; | ||
|
||
*out = IPC::MessageView(std::move(buffer_view), std::move(handles)); | ||
return true; | ||
} | ||
|
||
} // namespace mojo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2018 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_MESSAGE_MOJOM_TRAITS_H_ | ||
#define IPC_MESSAGE_MOJOM_TRAITS_H_ | ||
|
||
#include <vector> | ||
|
||
#include "base/optional.h" | ||
#include "ipc/ipc.mojom-shared.h" | ||
#include "ipc/message_view.h" | ||
#include "mojo/public/cpp/base/big_buffer.h" | ||
#include "mojo/public/cpp/bindings/struct_traits.h" | ||
#include "mojo/public/interfaces/bindings/native_struct.mojom.h" | ||
|
||
namespace mojo { | ||
|
||
template <> | ||
class StructTraits<IPC::mojom::MessageDataView, IPC::MessageView> { | ||
public: | ||
static mojo_base::BigBufferView buffer(IPC::MessageView& view); | ||
static base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles( | ||
IPC::MessageView& view); | ||
|
||
static bool Read(IPC::mojom::MessageDataView data, IPC::MessageView* out); | ||
}; | ||
|
||
} // namespace mojo | ||
|
||
#endif // IPC_MESSAGE_MOJOM_TRAITS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018 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/message_view.h" | ||
|
||
namespace IPC { | ||
|
||
MessageView::MessageView() = default; | ||
|
||
MessageView::MessageView( | ||
const Message& message, | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles) | ||
: buffer_view_(base::make_span<const uint8_t>( | ||
static_cast<const uint8_t*>(message.data()), | ||
message.size())), | ||
handles_(std::move(handles)) {} | ||
|
||
MessageView::MessageView( | ||
mojo_base::BigBufferView buffer_view, | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles) | ||
: buffer_view_(std::move(buffer_view)), handles_(std::move(handles)) {} | ||
|
||
MessageView::MessageView(MessageView&&) = default; | ||
|
||
MessageView::~MessageView() = default; | ||
|
||
MessageView& MessageView::operator=(MessageView&&) = default; | ||
|
||
} // namespace IPC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2018 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_MESSAGE_VIEW_H_ | ||
#define IPC_MESSAGE_VIEW_H_ | ||
|
||
#include <vector> | ||
|
||
#include "base/component_export.h" | ||
#include "base/containers/span.h" | ||
#include "base/macros.h" | ||
#include "ipc/ipc_message.h" | ||
#include "mojo/public/cpp/base/big_buffer.h" | ||
#include "mojo/public/interfaces/bindings/native_struct.mojom.h" | ||
|
||
namespace IPC { | ||
|
||
class COMPONENT_EXPORT(IPC_MOJOM) MessageView { | ||
public: | ||
MessageView(); | ||
MessageView( | ||
const Message& message, | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles); | ||
MessageView( | ||
mojo_base::BigBufferView buffer_view, | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles); | ||
MessageView(MessageView&&); | ||
~MessageView(); | ||
|
||
MessageView& operator=(MessageView&&); | ||
|
||
const char* data() const { | ||
return reinterpret_cast<const char*>(buffer_view_.data().data()); | ||
} | ||
|
||
uint32_t size() const { | ||
return static_cast<uint32_t>(buffer_view_.data().size()); | ||
} | ||
|
||
mojo_base::BigBufferView TakeBufferView() { return std::move(buffer_view_); } | ||
|
||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> TakeHandles() { | ||
return std::move(handles_); | ||
} | ||
|
||
private: | ||
mojo_base::BigBufferView buffer_view_; | ||
base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MessageView); | ||
}; | ||
|
||
} // namespace IPC | ||
|
||
#endif // IPC_MESSAGE_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2018 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. | ||
|
||
typemaps = [ "//ipc/message.typemap" ] |
Oops, something went wrong.