ipc/glue/SharedMemoryBasic_chromium.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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"
    16 //
    17 // This is a low-level wrapper around platform shared memory.  Don't
    18 // use it directly; use Shmem allocated through IPDL interfaces.
    19 //
    21 namespace mozilla {
    22 namespace ipc {
    24 class SharedMemoryBasic : public SharedMemory
    25 {
    26 public:
    27   typedef base::SharedMemoryHandle Handle;
    29   SharedMemoryBasic()
    30   {
    31   }
    33   SharedMemoryBasic(const Handle& aHandle)
    34     : mSharedMemory(aHandle, false)
    35   {
    36   }
    38   virtual bool Create(size_t aNbytes) MOZ_OVERRIDE
    39   {
    40     bool ok = mSharedMemory.Create("", false, false, aNbytes);
    41     if (ok) {
    42       Created(aNbytes);
    43     }
    44     return ok;
    45   }
    47   virtual bool Map(size_t nBytes) MOZ_OVERRIDE
    48   {
    49     bool ok = mSharedMemory.Map(nBytes);
    50     if (ok) {
    51       Mapped(nBytes);
    52     }
    53     return ok;
    54   }
    56   virtual void* memory() const MOZ_OVERRIDE
    57   {
    58     return mSharedMemory.memory();
    59   }
    61   virtual SharedMemoryType Type() const MOZ_OVERRIDE
    62   {
    63     return TYPE_BASIC;
    64   }
    66   static Handle NULLHandle()
    67   {
    68     return base::SharedMemory::NULLHandle();
    69   }
    71   static bool IsHandleValid(const Handle &aHandle)
    72   {
    73     return base::SharedMemory::IsHandleValid(aHandle);
    74   }
    76   bool ShareToProcess(base::ProcessHandle process,
    77                       Handle* new_handle)
    78   {
    79     base::SharedMemoryHandle handle;
    80     bool ret = mSharedMemory.ShareToProcess(process, &handle);
    81     if (ret)
    82       *new_handle = handle;
    83     return ret;
    84   }
    86 private:
    87   base::SharedMemory mSharedMemory;
    88 };
    90 } // namespace ipc
    91 } // namespace mozilla
    94 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h

mercurial