OLD | NEW |
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 "tools/battor_agent/battor_connection_impl.h" | 5 #include "tools/battor_agent/battor_connection_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "device/serial/buffer.h" | 9 #include "device/serial/buffer.h" |
10 #include "device/serial/serial_io_handler.h" | 10 #include "device/serial/serial_io_handler.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 149 } |
150 | 150 |
151 void BattOrConnectionImpl::BeginReadBytes(size_t max_bytes_to_read) { | 151 void BattOrConnectionImpl::BeginReadBytes(size_t max_bytes_to_read) { |
152 pending_read_buffer_ = | 152 pending_read_buffer_ = |
153 make_scoped_refptr(new net::IOBuffer(max_bytes_to_read)); | 153 make_scoped_refptr(new net::IOBuffer(max_bytes_to_read)); |
154 | 154 |
155 auto on_receive_buffer_filled = | 155 auto on_receive_buffer_filled = |
156 base::Bind(&BattOrConnectionImpl::OnBytesRead, AsWeakPtr()); | 156 base::Bind(&BattOrConnectionImpl::OnBytesRead, AsWeakPtr()); |
157 | 157 |
158 io_handler_->Read(make_scoped_ptr(new device::ReceiveBuffer( | 158 io_handler_->Read(make_scoped_ptr(new device::ReceiveBuffer( |
159 pending_read_buffer_, max_bytes_to_read, on_receive_buffer_filled))); | 159 pending_read_buffer_, static_cast<uint32_t>(max_bytes_to_read), |
| 160 on_receive_buffer_filled))); |
160 } | 161 } |
161 | 162 |
162 void BattOrConnectionImpl::OnBytesRead(int bytes_read, | 163 void BattOrConnectionImpl::OnBytesRead(int bytes_read, |
163 device::serial::ReceiveError error) { | 164 device::serial::ReceiveError error) { |
164 if (bytes_read == 0 || error != device::serial::ReceiveError::NONE) { | 165 if (bytes_read == 0 || error != device::serial::ReceiveError::NONE) { |
165 // If we didn't have a message before, and we weren't able to read any | 166 // If we didn't have a message before, and we weren't able to read any |
166 // additional bytes, then there's no valid message available. | 167 // additional bytes, then there's no valid message available. |
167 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); | 168 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); |
168 return; | 169 return; |
169 } | 170 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 255 } |
255 | 256 |
256 void BattOrConnectionImpl::OnBytesSent(int bytes_sent, | 257 void BattOrConnectionImpl::OnBytesSent(int bytes_sent, |
257 device::serial::SendError error) { | 258 device::serial::SendError error) { |
258 bool success = (error == device::serial::SendError::NONE) && | 259 bool success = (error == device::serial::SendError::NONE) && |
259 (pending_write_length_ == static_cast<size_t>(bytes_sent)); | 260 (pending_write_length_ == static_cast<size_t>(bytes_sent)); |
260 listener_->OnBytesSent(success); | 261 listener_->OnBytesSent(success); |
261 } | 262 } |
262 | 263 |
263 } // namespace battor | 264 } // namespace battor |
OLD | NEW |