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

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

Issue 621153003: Move mojo edk into mojo/edk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix checkdeps Created 6 years, 2 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
« no previous file with comments | « mojo/embedder/platform_handle_vector.h ('k') | mojo/embedder/platform_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_EMBEDDER_PLATFORM_SHARED_BUFFER_H_
6 #define MOJO_EMBEDDER_PLATFORM_SHARED_BUFFER_H_
7
8 #include <stddef.h>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "mojo/embedder/scoped_platform_handle.h"
14 #include "mojo/system/system_impl_export.h"
15
16 namespace mojo {
17 namespace embedder {
18
19 class PlatformSharedBufferMapping;
20
21 // |PlatformSharedBuffer| is an interface for a thread-safe, ref-counted wrapper
22 // around OS-specific shared memory. It has the following features:
23 // - A |PlatformSharedBuffer| simply represents a piece of shared memory that
24 // *may* be mapped and *may* be shared to another process.
25 // - A single |PlatformSharedBuffer| may be mapped multiple times. The
26 // lifetime of the mapping (owned by |PlatformSharedBufferMapping|) is
27 // separate from the lifetime of the |PlatformSharedBuffer|.
28 // - Sizes/offsets (of the shared memory and mappings) are arbitrary, and not
29 // restricted by page size. However, more memory may actually be mapped than
30 // requested.
31 //
32 // It currently does NOT support the following:
33 // - Sharing read-only. (This will probably eventually be supported.)
34 //
35 // TODO(vtl): Rectify this with |base::SharedMemory|.
36 class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer
37 : public base::RefCountedThreadSafe<PlatformSharedBuffer> {
38 public:
39 // Gets the size of shared buffer (in number of bytes).
40 virtual size_t GetNumBytes() const = 0;
41
42 // Maps (some) of the shared buffer into memory; [|offset|, |offset + length|]
43 // must be contained in [0, |num_bytes|], and |length| must be at least 1.
44 // Returns null on failure.
45 virtual scoped_ptr<PlatformSharedBufferMapping> Map(size_t offset,
46 size_t length) = 0;
47
48 // Checks if |offset| and |length| are valid arguments.
49 virtual bool IsValidMap(size_t offset, size_t length) = 0;
50
51 // Like |Map()|, but doesn't check its arguments (which should have been
52 // preflighted using |IsValidMap()|).
53 virtual scoped_ptr<PlatformSharedBufferMapping> MapNoCheck(size_t offset,
54 size_t length) = 0;
55
56 // Duplicates the underlying platform handle and passes it to the caller.
57 // TODO(vtl): On POSIX, we'll need two FDs to support sharing read-only.
58 virtual ScopedPlatformHandle DuplicatePlatformHandle() = 0;
59
60 // Passes the underlying platform handle to the caller. This should only be
61 // called if there's a unique reference to this object (owned by the caller).
62 // After calling this, this object should no longer be used, but should only
63 // be disposed of.
64 virtual ScopedPlatformHandle PassPlatformHandle() = 0;
65
66 protected:
67 friend class base::RefCountedThreadSafe<PlatformSharedBuffer>;
68
69 PlatformSharedBuffer() {}
70 virtual ~PlatformSharedBuffer() {}
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(PlatformSharedBuffer);
74 };
75
76 // An interface for a mapping of a |PlatformSharedBuffer| (compararable to a
77 // "file view" in Windows); see above. Created by (implementations of)
78 // |PlatformSharedBuffer::Map()|. Automatically unmaps memory on destruction.
79 //
80 // Mappings are NOT thread-safe.
81 //
82 // Note: This is an entirely separate class (instead of
83 // |PlatformSharedBuffer::Mapping|) so that it can be forward-declared.
84 class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBufferMapping {
85 public:
86 // IMPORTANT: Implementations must implement a destructor that unmaps memory.
87 virtual ~PlatformSharedBufferMapping() {}
88
89 virtual void* GetBase() const = 0;
90 virtual size_t GetLength() const = 0;
91
92 protected:
93 PlatformSharedBufferMapping() {}
94
95 private:
96 DISALLOW_COPY_AND_ASSIGN(PlatformSharedBufferMapping);
97 };
98
99 } // namespace embedder
100 } // namespace mojo
101
102 #endif // MOJO_EMBEDDER_PLATFORM_SHARED_BUFFER_H_
OLDNEW
« no previous file with comments | « mojo/embedder/platform_handle_vector.h ('k') | mojo/embedder/platform_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698