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