1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/glue/SharedMemoryBasic_chromium.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=8 et : 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef mozilla_ipc_SharedMemoryBasic_chromium_h 1.12 +#define mozilla_ipc_SharedMemoryBasic_chromium_h 1.13 + 1.14 +#include "base/shared_memory.h" 1.15 +#include "SharedMemory.h" 1.16 + 1.17 +#include "nsDebug.h" 1.18 + 1.19 +// 1.20 +// This is a low-level wrapper around platform shared memory. Don't 1.21 +// use it directly; use Shmem allocated through IPDL interfaces. 1.22 +// 1.23 + 1.24 +namespace mozilla { 1.25 +namespace ipc { 1.26 + 1.27 +class SharedMemoryBasic : public SharedMemory 1.28 +{ 1.29 +public: 1.30 + typedef base::SharedMemoryHandle Handle; 1.31 + 1.32 + SharedMemoryBasic() 1.33 + { 1.34 + } 1.35 + 1.36 + SharedMemoryBasic(const Handle& aHandle) 1.37 + : mSharedMemory(aHandle, false) 1.38 + { 1.39 + } 1.40 + 1.41 + virtual bool Create(size_t aNbytes) MOZ_OVERRIDE 1.42 + { 1.43 + bool ok = mSharedMemory.Create("", false, false, aNbytes); 1.44 + if (ok) { 1.45 + Created(aNbytes); 1.46 + } 1.47 + return ok; 1.48 + } 1.49 + 1.50 + virtual bool Map(size_t nBytes) MOZ_OVERRIDE 1.51 + { 1.52 + bool ok = mSharedMemory.Map(nBytes); 1.53 + if (ok) { 1.54 + Mapped(nBytes); 1.55 + } 1.56 + return ok; 1.57 + } 1.58 + 1.59 + virtual void* memory() const MOZ_OVERRIDE 1.60 + { 1.61 + return mSharedMemory.memory(); 1.62 + } 1.63 + 1.64 + virtual SharedMemoryType Type() const MOZ_OVERRIDE 1.65 + { 1.66 + return TYPE_BASIC; 1.67 + } 1.68 + 1.69 + static Handle NULLHandle() 1.70 + { 1.71 + return base::SharedMemory::NULLHandle(); 1.72 + } 1.73 + 1.74 + static bool IsHandleValid(const Handle &aHandle) 1.75 + { 1.76 + return base::SharedMemory::IsHandleValid(aHandle); 1.77 + } 1.78 + 1.79 + bool ShareToProcess(base::ProcessHandle process, 1.80 + Handle* new_handle) 1.81 + { 1.82 + base::SharedMemoryHandle handle; 1.83 + bool ret = mSharedMemory.ShareToProcess(process, &handle); 1.84 + if (ret) 1.85 + *new_handle = handle; 1.86 + return ret; 1.87 + } 1.88 + 1.89 +private: 1.90 + base::SharedMemory mSharedMemory; 1.91 +}; 1.92 + 1.93 +} // namespace ipc 1.94 +} // namespace mozilla 1.95 + 1.96 + 1.97 +#endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h