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