| 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 "ui/events/devices/device_util_linux.h" | 5 #include "ui/events/devices/device_util_linux.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_restrictions.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 | 17 |
| 17 base::FilePath GetInputPathInSys(const base::FilePath& path) { | 18 base::FilePath GetInputPathInSys(const base::FilePath& path) { |
| 18 return base::MakeAbsoluteFilePath( | 19 return base::MakeAbsoluteFilePath( |
| 19 base::FilePath("/sys/class/input").Append(path.BaseName())); | 20 base::FilePath("/sys/class/input").Append(path.BaseName())); |
| 20 } | 21 } |
| 21 | 22 |
| 22 InputDeviceType GetInputDeviceTypeFromPath(const base::FilePath& path) { | 23 InputDeviceType GetInputDeviceTypeFromPath(const base::FilePath& path) { |
| 23 DCHECK(!base::MessageLoopForUI::IsCurrent()); | 24 base::ThreadRestrictions::AssertIOAllowed(); |
| 24 std::string event_node = path.BaseName().value(); | 25 std::string event_node = path.BaseName().value(); |
| 25 if (event_node.empty() || | 26 if (event_node.empty() || |
| 26 !base::StartsWith(event_node, "event", | 27 !base::StartsWith(event_node, "event", |
| 27 base::CompareCase::INSENSITIVE_ASCII)) | 28 base::CompareCase::INSENSITIVE_ASCII)) |
| 28 return InputDeviceType::INPUT_DEVICE_UNKNOWN; | 29 return InputDeviceType::INPUT_DEVICE_UNKNOWN; |
| 29 | 30 |
| 30 base::FilePath sysfs_path = GetInputPathInSys(path); | 31 base::FilePath sysfs_path = GetInputPathInSys(path); |
| 31 | 32 |
| 32 // Device does not exist. | 33 // Device does not exist. |
| 33 if (sysfs_path.empty()) | 34 if (sysfs_path.empty()) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 if (subsystem_path == "/sys/bus/usb") | 64 if (subsystem_path == "/sys/bus/usb") |
| 64 return InputDeviceType::INPUT_DEVICE_EXTERNAL; | 65 return InputDeviceType::INPUT_DEVICE_EXTERNAL; |
| 65 if (subsystem_path == "/sys/class/bluetooth") | 66 if (subsystem_path == "/sys/class/bluetooth") |
| 66 return InputDeviceType::INPUT_DEVICE_EXTERNAL; | 67 return InputDeviceType::INPUT_DEVICE_EXTERNAL; |
| 67 } | 68 } |
| 68 | 69 |
| 69 return InputDeviceType::INPUT_DEVICE_UNKNOWN; | 70 return InputDeviceType::INPUT_DEVICE_UNKNOWN; |
| 70 } | 71 } |
| 71 | 72 |
| 72 } // namespace | 73 } // namespace |
| OLD | NEW |