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

Side by Side Diff: mojo/services/files/cpp/lib/input_stream_file.cc

Issue 1459033002: Replace (most) occurrences of mojo::Array<T>() with nullptr. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/services/files/cpp/input_stream_file.h" 5 #include "mojo/services/files/cpp/input_stream_file.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "mojo/public/cpp/environment/logging.h" 9 #include "mojo/public/cpp/environment/logging.h"
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 if (client_) 57 if (client_)
58 client_->OnClosed(); 58 client_->OnClosed();
59 } 59 }
60 60
61 void InputStreamFile::Read(uint32_t num_bytes_to_read, 61 void InputStreamFile::Read(uint32_t num_bytes_to_read,
62 int64_t offset, 62 int64_t offset,
63 mojo::files::Whence whence, 63 mojo::files::Whence whence,
64 const ReadCallback& callback) { 64 const ReadCallback& callback) {
65 if (is_closed_) { 65 if (is_closed_) {
66 callback.Run(mojo::files::Error::CLOSED, mojo::Array<uint8_t>()); 66 callback.Run(mojo::files::Error::CLOSED, nullptr);
67 return; 67 return;
68 } 68 }
69 69
70 if (offset != 0 || whence != mojo::files::Whence::FROM_CURRENT) { 70 if (offset != 0 || whence != mojo::files::Whence::FROM_CURRENT) {
71 // TODO(vtl): Is this the "right" behavior? 71 // TODO(vtl): Is this the "right" behavior?
72 callback.Run(mojo::files::Error::INVALID_ARGUMENT, mojo::Array<uint8_t>()); 72 callback.Run(mojo::files::Error::INVALID_ARGUMENT, nullptr);
73 return; 73 return;
74 } 74 }
75 75
76 bool should_start_read = pending_read_queue_.empty(); 76 bool should_start_read = pending_read_queue_.empty();
77 pending_read_queue_.push_back(PendingRead(num_bytes_to_read, callback)); 77 pending_read_queue_.push_back(PendingRead(num_bytes_to_read, callback));
78 if (should_start_read) 78 if (should_start_read)
79 StartRead(); 79 StartRead();
80 } 80 }
81 81
82 void InputStreamFile::Write(mojo::Array<uint8_t> bytes_to_write, 82 void InputStreamFile::Write(mojo::Array<uint8_t> bytes_to_write,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe 217 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe
218 // unsupported/EINVAL is better.) 218 // unsupported/EINVAL is better.)
219 callback.Run(mojo::files::Error::UNAVAILABLE, 219 callback.Run(mojo::files::Error::UNAVAILABLE,
220 mojo::ScopedSharedBufferHandle()); 220 mojo::ScopedSharedBufferHandle());
221 } 221 }
222 222
223 void InputStreamFile::Ioctl(uint32_t request, 223 void InputStreamFile::Ioctl(uint32_t request,
224 mojo::Array<uint32_t> in_values, 224 mojo::Array<uint32_t> in_values,
225 const IoctlCallback& callback) { 225 const IoctlCallback& callback) {
226 if (is_closed_) { 226 if (is_closed_) {
227 callback.Run(mojo::files::Error::CLOSED, mojo::Array<uint32_t>()); 227 callback.Run(mojo::files::Error::CLOSED, nullptr);
228 return; 228 return;
229 } 229 }
230 230
231 callback.Run(mojo::files::Error::UNIMPLEMENTED, mojo::Array<uint32_t>()); 231 callback.Run(mojo::files::Error::UNIMPLEMENTED, nullptr);
232 } 232 }
233 233
234 void InputStreamFile::StartRead() { 234 void InputStreamFile::StartRead() {
235 MOJO_DCHECK(!pending_read_queue_.empty()); 235 MOJO_DCHECK(!pending_read_queue_.empty());
236 236
237 // If we don't have a client, just drain all the reads. 237 // If we don't have a client, just drain all the reads.
238 if (!client_) { 238 if (!client_) {
239 while (!pending_read_queue_.empty()) { 239 while (!pending_read_queue_.empty()) {
240 // TODO(vtl): Is this what we want? 240 // TODO(vtl): Is this what we want?
241 pending_read_queue_.front().callback.Run(mojo::files::Error::UNAVAILABLE, 241 pending_read_queue_.front().callback.Run(mojo::files::Error::UNAVAILABLE,
242 mojo::Array<uint8_t>()); 242 nullptr);
243 pending_read_queue_.pop_front(); 243 pending_read_queue_.pop_front();
244 } 244 }
245 return; 245 return;
246 } 246 }
247 247
248 do { 248 do {
249 // Find a non-zero-byte read, completing any zero-byte reads at the front of 249 // Find a non-zero-byte read, completing any zero-byte reads at the front of
250 // the queue. Note that we do this in FIFO order (thus couldn't have 250 // the queue. Note that we do this in FIFO order (thus couldn't have
251 // completed them earlier). 251 // completed them earlier).
252 while (!pending_read_queue_.front().num_bytes) { 252 while (!pending_read_queue_.front().num_bytes) {
253 pending_read_queue_.front().callback.Run(mojo::files::Error::OK, 253 pending_read_queue_.front().callback.Run(mojo::files::Error::OK, nullptr);
254 mojo::Array<uint8_t>());
255 pending_read_queue_.pop_front(); 254 pending_read_queue_.pop_front();
256 255
257 if (pending_read_queue_.empty()) 256 if (pending_read_queue_.empty())
258 return; 257 return;
259 } 258 }
260 259
261 // Binding |this| is OK, since the client must not call the callback if we 260 // Binding |this| is OK, since the client must not call the callback if we
262 // are destroyed. 261 // are destroyed.
263 mojo::files::Error error = mojo::files::Error::INTERNAL; 262 mojo::files::Error error = mojo::files::Error::INTERNAL;
264 mojo::Array<uint8_t> data; 263 mojo::Array<uint8_t> data;
(...skipping 16 matching lines...) Expand all
281 else 280 else
282 return; // Asynchronous completion. 281 return; // Asynchronous completion.
283 } while (!pending_read_queue_.empty()); 282 } while (!pending_read_queue_.empty());
284 } 283 }
285 284
286 void InputStreamFile::CompleteRead(mojo::files::Error error, 285 void InputStreamFile::CompleteRead(mojo::files::Error error,
287 mojo::Array<uint8_t> data) { 286 mojo::Array<uint8_t> data) {
288 MOJO_CHECK(!pending_read_queue_.empty()); 287 MOJO_CHECK(!pending_read_queue_.empty());
289 288
290 if (error != mojo::files::Error::OK) { 289 if (error != mojo::files::Error::OK) {
291 pending_read_queue_.front().callback.Run(error, mojo::Array<uint8_t>()); 290 pending_read_queue_.front().callback.Run(error, nullptr);
292 pending_read_queue_.pop_front(); 291 pending_read_queue_.pop_front();
293 return; 292 return;
294 } 293 }
295 294
296 MOJO_CHECK(!data.is_null()); 295 MOJO_CHECK(!data.is_null());
297 MOJO_CHECK(data.size() <= pending_read_queue_.front().num_bytes); 296 MOJO_CHECK(data.size() <= pending_read_queue_.front().num_bytes);
298 pending_read_queue_.front().callback.Run(mojo::files::Error::OK, data.Pass()); 297 pending_read_queue_.front().callback.Run(mojo::files::Error::OK, data.Pass());
299 pending_read_queue_.pop_front(); 298 pending_read_queue_.pop_front();
300 } 299 }
301 300
302 } // namespace files_impl 301 } // namespace files_impl
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/versioning_test_service.cc ('k') | mojo/services/files/cpp/lib/output_stream_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698