Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_DATA_PIPE_IMPL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ |
| 6 #define MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ | 6 #define MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 12 #include "mojo/edk/system/data_pipe.h" | 11 #include "mojo/edk/system/data_pipe_impl.h" |
| 13 #include "mojo/edk/system/system_impl_export.h" | 12 #include "mojo/edk/system/system_impl_export.h" |
| 14 | 13 |
| 15 namespace mojo { | 14 namespace mojo { |
| 16 namespace system { | 15 namespace system { |
| 17 | 16 |
| 17 class DataPipe; | |
| 18 | |
| 18 // |LocalDataPipeImpl| is a subclass that "implements" |DataPipe| for data pipes | 19 // |LocalDataPipeImpl| is a subclass that "implements" |DataPipe| for data pipes |
| 19 // whose producer and consumer are both local. This class is thread-safe (with | 20 // whose producer and consumer are both local. This class's methods, other than |
| 20 // protection provided by |DataPipe|'s |lock_|. | 21 // the constructor and destructor, are always protected by |DataPipe|'s |lock_|. |
| 21 class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipeImpl : public DataPipe { | 22 class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipeImpl : public DataPipeImpl { |
| 22 public: | 23 public: |
| 23 // |validated_options| should be the output of |DataPipe::ValidateOptions()|. | 24 // |validated_options| should be the output of |DataPipe::ValidateOptions()|. |
|
viettrungluu
2015/02/19 19:08:46
Oops, this comment was stale too.
| |
| 24 // In particular: |struct_size| is ignored (so |validated_options| must be the | 25 // In particular: |struct_size| is ignored (so |validated_options| must be the |
| 25 // current version of the struct) and |capacity_num_bytes| must be nonzero. | 26 // current version of the struct) and |capacity_num_bytes| must be nonzero. |
| 26 explicit LocalDataPipeImpl( | 27 LocalDataPipeImpl(); |
| 27 const MojoCreateDataPipeOptions& validated_options); | 28 ~LocalDataPipeImpl() override; |
| 29 | |
| 30 static DataPipe* Create(const MojoCreateDataPipeOptions& validated_options); | |
|
yzshen1
2015/02/19 18:27:11
nit: It seems a little bit unusual for a static Cr
| |
| 28 | 31 |
| 29 private: | 32 private: |
| 30 friend class base::RefCountedThreadSafe<LocalDataPipeImpl>; | 33 // |DataPipeImpl| implementation: |
| 31 ~LocalDataPipeImpl() override; | 34 void ProducerClose() override; |
| 32 | 35 MojoResult ProducerWriteData(UserPointer<const void> elements, |
| 33 // |DataPipe| implementation: | 36 UserPointer<uint32_t> num_bytes, |
| 34 void ProducerCloseImplNoLock() override; | 37 uint32_t max_num_bytes_to_write, |
| 35 MojoResult ProducerWriteDataImplNoLock( | 38 uint32_t min_num_bytes_to_write) override; |
| 36 UserPointer<const void> elements, | 39 MojoResult ProducerBeginWriteData(UserPointer<void*> buffer, |
| 37 UserPointer<uint32_t> num_bytes, | 40 UserPointer<uint32_t> buffer_num_bytes, |
| 38 uint32_t max_num_bytes_to_write, | 41 uint32_t min_num_bytes_to_write) override; |
| 39 uint32_t min_num_bytes_to_write) override; | 42 MojoResult ProducerEndWriteData(uint32_t num_bytes_written) override; |
| 40 MojoResult ProducerBeginWriteDataImplNoLock( | 43 HandleSignalsState ProducerGetHandleSignalsState() const override; |
| 41 UserPointer<void*> buffer, | 44 void ProducerStartSerialize(Channel* channel, |
| 42 UserPointer<uint32_t> buffer_num_bytes, | 45 size_t* max_size, |
| 43 uint32_t min_num_bytes_to_write) override; | 46 size_t* max_platform_handles) override; |
| 44 MojoResult ProducerEndWriteDataImplNoLock( | 47 bool ProducerEndSerialize( |
| 45 uint32_t num_bytes_written) override; | |
| 46 HandleSignalsState ProducerGetHandleSignalsStateImplNoLock() const override; | |
| 47 void ProducerStartSerializeImplNoLock(Channel* channel, | |
| 48 size_t* max_size, | |
| 49 size_t* max_platform_handles) override; | |
| 50 bool ProducerEndSerializeImplNoLock( | |
| 51 Channel* channel, | 48 Channel* channel, |
| 52 void* destination, | 49 void* destination, |
| 53 size_t* actual_size, | 50 size_t* actual_size, |
| 54 embedder::PlatformHandleVector* platform_handles) override; | 51 embedder::PlatformHandleVector* platform_handles) override; |
| 55 void ConsumerCloseImplNoLock() override; | 52 void ConsumerClose() override; |
| 56 MojoResult ConsumerReadDataImplNoLock(UserPointer<void> elements, | 53 MojoResult ConsumerReadData(UserPointer<void> elements, |
| 57 UserPointer<uint32_t> num_bytes, | 54 UserPointer<uint32_t> num_bytes, |
| 58 uint32_t max_num_bytes_to_read, | 55 uint32_t max_num_bytes_to_read, |
| 59 uint32_t min_num_bytes_to_read, | 56 uint32_t min_num_bytes_to_read, |
| 60 bool peek) override; | 57 bool peek) override; |
| 61 MojoResult ConsumerDiscardDataImplNoLock( | 58 MojoResult ConsumerDiscardData(UserPointer<uint32_t> num_bytes, |
| 62 UserPointer<uint32_t> num_bytes, | 59 uint32_t max_num_bytes_to_discard, |
| 63 uint32_t max_num_bytes_to_discard, | 60 uint32_t min_num_bytes_to_discard) override; |
| 64 uint32_t min_num_bytes_to_discard) override; | 61 MojoResult ConsumerQueryData(UserPointer<uint32_t> num_bytes) override; |
| 65 MojoResult ConsumerQueryDataImplNoLock( | 62 MojoResult ConsumerBeginReadData(UserPointer<const void*> buffer, |
| 66 UserPointer<uint32_t> num_bytes) override; | 63 UserPointer<uint32_t> buffer_num_bytes, |
| 67 MojoResult ConsumerBeginReadDataImplNoLock( | 64 uint32_t min_num_bytes_to_read) override; |
| 68 UserPointer<const void*> buffer, | 65 MojoResult ConsumerEndReadData(uint32_t num_bytes_read) override; |
| 69 UserPointer<uint32_t> buffer_num_bytes, | 66 HandleSignalsState ConsumerGetHandleSignalsState() const override; |
| 70 uint32_t min_num_bytes_to_read) override; | 67 void ConsumerStartSerialize(Channel* channel, |
| 71 MojoResult ConsumerEndReadDataImplNoLock(uint32_t num_bytes_read) override; | 68 size_t* max_size, |
| 72 HandleSignalsState ConsumerGetHandleSignalsStateImplNoLock() const override; | 69 size_t* max_platform_handles) override; |
| 73 void ConsumerStartSerializeImplNoLock(Channel* channel, | 70 bool ConsumerEndSerialize( |
| 74 size_t* max_size, | |
| 75 size_t* max_platform_handles) override; | |
| 76 bool ConsumerEndSerializeImplNoLock( | |
| 77 Channel* channel, | 71 Channel* channel, |
| 78 void* destination, | 72 void* destination, |
| 79 size_t* actual_size, | 73 size_t* actual_size, |
| 80 embedder::PlatformHandleVector* platform_handles) override; | 74 embedder::PlatformHandleVector* platform_handles) override; |
| 81 | 75 |
| 82 void EnsureBufferNoLock(); | 76 void EnsureBuffer(); |
| 83 void DestroyBufferNoLock(); | 77 void DestroyBuffer(); |
| 84 | 78 |
| 85 // Get the maximum (single) write/read size right now (in number of elements); | 79 // Get the maximum (single) write/read size right now (in number of elements); |
| 86 // result fits in a |uint32_t|. | 80 // result fits in a |uint32_t|. |
| 87 size_t GetMaxNumBytesToWriteNoLock(); | 81 size_t GetMaxNumBytesToWrite(); |
| 88 size_t GetMaxNumBytesToReadNoLock(); | 82 size_t GetMaxNumBytesToRead(); |
| 89 | 83 |
| 90 // Marks the given number of bytes as consumed/discarded. |num_bytes| must be | 84 // Marks the given number of bytes as consumed/discarded. |num_bytes| must be |
| 91 // greater than |current_num_bytes_|. | 85 // greater than |current_num_bytes_|. |
| 92 void MarkDataAsConsumedNoLock(size_t num_bytes); | 86 void MarkDataAsConsumed(size_t num_bytes); |
| 93 | 87 |
| 94 // The members below are protected by |DataPipe|'s |lock_|: | |
| 95 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; | 88 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; |
| 96 // Circular buffer. | 89 // Circular buffer. |
| 97 size_t start_index_; | 90 size_t start_index_; |
| 98 size_t current_num_bytes_; | 91 size_t current_num_bytes_; |
| 99 | 92 |
| 100 DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImpl); | 93 DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImpl); |
| 101 }; | 94 }; |
| 102 | 95 |
| 103 } // namespace system | 96 } // namespace system |
| 104 } // namespace mojo | 97 } // namespace mojo |
| 105 | 98 |
| 106 #endif // MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ | 99 #endif // MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ |
| OLD | NEW |