| 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 #include <memory> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 | 13 |
| 13 namespace device { | 14 namespace device { |
| 14 | 15 |
| 15 // A ReadOnlyBuffer implementation that provides a view of a buffer owned by a | 16 // A ReadOnlyBuffer implementation that provides a view of a buffer owned by a |
| 16 // DataSinkReceiver. | 17 // DataSinkReceiver. |
| 17 class DataSinkReceiver::Buffer : public ReadOnlyBuffer { | 18 class DataSinkReceiver::Buffer : public ReadOnlyBuffer { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void DataSinkReceiver::RunReadyCallback() { | 137 void DataSinkReceiver::RunReadyCallback() { |
| 137 DCHECK(!shut_down_ && !current_error_); | 138 DCHECK(!shut_down_ && !current_error_); |
| 138 // If data arrives while a call to RunReadyCallback() is posted, we can be | 139 // If data arrives while a call to RunReadyCallback() is posted, we can be |
| 139 // called with buffer_in_use_ already set. | 140 // called with buffer_in_use_ already set. |
| 140 if (buffer_in_use_) | 141 if (buffer_in_use_) |
| 141 return; | 142 return; |
| 142 buffer_in_use_ = | 143 buffer_in_use_ = |
| 143 new Buffer(this, | 144 new Buffer(this, |
| 144 pending_data_buffers_.front()->GetData(), | 145 pending_data_buffers_.front()->GetData(), |
| 145 pending_data_buffers_.front()->GetRemainingBytes()); | 146 pending_data_buffers_.front()->GetRemainingBytes()); |
| 146 ready_callback_.Run(scoped_ptr<ReadOnlyBuffer>(buffer_in_use_)); | 147 ready_callback_.Run(std::unique_ptr<ReadOnlyBuffer>(buffer_in_use_)); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void DataSinkReceiver::Done(uint32_t bytes_read) { | 150 void DataSinkReceiver::Done(uint32_t bytes_read) { |
| 150 if (!DoneInternal(bytes_read)) | 151 if (!DoneInternal(bytes_read)) |
| 151 return; | 152 return; |
| 152 pending_data_buffers_.front()->OnDataConsumed(bytes_read); | 153 pending_data_buffers_.front()->OnDataConsumed(bytes_read); |
| 153 if (pending_data_buffers_.front()->GetRemainingBytes() == 0) | 154 if (pending_data_buffers_.front()->GetRemainingBytes() == 0) |
| 154 pending_data_buffers_.pop(); | 155 pending_data_buffers_.pop(); |
| 155 if (!pending_data_buffers_.empty()) { | 156 if (!pending_data_buffers_.empty()) { |
| 156 base::MessageLoop::current()->PostTask( | 157 base::MessageLoop::current()->PostTask( |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 callback_.Run(offset_, 0); | 278 callback_.Run(offset_, 0); |
| 278 } | 279 } |
| 279 void DataSinkReceiver::DataFrame::ReportError(uint32_t bytes_read, | 280 void DataSinkReceiver::DataFrame::ReportError(uint32_t bytes_read, |
| 280 int32_t error) { | 281 int32_t error) { |
| 281 offset_ += bytes_read; | 282 offset_ += bytes_read; |
| 282 DCHECK_LE(offset_, data_.size()); | 283 DCHECK_LE(offset_, data_.size()); |
| 283 callback_.Run(offset_, error); | 284 callback_.Run(offset_, error); |
| 284 } | 285 } |
| 285 | 286 |
| 286 } // namespace device | 287 } // namespace device |
| OLD | NEW |