diff options
author | jamesr <jamesr@chromium.org> | 2014-10-02 21:26:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-03 04:27:07 +0000 |
commit | a03ae49d253d7d1f517e2f92146a6ba201c78aa6 (patch) | |
tree | df4eae1239d49490fa4e85d184b9000224a7a31c /mojo/edk/embedder/platform_shared_buffer.h | |
parent | 24b9789375c3c23d0d10e5197c6a7674946ea44b (diff) | |
download | chromium_src-a03ae49d253d7d1f517e2f92146a6ba201c78aa6.zip chromium_src-a03ae49d253d7d1f517e2f92146a6ba201c78aa6.tar.gz chromium_src-a03ae49d253d7d1f517e2f92146a6ba201c78aa6.tar.bz2 |
Move mojo edk into mojo/edk
This creates a mojo/edk directory which contains the "embedder developer
kit" aka the set of code needed to embed mojo code.
mojo/edk/embedder = code from mojo/embedder
mojo/edk/system = code from mojo/system
mojo/edk/test = code used to test the previous two, from mojo/common/test
mojo/edk/ can only depend on mojo/public/, base/ and itself.
R=viettrungluu@chromium.org
TBR=sky@chromium.org for file renames
Committed: https://chromium.googlesource.com/chromium/src/+/ee7ff197a98da4636f33bd713de784948b487bd4
Review URL: https://codereview.chromium.org/621153003
Cr-Commit-Position: refs/heads/master@{#297986}
Diffstat (limited to 'mojo/edk/embedder/platform_shared_buffer.h')
-rw-r--r-- | mojo/edk/embedder/platform_shared_buffer.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/mojo/edk/embedder/platform_shared_buffer.h b/mojo/edk/embedder/platform_shared_buffer.h new file mode 100644 index 0000000..07f8b90 --- /dev/null +++ b/mojo/edk/embedder/platform_shared_buffer.h @@ -0,0 +1,102 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_ +#define MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_ + +#include <stddef.h> + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "mojo/edk/embedder/scoped_platform_handle.h" +#include "mojo/edk/system/system_impl_export.h" + +namespace mojo { +namespace embedder { + +class PlatformSharedBufferMapping; + +// |PlatformSharedBuffer| is an interface for a thread-safe, ref-counted wrapper +// around OS-specific shared memory. It has the following features: +// - A |PlatformSharedBuffer| simply represents a piece of shared memory that +// *may* be mapped and *may* be shared to another process. +// - A single |PlatformSharedBuffer| may be mapped multiple times. The +// lifetime of the mapping (owned by |PlatformSharedBufferMapping|) is +// separate from the lifetime of the |PlatformSharedBuffer|. +// - Sizes/offsets (of the shared memory and mappings) are arbitrary, and not +// restricted by page size. However, more memory may actually be mapped than +// requested. +// +// It currently does NOT support the following: +// - Sharing read-only. (This will probably eventually be supported.) +// +// TODO(vtl): Rectify this with |base::SharedMemory|. +class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer + : public base::RefCountedThreadSafe<PlatformSharedBuffer> { + public: + // Gets the size of shared buffer (in number of bytes). + virtual size_t GetNumBytes() const = 0; + + // Maps (some) of the shared buffer into memory; [|offset|, |offset + length|] + // must be contained in [0, |num_bytes|], and |length| must be at least 1. + // Returns null on failure. + virtual scoped_ptr<PlatformSharedBufferMapping> Map(size_t offset, + size_t length) = 0; + + // Checks if |offset| and |length| are valid arguments. + virtual bool IsValidMap(size_t offset, size_t length) = 0; + + // Like |Map()|, but doesn't check its arguments (which should have been + // preflighted using |IsValidMap()|). + virtual scoped_ptr<PlatformSharedBufferMapping> MapNoCheck(size_t offset, + size_t length) = 0; + + // Duplicates the underlying platform handle and passes it to the caller. + // TODO(vtl): On POSIX, we'll need two FDs to support sharing read-only. + virtual ScopedPlatformHandle DuplicatePlatformHandle() = 0; + + // Passes the underlying platform handle to the caller. This should only be + // called if there's a unique reference to this object (owned by the caller). + // After calling this, this object should no longer be used, but should only + // be disposed of. + virtual ScopedPlatformHandle PassPlatformHandle() = 0; + + protected: + friend class base::RefCountedThreadSafe<PlatformSharedBuffer>; + + PlatformSharedBuffer() {} + virtual ~PlatformSharedBuffer() {} + + private: + DISALLOW_COPY_AND_ASSIGN(PlatformSharedBuffer); +}; + +// An interface for a mapping of a |PlatformSharedBuffer| (compararable to a +// "file view" in Windows); see above. Created by (implementations of) +// |PlatformSharedBuffer::Map()|. Automatically unmaps memory on destruction. +// +// Mappings are NOT thread-safe. +// +// Note: This is an entirely separate class (instead of +// |PlatformSharedBuffer::Mapping|) so that it can be forward-declared. +class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBufferMapping { + public: + // IMPORTANT: Implementations must implement a destructor that unmaps memory. + virtual ~PlatformSharedBufferMapping() {} + + virtual void* GetBase() const = 0; + virtual size_t GetLength() const = 0; + + protected: + PlatformSharedBufferMapping() {} + + private: + DISALLOW_COPY_AND_ASSIGN(PlatformSharedBufferMapping); +}; + +} // namespace embedder +} // namespace mojo + +#endif // MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_ |