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

Side by Side Diff: mojo/public/cpp/system/data_pipe.h

Issue 2875143002: Reduce boilerplate when creating simple mojom::URLLoaders. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « media/remoting/demuxer_stream_adapter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file provides a C++ wrapping around the Mojo C API for data pipes, 5 // This file provides a C++ wrapping around the Mojo C API for data pipes,
6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more 6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more
7 // strongly-typed representations of |MojoHandle|s. 7 // strongly-typed representations of |MojoHandle|s.
8 // 8 //
9 // Please see "mojo/public/c/system/data_pipe.h" for complete documentation of 9 // Please see "mojo/public/c/system/data_pipe.h" for complete documentation of
10 // the API. 10 // the API.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return MojoEndReadData(data_pipe_consumer.value(), num_bytes_read); 127 return MojoEndReadData(data_pipe_consumer.value(), num_bytes_read);
128 } 128 }
129 129
130 // A wrapper class that automatically creates a data pipe and owns both handles. 130 // A wrapper class that automatically creates a data pipe and owns both handles.
131 // TODO(vtl): Make an even more friendly version? (Maybe templatized for a 131 // TODO(vtl): Make an even more friendly version? (Maybe templatized for a
132 // particular type instead of some "element"? Maybe functions that take 132 // particular type instead of some "element"? Maybe functions that take
133 // vectors?) 133 // vectors?)
134 class DataPipe { 134 class DataPipe {
135 public: 135 public:
136 DataPipe(); 136 DataPipe();
137 explicit DataPipe(uint32_t capacity_num_bytes);
137 explicit DataPipe(const MojoCreateDataPipeOptions& options); 138 explicit DataPipe(const MojoCreateDataPipeOptions& options);
138 ~DataPipe(); 139 ~DataPipe();
139 140
140 ScopedDataPipeProducerHandle producer_handle; 141 ScopedDataPipeProducerHandle producer_handle;
141 ScopedDataPipeConsumerHandle consumer_handle; 142 ScopedDataPipeConsumerHandle consumer_handle;
142 }; 143 };
143 144
144 inline DataPipe::DataPipe() { 145 inline DataPipe::DataPipe() {
145 MojoResult result = 146 MojoResult result =
146 CreateDataPipe(nullptr, &producer_handle, &consumer_handle); 147 CreateDataPipe(nullptr, &producer_handle, &consumer_handle);
147 ALLOW_UNUSED_LOCAL(result); 148 ALLOW_UNUSED_LOCAL(result);
148 DCHECK_EQ(MOJO_RESULT_OK, result); 149 DCHECK_EQ(MOJO_RESULT_OK, result);
149 } 150 }
150 151
152 inline DataPipe::DataPipe(uint32_t capacity_num_bytes) {
153 MojoCreateDataPipeOptions options;
154 options.struct_size = sizeof(MojoCreateDataPipeOptions);
155 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
156 options.element_num_bytes = 1;
157 options.capacity_num_bytes = capacity_num_bytes;
158 mojo::DataPipe data_pipe(options);
159 MojoResult result =
160 CreateDataPipe(&options, &producer_handle, &consumer_handle);
161 ALLOW_UNUSED_LOCAL(result);
162 DCHECK_EQ(MOJO_RESULT_OK, result);
163 }
164
151 inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) { 165 inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) {
152 MojoResult result = 166 MojoResult result =
153 CreateDataPipe(&options, &producer_handle, &consumer_handle); 167 CreateDataPipe(&options, &producer_handle, &consumer_handle);
154 ALLOW_UNUSED_LOCAL(result); 168 ALLOW_UNUSED_LOCAL(result);
155 DCHECK_EQ(MOJO_RESULT_OK, result); 169 DCHECK_EQ(MOJO_RESULT_OK, result);
156 } 170 }
157 171
158 inline DataPipe::~DataPipe() { 172 inline DataPipe::~DataPipe() {
159 } 173 }
160 174
161 } // namespace mojo 175 } // namespace mojo
162 176
163 #endif // MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ 177 #endif // MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_
OLDNEW
« no previous file with comments | « media/remoting/demuxer_stream_adapter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698