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

Unified Diff: mojo/common/common_custom_types_struct_traits_posix.cc

Issue 2561003002: Add mojo structs for ScopedFD and ScopedHandle. (Closed)
Patch Set: Created 4 years 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/common/common_custom_types_struct_traits_posix.cc
diff --git a/mojo/common/common_custom_types_struct_traits_posix.cc b/mojo/common/common_custom_types_struct_traits_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3319a5064952a2b69c4742e706d3a226be209c5f
--- /dev/null
+++ b/mojo/common/common_custom_types_struct_traits_posix.cc
@@ -0,0 +1,30 @@
+// 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/common/common_custom_types_struct_traits_posix.h"
+
+#include "mojo/public/cpp/system/platform_handle.h"
+
+namespace mojo {
+
+mojo::ScopedHandle
+StructTraits<common::mojom::FileDescriptorDataView,
+ base::ScopedFD>::wrapped_handle(base::ScopedFD& fd) {
+ DCHECK(fd.is_valid());
+ return mojo::WrapPlatformFile(fd.release());
+}
+
+bool StructTraits<common::mojom::FileDescriptorDataView, base::ScopedFD>::Read(
+ common::mojom::FileDescriptorDataView data,
+ base::ScopedFD* fd) {
+ base::PlatformFile platform_handle = base::kInvalidPlatformFile;
+ if (mojo::UnwrapPlatformFile(data.TakeWrappedHandle(), &platform_handle) !=
+ MOJO_RESULT_OK) {
+ return false;
+ }
+ *fd = base::ScopedFD(platform_handle);
+ return true;
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/common/common_custom_types_struct_traits_posix.h ('k') | mojo/common/common_custom_types_struct_traits_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698