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

Side by Side Diff: mojo/edk/embedder/platform_shared_buffer.h

Issue 1995753002: [mojo-edk] Expose portable API for platform handle wrapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_ 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_
6 #define MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_ 6 #define MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "base/memory/shared_memory_handle.h" 15 #include "base/memory/shared_memory_handle.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "mojo/edk/embedder/scoped_platform_handle.h" 17 #include "mojo/edk/embedder/scoped_platform_handle.h"
18 #include "mojo/edk/system/system_impl_export.h" 18 #include "mojo/edk/system/system_impl_export.h"
19 #include "mojo/public/c/system/types.h"
19 20
20 namespace mojo { 21 namespace mojo {
21 namespace edk { 22 namespace edk {
22 23
23 class PlatformSharedBufferMapping; 24 class PlatformSharedBufferMapping;
24 25
25 // |PlatformSharedBuffer| is a thread-safe, ref-counted wrapper around 26 // |PlatformSharedBuffer| is a thread-safe, ref-counted wrapper around
26 // OS-specific shared memory. It has the following features: 27 // OS-specific shared memory. It has the following features:
27 // - A |PlatformSharedBuffer| simply represents a piece of shared memory that 28 // - A |PlatformSharedBuffer| simply represents a piece of shared memory that
28 // *may* be mapped and *may* be shared to another process. 29 // *may* be mapped and *may* be shared to another process.
(...skipping 25 matching lines...) Expand all
54 ScopedPlatformHandle rw_platform_handle, 55 ScopedPlatformHandle rw_platform_handle,
55 ScopedPlatformHandle ro_platform_handle); 56 ScopedPlatformHandle ro_platform_handle);
56 57
57 // Creates a shared buffer of size |num_bytes| from the existing shared memory 58 // Creates a shared buffer of size |num_bytes| from the existing shared memory
58 // handle |handle|. 59 // handle |handle|.
59 static PlatformSharedBuffer* CreateFromSharedMemoryHandle( 60 static PlatformSharedBuffer* CreateFromSharedMemoryHandle(
60 size_t num_bytes, 61 size_t num_bytes,
61 bool read_only, 62 bool read_only,
62 base::SharedMemoryHandle handle); 63 base::SharedMemoryHandle handle);
63 64
65 // Returns a base::SharedMemoryHandle given a PlatformHandle and some
66 // associated settings.
67 static base::SharedMemoryHandle GetSharedMemoryHandleFromPlatformHandle(
68 MojoPlatformHandle platform_handle,
69 size_t size,
70 bool read_only);
71
72 // Returns a PlatformHandle from a given base::SharedMemoryHandle.
73 static PlatformHandle GetPlatformHandleFromSharedMemoryHandle(
74 base::SharedMemoryHandle memory_handle);
75
64 // Gets the size of shared buffer (in number of bytes). 76 // Gets the size of shared buffer (in number of bytes).
65 size_t GetNumBytes() const; 77 size_t GetNumBytes() const;
66 78
67 // Returns whether this shared buffer is read-only. 79 // Returns whether this shared buffer is read-only.
68 bool IsReadOnly() const; 80 bool IsReadOnly() const;
69 81
70 // Maps (some) of the shared buffer into memory; [|offset|, |offset + length|] 82 // Maps (some) of the shared buffer into memory; [|offset|, |offset + length|]
71 // must be contained in [0, |num_bytes|], and |length| must be at least 1. 83 // must be contained in [0, |num_bytes|], and |length| must be at least 1.
72 // Returns null on failure. 84 // Returns null on failure.
73 std::unique_ptr<PlatformSharedBufferMapping> Map(size_t offset, 85 std::unique_ptr<PlatformSharedBufferMapping> Map(size_t offset,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // created from a duplicate handle. 181 // created from a duplicate handle.
170 base::SharedMemory shared_memory_; 182 base::SharedMemory shared_memory_;
171 183
172 DISALLOW_COPY_AND_ASSIGN(PlatformSharedBufferMapping); 184 DISALLOW_COPY_AND_ASSIGN(PlatformSharedBufferMapping);
173 }; 185 };
174 186
175 } // namespace edk 187 } // namespace edk
176 } // namespace mojo 188 } // namespace mojo
177 189
178 #endif // MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_ 190 #endif // MOJO_EDK_EMBEDDER_PLATFORM_SHARED_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698