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

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

Issue 2043713004: Mojo: Add NotifyBadMessage API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no bindings Created 4 years, 6 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
« no previous file with comments | « mojo/edk/system/node_channel.h ('k') | mojo/edk/system/node_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/node_channel.cc
diff --git a/mojo/edk/system/node_channel.cc b/mojo/edk/system/node_channel.cc
index eee417799afaf273e237d227e2c9961e05669a15..1608a3d6b5f7cb6908b9323790ecd219f2514d92 100644
--- a/mojo/edk/system/node_channel.cc
+++ b/mojo/edk/system/node_channel.cc
@@ -44,6 +44,9 @@ enum class MessageType : uint32_t {
RELAY_PORTS_MESSAGE,
#endif
BROADCAST,
+#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
+ PORTS_MESSAGE_FROM_RELAY,
+#endif
};
struct Header {
@@ -112,6 +115,11 @@ struct IntroductionData {
struct RelayPortsMessageData {
ports::NodeName destination;
};
+
+// This struct is followed by the full payload of a relayed message.
+struct PortsMessageFromRelayData {
+ ports::NodeName source;
+};
#endif
template <typename DataType>
@@ -146,12 +154,14 @@ bool GetMessagePayload(const void* bytes,
scoped_refptr<NodeChannel> NodeChannel::Create(
Delegate* delegate,
ScopedPlatformHandle platform_handle,
- scoped_refptr<base::TaskRunner> io_task_runner) {
+ scoped_refptr<base::TaskRunner> io_task_runner,
+ const ProcessErrorCallback& process_error_callback) {
#if defined(OS_NACL)
LOG(FATAL) << "Multi-process not yet supported on NaCl";
return nullptr;
#else
- return new NodeChannel(delegate, std::move(platform_handle), io_task_runner);
+ return new NodeChannel(delegate, std::move(platform_handle), io_task_runner,
+ process_error_callback);
#endif
}
@@ -198,6 +208,11 @@ void NodeChannel::ShutDown() {
}
}
+void NodeChannel::NotifyBadMessage(const std::string& error) {
+ if (!process_error_callback_.is_null())
+ process_error_callback_.Run("Received bad user message: " + error);
+}
+
void NodeChannel::SetRemoteProcessHandle(base::ProcessHandle process_handle) {
DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
base::AutoLock lock(remote_process_handle_lock_);
@@ -380,13 +395,30 @@ void NodeChannel::RelayPortsMessage(const ports::NodeName& destination,
WriteChannelMessage(std::move(relay_message));
}
+
+void NodeChannel::PortsMessageFromRelay(const ports::NodeName& source,
+ Channel::MessagePtr message) {
+ size_t num_bytes = sizeof(PortsMessageFromRelayData) +
+ message->payload_size();
+ PortsMessageFromRelayData* data;
+ Channel::MessagePtr relayed_message = CreateMessage(
+ MessageType::PORTS_MESSAGE_FROM_RELAY, num_bytes, message->num_handles(),
+ &data);
+ data->source = source;
+ if (message->payload_size())
+ memcpy(data + 1, message->payload(), message->payload_size());
+ relayed_message->SetHandles(message->TakeHandles());
+ WriteChannelMessage(std::move(relayed_message));
+}
#endif // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
NodeChannel::NodeChannel(Delegate* delegate,
ScopedPlatformHandle platform_handle,
- scoped_refptr<base::TaskRunner> io_task_runner)
+ scoped_refptr<base::TaskRunner> io_task_runner,
+ const ProcessErrorCallback& process_error_callback)
: delegate_(delegate),
- io_task_runner_(io_task_runner)
+ io_task_runner_(io_task_runner),
+ process_error_callback_(process_error_callback)
#if !defined(OS_NACL)
, channel_(
Channel::Create(this, std::move(platform_handle), io_task_runner_))
@@ -643,6 +675,29 @@ void NodeChannel::OnChannelMessage(const void* payload,
DVLOG(1) << "Ignoring unhandled BROADCAST message.";
return;
+#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
+ case MessageType::PORTS_MESSAGE_FROM_RELAY:
+ const PortsMessageFromRelayData* data;
+ if (GetMessagePayload(payload, payload_size, &data)) {
+ size_t num_bytes = payload_size - sizeof(*data);
+ if (num_bytes < sizeof(Header))
+ break;
+ num_bytes -= sizeof(Header);
+
+ size_t num_handles = handles ? handles->size() : 0;
+ Channel::MessagePtr message(
+ new Channel::Message(num_bytes, num_handles));
+ message->SetHandles(std::move(handles));
+ if (num_bytes)
+ memcpy(message->mutable_payload(), data + 1, num_bytes);
+ delegate_->OnPortsMessageFromRelay(
+ remote_node_name_, data->source, std::move(message));
+ return;
+ }
+ break;
+
+#endif // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
+
default:
break;
}
« no previous file with comments | « mojo/edk/system/node_channel.h ('k') | mojo/edk/system/node_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698