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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 void DataSinkReceiver::ShutDown() { | 82 void DataSinkReceiver::ShutDown() { |
83 shut_down_ = true; | 83 shut_down_ = true; |
84 if (waiter_) | 84 if (waiter_) |
85 waiter_.reset(); | 85 waiter_.reset(); |
86 } | 86 } |
87 | 87 |
88 DataSinkReceiver::~DataSinkReceiver() { | 88 DataSinkReceiver::~DataSinkReceiver() { |
89 } | 89 } |
90 | 90 |
91 void DataSinkReceiver::Init(mojo::ScopedDataPipeConsumerHandle handle) { | 91 void DataSinkReceiver::Init(mojo::ScopedDataPipeConsumerHandle handle) { |
92 if (!handle.is_valid() || handle_.is_valid()) { | 92 if (handle_.is_valid()) { |
93 DispatchFatalError(); | 93 DispatchFatalError(); |
94 return; | 94 return; |
95 } | 95 } |
96 | 96 |
97 handle_ = handle.Pass(); | 97 handle_ = handle.Pass(); |
98 StartWaiting(); | 98 StartWaiting(); |
99 } | 99 } |
100 | 100 |
101 void DataSinkReceiver::Cancel(int32_t error) { | 101 void DataSinkReceiver::Cancel(int32_t error) { |
102 // If we have sent a ReportBytesSentAndError but have not received the | 102 // If we have sent a ReportBytesSentAndError but have not received the |
(...skipping 194 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 |