| 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 "extensions/browser/api/serial/serial_connection.h" | 5 #include "extensions/browser/api/serial/serial_connection.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 io_handler_->Open(port_, *device::serial::ConnectionOptions::From(options), | 218 io_handler_->Open(port_, *device::serial::ConnectionOptions::From(options), |
| 219 callback); | 219 callback); |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool SerialConnection::Receive(const ReceiveCompleteCallback& callback) { | 222 bool SerialConnection::Receive(const ReceiveCompleteCallback& callback) { |
| 223 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 223 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 224 if (!receive_complete_.is_null()) | 224 if (!receive_complete_.is_null()) |
| 225 return false; | 225 return false; |
| 226 receive_complete_ = callback; | 226 receive_complete_ = callback; |
| 227 receive_buffer_ = new net::IOBuffer(buffer_size_); | 227 receive_buffer_ = new net::IOBuffer(buffer_size_); |
| 228 io_handler_->Read(base::WrapUnique(new device::ReceiveBuffer( | 228 io_handler_->Read(base::MakeUnique<device::ReceiveBuffer>( |
| 229 receive_buffer_, buffer_size_, | 229 receive_buffer_, buffer_size_, |
| 230 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr())))); | 230 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr()))); |
| 231 receive_timeout_task_.reset(); | 231 receive_timeout_task_.reset(); |
| 232 if (receive_timeout_ > 0) { | 232 if (receive_timeout_ > 0) { |
| 233 receive_timeout_task_.reset(new TimeoutTask( | 233 receive_timeout_task_.reset(new TimeoutTask( |
| 234 base::Bind(&SerialConnection::OnReceiveTimeout, AsWeakPtr()), | 234 base::Bind(&SerialConnection::OnReceiveTimeout, AsWeakPtr()), |
| 235 base::TimeDelta::FromMilliseconds(receive_timeout_))); | 235 base::TimeDelta::FromMilliseconds(receive_timeout_))); |
| 236 } | 236 } |
| 237 return true; | 237 return true; |
| 238 } | 238 } |
| 239 | 239 |
| 240 bool SerialConnection::Send(const std::vector<char>& data, | 240 bool SerialConnection::Send(const std::vector<char>& data, |
| 241 const SendCompleteCallback& callback) { | 241 const SendCompleteCallback& callback) { |
| 242 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 242 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 243 if (!send_complete_.is_null()) | 243 if (!send_complete_.is_null()) |
| 244 return false; | 244 return false; |
| 245 send_complete_ = callback; | 245 send_complete_ = callback; |
| 246 io_handler_->Write(base::WrapUnique(new device::SendBuffer( | 246 io_handler_->Write(base::MakeUnique<device::SendBuffer>( |
| 247 data, base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr())))); | 247 data, base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr()))); |
| 248 send_timeout_task_.reset(); | 248 send_timeout_task_.reset(); |
| 249 if (send_timeout_ > 0) { | 249 if (send_timeout_ > 0) { |
| 250 send_timeout_task_.reset(new TimeoutTask( | 250 send_timeout_task_.reset(new TimeoutTask( |
| 251 base::Bind(&SerialConnection::OnSendTimeout, AsWeakPtr()), | 251 base::Bind(&SerialConnection::OnSendTimeout, AsWeakPtr()), |
| 252 base::TimeDelta::FromMilliseconds(send_timeout_))); | 252 base::TimeDelta::FromMilliseconds(send_timeout_))); |
| 253 } | 253 } |
| 254 return true; | 254 return true; |
| 255 } | 255 } |
| 256 | 256 |
| 257 bool SerialConnection::Configure( | 257 bool SerialConnection::Configure( |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 output->parity_bit = extensions::ConvertParityBitToMojo(input.parity_bit); | 413 output->parity_bit = extensions::ConvertParityBitToMojo(input.parity_bit); |
| 414 output->stop_bits = extensions::ConvertStopBitsToMojo(input.stop_bits); | 414 output->stop_bits = extensions::ConvertStopBitsToMojo(input.stop_bits); |
| 415 if (input.cts_flow_control.get()) { | 415 if (input.cts_flow_control.get()) { |
| 416 output->has_cts_flow_control = true; | 416 output->has_cts_flow_control = true; |
| 417 output->cts_flow_control = *input.cts_flow_control; | 417 output->cts_flow_control = *input.cts_flow_control; |
| 418 } | 418 } |
| 419 return output; | 419 return output; |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace mojo | 422 } // namespace mojo |
| OLD | NEW |