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

Unified Diff: content/browser/gamepad/platform_data_fetcher_linux.cc

Issue 9514017: Cleanup: More random cleanup for gamepad code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: revert content export removal Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/gamepad/platform_data_fetcher_linux.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/gamepad/platform_data_fetcher_linux.cc
===================================================================
--- content/browser/gamepad/platform_data_fetcher_linux.cc (revision 124050)
+++ content/browser/gamepad/platform_data_fetcher_linux.cc (working copy)
@@ -30,6 +30,33 @@
close(fd);
}
+bool IsGamepad(udev_device* dev, int* index, std::string* path) {
+ if (!udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"))
+ return false;
+
+ const char* node_path = udev_device_get_devnode(dev);
+ if (!node_path)
+ return false;
+
+ static const char kJoystickRoot[] = "/dev/input/js";
+ bool is_gamepad = StartsWithASCII(node_path, kJoystickRoot, true);
+ if (!is_gamepad)
+ return false;
+
+ int tmp_idx = -1;
+ const int base_len = sizeof(kJoystickRoot) - 1;
+ base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len);
+ if (!base::StringToInt(str, &tmp_idx))
+ return false;
+ if (tmp_idx < 0 ||
+ tmp_idx >= static_cast<int>(WebKit::WebGamepads::itemsLengthCap)) {
+ return false;
+ }
+ *index = tmp_idx;
+ *path = node_path;
+ return true;
+}
+
} // namespace
namespace content {
@@ -108,33 +135,6 @@
void GamepadPlatformDataFetcherLinux::OnFileCanWriteWithoutBlocking(int fd) {
}
-bool GamepadPlatformDataFetcherLinux::IsGamepad(udev_device* dev,
- int* index,
- std::string* path) {
- if (!udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"))
- return false;
-
- const char* node_path = udev_device_get_devnode(dev);
- if (!node_path)
- return false;
-
- static const char kJoystickRoot[] = "/dev/input/js";
- bool is_gamepad = StartsWithASCII(node_path, kJoystickRoot, true);
- if (!is_gamepad)
- return false;
-
- int tmp_idx = -1;
- const int base_len = sizeof(kJoystickRoot) - 1;
- base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len);
- if (!base::StringToInt(str, &tmp_idx))
- return false;
- if (tmp_idx < 0 || tmp_idx >= static_cast<int>(WebGamepads::itemsLengthCap))
- return false;
- *index = tmp_idx;
- *path = node_path;
- return true;
-}
-
// Used during enumeration, and monitor notifications.
void GamepadPlatformDataFetcherLinux::RefreshDevice(udev_device* dev) {
int index;
@@ -228,7 +228,7 @@
return;
}
- int& fd = device_fds_[index];
+ const int& fd = device_fds_[index];
WebGamepad& pad = data_.items[index];
DCHECK_GE(fd, 0);
« no previous file with comments | « content/browser/gamepad/platform_data_fetcher_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698