| 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_CONSUMER_DATA_PIPE_IMPL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ |
| 6 #define MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ | 6 #define MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
| 11 #include "mojo/edk/system/channel_endpoint.h" | 11 #include "mojo/edk/system/channel_endpoint.h" |
| 12 #include "mojo/edk/system/data_pipe_impl.h" | 12 #include "mojo/edk/system/data_pipe_impl.h" |
| 13 #include "mojo/edk/system/ref_ptr.h" | 13 #include "mojo/edk/util/ref_ptr.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace system { | 17 namespace system { |
| 18 | 18 |
| 19 // |RemoteConsumerDataPipeImpl| is a subclass that "implements" |DataPipe| for | 19 // |RemoteConsumerDataPipeImpl| is a subclass that "implements" |DataPipe| for |
| 20 // data pipes whose producer is local and whose consumer is remote. See | 20 // data pipes whose producer is local and whose consumer is remote. See |
| 21 // |DataPipeImpl| for more details. | 21 // |DataPipeImpl| for more details. |
| 22 class RemoteConsumerDataPipeImpl final : public DataPipeImpl { | 22 class RemoteConsumerDataPipeImpl final : public DataPipeImpl { |
| 23 public: | 23 public: |
| 24 // |buffer| is only required if |producer_two_phase_max_num_bytes_written()| | 24 // |buffer| is only required if |producer_two_phase_max_num_bytes_written()| |
| 25 // is nonzero (i.e., if we're in the middle of a two-phase write when the | 25 // is nonzero (i.e., if we're in the middle of a two-phase write when the |
| 26 // consumer handle is transferred); |start_index| is ignored if it is zero. | 26 // consumer handle is transferred); |start_index| is ignored if it is zero. |
| 27 RemoteConsumerDataPipeImpl( | 27 RemoteConsumerDataPipeImpl( |
| 28 RefPtr<ChannelEndpoint>&& channel_endpoint, | 28 util::RefPtr<ChannelEndpoint>&& channel_endpoint, |
| 29 size_t consumer_num_bytes, | 29 size_t consumer_num_bytes, |
| 30 std::unique_ptr<char, base::AlignedFreeDeleter> buffer, | 30 std::unique_ptr<char, base::AlignedFreeDeleter> buffer, |
| 31 size_t start_index); | 31 size_t start_index); |
| 32 ~RemoteConsumerDataPipeImpl() override; | 32 ~RemoteConsumerDataPipeImpl() override; |
| 33 | 33 |
| 34 // Processes messages that were received and queued by an |IncomingEndpoint|. | 34 // Processes messages that were received and queued by an |IncomingEndpoint|. |
| 35 // |*consumer_num_bytes| should be set to the value from the | 35 // |*consumer_num_bytes| should be set to the value from the |
| 36 // |SerializedDataPipeProducerDispatcher|. On success, returns true and | 36 // |SerializedDataPipeProducerDispatcher|. On success, returns true and |
| 37 // updates |*consumer_num_bytes|. On failure, returns false (it may or may not | 37 // updates |*consumer_num_bytes|. On failure, returns false (it may or may not |
| 38 // modify |*consumer_num_bytes|). Always clears |*messages|. | 38 // modify |*consumer_num_bytes|). Always clears |*messages|. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 embedder::PlatformHandleVector* platform_handles) override; | 88 embedder::PlatformHandleVector* platform_handles) override; |
| 89 bool OnReadMessage(unsigned port, MessageInTransit* message) override; | 89 bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
| 90 void OnDetachFromChannel(unsigned port) override; | 90 void OnDetachFromChannel(unsigned port) override; |
| 91 | 91 |
| 92 void EnsureBuffer(); | 92 void EnsureBuffer(); |
| 93 void DestroyBuffer(); | 93 void DestroyBuffer(); |
| 94 | 94 |
| 95 void Disconnect(); | 95 void Disconnect(); |
| 96 | 96 |
| 97 // Should be valid if and only if |consumer_open()| returns true. | 97 // Should be valid if and only if |consumer_open()| returns true. |
| 98 RefPtr<ChannelEndpoint> channel_endpoint_; | 98 util::RefPtr<ChannelEndpoint> channel_endpoint_; |
| 99 | 99 |
| 100 // The number of bytes we've sent the consumer, but don't *know* have been | 100 // The number of bytes we've sent the consumer, but don't *know* have been |
| 101 // consumed. | 101 // consumed. |
| 102 size_t consumer_num_bytes_; | 102 size_t consumer_num_bytes_; |
| 103 | 103 |
| 104 // Used for two-phase writes. | 104 // Used for two-phase writes. |
| 105 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; | 105 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; |
| 106 // This is nearly always zero, except when the two-phase write started on a | 106 // This is nearly always zero, except when the two-phase write started on a |
| 107 // |LocalDataPipeImpl|. | 107 // |LocalDataPipeImpl|. |
| 108 size_t start_index_; | 108 size_t start_index_; |
| 109 | 109 |
| 110 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImpl); | 110 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImpl); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 } // namespace system | 113 } // namespace system |
| 114 } // namespace mojo | 114 } // namespace mojo |
| 115 | 115 |
| 116 #endif // MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ | 116 #endif // MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ |
| OLD | NEW |