| 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 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/edk/system/data_pipe.h" | 10 #include "mojo/edk/system/data_pipe.h" |
| 11 #include "mojo/edk/system/memory.h" | 11 #include "mojo/edk/system/memory.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace system { | 14 namespace system { |
| 15 | 15 |
| 16 void DataPipeProducerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { | 16 void DataPipeProducerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { |
| 17 DCHECK(data_pipe); | 17 DCHECK(data_pipe); |
| 18 data_pipe_ = std::move(data_pipe); | 18 data_pipe_ = std::move(data_pipe); |
| 19 } | 19 } |
| 20 | 20 |
| 21 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { | 21 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { |
| 22 return Type::DATA_PIPE_PRODUCER; | 22 return Type::DATA_PIPE_PRODUCER; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 scoped_refptr<DataPipeProducerDispatcher> | 26 RefPtr<DataPipeProducerDispatcher> DataPipeProducerDispatcher::Deserialize( |
| 27 DataPipeProducerDispatcher::Deserialize(Channel* channel, | 27 Channel* channel, |
| 28 const void* source, | 28 const void* source, |
| 29 size_t size) { | 29 size_t size) { |
| 30 RefPtr<DataPipe> data_pipe; | 30 RefPtr<DataPipe> data_pipe; |
| 31 if (!DataPipe::ProducerDeserialize(channel, source, size, &data_pipe)) | 31 if (!DataPipe::ProducerDeserialize(channel, source, size, &data_pipe)) |
| 32 return nullptr; | 32 return nullptr; |
| 33 DCHECK(data_pipe); | 33 DCHECK(data_pipe); |
| 34 | 34 |
| 35 scoped_refptr<DataPipeProducerDispatcher> dispatcher = Create(); | 35 auto dispatcher = DataPipeProducerDispatcher::Create(); |
| 36 dispatcher->Init(std::move(data_pipe)); | 36 dispatcher->Init(std::move(data_pipe)); |
| 37 return dispatcher; | 37 return dispatcher; |
| 38 } | 38 } |
| 39 | 39 |
| 40 DataPipe* DataPipeProducerDispatcher::GetDataPipeForTest() { | 40 DataPipe* DataPipeProducerDispatcher::GetDataPipeForTest() { |
| 41 MutexLocker locker(&mutex()); | 41 MutexLocker locker(&mutex()); |
| 42 return data_pipe_.get(); | 42 return data_pipe_.get(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 DataPipeProducerDispatcher::DataPipeProducerDispatcher() { | 45 DataPipeProducerDispatcher::DataPipeProducerDispatcher() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { | 48 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { |
| 49 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. | 49 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. |
| 50 DCHECK(!data_pipe_); | 50 DCHECK(!data_pipe_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void DataPipeProducerDispatcher::CancelAllAwakablesNoLock() { | 53 void DataPipeProducerDispatcher::CancelAllAwakablesNoLock() { |
| 54 mutex().AssertHeld(); | 54 mutex().AssertHeld(); |
| 55 data_pipe_->ProducerCancelAllAwakables(); | 55 data_pipe_->ProducerCancelAllAwakables(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void DataPipeProducerDispatcher::CloseImplNoLock() { | 58 void DataPipeProducerDispatcher::CloseImplNoLock() { |
| 59 mutex().AssertHeld(); | 59 mutex().AssertHeld(); |
| 60 data_pipe_->ProducerClose(); | 60 data_pipe_->ProducerClose(); |
| 61 data_pipe_ = nullptr; | 61 data_pipe_ = nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 scoped_refptr<Dispatcher> | 64 RefPtr<Dispatcher> |
| 65 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 65 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
| 66 mutex().AssertHeld(); | 66 mutex().AssertHeld(); |
| 67 | 67 |
| 68 scoped_refptr<DataPipeProducerDispatcher> rv = Create(); | 68 auto dispatcher = DataPipeProducerDispatcher::Create(); |
| 69 rv->Init(std::move(data_pipe_)); | 69 dispatcher->Init(std::move(data_pipe_)); |
| 70 return scoped_refptr<Dispatcher>(rv.get()); | 70 return dispatcher; |
| 71 } | 71 } |
| 72 | 72 |
| 73 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( | 73 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( |
| 74 UserPointer<const void> elements, | 74 UserPointer<const void> elements, |
| 75 UserPointer<uint32_t> num_bytes, | 75 UserPointer<uint32_t> num_bytes, |
| 76 MojoWriteDataFlags flags) { | 76 MojoWriteDataFlags flags) { |
| 77 mutex().AssertHeld(); | 77 mutex().AssertHeld(); |
| 78 return data_pipe_->ProducerWriteData( | 78 return data_pipe_->ProducerWriteData( |
| 79 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); | 79 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); |
| 80 } | 80 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 Awakable* awakable, | 119 Awakable* awakable, |
| 120 HandleSignalsState* signals_state) { | 120 HandleSignalsState* signals_state) { |
| 121 mutex().AssertHeld(); | 121 mutex().AssertHeld(); |
| 122 data_pipe_->ProducerRemoveAwakable(awakable, signals_state); | 122 data_pipe_->ProducerRemoveAwakable(awakable, signals_state); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void DataPipeProducerDispatcher::StartSerializeImplNoLock( | 125 void DataPipeProducerDispatcher::StartSerializeImplNoLock( |
| 126 Channel* channel, | 126 Channel* channel, |
| 127 size_t* max_size, | 127 size_t* max_size, |
| 128 size_t* max_platform_handles) { | 128 size_t* max_platform_handles) { |
| 129 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 129 AssertHasOneRef(); // Only one ref => no need to take the lock. |
| 130 data_pipe_->ProducerStartSerialize(channel, max_size, max_platform_handles); | 130 data_pipe_->ProducerStartSerialize(channel, max_size, max_platform_handles); |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool DataPipeProducerDispatcher::EndSerializeAndCloseImplNoLock( | 133 bool DataPipeProducerDispatcher::EndSerializeAndCloseImplNoLock( |
| 134 Channel* channel, | 134 Channel* channel, |
| 135 void* destination, | 135 void* destination, |
| 136 size_t* actual_size, | 136 size_t* actual_size, |
| 137 embedder::PlatformHandleVector* platform_handles) { | 137 embedder::PlatformHandleVector* platform_handles) { |
| 138 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 138 AssertHasOneRef(); // Only one ref => no need to take the lock. |
| 139 | 139 |
| 140 bool rv = data_pipe_->ProducerEndSerialize(channel, destination, actual_size, | 140 bool rv = data_pipe_->ProducerEndSerialize(channel, destination, actual_size, |
| 141 platform_handles); | 141 platform_handles); |
| 142 data_pipe_ = nullptr; | 142 data_pipe_ = nullptr; |
| 143 return rv; | 143 return rv; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool DataPipeProducerDispatcher::IsBusyNoLock() const { | 146 bool DataPipeProducerDispatcher::IsBusyNoLock() const { |
| 147 mutex().AssertHeld(); | 147 mutex().AssertHeld(); |
| 148 return data_pipe_->ProducerIsBusy(); | 148 return data_pipe_->ProducerIsBusy(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace system | 151 } // namespace system |
| 152 } // namespace mojo | 152 } // namespace mojo |
| OLD | NEW |