| 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 "device/serial/serial_io_handler_win.h" | 5 #include "device/serial/serial_io_handler_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <setupapi.h> | 8 #include <setupapi.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 bool SerialIoHandlerWin::PostOpen() { | 233 bool SerialIoHandlerWin::PostOpen() { |
| 234 DCHECK(!comm_context_); | 234 DCHECK(!comm_context_); |
| 235 DCHECK(!read_context_); | 235 DCHECK(!read_context_); |
| 236 DCHECK(!write_context_); | 236 DCHECK(!write_context_); |
| 237 | 237 |
| 238 base::MessageLoopForIO::current()->RegisterIOHandler(file().GetPlatformFile(), | 238 base::MessageLoopForIO::current()->RegisterIOHandler(file().GetPlatformFile(), |
| 239 this); | 239 this); |
| 240 | 240 |
| 241 comm_context_.reset(new base::MessageLoopForIO::IOContext()); | 241 comm_context_.reset(new base::MessageLoopForIO::IOContext()); |
| 242 comm_context_->handler = this; | |
| 243 memset(&comm_context_->overlapped, 0, sizeof(comm_context_->overlapped)); | |
| 244 | |
| 245 read_context_.reset(new base::MessageLoopForIO::IOContext()); | 242 read_context_.reset(new base::MessageLoopForIO::IOContext()); |
| 246 read_context_->handler = this; | |
| 247 memset(&read_context_->overlapped, 0, sizeof(read_context_->overlapped)); | |
| 248 | |
| 249 write_context_.reset(new base::MessageLoopForIO::IOContext()); | 243 write_context_.reset(new base::MessageLoopForIO::IOContext()); |
| 250 write_context_->handler = this; | |
| 251 memset(&write_context_->overlapped, 0, sizeof(write_context_->overlapped)); | |
| 252 | 244 |
| 253 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner = | 245 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner = |
| 254 base::ThreadTaskRunnerHandle::Get(); | 246 base::ThreadTaskRunnerHandle::Get(); |
| 255 helper_ = | 247 helper_ = |
| 256 new UiThreadHelper(weak_factory_.GetWeakPtr(), io_thread_task_runner); | 248 new UiThreadHelper(weak_factory_.GetWeakPtr(), io_thread_task_runner); |
| 257 ui_thread_task_runner()->PostTask( | 249 ui_thread_task_runner()->PostTask( |
| 258 FROM_HERE, base::Bind(&UiThreadHelper::Start, helper_)); | 250 FROM_HERE, base::Bind(&UiThreadHelper::Start, helper_)); |
| 259 | 251 |
| 260 // A ReadIntervalTimeout of MAXDWORD will cause async reads to complete | 252 // A ReadIntervalTimeout of MAXDWORD will cause async reads to complete |
| 261 // immediately with any data that's available, even if there is none. | 253 // immediately with any data that's available, even if there is none. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 526 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
| 535 // For COM numbers less than 9, CreateFile is called with a string such as | 527 // For COM numbers less than 9, CreateFile is called with a string such as |
| 536 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. | 528 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. |
| 537 if (port_name.length() > std::string("COM9").length()) | 529 if (port_name.length() > std::string("COM9").length()) |
| 538 return std::string("\\\\.\\").append(port_name); | 530 return std::string("\\\\.\\").append(port_name); |
| 539 | 531 |
| 540 return port_name; | 532 return port_name; |
| 541 } | 533 } |
| 542 | 534 |
| 543 } // namespace device | 535 } // namespace device |
| OLD | NEW |