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

Unified Diff: base/memory/shared_memory_handle.h

Issue 1163943004: Make SharedMemoryHandle a class on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared_memory_make_class3_base
Patch Set: Fix NACL rewriting of IPC messages. Created 5 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
Index: base/memory/shared_memory_handle.h
diff --git a/base/memory/shared_memory_handle.h b/base/memory/shared_memory_handle.h
new file mode 100644
index 0000000000000000000000000000000000000000..080b31e51bccd035e1358f3513190fa82a1e8d49
--- /dev/null
+++ b/base/memory/shared_memory_handle.h
@@ -0,0 +1,99 @@
+// 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.
+
+#ifndef BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
+#define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
+
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+#elif defined(OS_MACOSX) && !defined(OS_IOS)
+#include <sys/types.h>
+#include "base/base_export.h"
+#include "base/file_descriptor_posix.h"
+#include "base/macros.h"
+#elif defined(OS_POSIX)
+#include <sys/types.h>
+#include "base/file_descriptor_posix.h"
+#endif
+
+namespace base {
+
+class Pickle;
+
+// SharedMemoryHandle is a platform specific type which represents
+// the underlying OS handle to a shared memory segment.
+#if defined(OS_WIN)
+typedef HANDLE SharedMemoryHandle;
+#elif defined(OS_MACOSX) && !defined(OS_IOS)
+
+class BASE_EXPORT SharedMemoryHandle {
+ public:
+ enum Mechanism {
Robert Sesek 2015/06/15 21:34:33 "Mechanism" seems very verbose to me. Does "Type"
erikchen 2015/06/16 00:59:27 I think "Type" is a poor choice for a type, since
Robert Sesek 2015/06/16 22:53:05 If it were just "Type" I'd agree, but since the fu
+ // Indicates that the SharedMemoryHandle is backed by a POSIX fd.
+ POSIX,
+ // Indicates that the SharedMemoryHandle is backed by the Mach primitive
+ // "memory object".
+ MACH,
+ };
+
+ // The default constructor returns an invalid SharedMemoryHandle.
+ SharedMemoryHandle();
+
+ // Constructs a SharedMemoryHandle backed by |file_descriptor|.
+ explicit SharedMemoryHandle(const FileDescriptor& file_descriptor);
+
+ // Constructs a SharedMemoryHandle backed by the components of a
+ // FileDescriptor.
+ SharedMemoryHandle(int fd, bool auto_close);
+
+ // Standard copy constructor. The new instance shares the underlying OS
+ // primitives.
+ SharedMemoryHandle(const SharedMemoryHandle& handle);
+
+ // Standard assignment operator. The updated instance shares the underlying
+ // OS primitives.
+ SharedMemoryHandle& operator=(const SharedMemoryHandle& handle);
+
+ // Comparison operators.
+ bool operator==(const SharedMemoryHandle& handle) const;
+ bool operator!=(const SharedMemoryHandle& handle) const;
+
+ // Serializes the mechanism.
+ void WriteMechanismToPickle(Pickle* pickle) const;
+
+ // Deserializes the mechanism from the pickle iterator.
+ bool ReadMechanismFromPickle(PickleIterator* iterator);
+
+ // Whether the instance is backed by a POSIX fd.
+ bool IsBackedByPOSIXFd() const;
+
+ // Returns the POSIX fd backing the SharedMemoryHandle. Requires that the
Robert Sesek 2015/06/15 21:34:32 Is this necessary if there's also GetFileDescripto
erikchen 2015/06/16 00:59:27 Nope. I've removed this method. I prefer to keep t
+ // SharedMemoryHandle be backed by a POSIX fd.
+ int GetFileHandle() const;
+
+ // Sets the POSIX fd backing the SharedMemoryHandle. Requires that the
+ // SharedMemoryHandle be backed by a POSIX fd.
+ void SetFileHandle(int fd, bool auto_close);
+
+ // Returns the address of the POSIX FileDescriptor backing the
+ // SharedMemoryHandle.
+ FileDescriptor* GetFileDescriptor();
+ const FileDescriptor* GetFileDescriptor() const;
+
+ // Duplicates the underlying OS resources.
Robert Sesek 2015/06/15 21:34:33 Move this up to be after or before teh assignment
erikchen 2015/06/16 00:59:27 Sure, done
+ SharedMemoryHandle Duplicate() const;
+
+ private:
+ Mechanism mechanism_;
+ FileDescriptor file_descriptor_;
+};
+#elif defined(OS_POSIX)
+typedef FileDescriptor SharedMemoryHandle;
+#endif
+
+} // namespace base
+
+#endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_

Powered by Google App Engine
This is Rietveld 408576698