| 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_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" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 auto dispatcher = DataPipeConsumerDispatcher::Create(); | 73 auto dispatcher = DataPipeConsumerDispatcher::Create(); |
| 74 dispatcher->Init(std::move(data_pipe_)); | 74 dispatcher->Init(std::move(data_pipe_)); |
| 75 return dispatcher; | 75 return dispatcher; |
| 76 } | 76 } |
| 77 | 77 |
| 78 MojoResult DataPipeConsumerDispatcher::SetDataPipeConsumerOptionsImplNoLock( | 78 MojoResult DataPipeConsumerDispatcher::SetDataPipeConsumerOptionsImplNoLock( |
| 79 UserPointer<const MojoDataPipeConsumerOptions> options) { | 79 UserPointer<const MojoDataPipeConsumerOptions> options) { |
| 80 mutex().AssertHeld(); | 80 mutex().AssertHeld(); |
| 81 | 81 |
| 82 UserOptionsReader<MojoDataPipeConsumerOptions> reader(options); | 82 // The default of 0 means 1 element (however big that is). |
| 83 if (!reader.is_valid()) | 83 uint32_t read_threshold_num_bytes = 0; |
| 84 return MOJO_RESULT_INVALID_ARGUMENT; | 84 if (!options.IsNull()) { |
| 85 UserOptionsReader<MojoDataPipeConsumerOptions> reader(options); |
| 86 if (!reader.is_valid()) |
| 87 return MOJO_RESULT_INVALID_ARGUMENT; |
| 85 | 88 |
| 86 if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDataPipeConsumerOptions, | 89 if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDataPipeConsumerOptions, |
| 87 read_threshold_num_bytes, reader)) | 90 read_threshold_num_bytes, reader)) |
| 88 return MOJO_RESULT_OK; | 91 return MOJO_RESULT_OK; |
| 89 | 92 |
| 90 return data_pipe_->ConsumerSetOptions( | 93 read_threshold_num_bytes = reader.options().read_threshold_num_bytes; |
| 91 reader.options().read_threshold_num_bytes); | 94 } |
| 95 |
| 96 return data_pipe_->ConsumerSetOptions(read_threshold_num_bytes); |
| 92 } | 97 } |
| 93 | 98 |
| 94 MojoResult DataPipeConsumerDispatcher::GetDataPipeConsumerOptionsImplNoLock( | 99 MojoResult DataPipeConsumerDispatcher::GetDataPipeConsumerOptionsImplNoLock( |
| 95 UserPointer<MojoDataPipeConsumerOptions> options, | 100 UserPointer<MojoDataPipeConsumerOptions> options, |
| 96 uint32_t options_num_bytes) { | 101 uint32_t options_num_bytes) { |
| 97 mutex().AssertHeld(); | 102 mutex().AssertHeld(); |
| 98 | 103 |
| 99 // Note: If/when |MojoDataPipeConsumerOptions| is extended beyond its initial | 104 // Note: If/when |MojoDataPipeConsumerOptions| is extended beyond its initial |
| 100 // definition, more work will be necessary. (See the definition of | 105 // definition, more work will be necessary. (See the definition of |
| 101 // |MojoGetDataPipeConsumerOptions()| in mojo/public/c/system/data_pipe.h.) | 106 // |MojoGetDataPipeConsumerOptions()| in mojo/public/c/system/data_pipe.h.) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return rv; | 217 return rv; |
| 213 } | 218 } |
| 214 | 219 |
| 215 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { | 220 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { |
| 216 mutex().AssertHeld(); | 221 mutex().AssertHeld(); |
| 217 return data_pipe_->ConsumerIsBusy(); | 222 return data_pipe_->ConsumerIsBusy(); |
| 218 } | 223 } |
| 219 | 224 |
| 220 } // namespace system | 225 } // namespace system |
| 221 } // namespace mojo | 226 } // namespace mojo |
| OLD | NEW |