michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ipc_SharedMemoryBasic_chromium_h michael@0: #define mozilla_ipc_SharedMemoryBasic_chromium_h michael@0: michael@0: #include "base/shared_memory.h" michael@0: #include "SharedMemory.h" michael@0: michael@0: #include "nsDebug.h" michael@0: michael@0: // michael@0: // This is a low-level wrapper around platform shared memory. Don't michael@0: // use it directly; use Shmem allocated through IPDL interfaces. michael@0: // michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: class SharedMemoryBasic : public SharedMemory michael@0: { michael@0: public: michael@0: typedef base::SharedMemoryHandle Handle; michael@0: michael@0: SharedMemoryBasic() michael@0: { michael@0: } michael@0: michael@0: SharedMemoryBasic(const Handle& aHandle) michael@0: : mSharedMemory(aHandle, false) michael@0: { michael@0: } michael@0: michael@0: virtual bool Create(size_t aNbytes) MOZ_OVERRIDE michael@0: { michael@0: bool ok = mSharedMemory.Create("", false, false, aNbytes); michael@0: if (ok) { michael@0: Created(aNbytes); michael@0: } michael@0: return ok; michael@0: } michael@0: michael@0: virtual bool Map(size_t nBytes) MOZ_OVERRIDE michael@0: { michael@0: bool ok = mSharedMemory.Map(nBytes); michael@0: if (ok) { michael@0: Mapped(nBytes); michael@0: } michael@0: return ok; michael@0: } michael@0: michael@0: virtual void* memory() const MOZ_OVERRIDE michael@0: { michael@0: return mSharedMemory.memory(); michael@0: } michael@0: michael@0: virtual SharedMemoryType Type() const MOZ_OVERRIDE michael@0: { michael@0: return TYPE_BASIC; michael@0: } michael@0: michael@0: static Handle NULLHandle() michael@0: { michael@0: return base::SharedMemory::NULLHandle(); michael@0: } michael@0: michael@0: static bool IsHandleValid(const Handle &aHandle) michael@0: { michael@0: return base::SharedMemory::IsHandleValid(aHandle); michael@0: } michael@0: michael@0: bool ShareToProcess(base::ProcessHandle process, michael@0: Handle* new_handle) michael@0: { michael@0: base::SharedMemoryHandle handle; michael@0: bool ret = mSharedMemory.ShareToProcess(process, &handle); michael@0: if (ret) michael@0: *new_handle = handle; michael@0: return ret; michael@0: } michael@0: michael@0: private: michael@0: base::SharedMemory mSharedMemory; michael@0: }; michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla michael@0: michael@0: michael@0: #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h