Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Unified Diff: mojo/edk/embedder/platform_shared_buffer.h

Issue 1689053003: Support read-only duplicates of Mojo shared buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-shm-interop
Patch Set: Rebase and fix comment. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/embedder/embedder.h ('k') | mojo/edk/embedder/platform_shared_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/embedder/platform_shared_buffer.h
diff --git a/mojo/edk/embedder/platform_shared_buffer.h b/mojo/edk/embedder/platform_shared_buffer.h
index dfe9165140345e6c1d307981d7b3707a0ecb2b89..1cfcd3a9aca860878d22a5800a3678488478768d 100644
--- a/mojo/edk/embedder/platform_shared_buffer.h
+++ b/mojo/edk/embedder/platform_shared_buffer.h
@@ -31,9 +31,6 @@ class PlatformSharedBufferMapping;
// - 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.)
class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
: public base::RefCountedThreadSafe<PlatformSharedBuffer> {
public:
@@ -45,6 +42,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
// handle |platform_handle|. Returns null on failure.
static PlatformSharedBuffer* CreateFromPlatformHandle(
size_t num_bytes,
+ bool read_only,
ScopedPlatformHandle platform_handle);
// Creates a shared buffer of size |num_bytes| from the existing shared memory
@@ -57,6 +55,9 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
// Gets the size of shared buffer (in number of bytes).
size_t GetNumBytes() const;
+ // Returns whether this shared buffer is read-only.
+ bool IsReadOnly() const;
+
// 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.
@@ -71,7 +72,6 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
size_t length);
// 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.
ScopedPlatformHandle DuplicatePlatformHandle();
// Duplicates the underlying shared memory handle and passes it to the caller.
@@ -83,10 +83,15 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
// be disposed of.
ScopedPlatformHandle PassPlatformHandle();
+ // Create and return a read-only duplicate of this shared buffer. If this
+ // shared buffer isn't capable of returning a read-only duplicate, then
+ // nullptr will be returned.
+ PlatformSharedBuffer* CreateReadOnlyDuplicate();
+
private:
friend class base::RefCountedThreadSafe<PlatformSharedBuffer>;
- explicit PlatformSharedBuffer(size_t num_bytes);
+ PlatformSharedBuffer(size_t num_bytes, bool read_only);
~PlatformSharedBuffer();
// This is called by |Create()| before this object is given to anyone.
@@ -100,6 +105,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
void InitFromSharedMemoryHandle(base::SharedMemoryHandle handle);
const size_t num_bytes_;
+ const bool read_only_;
base::Lock lock_;
scoped_ptr<base::SharedMemory> shared_memory_;
@@ -126,12 +132,13 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBufferMapping {
friend class PlatformSharedBuffer;
PlatformSharedBufferMapping(base::SharedMemoryHandle handle,
+ bool read_only,
size_t offset,
size_t length)
: offset_(offset),
length_(length),
base_(nullptr),
- shared_memory_(handle, false) {}
+ shared_memory_(handle, read_only) {}
bool Map();
void Unmap();
« no previous file with comments | « mojo/edk/embedder/embedder.h ('k') | mojo/edk/embedder/platform_shared_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698