Index: base/memory/shared_memory_handle.h |
diff --git a/base/memory/shared_memory_handle.h b/base/memory/shared_memory_handle.h |
index dc33eeafa11faef22f73be0d44dd30447e43118b..edf6c39d0ffe57422758dc75d75f87c7d78397f6 100644 |
--- a/base/memory/shared_memory_handle.h |
+++ b/base/memory/shared_memory_handle.h |
@@ -27,8 +27,49 @@ namespace base { |
// SharedMemoryHandle is a platform specific type which represents |
// the underlying OS handle to a shared memory segment. |
+// TODO(erikchen): Refactor this to create a single class on all platforms, |
+// rather than 3 separate class definitions that are very similar. |
+// https://crbug.com/713763. |
#if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
-typedef FileDescriptor SharedMemoryHandle; |
+class BASE_EXPORT SharedMemoryHandle { |
+ public: |
+ // The default constructor returns an invalid SharedMemoryHandle. |
+ SharedMemoryHandle(); |
+ |
+ // This constructor is deprecated, as it fails to propagate the GUID, which |
+ // will be added in the near future. |
+ // TODO(rockot): Remove this constructor once Mojo supports GUIDs. |
+ // https://crbug.com/713763. |
+ explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor); |
+ |
+ // Creates a SharedMemoryHandle from an |fd| supplied from an external |
+ // service. |
+ static SharedMemoryHandle ImportHandle(int fd); |
+ |
+ // Returns the underlying OS resource. |
+ int GetHandle() const; |
+ |
+ // Whether the underlying OS resource is valid. |
+ bool IsValid() const; |
+ |
+ // Closes the underlying OS resource. |
+ // The fact that this method needs to be "const" is an artifact of the |
+ // original interface for base::SharedMemory::CloseHandle. |
+ // TODO(erikchen): This doesn't clear the underlying reference, which seems |
+ // like a bug, but is how this class has always worked. Fix this: |
+ // https://crbug.com/716072. |
+ void Close() const; |
+ |
+ // Invalidates [but doesn't close] the underlying OS resource. This will leak |
+ // unless the caller is careful. |
+ int Release(); |
+ |
+ // Duplicates the underlying OS resource. |
+ SharedMemoryHandle Duplicate() const; |
+ |
+ // This must be public to support serialization by Chrome IPC. |
+ FileDescriptor file_descriptor; |
+}; |
#elif defined(OS_WIN) |
class BASE_EXPORT SharedMemoryHandle { |
public: |