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

Side by Side Diff: mojo/edk/system/shared_buffer_dispatcher.h

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 years, 3 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_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ 5 #ifndef MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
6 #define MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ 6 #define MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
7 7
8 #include "mojo/edk/embedder/platform_shared_buffer.h" 8 #include "mojo/edk/embedder/platform_shared_buffer.h"
9 #include "mojo/edk/system/memory.h" 9 #include "mojo/edk/system/memory.h"
10 #include "mojo/edk/system/simple_dispatcher.h" 10 #include "mojo/edk/system/simple_dispatcher.h"
11 #include "mojo/edk/system/system_impl_export.h" 11 #include "mojo/edk/system/system_impl_export.h"
12 #include "mojo/public/cpp/system/macros.h" 12 #include "mojo/public/cpp/system/macros.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 15
16 namespace embedder { 16 namespace edk {
17 class PlatformSupport; 17 class PlatformSupport;
18 }
19
20 namespace system {
21 18
22 // TODO(vtl): We derive from SimpleDispatcher, even though we don't currently 19 // TODO(vtl): We derive from SimpleDispatcher, even though we don't currently
23 // have anything that's waitable. I want to add a "transferrable" wait flag 20 // have anything that's waitable. I want to add a "transferrable" wait flag
24 // (which would entail overriding |GetHandleSignalsStateImplNoLock()|, etc.). 21 // (which would entail overriding |GetHandleSignalsStateImplNoLock()|, etc.).
25 class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher final 22 class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher final
26 : public SimpleDispatcher { 23 : public SimpleDispatcher {
27 public: 24 public:
28 // The default options to use for |MojoCreateSharedBuffer()|. (Real uses 25 // The default options to use for |MojoCreateSharedBuffer()|. (Real uses
29 // should obtain this via |ValidateCreateOptions()| with a null |in_options|; 26 // should obtain this via |ValidateCreateOptions()| with a null |in_options|;
30 // this is exposed directly for testing convenience.) 27 // this is exposed directly for testing convenience.)
31 static const MojoCreateSharedBufferOptions kDefaultCreateOptions; 28 static const MojoCreateSharedBufferOptions kDefaultCreateOptions;
32 29
33 // Validates and/or sets default options for |MojoCreateSharedBufferOptions|. 30 // Validates and/or sets default options for |MojoCreateSharedBufferOptions|.
34 // If non-null, |in_options| must point to a struct of at least 31 // If non-null, |in_options| must point to a struct of at least
35 // |in_options->struct_size| bytes. |out_options| must point to a (current) 32 // |in_options->struct_size| bytes. |out_options| must point to a (current)
36 // |MojoCreateSharedBufferOptions| and will be entirely overwritten on success 33 // |MojoCreateSharedBufferOptions| and will be entirely overwritten on success
37 // (it may be partly overwritten on failure). 34 // (it may be partly overwritten on failure).
38 static MojoResult ValidateCreateOptions( 35 static MojoResult ValidateCreateOptions(
39 UserPointer<const MojoCreateSharedBufferOptions> in_options, 36 UserPointer<const MojoCreateSharedBufferOptions> in_options,
40 MojoCreateSharedBufferOptions* out_options); 37 MojoCreateSharedBufferOptions* out_options);
41 38
42 // Static factory method: |validated_options| must be validated (obviously). 39 // Static factory method: |validated_options| must be validated (obviously).
43 // On failure, |*result| will be left as-is. 40 // On failure, |*result| will be left as-is.
44 // TODO(vtl): This should probably be made to return a scoped_refptr and have 41 // TODO(vtl): This should probably be made to return a scoped_refptr and have
45 // a MojoResult out parameter instead. 42 // a MojoResult out parameter instead.
46 static MojoResult Create( 43 static MojoResult Create(
47 embedder::PlatformSupport* platform_support, 44 PlatformSupport* platform_support,
48 const MojoCreateSharedBufferOptions& validated_options, 45 const MojoCreateSharedBufferOptions& validated_options,
49 uint64_t num_bytes, 46 uint64_t num_bytes,
50 scoped_refptr<SharedBufferDispatcher>* result); 47 scoped_refptr<SharedBufferDispatcher>* result);
51 48
52 // |Dispatcher| public methods: 49 // |Dispatcher| public methods:
53 Type GetType() const override; 50 Type GetType() const override;
54 51
55 // The "opposite" of |SerializeAndClose()|. (Typically this is called by 52 // The "opposite" of |SerializeAndClose()|. (Typically this is called by
56 // |Dispatcher::Deserialize()|.) 53 // |Dispatcher::Deserialize()|.)
57 static scoped_refptr<SharedBufferDispatcher> Deserialize( 54 static scoped_refptr<SharedBufferDispatcher> Deserialize(
58 Channel* channel,
59 const void* source, 55 const void* source,
60 size_t size, 56 size_t size,
61 embedder::PlatformHandleVector* platform_handles); 57 PlatformHandleVector* platform_handles);
62 58
63 private: 59 private:
64 static scoped_refptr<SharedBufferDispatcher> CreateInternal( 60 static scoped_refptr<SharedBufferDispatcher> CreateInternal(
65 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer) { 61 scoped_refptr<PlatformSharedBuffer> shared_buffer) {
66 return make_scoped_refptr(new SharedBufferDispatcher(shared_buffer.Pass())); 62 return make_scoped_refptr(new SharedBufferDispatcher(shared_buffer.Pass()));
67 } 63 }
68 64
69 explicit SharedBufferDispatcher( 65 explicit SharedBufferDispatcher(
70 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer); 66 scoped_refptr<PlatformSharedBuffer> shared_buffer);
71 ~SharedBufferDispatcher() override; 67 ~SharedBufferDispatcher() override;
72 68
73 // Validates and/or sets default options for 69 // Validates and/or sets default options for
74 // |MojoDuplicateBufferHandleOptions|. If non-null, |in_options| must point to 70 // |MojoDuplicateBufferHandleOptions|. If non-null, |in_options| must point to
75 // a struct of at least |in_options->struct_size| bytes. |out_options| must 71 // a struct of at least |in_options->struct_size| bytes. |out_options| must
76 // point to a (current) |MojoDuplicateBufferHandleOptions| and will be 72 // point to a (current) |MojoDuplicateBufferHandleOptions| and will be
77 // entirely overwritten on success (it may be partly overwritten on failure). 73 // entirely overwritten on success (it may be partly overwritten on failure).
78 static MojoResult ValidateDuplicateOptions( 74 static MojoResult ValidateDuplicateOptions(
79 UserPointer<const MojoDuplicateBufferHandleOptions> in_options, 75 UserPointer<const MojoDuplicateBufferHandleOptions> in_options,
80 MojoDuplicateBufferHandleOptions* out_options); 76 MojoDuplicateBufferHandleOptions* out_options);
81 77
82 // |Dispatcher| protected methods: 78 // |Dispatcher| protected methods:
83 void CloseImplNoLock() override; 79 void CloseImplNoLock() override;
84 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() 80 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock()
85 override; 81 override;
86 MojoResult DuplicateBufferHandleImplNoLock( 82 MojoResult DuplicateBufferHandleImplNoLock(
87 UserPointer<const MojoDuplicateBufferHandleOptions> options, 83 UserPointer<const MojoDuplicateBufferHandleOptions> options,
88 scoped_refptr<Dispatcher>* new_dispatcher) override; 84 scoped_refptr<Dispatcher>* new_dispatcher) override;
89 MojoResult MapBufferImplNoLock( 85 MojoResult MapBufferImplNoLock(
90 uint64_t offset, 86 uint64_t offset,
91 uint64_t num_bytes, 87 uint64_t num_bytes,
92 MojoMapBufferFlags flags, 88 MojoMapBufferFlags flags,
93 scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping) override; 89 scoped_ptr<PlatformSharedBufferMapping>* mapping) override;
94 void StartSerializeImplNoLock(Channel* channel, 90 void StartSerializeImplNoLock(size_t* max_size,
95 size_t* max_size, 91 size_t* max_platform_handles) override;
96 size_t* max_platform_handles) override
97 MOJO_NOT_THREAD_SAFE;
98 bool EndSerializeAndCloseImplNoLock( 92 bool EndSerializeAndCloseImplNoLock(
99 Channel* channel,
100 void* destination, 93 void* destination,
101 size_t* actual_size, 94 size_t* actual_size,
102 embedder::PlatformHandleVector* platform_handles) override 95 PlatformHandleVector* platform_handles) override;
103 MOJO_NOT_THREAD_SAFE;
104 96
105 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer_ 97 scoped_refptr<PlatformSharedBuffer> shared_buffer_;
106 MOJO_GUARDED_BY(mutex());
107 98
108 MOJO_DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher); 99 MOJO_DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher);
109 }; 100 };
110 101
111 } // namespace system 102 } // namespace edk
112 } // namespace mojo 103 } // namespace mojo
113 104
114 #endif // MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ 105 #endif // MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698