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

Side by Side Diff: base/memory/shared_memory_handle.h

Issue 2847033003: Get rid of SharedMemory::GiveToProcess. (Closed)
Patch Set: Comments from avi. Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_handle_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 void Close() const; 49 void Close() const;
50 50
51 // Whether ownership of the underlying OS resource is implicitly passed to 51 // Whether ownership of the underlying OS resource is implicitly passed to
52 // the IPC subsystem during serialization. 52 // the IPC subsystem during serialization.
53 void SetOwnershipPassesToIPC(bool ownership_passes); 53 void SetOwnershipPassesToIPC(bool ownership_passes);
54 bool OwnershipPassesToIPC() const; 54 bool OwnershipPassesToIPC() const;
55 55
56 // Whether the underlying OS resource is valid. 56 // Whether the underlying OS resource is valid.
57 bool IsValid() const; 57 bool IsValid() const;
58 58
59 // Duplicates the underlying OS resource.
60 SharedMemoryHandle Duplicate() const;
61
59 #if defined(OS_MACOSX) && !defined(OS_IOS) 62 #if defined(OS_MACOSX) && !defined(OS_IOS)
60 enum Type { 63 enum Type {
61 // The SharedMemoryHandle is backed by a POSIX fd. 64 // The SharedMemoryHandle is backed by a POSIX fd.
62 POSIX, 65 POSIX,
63 // The SharedMemoryHandle is backed by the Mach primitive "memory object". 66 // The SharedMemoryHandle is backed by the Mach primitive "memory object".
64 MACH, 67 MACH,
65 }; 68 };
66 69
67 // Constructs a SharedMemoryHandle backed by the components of a 70 // Constructs a SharedMemoryHandle backed by the components of a
68 // FileDescriptor. The newly created instance has the same ownership semantics 71 // FileDescriptor. The newly created instance has the same ownership semantics
69 // as base::FileDescriptor. This typically means that the SharedMemoryHandle 72 // as base::FileDescriptor. This typically means that the SharedMemoryHandle
70 // takes ownership of the |fd| if |auto_close| is true. Unfortunately, it's 73 // takes ownership of the |fd| if |auto_close| is true. Unfortunately, it's
71 // common for existing code to make shallow copies of SharedMemoryHandle, and 74 // common for existing code to make shallow copies of SharedMemoryHandle, and
72 // the one that is finally passed into a base::SharedMemory is the one that 75 // the one that is finally passed into a base::SharedMemory is the one that
73 // "consumes" the fd. 76 // "consumes" the fd.
74 explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor); 77 explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor);
75 78
76 // Makes a Mach-based SharedMemoryHandle of the given size. On error, 79 // Makes a Mach-based SharedMemoryHandle of the given size. On error,
77 // subsequent calls to IsValid() return false. 80 // subsequent calls to IsValid() return false.
78 explicit SharedMemoryHandle(mach_vm_size_t size); 81 explicit SharedMemoryHandle(mach_vm_size_t size);
79 82
80 // Makes a Mach-based SharedMemoryHandle from |memory_object|, a named entry 83 // Makes a Mach-based SharedMemoryHandle from |memory_object|, a named entry
81 // in the task with process id |pid|. The memory region has size |size|. 84 // in the task with process id |pid|. The memory region has size |size|.
82 SharedMemoryHandle(mach_port_t memory_object, 85 SharedMemoryHandle(mach_port_t memory_object,
83 mach_vm_size_t size, 86 mach_vm_size_t size,
84 base::ProcessId pid); 87 base::ProcessId pid);
85 88
86 // Duplicates the underlying OS resources.
87 SharedMemoryHandle Duplicate() const;
88
89 // Exposed so that the SharedMemoryHandle can be transported between 89 // Exposed so that the SharedMemoryHandle can be transported between
90 // processes. 90 // processes.
91 mach_port_t GetMemoryObject() const; 91 mach_port_t GetMemoryObject() const;
92 92
93 // Returns false on a failure to determine the size. On success, populates the 93 // Returns false on a failure to determine the size. On success, populates the
94 // output variable |size|. 94 // output variable |size|.
95 bool GetSize(size_t* size) const; 95 bool GetSize(size_t* size) const;
96 96
97 // The SharedMemoryHandle must be valid. 97 // The SharedMemoryHandle must be valid.
98 // Returns whether the SharedMemoryHandle was successfully mapped into memory. 98 // Returns whether the SharedMemoryHandle was successfully mapped into memory.
(...skipping 25 matching lines...) Expand all
124 124
125 // Returns the underlying OS resource. 125 // Returns the underlying OS resource.
126 int GetHandle() const; 126 int GetHandle() const;
127 127
128 // Takes ownership of the OS resource. 128 // Takes ownership of the OS resource.
129 void SetHandle(int fd); 129 void SetHandle(int fd);
130 130
131 // Invalidates [but doesn't close] the underlying OS resource. This will leak 131 // Invalidates [but doesn't close] the underlying OS resource. This will leak
132 // unless the caller is careful. 132 // unless the caller is careful.
133 int Release(); 133 int Release();
134
135 // Duplicates the underlying OS resource.
136 SharedMemoryHandle Duplicate() const;
137 #endif 134 #endif
138 135
139 private: 136 private:
140 #if defined(OS_MACOSX) && !defined(OS_IOS) 137 #if defined(OS_MACOSX) && !defined(OS_IOS)
141 friend class SharedMemory; 138 friend class SharedMemory;
142 139
143 // Shared code between copy constructor and operator=. 140 // Shared code between copy constructor and operator=.
144 void CopyRelevantData(const SharedMemoryHandle& handle); 141 void CopyRelevantData(const SharedMemoryHandle& handle);
145 142
146 Type type_; 143 Type type_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Defaults to |false|. 179 // Defaults to |false|.
183 bool ownership_passes_to_ipc_; 180 bool ownership_passes_to_ipc_;
184 #else 181 #else
185 FileDescriptor file_descriptor_; 182 FileDescriptor file_descriptor_;
186 #endif 183 #endif
187 }; 184 };
188 185
189 } // namespace base 186 } // namespace base
190 187
191 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ 188 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
OLDNEW
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_handle_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698