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

Side by Side Diff: apps/moterm/moterm_driver.cc

Issue 1363183004: Files services library: Add an "output stream" file impl helper class. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: files_impl 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
« no previous file with comments | « apps/moterm/moterm_driver.h ('k') | mojo/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "apps/moterm/moterm_driver.h" 5 #include "apps/moterm/moterm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 client_->OnDataReceived(translated_bytes.data(), 180 client_->OnDataReceived(translated_bytes.data(),
181 static_cast<uint32_t>(translated_bytes.size())); 181 static_cast<uint32_t>(translated_bytes.size()));
182 } 182 }
183 183
184 void MotermDriver::Close(const CloseCallback& callback) { 184 void MotermDriver::Close(const CloseCallback& callback) {
185 if (is_closed_) { 185 if (is_closed_) {
186 callback.Run(mojo::files::ERROR_CLOSED); 186 callback.Run(mojo::files::ERROR_CLOSED);
187 return; 187 return;
188 } 188 }
189 189
190 is_closed_ = true;
190 callback.Run(mojo::files::ERROR_OK); 191 callback.Run(mojo::files::ERROR_OK);
191 192
192 // TODO(vtl): Call pending read callbacks? 193 // TODO(vtl): Call pending read callbacks?
193 194
194 client_->OnClosed(); 195 client_->OnClosed();
195 } 196 }
196 197
197 void MotermDriver::Read(uint32_t num_bytes_to_read, 198 void MotermDriver::Read(uint32_t num_bytes_to_read,
198 int64_t offset, 199 int64_t offset,
199 mojo::files::Whence whence, 200 mojo::files::Whence whence,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // TODO(vtl): Is this the "right" behavior? 234 // TODO(vtl): Is this the "right" behavior?
234 callback.Run(mojo::files::ERROR_INVALID_ARGUMENT, 0); 235 callback.Run(mojo::files::ERROR_INVALID_ARGUMENT, 0);
235 return; 236 return;
236 } 237 }
237 238
238 if (!bytes_to_write.size()) { 239 if (!bytes_to_write.size()) {
239 callback.Run(mojo::files::ERROR_OK, 0); 240 callback.Run(mojo::files::ERROR_OK, 0);
240 return; 241 return;
241 } 242 }
242 243
243 HandleOutput(static_cast<const uint8_t*>(&bytes_to_write.front()), 244 HandleOutput(&bytes_to_write.front(), bytes_to_write.size());
244 bytes_to_write.size());
245 245
246 // TODO(vtl): Is this OK if the client detached (and we're destroyed?). 246 // TODO(vtl): Is this OK if the client detached (and we're destroyed?).
247 callback.Run(mojo::files::ERROR_OK, 247 callback.Run(mojo::files::ERROR_OK,
248 static_cast<uint32_t>(bytes_to_write.size())); 248 static_cast<uint32_t>(bytes_to_write.size()));
249 } 249 }
250 250
251 void MotermDriver::ReadToStream(mojo::ScopedDataPipeProducerHandle source, 251 void MotermDriver::ReadToStream(mojo::ScopedDataPipeProducerHandle source,
252 int64_t offset, 252 int64_t offset,
253 mojo::files::Whence whence, 253 mojo::files::Whence whence,
254 int64_t num_bytes_to_read, 254 int64_t num_bytes_to_read,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 482 }
483 if (1 + kVEOFIdx < in_values.size()) { 483 if (1 + kVEOFIdx < in_values.size()) {
484 uint32_t value = in_values[1 + kVEOFIdx]; 484 uint32_t value = in_values[1 + kVEOFIdx];
485 if (value > std::numeric_limits<uint8_t>::max()) 485 if (value > std::numeric_limits<uint8_t>::max())
486 return mojo::files::ERROR_INVALID_ARGUMENT; 486 return mojo::files::ERROR_INVALID_ARGUMENT;
487 veof_ = static_cast<uint8_t>(value); 487 veof_ = static_cast<uint8_t>(value);
488 } 488 }
489 489
490 return mojo::files::ERROR_OK; 490 return mojo::files::ERROR_OK;
491 } 491 }
OLDNEW
« no previous file with comments | « apps/moterm/moterm_driver.h ('k') | mojo/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698