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

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

Issue 1163943004: Make SharedMemoryHandle a class on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared_memory_make_class3_base
Patch Set: Fix logic error. Created 5 years, 6 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
(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 Type {
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|.
Tom Sepez 2015/06/17 18:51:55 nit: comment about who owns the FD. Must the call
erikchen 2015/06/18 17:58:33 I've added a long comment indicating the ownership
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 // Duplicates the underlying OS resources.
61 SharedMemoryHandle Duplicate() const;
62
63 // Comparison operators.
64 bool operator==(const SharedMemoryHandle& handle) const;
65 bool operator!=(const SharedMemoryHandle& handle) const;
66
67 // Getter and setter for a property.
68 Type GetType() const;
69 void SetType(Type type);
Tom Sepez 2015/06/17 18:51:55 Can the type change after the SMH is created? I'd
erikchen 2015/06/18 17:58:33 Yes, since code that uses base::SharedMemoryHandle
70
71 // Sets the POSIX fd backing the SharedMemoryHandle. Requires that the
72 // SharedMemoryHandle be backed by a POSIX fd.
73 void SetFileHandle(int fd, bool auto_close);
74
75 // Returns the address of the POSIX FileDescriptor backing the
76 // SharedMemoryHandle.
77 FileDescriptor* GetFileDescriptor();
78 const FileDescriptor* GetFileDescriptor() const;
79
80 private:
81 Type type_;
Tom Sepez 2015/06/17 18:51:55 const Type type_; per above.
erikchen 2015/06/18 17:58:33 That won't work, since SharedMemoryHandles are pas
82 FileDescriptor file_descriptor_;
83 };
84 #elif defined(OS_POSIX)
Tom Sepez 2015/06/17 18:51:55 nit: I might re-arrange this so that win/posix cas
erikchen 2015/06/18 17:58:33 Good suggestion, done.
85 typedef FileDescriptor SharedMemoryHandle;
86 #endif
87
88 } // namespace base
89
90 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698