Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 5 #ifndef BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
| 6 #define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 6 #define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #elif defined(OS_POSIX) | 21 #elif defined(OS_POSIX) |
| 22 #include <sys/types.h> | 22 #include <sys/types.h> |
| 23 #include "base/file_descriptor_posix.h" | 23 #include "base/file_descriptor_posix.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 | 27 |
| 28 // SharedMemoryHandle is a platform specific type which represents | 28 // SharedMemoryHandle is a platform specific type which represents |
| 29 // the underlying OS handle to a shared memory segment. | 29 // the underlying OS handle to a shared memory segment. |
| 30 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 30 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
| 31 typedef FileDescriptor SharedMemoryHandle; | 31 class BASE_EXPORT SharedMemoryHandle { |
|
Nico
2017/04/27 16:24:44
Since they're now classes everywhere, I think it'd
erikchen
2017/04/27 17:08:10
Added a TODO.
| |
| 32 public: | |
| 33 // The default constructor returns an invalid SharedMemoryHandle. | |
| 34 SharedMemoryHandle(); | |
| 35 | |
| 36 // This constructor is deprecated, as it fails to propagate the GUID, which | |
| 37 // will be added in the near future. | |
| 38 // TODO(rockot): Remove this constructor once Mojo supports GUIDs. | |
| 39 // https://crbug.com/713763. | |
| 40 explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor); | |
| 41 | |
| 42 // Creates a SharedMemoryHandle from an |fd| supplied from an external | |
| 43 // service. | |
| 44 static SharedMemoryHandle ImportHandle(int fd); | |
|
Nico
2017/04/27 16:24:44
This type of thing seems to be a ctor instead of a
erikchen
2017/04/27 17:08:10
The constructors on Mac/Win will be going away. On
| |
| 45 | |
| 46 // Returns the underlying OS resource. | |
| 47 int GetHandle() const; | |
| 48 | |
| 49 // Whether the underlying OS resource is valid. | |
| 50 bool IsValid() const; | |
| 51 | |
| 52 // Closes the underlying OS resource. | |
| 53 // The fact that this method needs to be "const" is an artifact of the | |
| 54 // original interface for base::SharedMemory::CloseHandle. | |
| 55 void Close() const; | |
| 56 | |
| 57 // Invalidates [but doesn't close] the underlying OS resource. | |
|
Nico
2017/04/27 16:24:44
Maybe say "leak unless careful" in the comment. So
erikchen
2017/04/27 17:08:10
Done.
| |
| 58 void Invalidate(); | |
| 59 | |
| 60 // Duplicates the underlying OS resource. | |
| 61 SharedMemoryHandle Duplicate() const; | |
| 62 | |
| 63 FileDescriptor file_descriptor; | |
|
Nico
2017/04/27 16:24:44
make private
erikchen
2017/04/27 17:08:10
Can't do that, Chrome IPC serialization requires t
Nico
2017/04/27 17:38:50
Add accessors for what's needed by IPC?
erikchen
2017/04/27 18:13:42
Done.
[The Chrome IPC macros don't support non-pu
| |
| 64 }; | |
| 32 #elif defined(OS_WIN) | 65 #elif defined(OS_WIN) |
| 33 class BASE_EXPORT SharedMemoryHandle { | 66 class BASE_EXPORT SharedMemoryHandle { |
| 34 public: | 67 public: |
| 35 // The default constructor returns an invalid SharedMemoryHandle. | 68 // The default constructor returns an invalid SharedMemoryHandle. |
| 36 SharedMemoryHandle(); | 69 SharedMemoryHandle(); |
| 37 SharedMemoryHandle(HANDLE h, base::ProcessId pid); | 70 SharedMemoryHandle(HANDLE h, base::ProcessId pid); |
| 38 | 71 |
| 39 // Standard copy constructor. The new instance shares the underlying OS | 72 // Standard copy constructor. The new instance shares the underlying OS |
| 40 // primitives. | 73 // primitives. |
| 41 SharedMemoryHandle(const SharedMemoryHandle& handle); | 74 SharedMemoryHandle(const SharedMemoryHandle& handle); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // Defaults to |false|. | 215 // Defaults to |false|. |
| 183 bool ownership_passes_to_ipc_; | 216 bool ownership_passes_to_ipc_; |
| 184 }; | 217 }; |
| 185 }; | 218 }; |
| 186 }; | 219 }; |
| 187 #endif | 220 #endif |
| 188 | 221 |
| 189 } // namespace base | 222 } // namespace base |
| 190 | 223 |
| 191 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 224 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
| OLD | NEW |