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/system/data_pipe_consumer_dispatcher.h" | 5 #include "mojo/system/data_pipe_consumer_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/system/data_pipe.h" | 8 #include "mojo/system/data_pipe.h" |
9 #include "mojo/system/memory.h" | 9 #include "mojo/system/memory.h" |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 lock().AssertAcquired(); | 44 lock().AssertAcquired(); |
45 | 45 |
46 scoped_refptr<DataPipeConsumerDispatcher> rv = | 46 scoped_refptr<DataPipeConsumerDispatcher> rv = |
47 new DataPipeConsumerDispatcher(); | 47 new DataPipeConsumerDispatcher(); |
48 rv->Init(data_pipe_); | 48 rv->Init(data_pipe_); |
49 data_pipe_ = NULL; | 49 data_pipe_ = NULL; |
50 return scoped_refptr<Dispatcher>(rv.get()); | 50 return scoped_refptr<Dispatcher>(rv.get()); |
51 } | 51 } |
52 | 52 |
53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock( | 53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock( |
54 void* elements, | 54 UserPointer<void> elements, |
55 uint32_t* num_bytes, | 55 UserPointer<uint32_t> num_bytes, |
56 MojoReadDataFlags flags) { | 56 MojoReadDataFlags flags) { |
57 lock().AssertAcquired(); | 57 lock().AssertAcquired(); |
58 | 58 |
59 if (!VerifyUserPointer<uint32_t>(num_bytes)) | |
60 return MOJO_RESULT_INVALID_ARGUMENT; | |
61 | |
62 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { | 59 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { |
63 // These flags are mutally exclusive. | 60 // These flags are mutally exclusive. |
64 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) | 61 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) |
65 return MOJO_RESULT_INVALID_ARGUMENT; | 62 return MOJO_RESULT_INVALID_ARGUMENT; |
66 DVLOG_IF(2, elements) << "Discard mode: ignoring non-null |elements|"; | 63 DVLOG_IF(2, !elements.IsNull()) |
| 64 << "Discard mode: ignoring non-null |elements|"; |
67 return data_pipe_->ConsumerDiscardData( | 65 return data_pipe_->ConsumerDiscardData( |
68 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 66 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); |
69 } | 67 } |
70 | 68 |
71 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) { | 69 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) { |
72 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above. | 70 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above. |
73 DVLOG_IF(2, elements) << "Query mode: ignoring non-null |elements|"; | 71 DVLOG_IF(2, !elements.IsNull()) |
| 72 << "Query mode: ignoring non-null |elements|"; |
74 return data_pipe_->ConsumerQueryData(num_bytes); | 73 return data_pipe_->ConsumerQueryData(num_bytes); |
75 } | 74 } |
76 | 75 |
77 // Only verify |elements| if we're neither discarding nor querying. | |
78 if (!VerifyUserPointerWithSize<1>(elements, *num_bytes)) | |
79 return MOJO_RESULT_INVALID_ARGUMENT; | |
80 | |
81 return data_pipe_->ConsumerReadData( | 76 return data_pipe_->ConsumerReadData( |
82 elements, num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 77 elements, num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); |
83 } | 78 } |
84 | 79 |
85 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock( | 80 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock( |
86 UserPointer<const void*> buffer, | 81 UserPointer<const void*> buffer, |
87 UserPointer<uint32_t> buffer_num_bytes, | 82 UserPointer<uint32_t> buffer_num_bytes, |
88 MojoReadDataFlags flags) { | 83 MojoReadDataFlags flags) { |
89 lock().AssertAcquired(); | 84 lock().AssertAcquired(); |
90 | 85 |
(...skipping 26 matching lines...) Expand all Loading... |
117 data_pipe_->ConsumerRemoveWaiter(waiter); | 112 data_pipe_->ConsumerRemoveWaiter(waiter); |
118 } | 113 } |
119 | 114 |
120 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { | 115 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { |
121 lock().AssertAcquired(); | 116 lock().AssertAcquired(); |
122 return data_pipe_->ConsumerIsBusy(); | 117 return data_pipe_->ConsumerIsBusy(); |
123 } | 118 } |
124 | 119 |
125 } // namespace system | 120 } // namespace system |
126 } // namespace mojo | 121 } // namespace mojo |
OLD | NEW |