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> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "mojo/edk/system/data_pipe.h" | 10 #include "mojo/edk/system/data_pipe.h" |
9 #include "mojo/edk/system/memory.h" | 11 #include "mojo/edk/system/memory.h" |
10 | 12 |
11 namespace mojo { | 13 namespace mojo { |
12 namespace system { | 14 namespace system { |
13 | 15 |
14 void DataPipeProducerDispatcher::Init(scoped_refptr<DataPipe> data_pipe) { | 16 void DataPipeProducerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { |
15 DCHECK(data_pipe); | 17 DCHECK(data_pipe); |
16 data_pipe_ = data_pipe; | 18 data_pipe_ = std::move(data_pipe); |
17 } | 19 } |
18 | 20 |
19 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { | 21 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { |
20 return Type::DATA_PIPE_PRODUCER; | 22 return Type::DATA_PIPE_PRODUCER; |
21 } | 23 } |
22 | 24 |
23 // static | 25 // static |
24 scoped_refptr<DataPipeProducerDispatcher> | 26 scoped_refptr<DataPipeProducerDispatcher> |
25 DataPipeProducerDispatcher::Deserialize(Channel* channel, | 27 DataPipeProducerDispatcher::Deserialize(Channel* channel, |
26 const void* source, | 28 const void* source, |
27 size_t size) { | 29 size_t size) { |
28 scoped_refptr<DataPipe> data_pipe; | 30 RefPtr<DataPipe> data_pipe; |
29 if (!DataPipe::ProducerDeserialize(channel, source, size, &data_pipe)) | 31 if (!DataPipe::ProducerDeserialize(channel, source, size, &data_pipe)) |
30 return nullptr; | 32 return nullptr; |
31 DCHECK(data_pipe); | 33 DCHECK(data_pipe); |
32 | 34 |
33 scoped_refptr<DataPipeProducerDispatcher> dispatcher = Create(); | 35 scoped_refptr<DataPipeProducerDispatcher> dispatcher = Create(); |
34 dispatcher->Init(data_pipe); | 36 dispatcher->Init(std::move(data_pipe)); |
35 return dispatcher; | 37 return dispatcher; |
36 } | 38 } |
37 | 39 |
38 DataPipe* DataPipeProducerDispatcher::GetDataPipeForTest() { | 40 DataPipe* DataPipeProducerDispatcher::GetDataPipeForTest() { |
39 MutexLocker locker(&mutex()); | 41 MutexLocker locker(&mutex()); |
40 return data_pipe_.get(); | 42 return data_pipe_.get(); |
41 } | 43 } |
42 | 44 |
43 DataPipeProducerDispatcher::DataPipeProducerDispatcher() { | 45 DataPipeProducerDispatcher::DataPipeProducerDispatcher() { |
44 } | 46 } |
(...skipping 12 matching lines...) Expand all Loading... |
57 mutex().AssertHeld(); | 59 mutex().AssertHeld(); |
58 data_pipe_->ProducerClose(); | 60 data_pipe_->ProducerClose(); |
59 data_pipe_ = nullptr; | 61 data_pipe_ = nullptr; |
60 } | 62 } |
61 | 63 |
62 scoped_refptr<Dispatcher> | 64 scoped_refptr<Dispatcher> |
63 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 65 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
64 mutex().AssertHeld(); | 66 mutex().AssertHeld(); |
65 | 67 |
66 scoped_refptr<DataPipeProducerDispatcher> rv = Create(); | 68 scoped_refptr<DataPipeProducerDispatcher> rv = Create(); |
67 rv->Init(data_pipe_); | 69 rv->Init(std::move(data_pipe_)); |
68 data_pipe_ = nullptr; | |
69 return scoped_refptr<Dispatcher>(rv.get()); | 70 return scoped_refptr<Dispatcher>(rv.get()); |
70 } | 71 } |
71 | 72 |
72 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( | 73 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( |
73 UserPointer<const void> elements, | 74 UserPointer<const void> elements, |
74 UserPointer<uint32_t> num_bytes, | 75 UserPointer<uint32_t> num_bytes, |
75 MojoWriteDataFlags flags) { | 76 MojoWriteDataFlags flags) { |
76 mutex().AssertHeld(); | 77 mutex().AssertHeld(); |
77 return data_pipe_->ProducerWriteData( | 78 return data_pipe_->ProducerWriteData( |
78 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); | 79 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return rv; | 143 return rv; |
143 } | 144 } |
144 | 145 |
145 bool DataPipeProducerDispatcher::IsBusyNoLock() const { | 146 bool DataPipeProducerDispatcher::IsBusyNoLock() const { |
146 mutex().AssertHeld(); | 147 mutex().AssertHeld(); |
147 return data_pipe_->ProducerIsBusy(); | 148 return data_pipe_->ProducerIsBusy(); |
148 } | 149 } |
149 | 150 |
150 } // namespace system | 151 } // namespace system |
151 } // namespace mojo | 152 } // namespace mojo |
OLD | NEW |