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

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

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Comments from thakis. 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
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"
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include <windows.h> 13 #include <windows.h>
14 #include "base/process/process_handle.h" 14 #include "base/process/process_handle.h"
15 #elif defined(OS_MACOSX) && !defined(OS_IOS) 15 #elif defined(OS_MACOSX) && !defined(OS_IOS)
16 #include <mach/mach.h> 16 #include <mach/mach.h>
17 #include "base/base_export.h" 17 #include "base/base_export.h"
18 #include "base/file_descriptor_posix.h" 18 #include "base/file_descriptor_posix.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/process/process_handle.h" 20 #include "base/process/process_handle.h"
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 // TODO(erikchen): Refactor this to create a single class on all platforms,
31 // rather than 3 separate class definitions that are very similar.
32 // https://crbug.com/713763.
30 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) 33 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS))
31 typedef FileDescriptor SharedMemoryHandle; 34 class BASE_EXPORT SharedMemoryHandle {
35 public:
36 // The default constructor returns an invalid SharedMemoryHandle.
37 SharedMemoryHandle();
38
39 // This constructor is deprecated, as it fails to propagate the GUID, which
40 // will be added in the near future.
41 // TODO(rockot): Remove this constructor once Mojo supports GUIDs.
42 // https://crbug.com/713763.
43 explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor);
44
45 // Creates a SharedMemoryHandle from an |fd| supplied from an external
46 // service.
47 static SharedMemoryHandle ImportHandle(int fd);
48
49 // Returns the underlying OS resource.
50 int GetHandle() const;
51
52 // Whether the underlying OS resource is valid.
53 bool IsValid() const;
54
55 // Closes the underlying OS resource.
56 // The fact that this method needs to be "const" is an artifact of the
57 // original interface for base::SharedMemory::CloseHandle.
58 // TODO(erikchen): This doesn't clear the underlying reference, which seems
59 // like a bug, but is how this class has always worked. Fix this:
60 // https://crbug.com/716072.
61 void Close() const;
62
63 // Invalidates [but doesn't close] the underlying OS resource. This will leak
64 // unless the caller is careful.
65 int Release();
66
67 // Duplicates the underlying OS resource.
68 SharedMemoryHandle Duplicate() const;
69
70 // This must be public to support serialization by Chrome IPC.
71 FileDescriptor file_descriptor;
72 };
32 #elif defined(OS_WIN) 73 #elif defined(OS_WIN)
33 class BASE_EXPORT SharedMemoryHandle { 74 class BASE_EXPORT SharedMemoryHandle {
34 public: 75 public:
35 // The default constructor returns an invalid SharedMemoryHandle. 76 // The default constructor returns an invalid SharedMemoryHandle.
36 SharedMemoryHandle(); 77 SharedMemoryHandle();
37 SharedMemoryHandle(HANDLE h, base::ProcessId pid); 78 SharedMemoryHandle(HANDLE h, base::ProcessId pid);
38 79
39 // Standard copy constructor. The new instance shares the underlying OS 80 // Standard copy constructor. The new instance shares the underlying OS
40 // primitives. 81 // primitives.
41 SharedMemoryHandle(const SharedMemoryHandle& handle); 82 SharedMemoryHandle(const SharedMemoryHandle& handle);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Defaults to |false|. 223 // Defaults to |false|.
183 bool ownership_passes_to_ipc_; 224 bool ownership_passes_to_ipc_;
184 }; 225 };
185 }; 226 };
186 }; 227 };
187 #endif 228 #endif
188 229
189 } // namespace base 230 } // namespace base
190 231
191 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ 232 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698