Fix typo in 9b54bd30006c008b4a951331b273613d5bac3abf
[pm.git] / ipc / glue / SharedMemoryBasic_chromium.h
blob8d57faa92dd2dc5290fede522c32bfc06bcaaab9
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/. */
8 #ifndef mozilla_ipc_SharedMemoryBasic_chromium_h
9 #define mozilla_ipc_SharedMemoryBasic_chromium_h
11 #include "base/shared_memory.h"
12 #include "SharedMemory.h"
14 #include "nsDebug.h"
17 // This is a low-level wrapper around platform shared memory. Don't
18 // use it directly; use Shmem allocated through IPDL interfaces.
21 namespace mozilla {
22 namespace ipc {
24 class SharedMemoryBasic final : public SharedMemory
26 public:
27 typedef base::SharedMemoryHandle Handle;
29 SharedMemoryBasic()
33 explicit SharedMemoryBasic(const Handle& aHandle)
34 : mSharedMemory(aHandle, false)
38 virtual bool Create(size_t aNbytes) override
40 bool ok = mSharedMemory.Create("", false, false, aNbytes);
41 if (ok) {
42 Created(aNbytes);
44 return ok;
47 virtual bool Map(size_t nBytes) override
49 bool ok = mSharedMemory.Map(nBytes);
50 if (ok) {
51 Mapped(nBytes);
53 return ok;
56 virtual void* memory() const override
58 return mSharedMemory.memory();
61 virtual SharedMemoryType Type() const override
63 return TYPE_BASIC;
66 static Handle NULLHandle()
68 return base::SharedMemory::NULLHandle();
71 static bool IsHandleValid(const Handle &aHandle)
73 return base::SharedMemory::IsHandleValid(aHandle);
76 bool ShareToProcess(base::ProcessHandle process,
77 Handle* new_handle)
79 base::SharedMemoryHandle handle;
80 bool ret = mSharedMemory.ShareToProcess(process, &handle);
81 if (ret)
82 *new_handle = handle;
83 return ret;
86 private:
87 ~SharedMemoryBasic()
91 base::SharedMemory mSharedMemory;
94 } // namespace ipc
95 } // namespace mozilla
98 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h