OLD | NEW |
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 #include "device/serial/data_sink_receiver.h" | 5 #include "device/serial/data_sink_receiver.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "device/serial/async_waiter.h" | 10 #include "device/serial/async_waiter.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 const char* buffer, | 234 const char* buffer, |
235 uint32_t buffer_size) | 235 uint32_t buffer_size) |
236 : receiver_(receiver), | 236 : receiver_(receiver), |
237 buffer_(buffer), | 237 buffer_(buffer), |
238 buffer_size_(buffer_size), | 238 buffer_size_(buffer_size), |
239 cancelled_(false), | 239 cancelled_(false), |
240 cancellation_error_(0) { | 240 cancellation_error_(0) { |
241 } | 241 } |
242 | 242 |
243 DataSinkReceiver::Buffer::~Buffer() { | 243 DataSinkReceiver::Buffer::~Buffer() { |
244 if (!receiver_) | 244 if (!receiver_.get()) |
245 return; | 245 return; |
246 if (cancelled_) | 246 if (cancelled_) |
247 receiver_->DoneWithError(0, cancellation_error_); | 247 receiver_->DoneWithError(0, cancellation_error_); |
248 else | 248 else |
249 receiver_->Done(0); | 249 receiver_->Done(0); |
250 } | 250 } |
251 | 251 |
252 void DataSinkReceiver::Buffer::Cancel(int32_t error) { | 252 void DataSinkReceiver::Buffer::Cancel(int32_t error) { |
253 cancelled_ = true; | 253 cancelled_ = true; |
254 cancellation_error_ = error; | 254 cancellation_error_ = error; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 MojoResult result = | 297 MojoResult result = |
298 mojo::ReadDataRaw(handle, NULL, &num_bytes, MOJO_READ_DATA_FLAG_DISCARD); | 298 mojo::ReadDataRaw(handle, NULL, &num_bytes, MOJO_READ_DATA_FLAG_DISCARD); |
299 if (result != MOJO_RESULT_OK) | 299 if (result != MOJO_RESULT_OK) |
300 return result; | 300 return result; |
301 DCHECK(num_bytes <= bytes_to_flush_); | 301 DCHECK(num_bytes <= bytes_to_flush_); |
302 bytes_to_flush_ -= num_bytes; | 302 bytes_to_flush_ -= num_bytes; |
303 return bytes_to_flush_ == 0 ? MOJO_RESULT_OK : MOJO_RESULT_SHOULD_WAIT; | 303 return bytes_to_flush_ == 0 ? MOJO_RESULT_OK : MOJO_RESULT_SHOULD_WAIT; |
304 } | 304 } |
305 | 305 |
306 } // namespace device | 306 } // namespace device |
OLD | NEW |