| Index: device/serial/serial_io_handler_win.cc
|
| diff --git a/device/serial/serial_io_handler_win.cc b/device/serial/serial_io_handler_win.cc
|
| index c814755d158fc11464a0f19e2114ecd5030dbefb..cd1045107fe746e285d1bf422297236228339638 100644
|
| --- a/device/serial/serial_io_handler_win.cc
|
| +++ b/device/serial/serial_io_handler_win.cc
|
| @@ -2,17 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <windows.h>
|
| +
|
| #include "device/serial/serial_io_handler_win.h"
|
| -
|
| -#include <windows.h>
|
| -#include <setupapi.h>
|
| -
|
| -#include "base/bind.h"
|
| -#include "base/scoped_observer.h"
|
| -#include "base/threading/thread_checker.h"
|
| -#include "device/core/device_info_query_win.h"
|
| -#include "device/core/device_monitor_win.h"
|
| -#include "third_party/re2/re2/re2.h"
|
|
|
| namespace device {
|
|
|
| @@ -138,12 +130,6 @@
|
| }
|
| }
|
|
|
| -// Searches for the COM port in the device's friendly name, assigns its value to
|
| -// com_port, and returns whether the operation was successful.
|
| -bool GetCOMPort(const std::string friendly_name, std::string* com_port) {
|
| - return RE2::PartialMatch(friendly_name, ".* \\((COM[0-9]+)\\)", com_port);
|
| -}
|
| -
|
| } // namespace
|
|
|
| // static
|
| @@ -153,81 +139,6 @@
|
| return new SerialIoHandlerWin(file_thread_task_runner, ui_thread_task_runner);
|
| }
|
|
|
| -class SerialIoHandlerWin::UiThreadHelper : public DeviceMonitorWin::Observer {
|
| - public:
|
| - UiThreadHelper(
|
| - base::WeakPtr<SerialIoHandlerWin> io_handler,
|
| - scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner)
|
| - : device_observer_(this),
|
| - io_handler_(io_handler),
|
| - io_thread_task_runner_(io_thread_task_runner) {}
|
| -
|
| - ~UiThreadHelper() { DCHECK(thread_checker_.CalledOnValidThread()); }
|
| -
|
| - static void Start(UiThreadHelper* self) {
|
| - self->thread_checker_.DetachFromThread();
|
| - DeviceMonitorWin* device_monitor = DeviceMonitorWin::GetForAllInterfaces();
|
| - if (device_monitor)
|
| - self->device_observer_.Add(device_monitor);
|
| - }
|
| -
|
| - private:
|
| - // DeviceMonitorWin::Observer
|
| - void OnDeviceRemoved(const GUID& class_guid,
|
| - const std::string& device_path) override {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| - io_thread_task_runner_->PostTask(
|
| - FROM_HERE, base::Bind(&SerialIoHandlerWin::OnDeviceRemoved, io_handler_,
|
| - device_path));
|
| - }
|
| -
|
| - base::ThreadChecker thread_checker_;
|
| - ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_;
|
| -
|
| - // This weak pointer is only valid when checked on this task runner.
|
| - base::WeakPtr<SerialIoHandlerWin> io_handler_;
|
| - scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(UiThreadHelper);
|
| -};
|
| -
|
| -void SerialIoHandlerWin::OnDeviceRemoved(const std::string& device_path) {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - DeviceInfoQueryWin device_info_query;
|
| - if (!device_info_query.device_info_list_valid()) {
|
| - DVPLOG(1) << "Failed to create a device information set";
|
| - return;
|
| - }
|
| -
|
| - // This will add the device so we can query driver info.
|
| - if (!device_info_query.AddDevice(device_path.c_str())) {
|
| - DVPLOG(1) << "Failed to get device interface data for " << device_path;
|
| - return;
|
| - }
|
| -
|
| - if (!device_info_query.GetDeviceInfo()) {
|
| - DVPLOG(1) << "Failed to get device info for " << device_path;
|
| - return;
|
| - }
|
| -
|
| - std::string friendly_name;
|
| - if (!device_info_query.GetDeviceStringProperty(SPDRP_FRIENDLYNAME,
|
| - &friendly_name)) {
|
| - DVPLOG(1) << "Failed to get device service property";
|
| - return;
|
| - }
|
| -
|
| - std::string com_port;
|
| - if (!GetCOMPort(friendly_name, &com_port)) {
|
| - DVPLOG(1) << "Failed to get port name from \"" << friendly_name << "\".";
|
| - return;
|
| - }
|
| -
|
| - if (port() == com_port)
|
| - CancelRead(serial::RECEIVE_ERROR_DISCONNECTED);
|
| -}
|
| -
|
| bool SerialIoHandlerWin::PostOpen() {
|
| DCHECK(!comm_context_);
|
| DCHECK(!read_context_);
|
| @@ -247,13 +158,6 @@
|
| write_context_.reset(new base::MessageLoopForIO::IOContext());
|
| write_context_->handler = this;
|
| memset(&write_context_->overlapped, 0, sizeof(write_context_->overlapped));
|
| -
|
| - scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner =
|
| - base::ThreadTaskRunnerHandle::Get();
|
| - helper_ =
|
| - new UiThreadHelper(weak_factory_.GetWeakPtr(), io_thread_task_runner);
|
| - ui_thread_task_runner()->PostTask(
|
| - FROM_HERE, base::Bind(&UiThreadHelper::Start, helper_));
|
|
|
| // A ReadIntervalTimeout of MAXDWORD will cause async reads to complete
|
| // immediately with any data that's available, even if there is none.
|
| @@ -367,11 +271,10 @@
|
| scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
|
| : SerialIoHandler(file_thread_task_runner, ui_thread_task_runner),
|
| event_mask_(0),
|
| - is_comm_pending_(false),
|
| - weak_factory_(this) {}
|
| + is_comm_pending_(false) {
|
| +}
|
|
|
| SerialIoHandlerWin::~SerialIoHandlerWin() {
|
| - ui_thread_task_runner()->DeleteSoon(FROM_HERE, helper_);
|
| }
|
|
|
| void SerialIoHandlerWin::OnIOCompleted(
|
|
|