OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ |
6 #define MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ | 6 #define MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "mojo/edk/system/channel_endpoint.h" | 12 #include "mojo/edk/system/channel_endpoint.h" |
12 #include "mojo/edk/system/data_pipe_impl.h" | 13 #include "mojo/edk/system/data_pipe_impl.h" |
13 #include "mojo/edk/system/system_impl_export.h" | 14 #include "mojo/edk/system/system_impl_export.h" |
14 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
15 | 16 |
16 namespace mojo { | 17 namespace mojo { |
17 namespace system { | 18 namespace system { |
18 | 19 |
19 class MessageInTransitQueue; | 20 class MessageInTransitQueue; |
20 | 21 |
21 // |RemoteProducerDataPipeImpl| is a subclass that "implements" |DataPipe| for | 22 // |RemoteProducerDataPipeImpl| is a subclass that "implements" |DataPipe| for |
22 // data pipes whose producer is remote and whose consumer is local. See | 23 // data pipes whose producer is remote and whose consumer is local. See |
23 // |DataPipeImpl| for more details. | 24 // |DataPipeImpl| for more details. |
24 class MOJO_SYSTEM_IMPL_EXPORT RemoteProducerDataPipeImpl final | 25 class MOJO_SYSTEM_IMPL_EXPORT RemoteProducerDataPipeImpl final |
25 : public DataPipeImpl { | 26 : public DataPipeImpl { |
26 public: | 27 public: |
27 explicit RemoteProducerDataPipeImpl(ChannelEndpoint* channel_endpoint); | 28 explicit RemoteProducerDataPipeImpl(ChannelEndpoint* channel_endpoint); |
28 RemoteProducerDataPipeImpl(ChannelEndpoint* channel_endpoint, | 29 RemoteProducerDataPipeImpl( |
29 scoped_ptr<char, base::AlignedFreeDeleter> buffer, | 30 ChannelEndpoint* channel_endpoint, |
30 size_t start_index, | 31 std::unique_ptr<char, base::AlignedFreeDeleter> buffer, |
31 size_t current_num_bytes); | 32 size_t start_index, |
| 33 size_t current_num_bytes); |
32 ~RemoteProducerDataPipeImpl() override; | 34 ~RemoteProducerDataPipeImpl() override; |
33 | 35 |
34 // Processes messages that were received and queued by an |IncomingEndpoint|. | 36 // Processes messages that were received and queued by an |IncomingEndpoint|. |
35 // On success, returns true and sets |*buffer| (to a buffer of size | 37 // On success, returns true and sets |*buffer| (to a buffer of size |
36 // |validated_options.capacity_num_bytes|) and |*buffer_num_bytes|. On | 38 // |validated_options.capacity_num_bytes|) and |*buffer_num_bytes|. On |
37 // failure, returns false. Always clears |*messages|. | 39 // failure, returns false. Always clears |*messages|. |
38 static bool ProcessMessagesFromIncomingEndpoint( | 40 static bool ProcessMessagesFromIncomingEndpoint( |
39 const MojoCreateDataPipeOptions& validated_options, | 41 const MojoCreateDataPipeOptions& validated_options, |
40 MessageInTransitQueue* messages, | 42 MessageInTransitQueue* messages, |
41 scoped_ptr<char, base::AlignedFreeDeleter>* buffer, | 43 std::unique_ptr<char, base::AlignedFreeDeleter>* buffer, |
42 size_t* buffer_num_bytes); | 44 size_t* buffer_num_bytes); |
43 | 45 |
44 private: | 46 private: |
45 // |DataPipeImpl| implementation: | 47 // |DataPipeImpl| implementation: |
46 // Note: None of the |Producer...()| methods should be called, except | 48 // Note: None of the |Producer...()| methods should be called, except |
47 // |ProducerGetHandleSignalsState()|. | 49 // |ProducerGetHandleSignalsState()|. |
48 void ProducerClose() override; | 50 void ProducerClose() override; |
49 MojoResult ProducerWriteData(UserPointer<const void> elements, | 51 MojoResult ProducerWriteData(UserPointer<const void> elements, |
50 UserPointer<uint32_t> num_bytes, | 52 UserPointer<uint32_t> num_bytes, |
51 uint32_t max_num_bytes_to_write, | 53 uint32_t max_num_bytes_to_write, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // Marks the given number of bytes as consumed/discarded. This will send a | 102 // Marks the given number of bytes as consumed/discarded. This will send a |
101 // message to the remote producer. |num_bytes| must be no greater than | 103 // message to the remote producer. |num_bytes| must be no greater than |
102 // |current_num_bytes_|. | 104 // |current_num_bytes_|. |
103 void MarkDataAsConsumed(size_t num_bytes); | 105 void MarkDataAsConsumed(size_t num_bytes); |
104 | 106 |
105 void Disconnect(); | 107 void Disconnect(); |
106 | 108 |
107 // Should be valid if and only if |producer_open()| returns true. | 109 // Should be valid if and only if |producer_open()| returns true. |
108 scoped_refptr<ChannelEndpoint> channel_endpoint_; | 110 scoped_refptr<ChannelEndpoint> channel_endpoint_; |
109 | 111 |
110 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; | 112 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; |
111 // Circular buffer. | 113 // Circular buffer. |
112 size_t start_index_; | 114 size_t start_index_; |
113 size_t current_num_bytes_; | 115 size_t current_num_bytes_; |
114 | 116 |
115 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImpl); | 117 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImpl); |
116 }; | 118 }; |
117 | 119 |
118 } // namespace system | 120 } // namespace system |
119 } // namespace mojo | 121 } // namespace mojo |
120 | 122 |
121 #endif // MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ | 123 #endif // MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ |
OLD | NEW |