Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Unified Diff: mojo/edk/system/ports_message.cc

Issue 1585493002: [mojo] Ports EDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/edk/system/ports_message.cc
diff --git a/mojo/edk/system/ports_message.cc b/mojo/edk/system/ports_message.cc
new file mode 100644
index 0000000000000000000000000000000000000000..91fe3f3bc35a077d26196bab547267c3769a5a36
--- /dev/null
+++ b/mojo/edk/system/ports_message.cc
@@ -0,0 +1,60 @@
+// 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.
+
+#include "mojo/edk/system/ports_message.h"
+
+#include "mojo/edk/system/node_channel.h"
+
+namespace mojo {
+namespace edk {
+
+// static
+scoped_ptr<PortsMessage> PortsMessage::NewUserMessage(size_t num_payload_bytes,
+ size_t num_ports,
+ size_t num_handles) {
+ return make_scoped_ptr(
+ new PortsMessage(num_payload_bytes, num_ports, num_handles));
+}
+
+PortsMessage::~PortsMessage() {}
+
+PortsMessage::PortsMessage(size_t num_payload_bytes,
+ size_t num_ports,
+ size_t num_handles)
+ : ports::Message(num_payload_bytes, num_ports) {
+ size_t size = num_header_bytes_ + num_ports_bytes_ + num_payload_bytes;
+ void* ptr;
+ channel_message_ = NodeChannel::CreatePortsMessage(size, &ptr, num_handles);
+ InitializeUserMessageHeader(ptr);
+}
+
+PortsMessage::PortsMessage(size_t num_header_bytes,
+ size_t num_payload_bytes,
+ size_t num_ports_bytes,
+ Channel::MessagePtr channel_message)
+ : ports::Message(num_header_bytes,
+ num_payload_bytes,
+ num_ports_bytes) {
+ if (channel_message) {
+ channel_message_ = std::move(channel_message);
+ void* data;
+ size_t num_data_bytes;
+ NodeChannel::GetPortsMessageData(channel_message_.get(), &data,
+ &num_data_bytes);
+ start_ = static_cast<char*>(data);
+ } else {
+ // TODO: Clean this up. In practice this branch of the constructor should
+ // only be reached from Node-internal calls to AllocMessage, which never
+ // carry ports or non-header bytes.
+ CHECK_EQ(num_payload_bytes, 0u);
+ CHECK_EQ(num_ports_bytes, 0u);
+ void* ptr;
+ channel_message_ =
+ NodeChannel::CreatePortsMessage(num_header_bytes, &ptr, 0);
+ start_ = static_cast<char*>(ptr);
+ }
+}
+
+} // namespace edk
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698