Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Side by Side Diff: mojo/edk/system/data_pipe_consumer_dispatcher.cc

Issue 1412283002: Convert mojo::system::Dispatcher to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no change Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_consumer_dispatcher.h" 5 #include "mojo/edk/system/data_pipe_consumer_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 DataPipeConsumerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { 16 void DataPipeConsumerDispatcher::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 DataPipeConsumerDispatcher::GetType() const { 21 Dispatcher::Type DataPipeConsumerDispatcher::GetType() const {
22 return Type::DATA_PIPE_CONSUMER; 22 return Type::DATA_PIPE_CONSUMER;
23 } 23 }
24 24
25 // static 25 // static
26 scoped_refptr<DataPipeConsumerDispatcher> 26 RefPtr<DataPipeConsumerDispatcher> DataPipeConsumerDispatcher::Deserialize(
27 DataPipeConsumerDispatcher::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::ConsumerDeserialize(channel, source, size, &data_pipe)) 31 if (!DataPipe::ConsumerDeserialize(channel, source, size, &data_pipe))
32 return nullptr; 32 return nullptr;
33 DCHECK(data_pipe); 33 DCHECK(data_pipe);
34 34
35 scoped_refptr<DataPipeConsumerDispatcher> dispatcher = Create(); 35 auto dispatcher = DataPipeConsumerDispatcher::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* DataPipeConsumerDispatcher::GetDataPipeForTest() { 40 DataPipe* DataPipeConsumerDispatcher::GetDataPipeForTest() {
41 MutexLocker locker(&mutex()); 41 MutexLocker locker(&mutex());
42 return data_pipe_.get(); 42 return data_pipe_.get();
43 } 43 }
44 44
45 DataPipeConsumerDispatcher::DataPipeConsumerDispatcher() { 45 DataPipeConsumerDispatcher::DataPipeConsumerDispatcher() {
46 } 46 }
47 47
48 DataPipeConsumerDispatcher::~DataPipeConsumerDispatcher() { 48 DataPipeConsumerDispatcher::~DataPipeConsumerDispatcher() {
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 DataPipeConsumerDispatcher::CancelAllAwakablesNoLock() { 53 void DataPipeConsumerDispatcher::CancelAllAwakablesNoLock() {
54 mutex().AssertHeld(); 54 mutex().AssertHeld();
55 data_pipe_->ConsumerCancelAllAwakables(); 55 data_pipe_->ConsumerCancelAllAwakables();
56 } 56 }
57 57
58 void DataPipeConsumerDispatcher::CloseImplNoLock() { 58 void DataPipeConsumerDispatcher::CloseImplNoLock() {
59 mutex().AssertHeld(); 59 mutex().AssertHeld();
60 data_pipe_->ConsumerClose(); 60 data_pipe_->ConsumerClose();
61 data_pipe_ = nullptr; 61 data_pipe_ = nullptr;
62 } 62 }
63 63
64 scoped_refptr<Dispatcher> 64 RefPtr<Dispatcher>
65 DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { 65 DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
66 mutex().AssertHeld(); 66 mutex().AssertHeld();
67 67
68 scoped_refptr<DataPipeConsumerDispatcher> rv = Create(); 68 auto dispatcher = DataPipeConsumerDispatcher::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 DataPipeConsumerDispatcher::ReadDataImplNoLock( 73 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
74 UserPointer<void> elements, 74 UserPointer<void> elements,
75 UserPointer<uint32_t> num_bytes, 75 UserPointer<uint32_t> num_bytes,
76 MojoReadDataFlags flags) { 76 MojoReadDataFlags flags) {
77 mutex().AssertHeld(); 77 mutex().AssertHeld();
78 78
79 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { 79 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) {
80 // These flags are mutally exclusive. 80 // These flags are mutally exclusive.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 Awakable* awakable, 143 Awakable* awakable,
144 HandleSignalsState* signals_state) { 144 HandleSignalsState* signals_state) {
145 mutex().AssertHeld(); 145 mutex().AssertHeld();
146 data_pipe_->ConsumerRemoveAwakable(awakable, signals_state); 146 data_pipe_->ConsumerRemoveAwakable(awakable, signals_state);
147 } 147 }
148 148
149 void DataPipeConsumerDispatcher::StartSerializeImplNoLock( 149 void DataPipeConsumerDispatcher::StartSerializeImplNoLock(
150 Channel* channel, 150 Channel* channel,
151 size_t* max_size, 151 size_t* max_size,
152 size_t* max_platform_handles) { 152 size_t* max_platform_handles) {
153 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. 153 AssertHasOneRef(); // Only one ref => no need to take the lock.
154 data_pipe_->ConsumerStartSerialize(channel, max_size, max_platform_handles); 154 data_pipe_->ConsumerStartSerialize(channel, max_size, max_platform_handles);
155 } 155 }
156 156
157 bool DataPipeConsumerDispatcher::EndSerializeAndCloseImplNoLock( 157 bool DataPipeConsumerDispatcher::EndSerializeAndCloseImplNoLock(
158 Channel* channel, 158 Channel* channel,
159 void* destination, 159 void* destination,
160 size_t* actual_size, 160 size_t* actual_size,
161 embedder::PlatformHandleVector* platform_handles) { 161 embedder::PlatformHandleVector* platform_handles) {
162 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. 162 AssertHasOneRef(); // Only one ref => no need to take the lock.
163 163
164 bool rv = data_pipe_->ConsumerEndSerialize(channel, destination, actual_size, 164 bool rv = data_pipe_->ConsumerEndSerialize(channel, destination, actual_size,
165 platform_handles); 165 platform_handles);
166 data_pipe_ = nullptr; 166 data_pipe_ = nullptr;
167 return rv; 167 return rv;
168 } 168 }
169 169
170 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { 170 bool DataPipeConsumerDispatcher::IsBusyNoLock() const {
171 mutex().AssertHeld(); 171 mutex().AssertHeld();
172 return data_pipe_->ConsumerIsBusy(); 172 return data_pipe_->ConsumerIsBusy();
173 } 173 }
174 174
175 } // namespace system 175 } // namespace system
176 } // namespace mojo 176 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.h ('k') | mojo/edk/system/data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698