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

Unified Diff: base/memory/shared_memory_handle_mac.cc

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.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
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_handle_mac.cc
diff --git a/base/memory/shared_memory_handle_mac.cc b/base/memory/shared_memory_handle_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..86f5c546ae2ce3977a0904a910ab63008a114d39
--- /dev/null
+++ b/base/memory/shared_memory_handle_mac.cc
@@ -0,0 +1,86 @@
+// Copyright 2015 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 "base/memory/shared_memory_handle.h"
+
+#include <unistd.h>
+
+#include "base/posix/eintr_wrapper.h"
+
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+namespace base {
+
+static_assert(sizeof(SharedMemoryHandle::Type) <=
+ sizeof(SharedMemoryHandle::TypeWireFormat),
+ "Size of enum SharedMemoryHandle::Type exceeds size of type "
+ "transmitted over wire.");
+
+SharedMemoryHandle::SharedMemoryHandle() : type_(POSIX), file_descriptor_() {}
+
+SharedMemoryHandle::SharedMemoryHandle(
+ const base::FileDescriptor& file_descriptor)
+ : type_(POSIX), file_descriptor_(file_descriptor) {}
+
+SharedMemoryHandle::SharedMemoryHandle(int fd, bool auto_close)
+ : type_(POSIX), file_descriptor_(fd, auto_close) {}
+
+SharedMemoryHandle::SharedMemoryHandle(const SharedMemoryHandle& handle)
+ : type_(handle.type_), file_descriptor_(handle.file_descriptor_) {}
+
+SharedMemoryHandle& SharedMemoryHandle::operator=(
+ const SharedMemoryHandle& handle) {
+ if (this == &handle)
+ return *this;
+
+ type_ = handle.type_;
+ file_descriptor_ = handle.file_descriptor_;
+ return *this;
+}
+
+bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const {
+ // Invalid handles are always equal, even if they have different types.
+ if (!IsValid() && !handle.IsValid())
+ return true;
+
+ return type_ == handle.type_ && file_descriptor_ == handle.file_descriptor_;
+}
+
+bool SharedMemoryHandle::operator!=(const SharedMemoryHandle& handle) const {
+ return !(*this == handle);
+}
+
+SharedMemoryHandle::Type SharedMemoryHandle::GetType() const {
+ return type_;
+}
+
+bool SharedMemoryHandle::IsValid() const {
+ switch (type_) {
+ case POSIX:
+ return file_descriptor_.fd >= 0;
+ case MACH:
+ return false;
+ }
+}
+
+void SharedMemoryHandle::SetFileHandle(int fd, bool auto_close) {
+ DCHECK_EQ(type_, POSIX);
+ file_descriptor_.fd = fd;
+ file_descriptor_.auto_close = auto_close;
+}
+
+const FileDescriptor SharedMemoryHandle::GetFileDescriptor() const {
+ DCHECK_EQ(type_, POSIX);
+ return file_descriptor_;
+}
+
+SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
+ DCHECK_EQ(type_, POSIX);
+ int duped_handle = HANDLE_EINTR(dup(file_descriptor_.fd));
+ if (duped_handle < 0)
+ return SharedMemoryHandle();
+ return SharedMemoryHandle(duped_handle, true);
+}
+
+} // namespace base
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698