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

Unified Diff: components/mus/gpu/gpu_type_converters.cc

Issue 1923593003: Add mus::mojom::ChannelHandle for passing IPC::ChannelHandle via mojo IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 8 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 | « components/mus/gpu/gpu_type_converters.h ('k') | components/mus/gpu/gpu_type_converters_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/gpu/gpu_type_converters.cc
diff --git a/components/mus/gpu/gpu_type_converters.cc b/components/mus/gpu/gpu_type_converters.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ddeed608a2c9fcb2a6774ba1d7ed08a84c97d4a2
--- /dev/null
+++ b/components/mus/gpu/gpu_type_converters.cc
@@ -0,0 +1,53 @@
+// 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 "components/mus/gpu/gpu_type_converters.h"
+
+#include "ipc/ipc_channel_handle.h"
+#include "mojo/platform_handle/platform_handle_functions.h"
+
+namespace mojo {
+
+// static
+mus::mojom::ChannelHandlePtr
+TypeConverter<mus::mojom::ChannelHandlePtr, IPC::ChannelHandle>::Convert(
+ const IPC::ChannelHandle& handle) {
+ mus::mojom::ChannelHandlePtr result = mus::mojom::ChannelHandle::New();
+ result->name = handle.name;
+#if defined(OS_WIN)
+ // On windows, a pipe handle Will NOT be marshalled over IPC.
+ DCHECK(handle.pipe.handle == NULL);
+#else
+ MojoPlatformHandle platform_handle =
+ handle.socket.fd == -1 ? -1 : dup(handle.socket.fd);
+ MojoHandle mojo_handle = MOJO_HANDLE_INVALID;
+ if (platform_handle != -1) {
+ MojoResult create_result =
+ MojoCreatePlatformHandleWrapper(platform_handle, &mojo_handle);
+ if (create_result == MOJO_RESULT_OK)
+ result->socket.reset(mojo::Handle(mojo_handle));
+ }
+#endif
+ return result;
+}
+
+// static
+IPC::ChannelHandle
+TypeConverter<IPC::ChannelHandle, mus::mojom::ChannelHandlePtr>::Convert(
+ const mus::mojom::ChannelHandlePtr& handle) {
+ if (handle.is_null())
+ return IPC::ChannelHandle();
+#if defined(OS_WIN)
+ // On windows, a pipe handle Will NOT be marshalled over IPC.
+ DCHECK(!handle->socket.is_valid());
+ return IPC::ChannelHandle(handle->name);
+#else
+ MojoPlatformHandle platform_handle = -1;
+ MojoExtractPlatformHandle(handle->socket.release().value(), &platform_handle);
+ return IPC::ChannelHandle(handle->name,
+ base::FileDescriptor(platform_handle, true));
+#endif
+}
+
+} // namespace mojo
« no previous file with comments | « components/mus/gpu/gpu_type_converters.h ('k') | components/mus/gpu/gpu_type_converters_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698