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

Unified Diff: base/memory/shared_memory_handle.h

Issue 1897623002: Remove POSIX shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from amistry. Created 4 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
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_handle_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.h
diff --git a/base/memory/shared_memory_handle.h b/base/memory/shared_memory_handle.h
index 5befcdd6b59f42c50a4ca905c0da28291706b4ca..8eff26b9dcaa811e75326b59d72a632e6bf0e2bf 100644
--- a/base/memory/shared_memory_handle.h
+++ b/base/memory/shared_memory_handle.h
@@ -14,9 +14,7 @@
#include "base/process/process_handle.h"
#elif defined(OS_MACOSX) && !defined(OS_IOS)
#include <mach/mach.h>
-#include <sys/types.h>
#include "base/base_export.h"
-#include "base/file_descriptor_posix.h"
#include "base/macros.h"
#include "base/process/process_handle.h"
#elif defined(OS_POSIX)
@@ -87,32 +85,9 @@ class BASE_EXPORT SharedMemoryHandle {
#else
class BASE_EXPORT SharedMemoryHandle {
public:
- // The values of these enums must not change, as they are used by the
- // histogram OSX.SharedMemory.Mechanism.
- enum Type {
- // The SharedMemoryHandle is backed by a POSIX fd.
- POSIX,
- // The SharedMemoryHandle is backed by the Mach primitive "memory object".
- MACH,
- };
- static const int TypeMax = 2;
-
- // The format that should be used to transmit |Type| over the wire.
- typedef int TypeWireFormat;
-
// The default constructor returns an invalid SharedMemoryHandle.
SharedMemoryHandle();
- // Constructs a SharedMemoryHandle backed by the components of a
- // FileDescriptor. The newly created instance has the same ownership semantics
- // as base::FileDescriptor. This typically means that the SharedMemoryHandle
- // takes ownership of the |fd| if |auto_close| is true. Unfortunately, it's
- // common for existing code to make shallow copies of SharedMemoryHandle, and
- // the one that is finally passed into a base::SharedMemory is the one that
- // "consumes" the fd.
- explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor);
- SharedMemoryHandle(int fd, bool auto_close);
-
// Makes a Mach-based SharedMemoryHandle of the given size. On error,
// subsequent calls to IsValid() return false.
explicit SharedMemoryHandle(mach_vm_size_t size);
@@ -138,28 +113,16 @@ class BASE_EXPORT SharedMemoryHandle {
bool operator==(const SharedMemoryHandle& handle) const;
bool operator!=(const SharedMemoryHandle& handle) const;
- // Returns the type.
- Type GetType() const;
-
// Whether the underlying OS primitive is valid. Once the SharedMemoryHandle
// is backed by a valid OS primitive, it becomes immutable.
bool IsValid() 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);
-
- // This method assumes that the SharedMemoryHandle is backed by a POSIX fd.
- // This is eventually no longer going to be true, so please avoid adding new
- // uses of this method.
- const FileDescriptor GetFileDescriptor() const;
-
// Exposed so that the SharedMemoryHandle can be transported between
// processes.
mach_port_t GetMemoryObject() const;
// Returns false on a failure to determine the size. On success, populates the
- // output variable |size|.
+ // output variable |size|. Returns 0 if the handle is invalid.
bool GetSize(size_t* size) const;
// The SharedMemoryHandle must be valid.
@@ -178,31 +141,21 @@ class BASE_EXPORT SharedMemoryHandle {
// Shared code between copy constructor and operator=.
void CopyRelevantData(const SharedMemoryHandle& handle);
- Type type_;
-
- // Each instance of a SharedMemoryHandle is backed either by a POSIX fd or a
- // mach port. |type_| determines the backing member.
- union {
- FileDescriptor file_descriptor_;
-
- struct {
- mach_port_t memory_object_;
+ mach_port_t memory_object_ = MACH_PORT_NULL;
- // The size of the shared memory region when |type_| is MACH. Only
- // relevant if |memory_object_| is not |MACH_PORT_NULL|.
- mach_vm_size_t size_;
+ // The size of the shared memory region when |type_| is MACH. Only
+ // relevant if |memory_object_| is not |MACH_PORT_NULL|.
+ mach_vm_size_t size_ = 0;
- // The pid of the process in which |memory_object_| is usable. Only
- // relevant if |memory_object_| is not |MACH_PORT_NULL|.
- base::ProcessId pid_;
+ // The pid of the process in which |memory_object_| is usable. Only
+ // relevant if |memory_object_| is not |MACH_PORT_NULL|.
+ base::ProcessId pid_ = 0;
- // Whether passing this object as a parameter to an IPC message passes
- // ownership of |memory_object_| to the IPC stack. This is meant to mimic
- // the behavior of the |auto_close| parameter of FileDescriptor.
- // Defaults to |false|.
- bool ownership_passes_to_ipc_;
- };
- };
+ // Whether passing this object as a parameter to an IPC message passes
+ // ownership of |memory_object_| to the IPC stack. This is meant to mimic
+ // the behavior of the |auto_close| parameter of FileDescriptor.
+ // Defaults to |false|.
+ bool ownership_passes_to_ipc_ = false;
};
#endif
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_handle_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698