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

Side by Side Diff: ui/events/devices/device_util_linux.cc

Issue 1287103004: Sync ui/events to chromium @ https://codereview.chromium.org/1210203002 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 4 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 | « ui/events/devices/device_util_linux.h ('k') | ui/events/devices/events_devices_export.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/events/devices/device_util_linux.h"
6
7 #include <string>
8
9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h"
14
15 namespace ui {
16
17 InputDeviceType GetInputDeviceTypeFromPath(const base::FilePath& path) {
18 DCHECK(!base::MessageLoopForUI::IsCurrent());
19 std::string event_node = path.BaseName().value();
20 if (event_node.empty() || !StartsWithASCII(event_node, "event", false))
21 return InputDeviceType::INPUT_DEVICE_UNKNOWN;
22
23 // Find sysfs device path for this device.
24 base::FilePath sysfs_path =
25 base::FilePath(FILE_PATH_LITERAL("/sys/class/input"));
26 sysfs_path = sysfs_path.Append(path.BaseName());
27 sysfs_path = base::MakeAbsoluteFilePath(sysfs_path);
28
29 // Device does not exist.
30 if (sysfs_path.empty())
31 return InputDeviceType::INPUT_DEVICE_UNKNOWN;
32
33 // Check ancestor devices for a known bus attachment.
34 for (base::FilePath path = sysfs_path; path != base::FilePath("/");
35 path = path.DirName()) {
36 // Bluetooth LE devices are virtual "uhid" devices.
37 if (path ==
38 base::FilePath(FILE_PATH_LITERAL("/sys/devices/virtual/misc/uhid")))
39 return InputDeviceType::INPUT_DEVICE_EXTERNAL;
40
41 std::string subsystem_path =
42 base::MakeAbsoluteFilePath(path.Append(FILE_PATH_LITERAL("subsystem")))
43 .value();
44 if (subsystem_path.empty())
45 continue;
46
47 // Internal bus attachments.
48 if (subsystem_path == "/sys/bus/pci")
49 return InputDeviceType::INPUT_DEVICE_INTERNAL;
50 if (subsystem_path == "/sys/bus/i2c")
51 return InputDeviceType::INPUT_DEVICE_INTERNAL;
52 if (subsystem_path == "/sys/bus/acpi")
53 return InputDeviceType::INPUT_DEVICE_INTERNAL;
54 if (subsystem_path == "/sys/bus/serio")
55 return InputDeviceType::INPUT_DEVICE_INTERNAL;
56 if (subsystem_path == "/sys/bus/platform")
57 return InputDeviceType::INPUT_DEVICE_INTERNAL;
58
59 // External bus attachments.
60 if (subsystem_path == "/sys/bus/usb")
61 return InputDeviceType::INPUT_DEVICE_EXTERNAL;
62 if (subsystem_path == "/sys/class/bluetooth")
63 return InputDeviceType::INPUT_DEVICE_EXTERNAL;
64 }
65
66 return InputDeviceType::INPUT_DEVICE_UNKNOWN;
67 }
68
69 } // namespace
OLDNEW
« no previous file with comments | « ui/events/devices/device_util_linux.h ('k') | ui/events/devices/events_devices_export.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698