| 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 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 SerialConnection::SerialConnection(const std::string& port, | 149 SerialConnection::SerialConnection(const std::string& port, |
| 150 const std::string& owner_extension_id) | 150 const std::string& owner_extension_id) |
| 151 : ApiResource(owner_extension_id), | 151 : ApiResource(owner_extension_id), |
| 152 port_(port), | 152 port_(port), |
| 153 persistent_(false), | 153 persistent_(false), |
| 154 buffer_size_(kDefaultBufferSize), | 154 buffer_size_(kDefaultBufferSize), |
| 155 receive_timeout_(0), | 155 receive_timeout_(0), |
| 156 send_timeout_(0), | 156 send_timeout_(0), |
| 157 paused_(false), | 157 paused_(false), |
| 158 io_handler_(device::SerialIoHandler::Create()) { | 158 io_handler_(device::SerialIoHandler::Create( |
| 159 content::BrowserThread::GetMessageLoopProxyForThread( |
| 160 content::BrowserThread::FILE))) { |
| 159 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 160 io_handler_->Initialize( | 162 io_handler_->Initialize( |
| 161 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr()), | 163 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr()), |
| 162 base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr()), | 164 base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr())); |
| 163 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 164 content::BrowserThread::FILE)); | |
| 165 } | 165 } |
| 166 | 166 |
| 167 SerialConnection::~SerialConnection() { | 167 SerialConnection::~SerialConnection() { |
| 168 io_handler_->CancelRead(device::serial::RECEIVE_ERROR_DISCONNECTED); | 168 io_handler_->CancelRead(device::serial::RECEIVE_ERROR_DISCONNECTED); |
| 169 io_handler_->CancelWrite(device::serial::SEND_ERROR_DISCONNECTED); | 169 io_handler_->CancelWrite(device::serial::SEND_ERROR_DISCONNECTED); |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool SerialConnection::IsPersistent() const { | 172 bool SerialConnection::IsPersistent() const { |
| 173 return persistent(); | 173 return persistent(); |
| 174 } | 174 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 *device::serial::ConnectionOptions::From(options)); | 245 *device::serial::ConnectionOptions::From(options)); |
| 246 io_handler_->CancelRead(device::serial::RECEIVE_ERROR_NONE); | 246 io_handler_->CancelRead(device::serial::RECEIVE_ERROR_NONE); |
| 247 return success; | 247 return success; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void SerialConnection::SetIoHandlerForTest( | 250 void SerialConnection::SetIoHandlerForTest( |
| 251 scoped_refptr<device::SerialIoHandler> handler) { | 251 scoped_refptr<device::SerialIoHandler> handler) { |
| 252 io_handler_ = handler; | 252 io_handler_ = handler; |
| 253 io_handler_->Initialize( | 253 io_handler_->Initialize( |
| 254 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr()), | 254 base::Bind(&SerialConnection::OnAsyncReadComplete, AsWeakPtr()), |
| 255 base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr()), | 255 base::Bind(&SerialConnection::OnAsyncWriteComplete, AsWeakPtr())); |
| 256 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 257 content::BrowserThread::FILE)); | |
| 258 } | 256 } |
| 259 | 257 |
| 260 bool SerialConnection::GetInfo(core_api::serial::ConnectionInfo* info) const { | 258 bool SerialConnection::GetInfo(core_api::serial::ConnectionInfo* info) const { |
| 261 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 259 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 262 info->paused = paused_; | 260 info->paused = paused_; |
| 263 info->persistent = persistent_; | 261 info->persistent = persistent_; |
| 264 info->name = name_; | 262 info->name = name_; |
| 265 info->buffer_size = buffer_size_; | 263 info->buffer_size = buffer_size_; |
| 266 info->receive_timeout = receive_timeout_; | 264 info->receive_timeout = receive_timeout_; |
| 267 info->send_timeout = send_timeout_; | 265 info->send_timeout = send_timeout_; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 output->parity_bit = extensions::ConvertParityBitToMojo(input.parity_bit); | 380 output->parity_bit = extensions::ConvertParityBitToMojo(input.parity_bit); |
| 383 output->stop_bits = extensions::ConvertStopBitsToMojo(input.stop_bits); | 381 output->stop_bits = extensions::ConvertStopBitsToMojo(input.stop_bits); |
| 384 if (input.cts_flow_control.get()) { | 382 if (input.cts_flow_control.get()) { |
| 385 output->has_cts_flow_control = true; | 383 output->has_cts_flow_control = true; |
| 386 output->cts_flow_control = *input.cts_flow_control; | 384 output->cts_flow_control = *input.cts_flow_control; |
| 387 } | 385 } |
| 388 return output.Pass(); | 386 return output.Pass(); |
| 389 } | 387 } |
| 390 | 388 |
| 391 } // namespace mojo | 389 } // namespace mojo |
| OLD | NEW |