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 "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
11 #include <windows.h> | 11 #include <windows.h> |
| 12 #include "base/process/process_handle.h" |
12 #elif defined(OS_MACOSX) | 13 #elif defined(OS_MACOSX) |
13 #include <sys/types.h> | 14 #include <sys/types.h> |
14 #include "base/base_export.h" | 15 #include "base/base_export.h" |
15 #include "base/file_descriptor_posix.h" | 16 #include "base/file_descriptor_posix.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #elif defined(OS_POSIX) | 18 #elif defined(OS_POSIX) |
18 #include <sys/types.h> | 19 #include <sys/types.h> |
19 #include "base/file_descriptor_posix.h" | 20 #include "base/file_descriptor_posix.h" |
20 #endif | 21 #endif |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 | 24 |
24 class Pickle; | 25 class Pickle; |
25 | 26 |
26 // SharedMemoryHandle is a platform specific type which represents | 27 // SharedMemoryHandle is a platform specific type which represents |
27 // the underlying OS handle to a shared memory segment. | 28 // the underlying OS handle to a shared memory segment. |
28 #if defined(OS_WIN) | 29 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
29 typedef HANDLE SharedMemoryHandle; | |
30 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | |
31 typedef FileDescriptor SharedMemoryHandle; | 30 typedef FileDescriptor SharedMemoryHandle; |
| 31 #elif defined(OS_WIN) |
| 32 class BASE_EXPORT SharedMemoryHandle { |
| 33 public: |
| 34 // The default constructor returns an invalid SharedMemoryHandle. |
| 35 SharedMemoryHandle(); |
| 36 SharedMemoryHandle(HANDLE h, base::ProcessId pid); |
| 37 |
| 38 // Standard copy constructor. The new instance shares the underlying OS |
| 39 // primitives. |
| 40 SharedMemoryHandle(const SharedMemoryHandle& handle); |
| 41 |
| 42 // Standard assignment operator. The updated instance shares the underlying |
| 43 // OS primitives. |
| 44 SharedMemoryHandle& operator=(const SharedMemoryHandle& handle); |
| 45 |
| 46 // Comparison operators. |
| 47 bool operator==(const SharedMemoryHandle& handle) const; |
| 48 bool operator!=(const SharedMemoryHandle& handle) const; |
| 49 |
| 50 // Closes the underlying OS resources. |
| 51 void Close() const; |
| 52 |
| 53 // Whether the underlying OS primitive is valid. |
| 54 bool IsValid() const; |
| 55 |
| 56 // Whether |pid_| is the same as the current process's id. |
| 57 bool BelongsToCurrentProcess() const; |
| 58 |
| 59 // Whether handle_ needs to be duplicated into the destination process when |
| 60 // an instance of this class is passed over a Chrome IPC channel. |
| 61 bool NeedsBrokering() const; |
| 62 |
| 63 HANDLE GetHandle() const; |
| 64 base::ProcessId GetPID() const; |
| 65 |
| 66 private: |
| 67 HANDLE handle_; |
| 68 |
| 69 // The process in which |handle_| is valid and can be used. If |handle_| is |
| 70 // invalid, this will be kNullProcessId. |
| 71 base::ProcessId pid_; |
| 72 }; |
32 #else | 73 #else |
33 class BASE_EXPORT SharedMemoryHandle { | 74 class BASE_EXPORT SharedMemoryHandle { |
34 public: | 75 public: |
35 enum Type { | 76 enum Type { |
36 // Indicates that the SharedMemoryHandle is backed by a POSIX fd. | 77 // Indicates that the SharedMemoryHandle is backed by a POSIX fd. |
37 POSIX, | 78 POSIX, |
38 // Indicates that the SharedMemoryHandle is backed by the Mach primitive | 79 // Indicates that the SharedMemoryHandle is backed by the Mach primitive |
39 // "memory object". | 80 // "memory object". |
40 MACH, | 81 MACH, |
41 }; | 82 }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 129 |
89 private: | 130 private: |
90 Type type_; | 131 Type type_; |
91 FileDescriptor file_descriptor_; | 132 FileDescriptor file_descriptor_; |
92 }; | 133 }; |
93 #endif | 134 #endif |
94 | 135 |
95 } // namespace base | 136 } // namespace base |
96 | 137 |
97 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 138 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
OLD | NEW |