Merge inbound to m-c on a CLOSED TREE.
[gecko.git] / ipc / glue / SharedMemoryBasic_chromium.h
blobac563bac0774cd0ed647be2be728bf7a8bb312cb
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 : public SharedMemory
26 public:
27 typedef base::SharedMemoryHandle Handle;
29 SharedMemoryBasic()
33 SharedMemoryBasic(const Handle& aHandle)
34 : mSharedMemory(aHandle, false)
38 virtual bool Create(size_t aNbytes) MOZ_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) MOZ_OVERRIDE
49 bool ok = mSharedMemory.Map(nBytes);
50 if (ok) {
51 Mapped(nBytes);
53 return ok;
56 virtual void* memory() const MOZ_OVERRIDE
58 return mSharedMemory.memory();
61 virtual SharedMemoryType Type() const MOZ_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 base::SharedMemory mSharedMemory;
90 } // namespace ipc
91 } // namespace mozilla
94 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h