Chromium Code Reviews| 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_sender.h" | 5 #include "device/serial/data_sender.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 void DataSender::OnConnectionError() { | 116 void DataSender::OnConnectionError() { |
| 117 ShutDown(); | 117 ShutDown(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void DataSender::RunCancelCallback() { | 120 void DataSender::RunCancelCallback() { |
| 121 DCHECK(sends_awaiting_ack_.empty()); | 121 DCHECK(sends_awaiting_ack_.empty()); |
| 122 if (pending_cancel_.is_null()) | 122 if (pending_cancel_.is_null()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 125 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 126 base::Bind(pending_cancel_)); | 126 std::move(pending_cancel_)); |
| 127 pending_cancel_.Reset(); | |
|
danakj
2016/09/24 01:20:01
can you still reset after in case code checks if i
dcheng
2016/09/24 01:29:56
I'm going to add a unit test for this... but this
| |
| 128 } | 127 } |
| 129 | 128 |
| 130 void DataSender::ShutDown() { | 129 void DataSender::ShutDown() { |
| 131 shut_down_ = true; | 130 shut_down_ = true; |
| 132 while (!sends_awaiting_ack_.empty()) { | 131 while (!sends_awaiting_ack_.empty()) { |
| 133 sends_awaiting_ack_.front()->DispatchFatalError(); | 132 sends_awaiting_ack_.front()->DispatchFatalError(); |
| 134 sends_awaiting_ack_.pop(); | 133 sends_awaiting_ack_.pop(); |
| 135 } | 134 } |
| 136 RunCancelCallback(); | 135 RunCancelCallback(); |
| 137 } | 136 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 167 void DataSender::PendingSend::SendData() { | 166 void DataSender::PendingSend::SendData() { |
| 168 uint32_t num_bytes_to_send = static_cast<uint32_t>(data_.size()); | 167 uint32_t num_bytes_to_send = static_cast<uint32_t>(data_.size()); |
| 169 mojo::Array<uint8_t> bytes(num_bytes_to_send); | 168 mojo::Array<uint8_t> bytes(num_bytes_to_send); |
| 170 memcpy(&bytes[0], data_.data(), num_bytes_to_send); | 169 memcpy(&bytes[0], data_.data(), num_bytes_to_send); |
| 171 sender_->sink_->OnData( | 170 sender_->sink_->OnData( |
| 172 std::move(bytes), | 171 std::move(bytes), |
| 173 base::Bind(&DataSender::PendingSend::OnDataSent, base::Unretained(this))); | 172 base::Bind(&DataSender::PendingSend::OnDataSent, base::Unretained(this))); |
| 174 } | 173 } |
| 175 | 174 |
| 176 } // namespace device | 175 } // namespace device |
| OLD | NEW |