| Index: device/hid/hid_service_linux.cc
|
| diff --git a/device/hid/hid_service_linux.cc b/device/hid/hid_service_linux.cc
|
| index f02a550e5a9d3822f9c7e8035fcd379499d3807e..34d73a95b5ea7e90c3d2ac7d398e31800d807ca3 100644
|
| --- a/device/hid/hid_service_linux.cc
|
| +++ b/device/hid/hid_service_linux.cc
|
| @@ -1,22 +1,19 @@
|
| -// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| #include <libudev.h>
|
| +#include <stdint.h>
|
| +
|
| #include <string>
|
| #include <vector>
|
|
|
| -#include "base/basictypes.h"
|
| -#include "base/bind.h"
|
| -#include "base/callback.h"
|
| #include "base/logging.h"
|
| -#include "base/memory/scoped_vector.h"
|
| #include "base/platform_file.h"
|
| +#include "base/stl_util.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_piece.h"
|
| #include "base/strings/string_split.h"
|
| -#include "base/threading/thread_restrictions.h"
|
| -#include "device/hid/hid_connection.h"
|
| #include "device/hid/hid_connection_linux.h"
|
| #include "device/hid/hid_device_info.h"
|
| #include "device/hid/hid_service_linux.h"
|
| @@ -110,26 +107,23 @@ void HidServiceLinux::Enumerate() {
|
| ScopedUdevDevicePtr hid_dev(
|
| udev_device_new_from_syspath(udev_.get(), udev_list_entry_get_name(i)));
|
| if (hid_dev) {
|
| - PlatformDeviceAdd(hid_dev.get());
|
| + PlatformAddDevice(hid_dev.get());
|
| }
|
| }
|
| -
|
| - initialized_ = true;
|
| }
|
|
|
| -void HidServiceLinux::PlatformDeviceAdd(udev_device* device) {
|
| +void HidServiceLinux::PlatformAddDevice(udev_device* device) {
|
| if (!device)
|
| return;
|
|
|
| - const char* device_id = udev_device_get_syspath(device);
|
| - if (!device_id)
|
| + const char* device_path = udev_device_get_syspath(device);
|
| + if (!device_path)
|
| return;
|
|
|
| -
|
| HidDeviceInfo device_info;
|
| - device_info.device_id = device_id;
|
| + device_info.device_id = GenerateDeviceId();
|
|
|
| - uint32 int_property = 0;
|
| + uint32_t int_property = 0;
|
| const char* str_property = NULL;
|
|
|
| const char* hid_id = udev_device_get_property_value(device, kHIDID);
|
| @@ -158,10 +152,13 @@ void HidServiceLinux::PlatformDeviceAdd(udev_device* device) {
|
| if (str_property != NULL)
|
| device_info.product_name = str_property;
|
|
|
| + if (!platform_resource_map_.Add(device_info.device_id, device_path))
|
| + return;
|
| +
|
| AddDevice(device_info);
|
| }
|
|
|
| -void HidServiceLinux::PlatformDeviceRemove(udev_device* raw_dev) {
|
| +void HidServiceLinux::PlatformRemoveDevice(udev_device* raw_dev) {
|
| // The returned the device is not referenced.
|
| udev_device* hid_dev =
|
| udev_device_get_parent_with_subsystem_devtype(raw_dev, "hid", NULL);
|
| @@ -169,22 +166,33 @@ void HidServiceLinux::PlatformDeviceRemove(udev_device* raw_dev) {
|
| if (!hid_dev)
|
| return;
|
|
|
| - const char* device_id = NULL;
|
| - device_id = udev_device_get_syspath(hid_dev);
|
| - if (device_id == NULL)
|
| + const char* device_path = NULL;
|
| + device_path = udev_device_get_syspath(hid_dev);
|
| + if (device_path == NULL)
|
| return;
|
|
|
| + HidDeviceId device_id;
|
| + if (!platform_resource_map_.GetIdByResource(device_path, &device_id))
|
| + return;
|
| + platform_resource_map_.RemoveById(device_id);
|
| +
|
| RemoveDevice(device_id);
|
| }
|
|
|
| -scoped_refptr<HidConnection> HidServiceLinux::Connect(std::string device_id) {
|
| - if (!ContainsKey(devices_, device_id))
|
| +scoped_refptr<HidConnection> HidServiceLinux::Connect(HidDeviceId device_id) {
|
| + HidDeviceInfo device_info;
|
| + if (!GetInfo(device_id, &device_info))
|
| return NULL;
|
| +
|
| + std::string device_path;
|
| + if (!platform_resource_map_.GetResourceById(device_id, &device_path))
|
| + return NULL;
|
| +
|
| ScopedUdevDevicePtr hid_device(
|
| - udev_device_new_from_syspath(udev_.get(), device_id.c_str()));
|
| + udev_device_new_from_syspath(udev_.get(), device_path.c_str()));
|
| if (hid_device) {
|
| scoped_refptr<HidConnectionLinux> connection =
|
| - new HidConnectionLinux(devices_[device_id], hid_device.Pass());
|
| + new HidConnectionLinux(device_info, hid_device.Pass());
|
| if (connection->initialized())
|
| return connection;
|
| }
|
| @@ -200,9 +208,9 @@ void HidServiceLinux::OnFileCanReadWithoutBlocking(int fd) {
|
|
|
| std::string action(udev_device_get_action(dev.get()));
|
| if (action == kUdevActionAdd) {
|
| - PlatformDeviceAdd(dev.get());
|
| + PlatformAddDevice(dev.get());
|
| } else if (action == kUdevActionRemove) {
|
| - PlatformDeviceRemove(dev.get());
|
| + PlatformRemoveDevice(dev.get());
|
| }
|
| }
|
|
|
|
|