| 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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "device/serial/buffer.h" | 14 #include "device/serial/buffer.h" |
| 14 #include "extensions/browser/api/api_resource_manager.h" | 15 #include "extensions/browser/api/api_resource_manager.h" |
| 15 #include "extensions/common/api/serial.h" | 16 #include "extensions/common/api/serial.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const int kDefaultBufferSize = 4096; | 22 const int kDefaultBufferSize = 4096; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 io_handler_->Open(port_, *device::serial::ConnectionOptions::From(options), | 216 io_handler_->Open(port_, *device::serial::ConnectionOptions::From(options), |
| 216 callback); | 217 callback); |
| 217 } | 218 } |
| 218 | 219 |
| 219 bool SerialConnection::Receive(const ReceiveCompleteCallback& callback) { | 220 bool SerialConnection::Receive(const ReceiveCompleteCallback& callback) { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 221 if (!receive_complete_.is_null()) | 222 if (!receive_complete_.is_null()) |
| 222 return false; | 223 return false; |
| 223 receive_complete_ = callback; | 224 receive_complete_ = callback; |
| 224 receive_buffer_ = new net::IOBuffer(buffer_size_); | 225 receive_buffer_ = new net::IOBuffer(buffer_size_); |
| 225 io_handler_->Read(make_scoped_ptr(new device::ReceiveBuffer( | 226 io_handler_->Read(base::WrapUnique(new device::ReceiveBuffer( |
| 226 receive_buffer_, buffer_size_, | 227 receive_buffer_, buffer_size_, |
| 227 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr())))); | 228 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr())))); |
| 228 receive_timeout_task_.reset(); | 229 receive_timeout_task_.reset(); |
| 229 if (receive_timeout_ > 0) { | 230 if (receive_timeout_ > 0) { |
| 230 receive_timeout_task_.reset(new TimeoutTask( | 231 receive_timeout_task_.reset(new TimeoutTask( |
| 231 base::Bind(&SerialConnection::OnReceiveTimeout, AsWeakPtr()), | 232 base::Bind(&SerialConnection::OnReceiveTimeout, AsWeakPtr()), |
| 232 base::TimeDelta::FromMilliseconds(receive_timeout_))); | 233 base::TimeDelta::FromMilliseconds(receive_timeout_))); |
| 233 } | 234 } |
| 234 return true; | 235 return true; |
| 235 } | 236 } |
| 236 | 237 |
| 237 bool SerialConnection::Send(const std::vector<char>& data, | 238 bool SerialConnection::Send(const std::vector<char>& data, |
| 238 const SendCompleteCallback& callback) { | 239 const SendCompleteCallback& callback) { |
| 239 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 240 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 240 if (!send_complete_.is_null()) | 241 if (!send_complete_.is_null()) |
| 241 return false; | 242 return false; |
| 242 send_complete_ = callback; | 243 send_complete_ = callback; |
| 243 io_handler_->Write(make_scoped_ptr(new device::SendBuffer( | 244 io_handler_->Write(base::WrapUnique(new device::SendBuffer( |
| 244 data, base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr())))); | 245 data, base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr())))); |
| 245 send_timeout_task_.reset(); | 246 send_timeout_task_.reset(); |
| 246 if (send_timeout_ > 0) { | 247 if (send_timeout_ > 0) { |
| 247 send_timeout_task_.reset(new TimeoutTask( | 248 send_timeout_task_.reset(new TimeoutTask( |
| 248 base::Bind(&SerialConnection::OnSendTimeout, AsWeakPtr()), | 249 base::Bind(&SerialConnection::OnSendTimeout, AsWeakPtr()), |
| 249 base::TimeDelta::FromMilliseconds(send_timeout_))); | 250 base::TimeDelta::FromMilliseconds(send_timeout_))); |
| 250 } | 251 } |
| 251 return true; | 252 return true; |
| 252 } | 253 } |
| 253 | 254 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 output->parity_bit = extensions::ConvertParityBitToMojo(input.parity_bit); | 412 output->parity_bit = extensions::ConvertParityBitToMojo(input.parity_bit); |
| 412 output->stop_bits = extensions::ConvertStopBitsToMojo(input.stop_bits); | 413 output->stop_bits = extensions::ConvertStopBitsToMojo(input.stop_bits); |
| 413 if (input.cts_flow_control.get()) { | 414 if (input.cts_flow_control.get()) { |
| 414 output->has_cts_flow_control = true; | 415 output->has_cts_flow_control = true; |
| 415 output->cts_flow_control = *input.cts_flow_control; | 416 output->cts_flow_control = *input.cts_flow_control; |
| 416 } | 417 } |
| 417 return output; | 418 return output; |
| 418 } | 419 } |
| 419 | 420 |
| 420 } // namespace mojo | 421 } // namespace mojo |
| OLD | NEW |