Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | |
| 6 #define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | |
| 7 | |
| 8 #include "build/build_config.h" | |
| 9 | |
| 10 #if defined(OS_WIN) | |
| 11 #include <windows.h> | |
| 12 #elif defined(OS_MACOSX) && !defined(OS_IOS) | |
| 13 #include <sys/types.h> | |
| 14 #include "base/base_export.h" | |
| 15 #include "base/file_descriptor_posix.h" | |
| 16 #include "base/macros.h" | |
| 17 #elif defined(OS_POSIX) | |
| 18 #include <sys/types.h> | |
| 19 #include "base/file_descriptor_posix.h" | |
| 20 #endif | |
| 21 | |
| 22 namespace base { | |
| 23 | |
| 24 class Pickle; | |
| 25 | |
| 26 // SharedMemoryHandle is a platform specific type which represents | |
| 27 // the underlying OS handle to a shared memory segment. | |
| 28 #if defined(OS_WIN) | |
| 29 typedef HANDLE SharedMemoryHandle; | |
| 30 #elif defined(OS_MACOSX) && !defined(OS_IOS) | |
| 31 | |
| 32 class BASE_EXPORT SharedMemoryHandle { | |
| 33 public: | |
| 34 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
| |
| 35 // Indicates that the SharedMemoryHandle is backed by a POSIX fd. | |
| 36 POSIX, | |
| 37 // Indicates that the SharedMemoryHandle is backed by the Mach primitive | |
| 38 // "memory object". | |
| 39 MACH, | |
| 40 }; | |
| 41 | |
| 42 // The default constructor returns an invalid SharedMemoryHandle. | |
| 43 SharedMemoryHandle(); | |
| 44 | |
| 45 // Constructs a SharedMemoryHandle backed by |file_descriptor|. | |
| 46 explicit SharedMemoryHandle(const FileDescriptor& file_descriptor); | |
| 47 | |
| 48 // Constructs a SharedMemoryHandle backed by the components of a | |
| 49 // FileDescriptor. | |
| 50 SharedMemoryHandle(int fd, bool auto_close); | |
| 51 | |
| 52 // Standard copy constructor. The new instance shares the underlying OS | |
| 53 // primitives. | |
| 54 SharedMemoryHandle(const SharedMemoryHandle& handle); | |
| 55 | |
| 56 // Standard assignment operator. The updated instance shares the underlying | |
| 57 // OS primitives. | |
| 58 SharedMemoryHandle& operator=(const SharedMemoryHandle& handle); | |
| 59 | |
| 60 // Comparison operators. | |
| 61 bool operator==(const SharedMemoryHandle& handle) const; | |
| 62 bool operator!=(const SharedMemoryHandle& handle) const; | |
| 63 | |
| 64 // Serializes the mechanism. | |
| 65 void WriteMechanismToPickle(Pickle* pickle) const; | |
| 66 | |
| 67 // Deserializes the mechanism from the pickle iterator. | |
| 68 bool ReadMechanismFromPickle(PickleIterator* iterator); | |
| 69 | |
| 70 // Whether the instance is backed by a POSIX fd. | |
| 71 bool IsBackedByPOSIXFd() const; | |
| 72 | |
| 73 // 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
| |
| 74 // SharedMemoryHandle be backed by a POSIX fd. | |
| 75 int GetFileHandle() const; | |
| 76 | |
| 77 // Sets the POSIX fd backing the SharedMemoryHandle. Requires that the | |
| 78 // SharedMemoryHandle be backed by a POSIX fd. | |
| 79 void SetFileHandle(int fd, bool auto_close); | |
| 80 | |
| 81 // Returns the address of the POSIX FileDescriptor backing the | |
| 82 // SharedMemoryHandle. | |
| 83 FileDescriptor* GetFileDescriptor(); | |
| 84 const FileDescriptor* GetFileDescriptor() const; | |
| 85 | |
| 86 // 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
| |
| 87 SharedMemoryHandle Duplicate() const; | |
| 88 | |
| 89 private: | |
| 90 Mechanism mechanism_; | |
| 91 FileDescriptor file_descriptor_; | |
| 92 }; | |
| 93 #elif defined(OS_POSIX) | |
| 94 typedef FileDescriptor SharedMemoryHandle; | |
| 95 #endif | |
| 96 | |
| 97 } // namespace base | |
| 98 | |
| 99 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | |
| OLD | NEW |