|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef mozilla_ipc_SharedMemoryBasic_chromium_h |
|
9 #define mozilla_ipc_SharedMemoryBasic_chromium_h |
|
10 |
|
11 #include "base/shared_memory.h" |
|
12 #include "SharedMemory.h" |
|
13 |
|
14 #include "nsDebug.h" |
|
15 |
|
16 // |
|
17 // This is a low-level wrapper around platform shared memory. Don't |
|
18 // use it directly; use Shmem allocated through IPDL interfaces. |
|
19 // |
|
20 |
|
21 namespace mozilla { |
|
22 namespace ipc { |
|
23 |
|
24 class SharedMemoryBasic : public SharedMemory |
|
25 { |
|
26 public: |
|
27 typedef base::SharedMemoryHandle Handle; |
|
28 |
|
29 SharedMemoryBasic() |
|
30 { |
|
31 } |
|
32 |
|
33 SharedMemoryBasic(const Handle& aHandle) |
|
34 : mSharedMemory(aHandle, false) |
|
35 { |
|
36 } |
|
37 |
|
38 virtual bool Create(size_t aNbytes) MOZ_OVERRIDE |
|
39 { |
|
40 bool ok = mSharedMemory.Create("", false, false, aNbytes); |
|
41 if (ok) { |
|
42 Created(aNbytes); |
|
43 } |
|
44 return ok; |
|
45 } |
|
46 |
|
47 virtual bool Map(size_t nBytes) MOZ_OVERRIDE |
|
48 { |
|
49 bool ok = mSharedMemory.Map(nBytes); |
|
50 if (ok) { |
|
51 Mapped(nBytes); |
|
52 } |
|
53 return ok; |
|
54 } |
|
55 |
|
56 virtual void* memory() const MOZ_OVERRIDE |
|
57 { |
|
58 return mSharedMemory.memory(); |
|
59 } |
|
60 |
|
61 virtual SharedMemoryType Type() const MOZ_OVERRIDE |
|
62 { |
|
63 return TYPE_BASIC; |
|
64 } |
|
65 |
|
66 static Handle NULLHandle() |
|
67 { |
|
68 return base::SharedMemory::NULLHandle(); |
|
69 } |
|
70 |
|
71 static bool IsHandleValid(const Handle &aHandle) |
|
72 { |
|
73 return base::SharedMemory::IsHandleValid(aHandle); |
|
74 } |
|
75 |
|
76 bool ShareToProcess(base::ProcessHandle process, |
|
77 Handle* new_handle) |
|
78 { |
|
79 base::SharedMemoryHandle handle; |
|
80 bool ret = mSharedMemory.ShareToProcess(process, &handle); |
|
81 if (ret) |
|
82 *new_handle = handle; |
|
83 return ret; |
|
84 } |
|
85 |
|
86 private: |
|
87 base::SharedMemory mSharedMemory; |
|
88 }; |
|
89 |
|
90 } // namespace ipc |
|
91 } // namespace mozilla |
|
92 |
|
93 |
|
94 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h |