Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: extensions/browser/api/serial/serial_connection.cc

Issue 401563002: Add a partial Mojo serial connection interface and implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/api/serial/serial_apitest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « extensions/browser/api/serial/serial_apitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698