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

Unified Diff: base/memory/shared_memory_handle.h

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Comments from thakis. Created 3 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
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:

Powered by Google App Engine
This is Rietveld 408576698